功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+140
View File
@@ -16,6 +16,10 @@ const productApi = require('../../api/product')
const shopApi = require('../../api/shop')
const userApi = require('../../api/user')
/**
* home page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 96
@@ -32,31 +36,52 @@ Page({
bannerImages: [],
featuredItems: [],
popularItems: [],
announcements: [],
popularPage: 1,
pageSize: 6,
hasMore: false,
popularTotal: 0
}),
/**
* `onLoad` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onLoad() {
this.homeRequestId = 0
this.ensureKeyboardSafe()
this.loadHomeData()
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.ensureKeyboardSafe()
this.syncUserState()
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.initialized && this.data.isLoggedIn) {
this.loadUserProfile()
}
},
/**
* `onHide` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
/**
* `onUnload` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
@@ -68,13 +93,25 @@ Page({
wx.stopPullDownRefresh()
},
/**
* `onReachBottom` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onReachBottom() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.hasMore || this.data.loadingMore) {
return
}
this.loadPopularProducts(false)
},
/**
* `ensureKeyboardSafe` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 96,
@@ -82,6 +119,10 @@ Page({
})
},
/**
* `syncUserState` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
syncUserState() {
const app = getApp()
const userInfo = auth.getStoredUserInfo()
@@ -89,6 +130,10 @@ Page({
const navTitle = userInfo && String(userInfo.shopName || '').trim()
? String(userInfo.shopName).trim()
: '游客模式'
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (app) {
app.globalData.userInfo = userInfo
app.globalData.isLoggedIn = isLoggedIn
@@ -118,6 +163,24 @@ Page({
} catch (error) {}
},
async loadAnnouncements() {
if (!auth.isLoggedIn()) {
this.setData({ announcements: [] })
return
}
try {
const list = await userApi.listMyAnnouncements()
this.setData({
announcements: Array.isArray(list) ? list.map(item => ({
...item,
displayText: `${item.publisherName || '平台'}:${item.content || ''}`
})) : []
})
} catch (error) {
this.setData({ announcements: [] })
}
},
async loadHomeData() {
const requestId = ++this.homeRequestId
this.setData({ loading: true })
@@ -126,11 +189,16 @@ Page({
try {
await Promise.all([
this.loadUserProfile(),
this.loadAnnouncements(),
this.loadBannerImages(requestId),
this.loadFeaturedProducts(requestId),
this.loadPopularProducts(true, requestId)
])
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({
initialized: true
@@ -142,6 +210,10 @@ Page({
icon: 'none'
})
} finally {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({ loading: false })
}
@@ -166,6 +238,10 @@ Page({
return resolved.filter(item => item.imageUrl)
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({
bannerImages: Array.isArray(banners) ? banners : []
@@ -183,6 +259,10 @@ Page({
return buildProductCards(result && result.list ? result.list : [])
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({
featuredItems: Array.isArray(items) ? items : []
@@ -203,6 +283,10 @@ Page({
tag: '热门'
})
const cards = await buildProductCards(result && result.list ? result.list : [])
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (currentRequestId !== this.homeRequestId) {
return
}
@@ -215,6 +299,10 @@ Page({
hasMore: mergedItems.length < total
})
} catch (error) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (currentRequestId !== this.homeRequestId) {
return
}
@@ -223,6 +311,10 @@ Page({
icon: 'none'
})
} finally {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (currentRequestId === this.homeRequestId) {
this.setData({
loadingMore: false
@@ -231,20 +323,36 @@ Page({
}
},
/**
* `handleSearchInput` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
})
},
/**
* `handleSearchFocus` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleSearchFocus(event) {
handleKeyboardFocus(this, event)
},
/**
* `handleSearchBlur` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleSearchBlur() {
handleKeyboardBlur(this)
},
/**
* `handleSearchConfirm` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleSearchConfirm() {
resetKeyboardSafe(this)
navigation.openProducts({
@@ -252,8 +360,16 @@ Page({
})
},
/**
* `handleBannerTap` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBannerTap(event) {
const shopId = event.currentTarget.dataset.shopId
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopId) {
return
}
@@ -264,7 +380,15 @@ Page({
})
},
/**
* `handleProfileTap` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleProfileTap() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.isLoggedIn) {
navigation.switchTab('/pages/profile/index')
return
@@ -273,8 +397,16 @@ Page({
navigation.openAuth()
},
/**
* `handleProductSelect` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleProductSelect(event) {
const product = event.detail || {}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!product.id) {
return
}
@@ -284,12 +416,20 @@ Page({
})
},
/**
* `handleSeeAllFeatured` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleSeeAllFeatured() {
navigation.openProducts({
tag: '精选'
})
},
/**
* `handleSeeAllPopular` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleSeeAllPopular() {
navigation.openProducts({
tag: '热门'