Refactor:分包

This commit is contained in:
lifizer
2026-05-12 15:19:37 +08:00
parent 6caf9afcc0
commit 535a98e43a
62 changed files with 250 additions and 20914 deletions
+357
View File
@@ -0,0 +1,357 @@
<template>
<view class="v12-pb-10">
<view class="v12-justify-around v12-pa-2 v12-white data-nav">
<view
v-for="(day, i) in currentWeek"
:key="i"
class="v12-font-26"
>
<view style="color:#BCBCBC" class="day-wrap">{{ getDate(day) }}</view>
<view class="v12-dark-text day-wrap" :class="{'active': actived === i, 'disabled': disabled(day)}" @click="handle(day, i)">{{ getDay(day) }}</view>
</view>
</view>
<view v-if="isLoad" class="history-wrap">
<view
v-for="(item, index) in items"
:key="index"
class="v12-mt-3"
:id="`history-${item.historyDate}`"
>
<view class="" style="height: 56px; width: 100%" v-if="isSrcoll"></view>
<view >
<text class="v12-font-bold v12-font-32">{{ item.historyDate }}</text>
<view class="wrapper">
<view
v-for="(historyItem, historyKey) in item.histories"
:key="historyKey"
class="v12-white v12-radius-20 history-card"
@click="goodsDetail(historyItem)"
>
<view class="delete-icon" @click.stop="deleteHistoryItem(historyItem)">
<u-icon
name="close"
color="#fff"
size="16"
/>
</view>
<image
class="goods-img"
:src="historyItem.image"
mode="scaleToFill"
/>
<view v-if="isInvalidItem(historyItem)" class="invalid-mask">
<text class="invalid-mask-text">商品已下架</text>
</view>
<view class="good-info">
<view
v-if="historyItem.couponName"
:style="{
opacity: !historyItem.couponName ? 0 : 1
}"
class="v12-align-center v12-mt-2"
>
<view class="v12-primary-text v12-primary-border v12-radius-6 v12-font-18 v12-px-1"></view>
<view class="v12-primary-text v12-primary-border v12-radius-6 v12-font-18 v12-px-1">{{ historyItem.couponName }}</view>
</view>
<view class="more-t v12-font-20 v12-mt-2">{{ historyItem.storeName }}</view>
<view class="v12-justify-between v12-mt-2 price">
<view v-if="!historyItem.isNegotiable" class="v12-font-bold v12-primary-text" :class="{'v12-align-center': (historyItem.price).toString().length < 5 && (historyItem.otPrice).toString().length < 5 }">
<text class="v12-font-16"></text>
<text class="v12-font-24 v12-mr-1">{{ historyItem.price }}</text>
<view class="ot-price v12-font-weight-400">
<text class="v12-font-22"></text>
<text class="v12-font-22">{{ historyItem.otPrice }}</text>
<view class="under-line"></view>
</view>
</view>
<view v-else class="v12-font-26 v12-primary-text v12-font-bold">价格面议</view>
<image
:src="webUrl+'/orderIcon/组 355.png'"
class="icon"
/>
</view>
</view>
</view>
</view>
</view>
</view>
<view class="v12-px-6" v-if="items.length > 0">
<u-divider text=" · 已经到底啦 · " textPosition="center"></u-divider>
</view>
<image
v-if="items.length === 0"
:src="webUrl + '/orderIcon/nohistory.png'"
class="img-nodata v12-mt-16"
mode="widthFix"
/>
</view>
<goo-skeleton
v-else
:show-avatar="false"
/>
</view>
</template>
<script>
import { getHistory, deleteHistory as deleteHistoryApi } from '@/api/user'
export default {
data() {
return {
currentWeek: [],
actived: 0,
webUrl: this.$VUE_APP_RESOURCES_URL,
isLoad: false,
items: [],
isSrcoll: false
}
},
onLoad() {
this.queryHistory()
},
onShow() {
this.$nextTick(() => {
this.currentWeek = this.getWeek()
this.actived = this.getActived()
})
},
methods: {
disabled(day) {
const dayItems = this.items.filter(item => {
return item.historyDate === day
}).map(e => {
return e.histories
}).flat()
return dayItems.length === 0
},
getActived() {
const weekMap = this.currentWeek.map(e => new Date(e).getDay())
const today = new Date().getDay()
return weekMap.indexOf(today)
},
getWeek() {
const dates = []
const now = new Date();
// 0-6, 0是周日
const dayOfWeek = now.getDay()
// 当前日
const numDate = now.getDate()
const numDaysToMonday = dayOfWeek - 1 > -1 ? dayOfWeek : 0
// 得到本周周一的日期
const monday = new Date(now)
monday.setDate(numDate - numDaysToMonday)
// 生成本周剩余的日期
for (let i = 0; i < 7; i++) {
dates.push(new Date(monday).toISOString().slice(0, 10))
monday.setDate(monday.getDate() + 1)
}
return dates
},
getDay(date) {
return new Date(date).getDate()
},
getDate(date) {
const dateMap = {
1: '一',
2: '二',
3: '三',
4: '四',
5: '五',
6: '六',
0: '日'
}
const d = new Date(date).getDay()
return dateMap[d]
},
handle(day, i) {
if(this.disabled(day)) return
this.actived = i
this.isSrcoll = true
uni.pageScrollTo({
selector:`#history-${day}`,
duration:200,
success:(success)=>{
this.isSrcoll = false
},
})
},
formatStr(str) {
const regx = /-/g
return str.replace(regx, '')
},
goodsDetail (item) {
if (this.isInvalidItem(item)) {
uni.showToast({
title: '商品已下架',
icon: 'none'
})
return
}
this.$yrouter.push({
path: '/pages/shop/GoodsCon/index',
query: {
id: item.productId
}
})
},
isInvalidItem(item) {
if (!item) return false
if (item.isInvalid === true || item.isInvalid === 'true') return true
return Number(item.isInvalid) === 1
},
deleteHistoryItem(historyItem) {
const id = historyItem.id
if (!id) return
uni.showModal({
title: '提示',
content: '确认删除该浏览足迹吗?',
success: (res) => {
if (res.confirm) {
deleteHistoryApi(id).then(() => {
this.queryHistory()
})
}
}
})
},
queryHistory() {
this.items = []
this.isLoad = false
getHistory().then(res => {
const { data = [] } = res
if (data.length > 0) {
this.items = data.filter(e => e.histories && e.histories.length > 0).reverse()
// data.map(item => {
// if (item.histories) {
// if (item.histories.length > 0) {
// this.items.push(item)
// }
// }
// })
}
}).finally(() => {
this.isLoad = true
})
}
}
}
</script>
<style lang="less" scoped>
.data-nav{
position: sticky;
width: 100%;
top: 0;
z-index: 9;
box-sizing: border-box;
}
.disabled{
color: #CBCBCB !important;
}
.history-wrap {
padding: 0 20rpx;
.img-nodata {
width: 100%;
}
}
.under-line{
width: 100%;
height: 3rpx;
background-color: #CBCBCB;
position: absolute;
top: 4rpx;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.wrapper{
display: flex;
flex-wrap: wrap;
width: 710rpx;
margin: 0 auto;
}
.history-card{
width: 226rpx;
box-sizing: border-box;
margin-top: 16rpx;
margin-right: 16rpx;
border-radius: 20rpx;
overflow: hidden;
position: relative;
&:nth-child(3n) {
margin-right: 0;
}
.goods-img {
display: block;
width: 226rpx;
height: 226rpx;
}
.invalid-mask{
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.45);
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
.invalid-mask-text{
color: #fff;
font-size: 24rpx;
padding: 8rpx 16rpx;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 24rpx;
background: rgba(0, 0, 0, 0.2);
}
}
.good-info {
padding: 12rpx 12rpx 20rpx 12rpx;
.price {
line-height: 34rpx;
align-items: flex-end;
.ot-price {
// margin: 0 0 0 10rpx;
color: #CBCBCB;
position: relative;
}
}
.icon {
display: block;
width: 34rpx;
height: 34rpx;
}
}
}
.delete-icon{
position: absolute;
top: 8rpx;
right: 8rpx;
z-index: 2;
width: 32rpx;
height: 32rpx;
border-radius: 16rpx;
// background-color: rgba(0, 0, 0, 0.35);
display: flex;
align-items: center;
justify-content: center;
}
.active{
background: #C52733;
color: #fff !important;
}
.day-wrap{
width: 40rpx;
height: 40rpx;
line-height: 40rpx;
text-align: center;
border-radius: 50%;
}
</style>