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
|
||||
*/
|
||||
deviceIds?: string[] | number[];
|
||||
deviceIds?: any[];
|
||||
}
|
||||
|
||||
export interface AuthRecordQuery extends PageQuery {
|
||||
|
@ -1,14 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { useBeforeCloseDiff } from '#/utils/popup';
|
||||
import { message, Tree } from 'ant-design-vue';
|
||||
import { authRecordAdd, queryAuthDevice, queryTree } from '#/api/sis/authRecord';
|
||||
import { useVbenModal } from '@vben/common-ui'
|
||||
import { useBeforeCloseDiff } from '#/utils/popup'
|
||||
import { message, Tree } from 'ant-design-vue'
|
||||
import { authRecordAdd, queryAuthDevice, queryTree } from '#/api/sis/authRecord'
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
const title = ref('门禁授权');
|
||||
const { onBeforeClose } = useBeforeCloseDiff({});
|
||||
const emit = defineEmits<{ reload: [] }>()
|
||||
const title = ref('门禁授权')
|
||||
const { onBeforeClose } = useBeforeCloseDiff({})
|
||||
const [BasicModal, modalApi] = useVbenModal({
|
||||
// 在这里更改宽度
|
||||
class: 'w-[700px]',
|
||||
@ -18,41 +18,51 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (isOpen) {
|
||||
const { id } = modalApi.getData();
|
||||
const { id } = modalApi.getData()
|
||||
queryAuthDevice(id).then((res = []) => {
|
||||
const arr: any[] = [];
|
||||
const arr: any[] = []
|
||||
res.forEach((item) => {
|
||||
arr.push(item.deviceId);
|
||||
checkedKeys.value = arr;
|
||||
});
|
||||
});
|
||||
arr.push(item.deviceId)
|
||||
checkedKeys.value = arr
|
||||
})
|
||||
})
|
||||
} else {
|
||||
// 关闭时清除选中
|
||||
checkedKeys.value = [];
|
||||
checkedKeys.value = []
|
||||
}
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
modalApi.lock(true);
|
||||
const { id } = modalApi.getData();
|
||||
const arr = checkedKeys.value;
|
||||
if (!arr || arr.length == 0) {
|
||||
message.error('请选择授权设备');
|
||||
return;
|
||||
modalApi.lock(true)
|
||||
const { id } = modalApi.getData()
|
||||
|
||||
if (eleIds.value.length === 0 && acIds.value.length === 0) {
|
||||
message.error('请选择授权设备')
|
||||
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 = {
|
||||
libId: id,
|
||||
deviceIds: arr,
|
||||
};
|
||||
deviceIds: [acIds.value, eleIds.value, floorIds.value],
|
||||
}
|
||||
authRecordAdd(params);
|
||||
emit('reload');
|
||||
modalApi.close();
|
||||
// console.log(params)
|
||||
emit('reload')
|
||||
modalApi.close()
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(error)
|
||||
} finally {
|
||||
modalApi.lock(false);
|
||||
modalApi.lock(false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,35 +71,75 @@ function handleClosed() {
|
||||
// resetInitialized();
|
||||
}
|
||||
|
||||
const checkedKeys = ref<any[]>([]);
|
||||
const treeData = ref([]);
|
||||
|
||||
const checkedKeys = ref<any[]>([])
|
||||
const treeData = ref([])
|
||||
const fieldNames = {
|
||||
title: 'label',
|
||||
title: 'title',
|
||||
label: 'label',
|
||||
key: 'code',
|
||||
children: 'children',
|
||||
};
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadDeviceTree();
|
||||
});
|
||||
loadDeviceTree()
|
||||
})
|
||||
|
||||
function loadDeviceTree() {
|
||||
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>
|
||||
|
||||
<template>
|
||||
<BasicModal :title="title">
|
||||
<div class="p-4">
|
||||
<Tree
|
||||
checkable
|
||||
:fieldNames="fieldNames"
|
||||
:tree-data="treeData"
|
||||
v-model:checkedKeys="checkedKeys"
|
||||
>
|
||||
<Tree checkable checkStrictly :tree-data="treeData" :fieldNames="fieldNames" v-model:checkedKeys="checkedKeys"
|
||||
:onCheck="handleCheck">
|
||||
</Tree>
|
||||
</div>
|
||||
</BasicModal>
|
||||
|
Loading…
Reference in New Issue
Block a user