功能:收口小程序前后台安全与防重复提交
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
permissionCodes: [],
|
||||
roleLabel: '',
|
||||
shopScopeText: '',
|
||||
currentShopText: ''
|
||||
},
|
||||
|
||||
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,
|
||||
permissionCodes: app.globalData.permissionCodes || [],
|
||||
roleLabel: userInfo ? permission.getRoleLabel(userInfo.type) : '--',
|
||||
shopScopeText,
|
||||
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为无店铺登录'
|
||||
})
|
||||
},
|
||||
|
||||
handleOpenOrders() {
|
||||
navigation.switchTab('/pages/orders/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
handleOpenManage() {
|
||||
navigation.switchTab('/pages/manage/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
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)
|
||||
const items = shops.map(shop => ({
|
||||
label: shop.shopName,
|
||||
value: shop.id
|
||||
}))
|
||||
|
||||
if (allowShoplessLogin && permission.isPlatformAdmin(userInfo)) {
|
||||
items.unshift({
|
||||
label: '无店铺登录',
|
||||
value: ''
|
||||
})
|
||||
}
|
||||
|
||||
if (!items.length) {
|
||||
wx.showToast({
|
||||
title: '当前账号没有可切换的店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
wx.showActionSheet({
|
||||
itemList: items.map(item => item.label),
|
||||
success: async action => {
|
||||
const target = items[action.tapIndex]
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await getApp().switchAdminShop(target.value || undefined)
|
||||
wx.showToast({
|
||||
title: '店铺已切换',
|
||||
icon: 'none'
|
||||
})
|
||||
this.onShow()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '切换店铺失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '店铺列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleLogout() {
|
||||
try {
|
||||
await authApi.logout().catch(() => undefined)
|
||||
} finally {
|
||||
getApp().clearAdminSession()
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<navigation-bar title="我的" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view class="hero-panel">
|
||||
<text class="hero-kicker">{{userInfo.account || '后台账号'}}</text>
|
||||
<text class="hero-title">{{userInfo.nickname || '未设置昵称'}}</text>
|
||||
<text class="hero-desc">当前角色:{{roleLabel}}。{{currentShopText}}</text>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">账号信息</text>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">账号</text>
|
||||
<text class="meta-value">{{userInfo.account || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">权限数</text>
|
||||
<text class="meta-value">{{permissionCodes.length}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">店铺状态</text>
|
||||
<text class="meta-value">{{currentShop ? currentShop.shopName : '无店铺登录'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">可登录店铺</text>
|
||||
<text class="meta-value">{{shopScopeText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="secondary-btn" bindtap="handleSwitchShop">切换店铺</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">常用入口</text>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn primary" bindtap="handleOpenOrders">查看订单</view>
|
||||
<view class="mini-btn" bindtap="handleOpenManage">经营模块</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">退出登录</text>
|
||||
<text class="section-desc">退出后会清理管理端会话、当前店铺和权限快照;再次进入需要重新登录。</text>
|
||||
<view class="action-row">
|
||||
<button class="danger-btn" bindtap="handleLogout">退出当前账号</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
Reference in New Issue
Block a user