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

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
+108
View File
@@ -21,6 +21,10 @@ const ALL_CATEGORY = '\u5168\u90e8'
const FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
const CART_BUSY_MESSAGE = '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
/**
* products 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
@@ -39,6 +43,10 @@ Page({
hasMore: false
}),
/**
* `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(options) {
this.filterRequestId = 0
this.ensureKeyboardSafe()
@@ -51,6 +59,10 @@ Page({
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (this.data.initialized && pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
/**
* `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) {
app.globalData.pendingProductFilter = null
}
@@ -58,16 +70,28 @@ Page({
return
}
/**
* `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) {
await this.syncProductCartState()
}
},
/**
* `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)
@@ -78,13 +102,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.loadProducts(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,
@@ -127,6 +163,10 @@ Page({
const app = getApp()
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
/**
* `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) {
app.globalData.pendingProductFilter = null
}
@@ -169,6 +209,10 @@ Page({
})
const cards = await buildProductCards(result && result.list ? result.list : [])
const displayCards = await this.attachCartState(cards)
/**
* `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.filterRequestId) {
return
}
@@ -183,9 +227,17 @@ Page({
filterSummaryText: this.buildFilterSummary(keyword, tag, 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 (requestId !== this.filterRequestId) {
return
}
/**
* `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 (reset) {
this.setData({
products: [],
@@ -199,6 +251,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.filterRequestId) {
this.setData({
loading: false,
@@ -208,11 +264,23 @@ Page({
}
},
/**
* `buildFilterSummary` 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.
*/
buildFilterSummary(keyword, tag, total) {
const chips = []
/**
* `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 (tag) {
chips.push(tag)
}
/**
* `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 (keyword) {
chips.push(`\u641c\u7d22\uff1a${keyword}`)
}
@@ -220,6 +288,10 @@ Page({
return chips.join(' \u00b7 ')
},
/**
* `normalizeId` 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.
*/
normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
},
@@ -250,6 +322,10 @@ Page({
return this.markCardsInCart(cards, idSet)
},
/**
* `markCardsInCart` 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.
*/
markCardsInCart(cards, idSet) {
const productIdSet = idSet || new Set()
return (Array.isArray(cards) ? cards : []).map(item => ({
@@ -265,8 +341,16 @@ Page({
})
},
/**
* `markProductInCart` 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.
*/
markProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
/**
* `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 (!normalizedId) {
return
}
@@ -286,16 +370,28 @@ 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)
},
@@ -372,8 +468,16 @@ Page({
}
},
/**
* `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
}
@@ -386,6 +490,10 @@ Page({
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
/**
* `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 (!productId) {
return
}