111 lines
2.3 KiB
JavaScript
111 lines
2.3 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: '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) {
|
|
console.log(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
|
|
})
|
|
},
|
|
}
|
|
})
|