feat(sis): 优化门禁授权功能
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
09343106c8
commit
60007098a4
@ -28,7 +28,7 @@ export interface AuthRecordForm extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 设备ids
|
* 设备ids
|
||||||
*/
|
*/
|
||||||
deviceIds?: string[] | number[];
|
deviceIds?: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuthRecordQuery extends PageQuery {
|
export interface AuthRecordQuery extends PageQuery {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui'
|
||||||
import { useBeforeCloseDiff } from '#/utils/popup';
|
import { useBeforeCloseDiff } from '#/utils/popup'
|
||||||
import { message, Tree } from 'ant-design-vue';
|
import { message, Tree } from 'ant-design-vue'
|
||||||
import { authRecordAdd, queryAuthDevice, queryTree } from '#/api/sis/authRecord';
|
import { authRecordAdd, queryAuthDevice, queryTree } from '#/api/sis/authRecord'
|
||||||
|
|
||||||
const emit = defineEmits<{ reload: [] }>();
|
const emit = defineEmits<{ reload: [] }>()
|
||||||
const title = ref('门禁授权');
|
const title = ref('门禁授权')
|
||||||
const { onBeforeClose } = useBeforeCloseDiff({});
|
const { onBeforeClose } = useBeforeCloseDiff({})
|
||||||
const [BasicModal, modalApi] = useVbenModal({
|
const [BasicModal, modalApi] = useVbenModal({
|
||||||
// 在这里更改宽度
|
// 在这里更改宽度
|
||||||
class: 'w-[700px]',
|
class: 'w-[700px]',
|
||||||
@ -18,41 +18,51 @@ const [BasicModal, modalApi] = useVbenModal({
|
|||||||
onConfirm: handleConfirm,
|
onConfirm: handleConfirm,
|
||||||
onOpenChange: async (isOpen) => {
|
onOpenChange: async (isOpen) => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
const { id } = modalApi.getData();
|
const { id } = modalApi.getData()
|
||||||
queryAuthDevice(id).then((res = []) => {
|
queryAuthDevice(id).then((res = []) => {
|
||||||
const arr: any[] = [];
|
const arr: any[] = []
|
||||||
res.forEach((item) => {
|
res.forEach((item) => {
|
||||||
arr.push(item.deviceId);
|
arr.push(item.deviceId)
|
||||||
checkedKeys.value = arr;
|
checkedKeys.value = arr
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
} else {
|
} else {
|
||||||
// 关闭时清除选中
|
// 关闭时清除选中
|
||||||
checkedKeys.value = [];
|
checkedKeys.value = []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
|
|
||||||
async function handleConfirm() {
|
async function handleConfirm() {
|
||||||
try {
|
try {
|
||||||
modalApi.lock(true);
|
modalApi.lock(true)
|
||||||
const { id } = modalApi.getData();
|
const { id } = modalApi.getData()
|
||||||
const arr = checkedKeys.value;
|
|
||||||
if (!arr || arr.length == 0) {
|
if (eleIds.value.length === 0 && acIds.value.length === 0) {
|
||||||
message.error('请选择授权设备');
|
message.error('请选择授权设备')
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
// if (eleIds.value.length !== 0 && eleIds.value.length === 0) {
|
||||||
|
// message.error('请选择授权设备')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
if (eleIds.value.length !== 0 && floorIds.value.length === 0) {
|
||||||
|
message.error('存在电梯未选中授权楼层,请选择!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
libId: id,
|
libId: id,
|
||||||
deviceIds: arr,
|
deviceIds: [acIds.value, eleIds.value, floorIds.value],
|
||||||
};
|
}
|
||||||
authRecordAdd(params);
|
authRecordAdd(params);
|
||||||
emit('reload');
|
// console.log(params)
|
||||||
modalApi.close();
|
emit('reload')
|
||||||
|
modalApi.close()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
modalApi.lock(false);
|
modalApi.lock(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,35 +71,75 @@ function handleClosed() {
|
|||||||
// resetInitialized();
|
// resetInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkedKeys = ref<any[]>([]);
|
const checkedKeys = ref<any[]>([])
|
||||||
const treeData = ref([]);
|
const treeData = ref([])
|
||||||
|
|
||||||
const fieldNames = {
|
const fieldNames = {
|
||||||
title: 'label',
|
title: 'title',
|
||||||
|
label: 'label',
|
||||||
key: 'code',
|
key: 'code',
|
||||||
children: 'children',
|
children: 'children',
|
||||||
};
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
loadDeviceTree();
|
loadDeviceTree()
|
||||||
});
|
})
|
||||||
|
|
||||||
function loadDeviceTree() {
|
function loadDeviceTree() {
|
||||||
queryTree().then((data: any) => {
|
queryTree().then((data: any) => {
|
||||||
treeData.value = data;
|
treeData.value = data
|
||||||
});
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type Key = string | number
|
||||||
|
const eleIds = ref<any[]>([])
|
||||||
|
const acIds = ref<any[]>([])
|
||||||
|
const floorIds = ref<any[]>([])
|
||||||
|
function handleCheck(checked: Key[] | { checked: Key[]; halfChecked: Key[] }, info: any) {
|
||||||
|
if (info.checked) {
|
||||||
|
|
||||||
|
switch (info.node.label) {
|
||||||
|
case 'floor':
|
||||||
|
const floorArr: any[] = [info.node.code]
|
||||||
|
floorIds.value = floorIds.value.concat(floorArr)
|
||||||
|
break
|
||||||
|
case 'accessControl':
|
||||||
|
const acArr: any[] = [info.node.code]
|
||||||
|
acIds.value = acIds.value.concat(acArr)
|
||||||
|
break
|
||||||
|
case 'elevator':
|
||||||
|
const eleArr: any[] = [info.node.code]
|
||||||
|
eleIds.value = eleIds.value.concat(eleArr)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (info.node.label) {
|
||||||
|
case 'floor':
|
||||||
|
floorIds.value = floorIds.value.filter(item => item !== info.node.code)
|
||||||
|
break
|
||||||
|
case 'accessControl':
|
||||||
|
acIds.value = acIds.value.filter(item => item !== info.node.code)
|
||||||
|
break
|
||||||
|
case 'elevator':
|
||||||
|
eleIds.value = eleIds.value.filter(item => item !== info.node.code)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log('floorIds', floorIds.value)
|
||||||
|
console.log('acIds', acIds.value)
|
||||||
|
console.log('eleIds', eleIds.value)
|
||||||
|
// checkData.handlfChecked = [0, 1, 2]
|
||||||
|
// checkedKeys.value = { checked: checkData.checked, halfChecked: checkData.handlfChecked }
|
||||||
|
// console.log("checked---", checked)
|
||||||
|
// console.log("halfChecked---", info)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<BasicModal :title="title">
|
<BasicModal :title="title">
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<Tree
|
<Tree checkable checkStrictly :tree-data="treeData" :fieldNames="fieldNames" v-model:checkedKeys="checkedKeys"
|
||||||
checkable
|
:onCheck="handleCheck">
|
||||||
:fieldNames="fieldNames"
|
|
||||||
:tree-data="treeData"
|
|
||||||
v-model:checkedKeys="checkedKeys"
|
|
||||||
>
|
|
||||||
</Tree>
|
</Tree>
|
||||||
</div>
|
</div>
|
||||||
</BasicModal>
|
</BasicModal>
|
||||||
|
Loading…
Reference in New Issue
Block a user