607 lines
12 KiB
JavaScript
607 lines
12 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
|
|
// 页面配置
|
|
const pages = [
|
|
{
|
|
name: 'home',
|
|
path: '/pages/main/home',
|
|
tabBar: true
|
|
},
|
|
{
|
|
name: 'mine',
|
|
path: '/pages/main/mine',
|
|
tabBar: true
|
|
},
|
|
{
|
|
name: 'userInfo',
|
|
path: '/pages/user/userInfo',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'updateName',
|
|
path: '/pages/user/updateName',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'updatePassword',
|
|
path: '/pages/user/updatePassword',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'updateEmail',
|
|
path: '/pages/user/updateEmail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'verifyEmail',
|
|
path: '/pages/user/verifyEmail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'webview',
|
|
path: '/pages/others/webview',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'lockDetail',
|
|
path: '/pages/main/lockDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'searchDevice',
|
|
path: '/pages/addDevice/searchDevice',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindLock',
|
|
path: '/pages/addDevice/bindLock',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'setting',
|
|
path: '/pages/setting/setting',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'keyList',
|
|
path: '/pages/feature/keyList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createKey',
|
|
path: '/pages/feature/createKey',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'passwordList',
|
|
path: '/pages/feature/passwordList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createPassword',
|
|
path: '/pages/feature/createPassword',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'passwordDetail',
|
|
path: '/pages/feature/passwordDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'keyDetail',
|
|
path: '/pages/feature/keyDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'notificationList',
|
|
path: '/pages/main/notificationList',
|
|
tabBar: true
|
|
},
|
|
{
|
|
name: 'notificationDetail',
|
|
path: '/pages/others/notificationDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'addLockGuid',
|
|
path: '/pages/addDevice/addLockGuid',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'cardList',
|
|
path: '/pages/feature/cardList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createCard',
|
|
path: '/pages/feature/createCard',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'cardDetail',
|
|
path: '/pages/feature/cardDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindCard',
|
|
path: '/pages/feature/bindCard',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'fingerprintList',
|
|
path: '/pages/feature/fingerprintList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createFingerprint',
|
|
path: '/pages/feature/createFingerprint',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'fingerprintDetail',
|
|
path: '/pages/feature/fingerprintDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindFingerprint',
|
|
path: '/pages/feature/bindFingerprint',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'faceList',
|
|
path: '/pages/feature/faceList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createFace',
|
|
path: '/pages/feature/createFace',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'faceDetail',
|
|
path: '/pages/feature/faceDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindFace',
|
|
path: '/pages/feature/bindFace',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'remoteList',
|
|
path: '/pages/feature/remoteList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createRemote',
|
|
path: '/pages/feature/createRemote',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'remoteDetail',
|
|
path: '/pages/feature/remoteDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindRemote',
|
|
path: '/pages/feature/bindRemote',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'palmVeinList',
|
|
path: '/pages/feature/palmVeinList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createPalmVein',
|
|
path: '/pages/feature/createPalmVein',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'palmVeinDetail',
|
|
path: '/pages/feature/palmVeinDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'bindPalmVein',
|
|
path: '/pages/feature/bindPalmVein',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'createAdmin',
|
|
path: '/pages/feature/createAdmin',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'adminDetail',
|
|
path: '/pages/feature/adminDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'adminList',
|
|
path: '/pages/feature/adminList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'recordList',
|
|
path: '/pages/feature/recordList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'recordDetail',
|
|
path: '/pages/feature/recordDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'typeRecordList',
|
|
path: '/pages/feature/typeRecordList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'cycleDate',
|
|
path: '/pages/others/cycleDate',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'temporaryDate',
|
|
path: '/pages/others/temporaryDate',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'lockInfo',
|
|
path: '/pages/setting/lockInfo',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'syncElec',
|
|
path: '/pages/setting/syncElec',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'selectGroup',
|
|
path: '/pages/setting/selectGroup',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'updateSetting',
|
|
path: '/pages/setting/updateSetting',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'lockSound',
|
|
path: '/pages/setting/lockSound',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'autoLock',
|
|
path: '/pages/setting/autoLock',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'faceSetting',
|
|
path: '/pages/setting/faceSetting',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'lockDate',
|
|
path: '/pages/setting/lockDate',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'uploadLockData',
|
|
path: '/pages/setting/uploadLockData',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'openDirection',
|
|
path: '/pages/setting/openDirection',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'motorTorsion',
|
|
path: '/pages/setting/motorTorsion',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'catEye',
|
|
path: '/pages/setting/catEye',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'messageReminder',
|
|
path: '/pages/setting/messageReminder',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'openDoorNotice',
|
|
path: '/pages/setting/openDoorNotice',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'noticeDetail',
|
|
path: '/pages/setting/noticeDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'lockUser',
|
|
path: '/pages/setting/lockUser',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'noticeWay',
|
|
path: '/pages/setting/noticeWay',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'notOpenDoor',
|
|
path: '/pages/setting/notOpenDoor',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'lowElecNotice',
|
|
path: '/pages/setting/lowElecNotice',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'coercionOpenDoor',
|
|
path: '/pages/setting/coercionOpenDoor',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'coercionFingerprint',
|
|
path: '/pages/setting/coercionFingerprint',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'catEyeMode',
|
|
path: '/pages/setting/catEyeMode',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'customCatEye',
|
|
path: '/pages/setting/customCatEye',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'realTimePicture',
|
|
path: '/pages/setting/realTimePicture',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'videoSlot',
|
|
path: '/pages/setting/videoSlot',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'passageMode',
|
|
path: '/pages/setting/passageMode',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'distributionNetwork',
|
|
path: '/pages/addDevice/distributionNetwork',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'p2pPlayer',
|
|
path: '/pages/p2p/p2pPlayer',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'authorizeWechat',
|
|
path: '/pages/p2p/authorizeWechat',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'videoDetail',
|
|
path: '/pages/p2p/videoDetail',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'videoLog',
|
|
path: '/pages/p2p/videoLog',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'videoEdit',
|
|
path: '/pages/p2p/videoEdit',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'login',
|
|
path: '/pages/user/login',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'register',
|
|
path: '/pages/user/register',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'forgotPassword',
|
|
path: '/pages/user/forgotPassword',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'countryList',
|
|
path: '/pages/user/countryList',
|
|
tabBar: false
|
|
},
|
|
{
|
|
name: 'safeVerify',
|
|
path: '/pages/user/safeVerify',
|
|
tabBar: false
|
|
}
|
|
]
|
|
|
|
export const useBasicStore = defineStore('basic', {
|
|
state() {
|
|
return {
|
|
// 设备信息
|
|
deviceInfo: null,
|
|
// 胶囊按钮的位置信息
|
|
buttonInfo: {},
|
|
// 分享配置
|
|
shareConfig: {}
|
|
}
|
|
},
|
|
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) {
|
|
if (!data.type || data.type === 'navigateTo' || data.type === 'to') {
|
|
let url = `${page.path}?`
|
|
if (data.params) {
|
|
Object.keys(data.params).forEach((key, index) => {
|
|
if (index === 0) {
|
|
url += `${key}=${data.params[key]}`
|
|
} else {
|
|
url += `&${key}=${data.params[key]}`
|
|
}
|
|
})
|
|
}
|
|
uni.navigateTo({
|
|
url,
|
|
...data
|
|
})
|
|
} else {
|
|
uni.$u.route({
|
|
url: page.path,
|
|
...data
|
|
})
|
|
}
|
|
}
|
|
},
|
|
// 获取当前网络状态
|
|
getNetworkType() {
|
|
return new Promise(resolve => {
|
|
uni.getNetworkType({
|
|
success(res) {
|
|
if (res.networkType === 'none') {
|
|
uni.showToast({
|
|
title: '网络访问失败,请检查网络是否正常',
|
|
icon: 'none'
|
|
})
|
|
resolve(false)
|
|
return
|
|
}
|
|
resolve(true)
|
|
},
|
|
fail() {
|
|
resolve(false)
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 获取设备信息
|
|
getDeviceInfo() {
|
|
const that = this
|
|
return new Promise(resolve => {
|
|
if (that.deviceInfo?.model) {
|
|
resolve(that.deviceInfo)
|
|
return
|
|
}
|
|
uni.getSystemInfo({
|
|
success(res) {
|
|
that.deviceInfo = res
|
|
resolve(that.deviceInfo)
|
|
},
|
|
fail() {
|
|
resolve({})
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 获取胶囊信息
|
|
getButtonInfo() {
|
|
return new Promise(resolve => {
|
|
// #ifdef MP-WEIXIN
|
|
if (this.buttonInfo?.top) {
|
|
resolve(this.buttonInfo)
|
|
return
|
|
}
|
|
this.buttonInfo = uni.getMenuButtonBoundingClientRect()
|
|
// #endif
|
|
resolve(this.buttonInfo)
|
|
})
|
|
},
|
|
// 计算字符串长度
|
|
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
|
|
},
|
|
// 回退页面并弹出toast提示
|
|
backAndToast(message, delta = 1) {
|
|
uni.navigateBack({
|
|
delta,
|
|
complete() {
|
|
setTimeout(() => {
|
|
uni.showToast({
|
|
title: message,
|
|
icon: 'none'
|
|
})
|
|
}, 300)
|
|
}
|
|
})
|
|
},
|
|
// 分享跳转
|
|
shareJump(data = this.shareConfig) {
|
|
if (data.path) {
|
|
const target = data.path.split('/')
|
|
if (target.length > 1) {
|
|
data.path = data.path.slice(target[0].length + 1, data.path.length)
|
|
} else {
|
|
delete data.path
|
|
}
|
|
const page = pages.find(page => {
|
|
return page.name === target[0]
|
|
})
|
|
if (page) {
|
|
if (page.tabBar) {
|
|
wx.switchTab({
|
|
url: page.path
|
|
})
|
|
} else {
|
|
const url = page.path + '?' + getParams(data)
|
|
wx.navigateTo({ url })
|
|
}
|
|
} else {
|
|
delete data.path
|
|
}
|
|
} else {
|
|
delete data.path
|
|
}
|
|
this.shareConfig = data
|
|
|
|
function getParams(params) {
|
|
let paramStr = ''
|
|
Object.keys(params).forEach(item => {
|
|
if (paramStr === '') {
|
|
paramStr = `${item}=${params[item]}`
|
|
} else {
|
|
paramStr = `${paramStr}&${item}=${params[item]}`
|
|
}
|
|
})
|
|
return paramStr
|
|
}
|
|
}
|
|
}
|
|
})
|