Files

252 lines
12 KiB
JavaScript
Raw Permalink Normal View History

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.
*/
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.
*/
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.
*/
const permission = require('../../utils/permission')
2026-06-04 16:39:06 +08:00
const sessionSwitch = require('../../../utils/session-switch')
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为平台总览模式'
})
},
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.
*/
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.
*/
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()
},
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)
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.
*/
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.
*/
icon: 'none'
})
return
}
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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'
})
}
}
})