2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: authApi supports index.js by holding or executing the auth api page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
const authApi = require('../../api/auth')
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
const navigation = require('../../utils/navigation')
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: permission supports index.js by holding or executing the permission page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
const permission = require('../../utils/permission')
|
2026-06-04 16:39:06 +08:00
|
|
|
const sessionSwitch = require('../../../utils/session-switch')
|
2026-04-20 16:02:57 +08:00
|
|
|
|
|
|
|
|
Page({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: data supports index.js by holding or executing the data page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
data: {
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: userInfo supports index.js by holding or executing the user info page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
userInfo: null,
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: currentShop supports index.js by holding or executing the current shop page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
currentShop: null,
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: permissionCodes supports index.js by holding or executing the permission codes page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
permissionCodes: [],
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: roleLabel supports index.js by holding or executing the role label page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
roleLabel: '',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: shopScopeText supports index.js by holding or executing the shop scope text page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
shopScopeText: '',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: currentShopText supports index.js by holding or executing the current shop text page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
currentShopText: ''
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
onShow() {
|
|
|
|
|
if (!navigation.ensureLogin('进入个人中心')) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const app = getApp()
|
|
|
|
|
const userInfo = app.globalData.userInfo
|
|
|
|
|
const currentShop = app.globalData.currentShop
|
|
|
|
|
const shopScopeText = userInfo
|
|
|
|
|
? (Array.isArray(userInfo.shopNames) && userInfo.shopNames.length
|
|
|
|
|
? userInfo.shopNames.join(' / ')
|
|
|
|
|
: (userInfo.shopName || '--'))
|
|
|
|
|
: '--'
|
|
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
|
userInfo,
|
|
|
|
|
currentShop,
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: permissionCodes supports index.js by holding or executing the permission codes page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
permissionCodes: app.globalData.permissionCodes || [],
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: roleLabel supports index.js by holding or executing the role label page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
roleLabel: userInfo ? permission.getRoleLabel(userInfo.type) : '--',
|
|
|
|
|
shopScopeText,
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: currentShopText supports index.js by holding or executing the current shop text page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为平台总览模式'
|
2026-04-20 16:02:57 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: handleOpenOrders supports index.js by holding or executing the handle open orders page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleOpenOrders() {
|
|
|
|
|
navigation.switchTab('/pages/orders/index').catch(() => undefined)
|
|
|
|
|
},
|
|
|
|
|
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: handleOpenManage supports index.js by holding or executing the handle open manage page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
handleOpenManage() {
|
|
|
|
|
navigation.switchTab('/pages/manage/index').catch(() => undefined)
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-04 16:39:06 +08:00
|
|
|
handleOpenWorkbench() {
|
|
|
|
|
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
handleOpenCustomerHome() {
|
|
|
|
|
sessionSwitch.openCustomerHome()
|
|
|
|
|
},
|
|
|
|
|
|
2026-04-20 16:02:57 +08:00
|
|
|
async handleSwitchShop() {
|
|
|
|
|
const userInfo = this.data.userInfo
|
|
|
|
|
if (!userInfo || !userInfo.account) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const result = await authApi.getLoginShops(userInfo.account)
|
|
|
|
|
const shops = Array.isArray(result && result.shops) ? result.shops : []
|
|
|
|
|
const allowShoplessLogin = Boolean(result && result.allowShoplessLogin)
|
2026-05-21 18:43:59 +08:00
|
|
|
if (allowShoplessLogin && permission.isPlatformAdmin(userInfo)) {
|
|
|
|
|
wx.showToast({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
title: '平台管理员固定为总览模式',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-05-21 18:43:59 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-04-20 16:02:57 +08:00
|
|
|
const items = shops.map(shop => ({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: label supports index.js by holding or executing the label page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
label: shop.shopName,
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: value supports index.js by holding or executing the value page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
value: shop.id
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
if (!items.length) {
|
|
|
|
|
wx.showToast({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
title: '当前账号没有可切换的店铺',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wx.showActionSheet({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: itemList supports index.js by holding or executing the item list page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
itemList: items.map(item => item.label),
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: success supports index.js by holding or executing the success page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
success: async action => {
|
|
|
|
|
const target = items[action.tapIndex]
|
|
|
|
|
if (!target) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await getApp().switchAdminShop(target.value || undefined)
|
|
|
|
|
wx.showToast({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
title: '店铺已切换',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
this.onShow()
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
title: error.message || '切换店铺失败',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
wx.showToast({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
title: error.message || '店铺列表加载失败',
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-04-20 16:02:57 +08:00
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async handleLogout() {
|
|
|
|
|
try {
|
|
|
|
|
await authApi.logout().catch(() => undefined)
|
|
|
|
|
} finally {
|
|
|
|
|
getApp().clearAdminSession()
|
|
|
|
|
wx.reLaunch({
|
2026-05-23 18:45:41 +08:00
|
|
|
/**
|
|
|
|
|
* Purpose: url supports index.js by holding or executing the url page or API role.
|
|
|
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
|
|
|
*/
|
2026-06-04 16:39:06 +08:00
|
|
|
url: '/admin/pages/login/index'
|
2026-04-20 16:02:57 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|