范鹏 f9669c8d2c 1. 完成锁密码相关功能
2. 完成锁电子钥匙相关功能
2024-08-28 16:55:11 +08:00

139 lines
3.8 KiB
JavaScript

/**
* @description 锁信息数据持久化
*/
import { defineStore } from 'pinia'
import { getLockListRequest } from '@/api/lock'
import { getPsaawordListRequest } from '@/api/keyboardPwd'
import { timeFormat } from 'uview-plus'
import { getKeyListRequest } from '@/api/key'
export const useLockStore = defineStore('lock', {
state() {
return {
// 锁列表
lockList: [],
// 锁总数
lockTotal: 0,
// 密码列表
passwordList: [],
// 密码总数
passwordTotal: 0,
// 当前密码详情
currentPasswordInfo: {},
// 电子钥匙总数
keyTotal: 0,
// 电子钥匙列表
keyList: [],
// 当前电子钥匙详情
currentKeyInfo: {},
// 电子钥匙列表搜索数据
keySearch: {
pageNo: 1,
pageSize: 50,
searchStr: '',
endDate: '0',
startDate: '0',
keyStatus: [110401,110402],
keyRight: 0
},
}
},
actions: {
updateKeySearch(search) {
this.keySearch = search
},
updateCurrentKeyInfo(info) {
this.currentKeyInfo = info
},
updateCurrentPasswordInfo(info) {
this.currentPasswordInfo = info
},
getRole(userType) {
if(userType === 110301) {
return '超级管理员'
} else {
return '普通用户'
}
},
getTimeLimit(keyType) {
if(keyType === 1) {
return '永久'
} else if(keyType === 2) {
return '限时'
} else if(keyType === 3) {
return '单次'
} else {
return '循环'
}
},
async getLockList(params) {
const { code, data, message } = await getLockListRequest(params)
if(code === 0) {
this.lockTotal = data.total
if(params.pageNo === 1) {
this.lockList = data.groupList
} else {
this.lockList = this.lockList.concat(data.groupList)
}
return { code }
} else {
uni.showToast({
title: message,
icon: 'none'
})
return { code, message }
}
},
async getPasswordList(params) {
const { code, data, message } = await getPsaawordListRequest(params)
if(code === 0) {
this.passwordTotal = data.total
for(let i = 0; i < data.list.length; i++) {
if(data.list[i].keyboardPwdType === 2) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].created_at), 'yyyy-mm-dd h:M')} 永久`
} else if(data.list[i].keyboardPwdType === 3) {
data.list[i].timeText = `${data.list[i].validTimeStr} 限时`
}
}
if(params.pageNo === 1) {
this.passwordList = data.list
} else {
this.passwordList = this.passwordList.concat(data.list)
}
return { code }
} else {
uni.showToast({
title: message,
icon: 'none'
})
return { code, message }
}
},
async getKeyList(params) {
const { code, data, message } = await getKeyListRequest(params)
if(code === 0) {
this.keyTotal = data.total
for(let i = 0; i < data.list.length; i++) {
if(data.list[i].keyType === 2) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} - ${timeFormat(new Date(data.list[i].endDate), 'yyyy-mm-dd h:M')} 限时`
} else {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 永久`
}
}
if(params.pageNo === 1) {
this.keyList = data.list
} else {
this.keyList = this.keyList.concat(data.list)
}
return { code }
} else {
uni.showToast({
title: message,
icon: 'none'
})
return { code, message }
}
}
}
})