wx-starlock/stores/basic.js
范鹏 0b595ed01c 1. 添加全局登录状态
2. 完成修改安全问题
3. 优化请求处理
2024-08-21 16:20:11 +08:00

115 lines
2.4 KiB
JavaScript

import { defineStore } from 'pinia'
// 页面配置
const pages = [
{
name: 'home',
path: '/pages/home/home',
tabBar: true
},
{
name: 'mine',
path: '/pages/mine/mine',
tabBar: true
},
{
name: 'userInfo',
path: '/pages/userInfo/userInfo',
tabBar: false
},
{
name: 'updateName',
path: '/pages/updateName/updateName',
tabBar: false
},
{
name: 'updatePassword',
path: '/pages/updatePassword/updatePassword',
tabBar: false
},
{
name: 'updateEmail',
path: '/pages/updateEmail/updateEmail',
tabBar: false
},
{
name: 'verifyEmail',
path: '/pages/verifyEmail/verifyEmail',
tabBar: false
},
{
name: 'safeQuestion',
path: '/pages/safeQuestion/safeQuestion',
tabBar: false
},
{
name: 'updateSafeQuestion',
path: '/pages/updateSafeQuestion/updateSafeQuestion',
tabBar: false
},
{
name: 'webview',
path: '/pages/webview/webview',
tabBar: false
}
]
export const useBasicStore = defineStore('basic', {
state() {
return {
// 设备信息
deviceInfo: null,
// 胶囊按钮的位置信息
buttonInfo: null
}
},
actions: {
// 路由跳转
/* data 入参 name string页面名称 type string跳转方式 params object传递参数 delta number返回页面数
* 具体入参查看文档 https://www.uviewui.com/js/route.html */
routeJump(data) {
const page = pages.find((page) => {
return page.name === data.name
})
if (page) {
uni.$u.route({
url: page.path,
...data
})
}
},
// 获取设备信息
getDeviceInfo() {
const that = this
return new Promise((resolve) => {
if (that.deviceInfo?.model) {
resolve(that.deviceInfo)
return
}
uni.getSystemInfo({
success: function (res) {
that.deviceInfo = res
resolve(that.deviceInfo)
},
fail: function () {
resolve({})
}
})
})
},
// 获取胶囊信息
getButtonInfo() {
return new Promise((resolve, reject) => {
if (this.buttonInfo?.top) {
resolve(this.buttonInfo)
return
}
this.buttonInfo = uni.getMenuButtonBoundingClientRect()
resolve(this.buttonInfo)
return
})
},
}
})