187 lines
3.9 KiB
JavaScript
187 lines
3.9 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
|
|
},
|
|
{
|
|
name: 'lockDetail',
|
|
path: '/pages/lockDetail/lockDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'searchDevice',
|
|
path: '/pages/searchDevice/searchDevice',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'selectAddress',
|
|
path: '/pages/selectAddress/selectAddress',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindLock',
|
|
path: '/pages/bindLock/bindLock',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'setting',
|
|
path: '/pages/setting/setting',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'keyList',
|
|
path: '/pages/keyList/keyList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createKey',
|
|
path: '/pages/createKey/createKey',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'passwordList',
|
|
path: '/pages/passwordList/passwordList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createPassword',
|
|
path: '/pages/createPassword/createPassword',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'passwordDetail',
|
|
path: '/pages/passwordDetail/passwordDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'keyDetail',
|
|
path: '/pages/keyDetail/keyDetail',
|
|
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
|
|
})
|
|
},
|
|
// 计算字符串长度
|
|
calculateStringTotalWidth(str) {
|
|
let totalWidth = 0
|
|
// 遍历字符串中的每一个字符
|
|
for (let i = 0; i < str.length; i++) {
|
|
const char = str[i]
|
|
// 判断当前字符是全角字符还是半角字符
|
|
if (/[\uFF01-\uFF60\uFFE0-\uFFE6\u4E00-\u9FFF\u3000-\u303F]/.test(char)) {
|
|
// 全角字符宽度为 2
|
|
totalWidth += 2
|
|
} else {
|
|
// 半角字符宽度为 1
|
|
totalWidth += 1
|
|
}
|
|
}
|
|
return totalWidth
|
|
}
|
|
}
|
|
})
|