tmp
This commit is contained in:
+32
-35
@@ -3,8 +3,9 @@ const API = require('../../utils/api.js')
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
phoneNumber: '',
|
||||
displayName: '',
|
||||
avatar: '',
|
||||
levelText: '初级陪诊员',
|
||||
version: '1.0.0',
|
||||
showLoginPopup: false,
|
||||
loginForm: {
|
||||
@@ -12,7 +13,7 @@ Page({
|
||||
mobile: ''
|
||||
},
|
||||
menuList: [
|
||||
{ icon: 'user', title: '个人资料', url: '' },
|
||||
{ icon: 'user', title: '个人资料', url: '/pages/me/index' },
|
||||
{ icon: 'notification', title: '消息通知', url: '' },
|
||||
{ icon: 'lock-on', title: '账号安全', url: '' },
|
||||
{ icon: 'help-circle', title: '帮助中心', url: '' },
|
||||
@@ -38,28 +39,34 @@ Page({
|
||||
},
|
||||
|
||||
onUserLogin(user) {
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo: user,
|
||||
phoneNumber: this.maskPhoneNumber(user.mobile || '')
|
||||
})
|
||||
this.applyUser(user)
|
||||
},
|
||||
|
||||
checkLoginStatus() {
|
||||
const app = getApp()
|
||||
const user = app.globalData.user
|
||||
if (user && user.security && user.security.token) {
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo: user,
|
||||
phoneNumber: this.maskPhoneNumber(user.mobile || '')
|
||||
})
|
||||
}
|
||||
this.applyUser(app.globalData.user)
|
||||
},
|
||||
|
||||
maskPhoneNumber(phone) {
|
||||
if (!phone || phone.length < 7) return phone
|
||||
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
|
||||
/**
|
||||
* 将用户对象映射为页面展示字段(真实信息)
|
||||
*/
|
||||
applyUser(user) {
|
||||
if (!user || !user.security || !user.security.token) {
|
||||
this.setData({
|
||||
isLoggedIn: false,
|
||||
displayName: '',
|
||||
avatar: '',
|
||||
levelText: '初级陪诊员'
|
||||
})
|
||||
return
|
||||
}
|
||||
const p = user.profile || {}
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
displayName: p.name || '管理员',
|
||||
avatar: p.avatar || '',
|
||||
levelText: user.level || p.level || '初级陪诊员'
|
||||
})
|
||||
},
|
||||
|
||||
getAppVersion() {
|
||||
@@ -112,14 +119,12 @@ Page({
|
||||
if (data.code == 0) {
|
||||
const app = getApp()
|
||||
app.globalData.user = data.data.user
|
||||
this.applyUser(app.globalData.user)
|
||||
this.setData({
|
||||
isLoggedIn: true,
|
||||
userInfo: app.globalData.user,
|
||||
phoneNumber: this.maskPhoneNumber(app.globalData.user.profile.mobile || ''),
|
||||
showLoginPopup: false,
|
||||
loginForm: { name: '', mobile: '' }
|
||||
})
|
||||
|
||||
|
||||
wx.showToast({ title: '登录成功', icon: 'success' })
|
||||
} else {
|
||||
wx.showToast({ title: '登录失败', icon: 'none' })
|
||||
@@ -159,7 +164,7 @@ Page({
|
||||
wx.showModal({
|
||||
title: '退出登录',
|
||||
content: '确定要退出登录吗?',
|
||||
confirmColor: '#4c6ef5',
|
||||
confirmColor: '#1a8a63',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.showLoading({ title: '退出中...' })
|
||||
@@ -183,11 +188,7 @@ Page({
|
||||
wx.removeStorageSync('admin_ai_session_id')
|
||||
wx.removeStorageSync('admin_ai_chat_history')
|
||||
|
||||
this.setData({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
phoneNumber: ''
|
||||
})
|
||||
this.applyUser(null)
|
||||
|
||||
wx.showToast({ title: '已退出登录', icon: 'success' })
|
||||
},
|
||||
@@ -200,18 +201,14 @@ Page({
|
||||
wx.showModal({
|
||||
title: '清除缓存',
|
||||
content: '确定要清除所有缓存数据吗?',
|
||||
confirmColor: '#4c6ef5',
|
||||
confirmColor: '#1a8a63',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
wx.clearStorage({
|
||||
success: () => {
|
||||
const app = getApp()
|
||||
app.globalData.user = null
|
||||
this.setData({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
phoneNumber: ''
|
||||
})
|
||||
this.applyUser(null)
|
||||
wx.showToast({ title: '缓存已清除', icon: 'success' })
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user