consumer模块完成度95%,能编译在安卓端运行,在解决数据获取和页面布局问题
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-else-if="!loading" class="empty-state">
|
||||
<view v-else-if="loading == false" class="empty-state">
|
||||
<text class="empty-text">暂无关注的店铺</text>
|
||||
<button class="go-shop-btn" @click="goHome">去逛逛</button>
|
||||
</view>
|
||||
@@ -44,82 +44,83 @@ type FollowedShop = {
|
||||
total_sales: number
|
||||
}
|
||||
|
||||
const shops = ref<FollowedShop[]>([])
|
||||
const loading = ref(true)
|
||||
const shops = ref<Array<FollowedShop>>([])
|
||||
const loading = ref<boolean>(true)
|
||||
|
||||
onMounted(() => {
|
||||
loadFollowedShops()
|
||||
})
|
||||
|
||||
const loadFollowedShops = async () => {
|
||||
const loadFollowedShops = async (): Promise<void> => {
|
||||
loading.value = true
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (!userId) {
|
||||
if (userId == null || userId == '') {
|
||||
uni.navigateTo({ url: '/pages/auth/login' })
|
||||
return
|
||||
}
|
||||
|
||||
const res = await supabaseService.getFollowedShops(userId)
|
||||
// res is array of { id, user_id, shop_id, ml_shops: {...} }
|
||||
|
||||
const list: FollowedShop[] = []
|
||||
res.forEach((item: any) => {
|
||||
const shopData = item['ml_shops'] as any
|
||||
if (shopData != null) {
|
||||
list.push({
|
||||
id: shopData['id'] as string, // Shop ID
|
||||
merchant_id: shopData['merchant_id'] as string,
|
||||
shop_name: shopData['shop_name'] as string,
|
||||
shop_logo: shopData['shop_logo'] as string | null,
|
||||
description: shopData['description'] as string | null,
|
||||
rating_avg: (shopData['rating_avg'] != null) ? (shopData['rating_avg'] as number) : 5.0,
|
||||
total_sales: (shopData['total_sales'] != null) ? (shopData['total_sales'] as number) : 0
|
||||
})
|
||||
const list: Array<FollowedShop> = []
|
||||
if (res != null && Array.isArray(res)) {
|
||||
for (let i: number = 0; i < res.length; i++) {
|
||||
const item = res[i] as UTSJSONObject
|
||||
const shopDataRaw = item.get('ml_shops')
|
||||
if (shopDataRaw != null) {
|
||||
const shopData = shopDataRaw as UTSJSONObject
|
||||
const shop: FollowedShop = {
|
||||
id: shopData.getString('id') ?? '',
|
||||
merchant_id: shopData.getString('merchant_id') ?? '',
|
||||
shop_name: shopData.getString('shop_name') ?? '',
|
||||
shop_logo: shopData.getString('shop_logo'),
|
||||
description: shopData.getString('description'),
|
||||
rating_avg: shopData.getNumber('rating_avg') ?? 5.0,
|
||||
total_sales: shopData.getNumber('total_sales') ?? 0
|
||||
} as FollowedShop
|
||||
list.push(shop)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
shops.value = list
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
const unfollow = async (shop: FollowedShop) => {
|
||||
const doUnfollow = async (shopId: string, userId: string): Promise<void> => {
|
||||
const success = await supabaseService.unfollowShop(shopId, userId)
|
||||
if (success) {
|
||||
uni.showToast({ title: '已取消', icon: 'none' })
|
||||
loadFollowedShops()
|
||||
} else {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
const unfollow = async (shop: FollowedShop): Promise<void> => {
|
||||
const userId = supabaseService.getCurrentUserId()
|
||||
if (!userId) return
|
||||
if (userId == null || userId == '') return
|
||||
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定取消关注该店铺吗?',
|
||||
success: async (res) => {
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
const success = await supabaseService.unfollowShop(shop.id, userId)
|
||||
if (success) {
|
||||
uni.showToast({ title: '已取消', icon: 'none' })
|
||||
loadFollowedShops() // Reload list
|
||||
} else {
|
||||
uni.showToast({ title: '操作失败', icon: 'none' })
|
||||
}
|
||||
doUnfollow(shop.id, userId)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const goToShop = (shop: FollowedShop) => {
|
||||
// Navigate using the Shop ID or Merchant ID?
|
||||
// shop-detail uses merchantId parameter but we patched it to handle ShopID too.
|
||||
// Let's prefer passing the raw ID we have.
|
||||
// If shop.id is UUID of shop, and shop.merchant_id is User UUID.
|
||||
// Since shop-detail handles both, passing shop.id (which is ml_shops.id) is fine?
|
||||
// Wait, shop-detail logic: 1. getShopByMerchantId(id) [tries merchant_id then id].
|
||||
// So passing shop.id is safer if merchant_id is not unique or confusing.
|
||||
const goToShop = (shop: FollowedShop): void => {
|
||||
const targetId = shop.merchant_id != '' ? shop.merchant_id : shop.id
|
||||
uni.navigateTo({
|
||||
url: `/pages/mall/consumer/shop-detail?merchantId=${targetId}`
|
||||
})
|
||||
}
|
||||
|
||||
const goHome = () => {
|
||||
const goHome = (): void => {
|
||||
uni.switchTab({ url: '/pages/mall/consumer/index' })
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadFollowedShops()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -217,4 +218,4 @@ const goHome = () => {
|
||||
padding-top: 50px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user