20260227-1

This commit is contained in:
cyh666666
2026-02-27 16:51:56 +08:00
1526 changed files with 2457 additions and 38509 deletions

View File

@@ -33,12 +33,11 @@
</view>
<view class="item-content" @click="viewProduct(item)">
<image class="product-image" :src="item.image" mode="aspectFill" />
<view class="product-info">
<text class="product-name">{{ item.name }}</text>
<view class="product-bottom">
<view class="product-price-row">
<text class="current-price">¥{{ item.price }}</text>
</view>
<text class="product-name" :lines="2">{{ item.name }}</text>
<view class="product-bottom">
<text class="product-price">¥{{ item.price }}</text>
<view class="product-add-btn" @click.stop="addToCart(item)">
<text class="add-icon">+</text>
</view>
</view>
</view>
@@ -83,6 +82,7 @@ type FootprintType = {
shopName: string
viewTime: number
selected: boolean
merchant_id: string
}
type FootprintGroup = {
@@ -178,12 +178,25 @@ const clearAll = () => {
content: '确定要清空所有浏览记录吗?',
success: (res) => {
if (res.confirm) {
footprints.value = []
uni.removeStorageSync('footprints')
uni.showLoading({ title: '清空中...' })
uni.showToast({
title: '已清空',
icon: 'success'
supabaseService.clearFootprints().then((success) => {
uni.hideLoading()
if (success) {
footprints.value = []
uni.removeStorageSync('footprints')
uni.showToast({
title: '已清空',
icon: 'success'
})
} else {
uni.showToast({
title: '清空失败',
icon: 'none'
})
}
})
}
}
@@ -238,42 +251,108 @@ const deleteSelected = () => {
content: `确定要删除选中的${selectedItems.length}条记录吗?`,
success: (res) => {
if (res.confirm) {
uni.showLoading({ title: '删除中' })
uni.showLoading({ title: '删除中...' })
uni.hideLoading()
footprints.value = footprints.value.filter((item): Boolean => item.selected !== true)
const dataToSave: FootprintSaveType[] = []
for (let i = 0; i < footprints.value.length; i++) {
const item = footprints.value[i]
dataToSave.push({
id: item.id,
name: item.name,
price: item.price,
original_price: item.original_price,
image: item.image,
sales: item.sales,
shopId: item.shopId,
shopName: item.shopName,
viewTime: item.viewTime
} as FootprintSaveType)
// 收集要删除的商品ID
const productIds: string[] = []
for (let i = 0; i < selectedItems.length; i++) {
productIds.push(selectedItems[i].id)
}
uni.setStorageSync('footprints', JSON.stringify(dataToSave))
uni.showToast({
title: '删除成功',
icon: 'success'
// 调用服务层批量删除
supabaseService.deleteFootprints(productIds).then((success) => {
uni.hideLoading()
if (success) {
// 从本地列表中移除
footprints.value = footprints.value.filter((item): Boolean => item.selected !== true)
// 更新本地缓存
const dataToSave: FootprintSaveType[] = []
for (let i = 0; i < footprints.value.length; i++) {
const item = footprints.value[i]
dataToSave.push({
id: item.id,
name: item.name,
price: item.price,
original_price: item.original_price,
image: item.image,
sales: item.sales,
shopId: item.shopId,
shopName: item.shopName,
viewTime: item.viewTime
} as FootprintSaveType)
}
uni.setStorageSync('footprints', JSON.stringify(dataToSave))
uni.showToast({
title: '删除成功',
icon: 'success'
})
if (footprints.value.length === 0) {
isEditMode.value = false
}
} else {
uni.showToast({
title: '删除失败',
icon: 'none'
})
}
})
if (footprints.value.length === 0) {
isEditMode.value = false
}
}
}
})
}
const addToCart = async (item: FootprintType) => {
uni.showLoading({ title: '检查商品...' })
try {
const productId = item.id
const merchantId = item.merchant_id ?? item.shopId ?? ''
// 检查商品是否有SKU
const skus = await supabaseService.getProductSkus(productId)
uni.hideLoading()
if (skus.length > 0) {
// 有规格,提示并跳转到商品详情页选择规格
uni.showToast({
title: '请选择规格',
icon: 'none'
})
setTimeout(() => {
uni.navigateTo({
url: '/pages/mall/consumer/product-detail?id=' + productId
})
}, 500)
} else {
// 无规格,直接加入购物车
uni.showLoading({ title: '添加中...' })
const success = await supabaseService.addToCart(productId, 1, '', merchantId)
uni.hideLoading()
if (success) {
uni.showToast({
title: '已添加到购物车',
icon: 'success'
})
} else {
uni.showToast({
title: '添加失败',
icon: 'none'
})
}
}
} catch (e) {
console.error('添加到购物车异常', e)
uni.hideLoading()
uni.showToast({
title: '操作失败',
icon: 'none'
})
}
}
const viewProduct = (item: FootprintType) => {
if (isEditMode.value) return
@@ -309,7 +388,8 @@ const parseFootprintItem = (item: any): FootprintType => {
shopId: itemObj.getString('shopId') ?? '',
shopName: itemObj.getString('shopName') ?? '',
viewTime: itemObj.getNumber('viewTime') ?? 0,
selected: false
selected: false,
merchant_id: itemObj.getString('merchant_id') ?? ''
} as FootprintType
}
@@ -493,10 +573,11 @@ onMounted(() => {
.footprint-item {
display: flex;
flex-direction: column;
margin-bottom: 10px;
border-bottom: none;
background: #fff;
border-radius: 8px;
overflow: hidden;
width: 48%;
background-color: #fff;
margin-bottom: 12px;
position: relative;
}
@@ -535,7 +616,6 @@ onMounted(() => {
}
.item-content {
flex: 1;
display: flex;
flex-direction: column;
}
@@ -543,48 +623,50 @@ onMounted(() => {
.product-image {
width: 100%;
height: 170px;
border-radius: 5px;
margin-right: 0;
border-radius: 8px;
margin-bottom: 8px;
background-color: #f5f5f5;
}
.product-info {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
padding: 0 4px;
background: #f5f5f5;
}
.product-name {
font-size: 14px;
color: #333333;
font-size: 13px;
color: #333;
margin-bottom: 5px;
line-height: 1.4;
margin-bottom: 6px;
height: 36px;
overflow: hidden;
text-overflow: ellipsis;
lines: 2;
height: 40px;
padding: 0 8px;
}
.product-bottom {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
align-items: center;
padding: 0 8px 8px;
}
.product-price-row {
display: flex;
align-items: flex-end;
}
.current-price {
font-size: 16px;
color: #ff4757;
.product-price {
font-size: 15px;
color: #ff5000;
font-weight: bold;
}
.product-add-btn {
width: 24px;
height: 24px;
background-color: #ff5000;
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
}
.add-icon {
color: #fff;
font-size: 16px;
font-weight: bold;
margin-right: 0;
}
@media (min-width: 768px) {