2024-09-02 17:18:14 +08:00

206 lines
6.3 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,
// 锁列表搜索数据
lockSearch: {
pageNo: 1,
pageSize: 50,
searchStr: ''
},
// 密码列表
passwordList: [],
// 密码总数
passwordTotal: 0,
// 当前密码详情
currentPasswordInfo: {},
// 密码列表搜索数据
passwordSearch: {
pageNo: 1,
pageSize: 50,
searchStr: ''
},
// 电子钥匙总数
keyTotal: 0,
// 电子钥匙列表
keyList: [],
// 当前电子钥匙详情
currentKeyInfo: {},
// 电子钥匙列表搜索数据
keySearch: {
pageNo: 1,
pageSize: 50,
searchStr: '',
endDate: '0',
startDate: '0',
keyStatus: [110401,110402,110412],
keyRight: 0
},
}
},
actions: {
updateLockSearch(search) {
this.lockSearch = search
},
updatePasswordSearch(search) {
this.passwordSearch = search
},
updateKeySearch(search) {
this.keySearch = search
},
updateCurrentKeyInfo(info) {
this.currentKeyInfo = info
},
updateCurrentPasswordInfo(info) {
this.currentPasswordInfo = info
},
getRole(userType, keyRight) {
if(userType === 110301) {
return '超级管理员'
} else if(keyRight === 1) {
return '授权管理员'
} else {
return '普通用户'
}
},
getKeyStatus(keyStatus) {
if(keyStatus === 110401) {
return '正常'
} else if(keyStatus === 110402) {
return '待接收'
} else if(keyStatus === 110412) {
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 === 1) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 单次`
} else if(data.list[i].keyboardPwdType === 2) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 永久`
} else if(data.list[i].keyboardPwdType === 3) {
data.list[i].timeText = `${data.list[i].validTimeStr} 限时`
} else if(data.list[i].keyboardPwdType === 4) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 清空码`
} else {
let text = ''
if(data.list[i].keyboardPwdType === 5) {
text = '周末'
} else if(data.list[i].keyboardPwdType === 6) {
text = '每日'
} else if(data.list[i].keyboardPwdType === 7) {
text = '工作日'
} else if(data.list[i].keyboardPwdType === 8) {
text = '周一'
} else if(data.list[i].keyboardPwdType === 9) {
text = '周二'
} else if(data.list[i].keyboardPwdType === 10) {
text = '周三'
} else if(data.list[i].keyboardPwdType === 11) {
text = '周四'
} else if(data.list[i].keyboardPwdType === 12) {
text = '周五'
} else if(data.list[i].keyboardPwdType === 13) {
text = '周六'
} else if(data.list[i].keyboardPwdType === 14) {
text = '周日'
}
data.list[i].timeText = `${text} ${data.list[i].hoursStart}:00-${data.list[i].hoursEnd}:00 循环`
}
if(data.list[i].isCustom === 1) {
data.list[i].timeText += ' 自定义'
}
}
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++) {
console.log(data.list[i].keyType)
if(data.list[i].keyType === 1) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].sendDate), 'yyyy-mm-dd h:M')} 永久`
} else 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 if(data.list[i].keyType === 3) {
data.list[i].timeText = `${timeFormat(new Date(data.list[i].sendDate), 'yyyy-mm-dd h:M')} 单次`
} else {
data.list[i].timeText = `循环`
}
}
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 }
}
}
}
})