feat(authGroup): 暂时移除电梯授权
All checks were successful
/ Explore-Gitea-Actions (push) Successful in 6m24s

This commit is contained in:
zcxlsm 2025-08-23 13:18:59 +08:00
parent 99b02c16eb
commit 5c40b534f2

View File

@ -1,157 +1,171 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref, onMounted } from 'vue' import { computed, ref, onMounted } from "vue";
import { useVbenModal } from '@vben/common-ui' import { useVbenModal } from "@vben/common-ui";
import { $t } from '@vben/locales' import { $t } from "@vben/locales";
import { cloneDeep } from '@vben/utils' import { cloneDeep } from "@vben/utils";
import { useVbenForm } from '#/adapter/form' import { useVbenForm } from "#/adapter/form";
import { authGroupAdd, authGroupInfo, authGroupUpdate } from '#/api/sis/authGroup' import {
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup' authGroupAdd,
import { queryTree } from '#/api/sis/authRecord' authGroupInfo,
import { message, Tree } from 'ant-design-vue' authGroupUpdate,
} from "#/api/sis/authGroup";
import { defaultFormValueGetter, useBeforeCloseDiff } from "#/utils/popup";
import { queryTree } from "#/api/sis/authRecord";
import { message, Tree } from "ant-design-vue";
import { modalSchema } from './data' import { modalSchema } from "./data";
const emit = defineEmits<{ reload: [] }>() const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false) const isUpdate = ref(false);
const title = computed(() => { const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add') return isUpdate.value ? $t("pages.common.edit") : $t("pages.common.add");
}) });
const [BasicForm, formApi] = useVbenForm({ const [BasicForm, formApi] = useVbenForm({
commonConfig: { commonConfig: {
// //
formItemClass: 'col-span-2', formItemClass: "col-span-2",
// label px // label px
labelWidth: 80, labelWidth: 80,
// //
componentProps: { componentProps: {
class: 'w-full', class: "w-full",
} },
}, },
schema: modalSchema(), schema: modalSchema(),
showDefaultActions: false, showDefaultActions: false,
wrapperClass: 'grid-cols-2', wrapperClass: "grid-cols-2",
}) });
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff( const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{ {
initializedGetter: defaultFormValueGetter(formApi), initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi), currentGetter: defaultFormValueGetter(formApi),
}, }
) );
const [BasicModal, modalApi] = useVbenModal({ const [BasicModal, modalApi] = useVbenModal({
// //
class: 'w-[550px]', class: "w-[550px]",
fullscreenButton: false, fullscreenButton: false,
onBeforeClose, onBeforeClose,
onClosed: handleClosed, onClosed: handleClosed,
onConfirm: handleConfirm, onConfirm: handleConfirm,
onOpenChange: async (isOpen) => { onOpenChange: async (isOpen) => {
if (!isOpen) { if (!isOpen) {
return null return null;
} }
modalApi.modalLoading(true) modalApi.modalLoading(true);
loadDeviceTree() loadDeviceTree();
const { id } = modalApi.getData() as { id?: number | string } const { id } = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id isUpdate.value = !!id;
if (isUpdate.value && id) { if (isUpdate.value && id) {
const record = await authGroupInfo(id) const record = await authGroupInfo(id);
checkedKeys.value = (record.acIds || []).concat(record.floorIds || []) checkedKeys.value = (record.acIds || []).concat(record.floorIds || []);
await formApi.setValues(record) await formApi.setValues(record);
} }
await markInitialized() await markInitialized();
modalApi.modalLoading(false) modalApi.modalLoading(false);
}, },
}) });
async function handleConfirm() { async function handleConfirm() {
try { try {
modalApi.lock(true) modalApi.lock(true);
const { valid } = await formApi.validate() const { valid } = await formApi.validate();
if (!valid) { if (!valid) {
return return;
} }
if (eleIds.value.length === 0 && acIds.value.length === 0) { if (eleIds.value.length === 0 && acIds.value.length === 0) {
message.error('请选择授权设备') message.error("请选择授权设备");
return return;
} }
const data = cloneDeep(await formApi.getValues()) const data = cloneDeep(await formApi.getValues());
data.acIds = acIds.value data.acIds = acIds.value;
data.eleIds = eleIds.value data.eleIds = eleIds.value;
data.floorIds = floorIds.value data.floorIds = floorIds.value;
await (isUpdate.value ? authGroupUpdate(data) : authGroupAdd(data)) await (isUpdate.value ? authGroupUpdate(data) : authGroupAdd(data));
resetInitialized() resetInitialized();
emit('reload') emit("reload");
modalApi.close() modalApi.close();
} catch (error) { } catch (error) {
console.error(error) console.error(error);
} finally { } finally {
modalApi.lock(false) modalApi.lock(false);
} }
} }
async function handleClosed() { async function handleClosed() {
await formApi.resetForm() await formApi.resetForm();
checkedKeys.value = [] checkedKeys.value = [];
resetInitialized() resetInitialized();
} }
const treeData = ref([]);
const treeData = ref([])
function loadDeviceTree() { function loadDeviceTree() {
queryTree().then((data: any) => { queryTree().then((data: any) => {
treeData.value = data data[0].children.forEach((item: any) => {
}) if (item.code === 2) {
item.disabled = true;
item.children.forEach((item: any) => {
item.disabled = true;
item.children.forEach((item: any) => {
item.disabled = true;
});
});
}
});
treeData.value = data;
});
} }
const fieldNames = { const fieldNames = {
title: 'title', title: "title",
label: 'label', label: "label",
key: 'code', key: "code",
children: 'children', children: "children",
} };
const checkedKeys = ref<any[]>([]) const checkedKeys = ref<any[]>([]);
type Key = string | number type Key = string | number;
const eleIds = ref<any[]>([]) const eleIds = ref<any[]>([]);
const acIds = ref<any[]>([]) const acIds = ref<any[]>([]);
const floorIds = ref<any[]>([]) const floorIds = ref<any[]>([]);
function handleCheck(checked: Key[] | { checked: Key[]; halfChecked: Key[] }, info: any) { function handleCheck(
checked: Key[] | { checked: Key[]; halfChecked: Key[] },
acIds.value = [] info: any
eleIds.value = [] ) {
floorIds.value = [] acIds.value = [];
eleIds.value = [];
floorIds.value = [];
info.checkedNodesPositions.forEach((item: any) => { info.checkedNodesPositions.forEach((item: any) => {
switch (item.node.label) { switch (item.node.label) {
case 'accessControl': case "accessControl":
acIds.value = acIds.value.concat(item.node.code) acIds.value = acIds.value.concat(item.node.code);
break break;
case 'floor': case "floor":
floorIds.value = floorIds.value.concat(item.node.code) floorIds.value = floorIds.value.concat(item.node.code);
eleIds.value = eleIds.value.concat(item.node.parentCode) eleIds.value = eleIds.value.concat(item.node.parentCode);
break break;
case 'elevator': case "elevator":
eleIds.value = eleIds.value.concat(item.node.code) eleIds.value = eleIds.value.concat(item.node.code);
break break;
} }
}) });
// //
acIds.value = [...new Set(acIds.value)] acIds.value = [...new Set(acIds.value)];
eleIds.value = [...new Set(eleIds.value)] eleIds.value = [...new Set(eleIds.value)];
floorIds.value = [...new Set(floorIds.value)] floorIds.value = [...new Set(floorIds.value)];
} }
</script> </script>
@ -159,8 +173,11 @@ function handleCheck(checked: Key[] | { checked: Key[]; halfChecked: Key[] }, in
<BasicModal :title="title"> <BasicModal :title="title">
<BasicForm /> <BasicForm />
<div class="p-4"> <div class="p-4">
<Tree checkable :tree-data="treeData" :fieldNames="fieldNames" v-model:checkedKeys="checkedKeys" <Tree checkable
:onCheck="handleCheck"> :tree-data="treeData"
:fieldNames="fieldNames"
v-model:checkedKeys="checkedKeys"
:onCheck="handleCheck">
</Tree> </Tree>
</div> </div>
</BasicModal> </BasicModal>