功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -9,6 +9,10 @@ const navigation = require('../../utils/navigation')
|
||||
const { DEFAULT_AVATAR } = require('../../utils/config')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
/**
|
||||
* profile page logic.
|
||||
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
||||
*/
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
@@ -18,9 +22,14 @@ Page({
|
||||
orderCount: 0,
|
||||
couponCount: 0,
|
||||
wishlistCount: 0,
|
||||
unreadMessageCount: 0,
|
||||
defaultAvatar: DEFAULT_AVATAR
|
||||
},
|
||||
|
||||
/**
|
||||
* `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.loadProfile()
|
||||
},
|
||||
@@ -34,6 +43,10 @@ Page({
|
||||
loading: isLoggedIn
|
||||
})
|
||||
|
||||
/**
|
||||
* `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 (!isLoggedIn) {
|
||||
this.setData({
|
||||
userInfo: null,
|
||||
@@ -46,11 +59,12 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
const [userInfo, orders, coupons, wishlist] = await Promise.all([
|
||||
const [userInfo, orders, coupons, wishlist, unreadMessages] = await Promise.all([
|
||||
userApi.getUserInfo(),
|
||||
orderApi.getOrderList(),
|
||||
couponApi.listUserCoupons(),
|
||||
wishlistApi.getWishlist()
|
||||
wishlistApi.getWishlist(),
|
||||
userApi.getMyUnreadMessageCount()
|
||||
])
|
||||
|
||||
getApp().refreshUserInfo(userInfo)
|
||||
@@ -58,8 +72,10 @@ Page({
|
||||
userInfo,
|
||||
orderCount: Array.isArray(orders) ? orders.length : 0,
|
||||
couponCount: Array.isArray(coupons) ? coupons.length : 0,
|
||||
wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0
|
||||
wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0,
|
||||
unreadMessageCount: Number((unreadMessages && unreadMessages.unreadCount) || 0)
|
||||
})
|
||||
await this.checkPopupMessages()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '\u4e2a\u4eba\u4e2d\u5fc3\u52a0\u8f7d\u5931\u8d25',
|
||||
@@ -72,11 +88,23 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenAuth` 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.
|
||||
*/
|
||||
handleOpenAuth() {
|
||||
navigation.openAuth('/pages/profile/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenSettings` 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.
|
||||
*/
|
||||
handleOpenSettings() {
|
||||
/**
|
||||
* `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) {
|
||||
this.handleOpenAuth()
|
||||
return
|
||||
@@ -84,6 +112,10 @@ Page({
|
||||
navigation.navigate('/pages/settings/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenOrders` 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.
|
||||
*/
|
||||
handleOpenOrders() {
|
||||
if (!navigation.ensureLogin('\u67e5\u770b\u8ba2\u5355')) {
|
||||
return
|
||||
@@ -91,6 +123,10 @@ Page({
|
||||
navigation.navigate('/pages/orders/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenWishlist` 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.
|
||||
*/
|
||||
handleOpenWishlist() {
|
||||
if (!navigation.ensureLogin('\u67e5\u770b\u6536\u85cf')) {
|
||||
return
|
||||
@@ -98,6 +134,10 @@ Page({
|
||||
navigation.navigate('/pages/wishlist/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenCoupons` 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.
|
||||
*/
|
||||
handleOpenCoupons() {
|
||||
if (!navigation.ensureLogin('\u67e5\u770b\u4f18\u60e0\u5238')) {
|
||||
return
|
||||
@@ -105,6 +145,62 @@ Page({
|
||||
navigation.navigate('/pages/coupons/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenVipCenter` 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.
|
||||
*/
|
||||
handleOpenVipCenter() {
|
||||
if (!navigation.ensureLogin('查看 VIP 中心')) {
|
||||
return
|
||||
}
|
||||
navigation.navigate('/pages/vip-center/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleOpenNotifications` 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.
|
||||
*/
|
||||
handleOpenNotifications() {
|
||||
if (!navigation.ensureLogin('查看消息通知')) {
|
||||
return
|
||||
}
|
||||
navigation.navigate('/pages/notifications/index')
|
||||
},
|
||||
|
||||
async checkPopupMessages() {
|
||||
/**
|
||||
* `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._checkingPopupMessages) {
|
||||
return
|
||||
}
|
||||
this._checkingPopupMessages = true
|
||||
try {
|
||||
const messages = await userApi.listMyPopupMessages()
|
||||
/**
|
||||
* `for` 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.
|
||||
*/
|
||||
for (const item of messages || []) {
|
||||
await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: item.title || '消息通知',
|
||||
content: item.content || '',
|
||||
showCancel: false,
|
||||
confirmText: '我知道了',
|
||||
complete: resolve
|
||||
})
|
||||
})
|
||||
await userApi.markMessagePopupShown(item.id)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载待弹窗消息失败', error)
|
||||
} finally {
|
||||
this._checkingPopupMessages = false
|
||||
}
|
||||
},
|
||||
|
||||
async handleSwitchShop() {
|
||||
if (!navigation.ensureLogin('\u5207\u6362\u95e8\u5e97')) {
|
||||
return
|
||||
@@ -114,6 +210,10 @@ Page({
|
||||
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
|
||||
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
|
||||
|
||||
/**
|
||||
* `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 (!shopIds.length) {
|
||||
wx.showToast({
|
||||
title: '\u5f53\u524d\u8d26\u53f7\u8fd8\u6ca1\u6709\u53ef\u7528\u95e8\u5e97',
|
||||
@@ -122,6 +222,10 @@ 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 (shopIds.length === 1) {
|
||||
navigation.navigate('/pages/shop-detail/index', {
|
||||
id: shopIds[0],
|
||||
@@ -140,6 +244,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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 (selection < 0 || selection >= shopIds.length) {
|
||||
return
|
||||
}
|
||||
@@ -168,6 +276,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleLogout() {
|
||||
/**
|
||||
* `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) {
|
||||
this.handleOpenAuth()
|
||||
return
|
||||
@@ -183,6 +295,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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 (!confirmed) {
|
||||
return
|
||||
}
|
||||
@@ -209,10 +325,18 @@ Page({
|
||||
|
||||
async handleAvatarError() {
|
||||
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
|
||||
/**
|
||||
* `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 (!currentAvatar) {
|
||||
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._avatarReloadSource === currentAvatar) {
|
||||
this.setData({
|
||||
'userInfo.avatar': ''
|
||||
@@ -225,6 +349,10 @@ Page({
|
||||
try {
|
||||
const userInfo = await userApi.getUserInfo()
|
||||
getApp().refreshUserInfo(userInfo)
|
||||
/**
|
||||
* `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 (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
|
||||
this.setData({
|
||||
'userInfo.avatar': ''
|
||||
|
||||
Reference in New Issue
Block a user