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
17c7bc0512
commit
e0a64edc14
10
apps/web-antd/src/api/sis/authGroup/model.d.ts
vendored
10
apps/web-antd/src/api/sis/authGroup/model.d.ts
vendored
@ -21,6 +21,16 @@ export interface AuthGroupVO {
|
||||
*/
|
||||
isEnable: boolean;
|
||||
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
acIds?: string[] | number[];
|
||||
|
||||
/**
|
||||
* 楼层id
|
||||
*/
|
||||
floorIds?: string[] | number[];
|
||||
|
||||
}
|
||||
|
||||
export interface AuthGroupForm extends BaseEntity {
|
||||
|
@ -1,177 +1,182 @@
|
||||
import type { BaseEntity, PageQuery } from '#/api/common';
|
||||
import type { BaseEntity, PageQuery } from '#/api/common'
|
||||
|
||||
export interface DeviceManageVO {
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
id: string | number;
|
||||
id: string | number
|
||||
|
||||
/**
|
||||
* 设备编码
|
||||
*/
|
||||
deviceNo: string;
|
||||
deviceNo: string
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
deviceName: string;
|
||||
deviceName: string
|
||||
|
||||
/**
|
||||
* 设备ip
|
||||
*/
|
||||
deviceIp: string;
|
||||
deviceIp: string
|
||||
|
||||
/**
|
||||
* 设备端口
|
||||
*/
|
||||
devicePort: number;
|
||||
devicePort: number
|
||||
|
||||
/**
|
||||
* 设备账号
|
||||
*/
|
||||
deviceAccount: string;
|
||||
deviceAccount: string
|
||||
|
||||
/**
|
||||
* 设备密码
|
||||
*/
|
||||
devicePwd: string;
|
||||
devicePwd: string
|
||||
|
||||
/**
|
||||
* 设备
|
||||
*/
|
||||
deviceMac: string;
|
||||
deviceMac: string
|
||||
|
||||
/**
|
||||
* 设备在线状态 0:离线 1:在线 2:未知
|
||||
*/
|
||||
deviceStatus: number;
|
||||
deviceStatus: number
|
||||
|
||||
/**
|
||||
* 父级设备id
|
||||
*/
|
||||
parentId: string | number;
|
||||
parentId: string | number
|
||||
|
||||
/**
|
||||
* 设备通道编号
|
||||
*/
|
||||
channelNo: string;
|
||||
channelNo: string
|
||||
|
||||
/**
|
||||
* 录像机ip
|
||||
*/
|
||||
vcrIp: string;
|
||||
vcrIp: string
|
||||
|
||||
/**
|
||||
* 录像机端口
|
||||
*/
|
||||
vcrPort: number;
|
||||
vcrPort: number
|
||||
|
||||
/**
|
||||
* 录像机账号
|
||||
*/
|
||||
vcrAccount: string;
|
||||
vcrAccount: string
|
||||
|
||||
/**
|
||||
* 录像机密码
|
||||
*/
|
||||
vcrPwd: string;
|
||||
vcrPwd: string
|
||||
|
||||
/**
|
||||
* 门禁id
|
||||
*/
|
||||
accessControlId: string | number;
|
||||
accessControlId: string | number
|
||||
|
||||
/**
|
||||
* 楼层id
|
||||
*/
|
||||
floorId: string | number
|
||||
}
|
||||
|
||||
export interface DeviceManageForm extends BaseEntity {
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
id?: string | number;
|
||||
id?: string | number
|
||||
|
||||
/**
|
||||
* 设备编码
|
||||
*/
|
||||
deviceNo?: string;
|
||||
deviceNo?: string
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
deviceName?: string;
|
||||
deviceName?: string
|
||||
|
||||
/**
|
||||
* 设备ip
|
||||
*/
|
||||
deviceIp?: string;
|
||||
deviceIp?: string
|
||||
|
||||
/**
|
||||
* 设备端口
|
||||
*/
|
||||
devicePort?: number;
|
||||
devicePort?: number
|
||||
|
||||
/**
|
||||
* 设备账号
|
||||
*/
|
||||
deviceAccount?: string;
|
||||
deviceAccount?: string
|
||||
|
||||
/**
|
||||
* 设备密码
|
||||
*/
|
||||
devicePwd?: string;
|
||||
devicePwd?: string
|
||||
|
||||
/**
|
||||
* 设备
|
||||
*/
|
||||
deviceMac?: string;
|
||||
deviceMac?: string
|
||||
|
||||
/**
|
||||
* 设备在线状态 0:离线 1:在线 2:未知
|
||||
*/
|
||||
deviceStatus?: number;
|
||||
deviceStatus?: number
|
||||
}
|
||||
|
||||
export interface DeviceManageQuery extends PageQuery {
|
||||
/**
|
||||
* 设备编码
|
||||
*/
|
||||
deviceNo?: string;
|
||||
deviceNo?: string
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
deviceName?: string;
|
||||
deviceName?: string
|
||||
|
||||
/**
|
||||
* 设备ip
|
||||
*/
|
||||
deviceIp?: string;
|
||||
deviceIp?: string
|
||||
|
||||
/**
|
||||
* 设备端口
|
||||
*/
|
||||
devicePort?: number;
|
||||
devicePort?: number
|
||||
|
||||
/**
|
||||
* 设备账号
|
||||
*/
|
||||
deviceAccount?: string;
|
||||
deviceAccount?: string
|
||||
|
||||
/**
|
||||
* 设备密码
|
||||
*/
|
||||
devicePwd?: string;
|
||||
devicePwd?: string
|
||||
|
||||
/**
|
||||
* 设备
|
||||
*/
|
||||
deviceMac?: string;
|
||||
deviceMac?: string
|
||||
|
||||
/**
|
||||
* 设备在线状态 0:离线 1:在线 2:未知
|
||||
*/
|
||||
deviceStatus?: number;
|
||||
deviceStatus?: number
|
||||
|
||||
/**
|
||||
* 日期范围参数
|
||||
*/
|
||||
params?: any;
|
||||
params?: any
|
||||
}
|
||||
|
@ -59,22 +59,3 @@ export function elevatorInfoUpdate(data: ElevatorInfoForm) {
|
||||
export function elevatorInfoRemove(elevatorId: ID | IDS) {
|
||||
return requestClient.deleteWithMsg<void>(`/sis/elevatorInfo/${elevatorId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增电梯⇄楼层关联
|
||||
* @param params
|
||||
* @returns void
|
||||
*/
|
||||
export function refAdd(data: ElevatorFloorRefForm) {
|
||||
return requestClient.postWithMsg<void>('/sis/elevatorInfo/ref/add', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询电梯⇄楼层关联
|
||||
* @param id
|
||||
* @returns void
|
||||
*/
|
||||
export function refQuery(id: ID) {
|
||||
return requestClient.get<ElevatorFloorRefVo[]>(`/sis/elevatorInfo/ref/${id}`);
|
||||
}
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep, getPopupContainer, handleNode } from '@vben/utils';
|
||||
import { useVbenModal } from '@vben/common-ui'
|
||||
import { $t } from '@vben/locales'
|
||||
import { cloneDeep, getPopupContainer, handleNode } from '@vben/utils'
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { useVbenForm } from '#/adapter/form'
|
||||
import {
|
||||
accessControlAdd,
|
||||
accessControlInfo,
|
||||
accessControlUpdate,
|
||||
} from '#/api/sis/accessControl';
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
import { communityTree } from '#/api/property/community';
|
||||
import { modalSchema } from './data';
|
||||
} from '#/api/sis/accessControl'
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup'
|
||||
import { communityTree } from '#/api/property/community'
|
||||
import { modalSchema } from './data'
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
const emit = defineEmits<{ reload: [] }>()
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const isUpdate = ref(false)
|
||||
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({
|
||||
commonConfig: {
|
||||
@ -36,14 +36,14 @@ const [BasicForm, formApi] = useVbenForm({
|
||||
schema: modalSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-1',
|
||||
});
|
||||
})
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
const [BasicModal, modalApi] = useVbenModal({
|
||||
// 在这里更改宽度
|
||||
@ -54,53 +54,53 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
modalApi.modalLoading(true);
|
||||
setupCommunitySelect();
|
||||
const { id } = modalApi.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
modalApi.modalLoading(true)
|
||||
setupCommunitySelect()
|
||||
const { id } = modalApi.getData() as { id?: number | string }
|
||||
isUpdate.value = !!id
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await accessControlInfo(id);
|
||||
await formApi.setValues(record);
|
||||
const record = await accessControlInfo(id)
|
||||
await formApi.setValues(record)
|
||||
}
|
||||
await markInitialized();
|
||||
await markInitialized()
|
||||
|
||||
modalApi.modalLoading(false);
|
||||
modalApi.modalLoading(false)
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
modalApi.lock(true);
|
||||
const { valid } = await formApi.validate();
|
||||
modalApi.lock(true)
|
||||
const { valid } = await formApi.validate()
|
||||
if (!valid) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? accessControlUpdate(data) : accessControlAdd(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
modalApi.close();
|
||||
const data = cloneDeep(await formApi.getValues())
|
||||
await (isUpdate.value ? accessControlUpdate(data) : accessControlAdd(data))
|
||||
resetInitialized()
|
||||
emit('reload')
|
||||
modalApi.close()
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(error)
|
||||
} finally {
|
||||
modalApi.lock(false);
|
||||
modalApi.lock(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function setupCommunitySelect() {
|
||||
const areaList = await communityTree(4);
|
||||
const areaList = await communityTree(3)
|
||||
// 选中后显示在输入框的值 即父节点 / 子节点
|
||||
// addFullName(areaList, 'areaName', ' / ');
|
||||
const splitStr = '/';
|
||||
const splitStr = '/'
|
||||
handleNode(areaList, 'label', splitStr, function (node: any) {
|
||||
if (node.level != 4) {
|
||||
node.disabled = true;
|
||||
if (node.level != 3) {
|
||||
node.disabled = true
|
||||
}
|
||||
});
|
||||
})
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: () => ({
|
||||
@ -124,12 +124,12 @@ async function setupCommunitySelect() {
|
||||
}),
|
||||
fieldName: 'floorId',
|
||||
},
|
||||
]);
|
||||
])
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
await formApi.resetForm()
|
||||
resetInitialized()
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -25,9 +25,8 @@ export const querySchema: FormSchemaGetter = () => [
|
||||
children: 'children',
|
||||
},
|
||||
api: async () => {
|
||||
const areaList = await communityTree(4);
|
||||
const areaList = await communityTree(3);
|
||||
addFullName(areaList, 'label', '/');
|
||||
console.log(areaList);
|
||||
return areaList;
|
||||
},
|
||||
},
|
||||
|
@ -1,26 +1,26 @@
|
||||
<script setup lang="ts">
|
||||
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
|
||||
import { getVxePopupContainer } from '@vben/utils';
|
||||
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui'
|
||||
import { getVxePopupContainer } from '@vben/utils'
|
||||
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue'
|
||||
|
||||
import {
|
||||
useVbenVxeGrid,
|
||||
vxeCheckboxChecked,
|
||||
type VxeGridProps,
|
||||
} from '#/adapter/vxe-table';
|
||||
} from '#/adapter/vxe-table'
|
||||
|
||||
import {
|
||||
accessControlExport,
|
||||
accessControlList,
|
||||
accessControlRemove,
|
||||
accessControlSync
|
||||
} from '#/api/sis/accessControl';
|
||||
import type { AccessControlForm } from '#/api/sis/accessControl/model';
|
||||
import { commonDownloadExcel } from '#/utils/file/download';
|
||||
} from '#/api/sis/accessControl'
|
||||
import type { AccessControlForm } from '#/api/sis/accessControl/model'
|
||||
import { commonDownloadExcel } from '#/utils/file/download'
|
||||
|
||||
import accessControlModal from './accessControlModal.vue';
|
||||
import { columns, querySchema } from './data';
|
||||
import accessControlModal from './accessControlModal.vue'
|
||||
import { columns, querySchema } from './data'
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
@ -40,7 +40,7 @@ const formOptions: VbenFormProps = {
|
||||
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'],
|
||||
// ],
|
||||
// ],
|
||||
};
|
||||
}
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
@ -64,7 +64,7 @@ const gridOptions: VxeGridProps = {
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
})
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -73,49 +73,49 @@ const gridOptions: VxeGridProps = {
|
||||
},
|
||||
// 表格全局唯一表示 保存列配置需要用到
|
||||
id: 'property-accessControl-index',
|
||||
};
|
||||
}
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
});
|
||||
})
|
||||
|
||||
const [AccessControlModal, modalApi] = useVbenModal({
|
||||
connectedComponent: accessControlModal,
|
||||
});
|
||||
})
|
||||
|
||||
function handleAdd() {
|
||||
modalApi.setData({});
|
||||
modalApi.open();
|
||||
modalApi.setData({})
|
||||
modalApi.open()
|
||||
}
|
||||
|
||||
async function handleEdit(row: Required<AccessControlForm>) {
|
||||
modalApi.setData({ id: row.id });
|
||||
modalApi.open();
|
||||
modalApi.setData({ id: row.id })
|
||||
modalApi.open()
|
||||
}
|
||||
|
||||
async function handleDelete(row: Required<AccessControlForm>) {
|
||||
await accessControlRemove(row.id);
|
||||
await tableApi.query();
|
||||
await accessControlRemove(row.id)
|
||||
await tableApi.query()
|
||||
}
|
||||
|
||||
async function handleSyncE8() {
|
||||
await accessControlSync();
|
||||
await tableApi.query();
|
||||
await accessControlSync()
|
||||
await tableApi.query()
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: Required<AccessControlForm>) => row.id);
|
||||
const rows = tableApi.grid.getCheckboxRecords()
|
||||
const ids = rows.map((row: Required<AccessControlForm>) => row.id)
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await accessControlRemove(ids);
|
||||
await tableApi.query();
|
||||
await accessControlRemove(ids)
|
||||
await tableApi.query()
|
||||
},
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function handleDownloadExcel() {
|
||||
@ -126,7 +126,7 @@ function handleDownloadExcel() {
|
||||
{
|
||||
fieldMappingTime: formOptions.fieldMappingTime,
|
||||
},
|
||||
);
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -136,49 +136,23 @@ function handleDownloadExcel() {
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button @click="handleSyncE8">同步</a-button>
|
||||
<a-button
|
||||
v-access:code="['property:accessControl:export']"
|
||||
@click="handleDownloadExcel"
|
||||
>
|
||||
<a-button v-access:code="['property:accessControl:export']" @click="handleDownloadExcel">
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!vxeCheckboxChecked(tableApi)"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['property:accessControl:remove']"
|
||||
@click="handleMultiDelete"
|
||||
>
|
||||
<a-button :disabled="!vxeCheckboxChecked(tableApi)" danger type="primary"
|
||||
v-access:code="['property:accessControl:remove']" @click="handleMultiDelete">
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['property:accessControl:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<Space>
|
||||
<ghost-button
|
||||
v-access:code="['property:accessControl:edit']"
|
||||
@click.stop="handleEdit(row)"
|
||||
>
|
||||
<ghost-button v-access:code="['property:accessControl:edit']" @click.stop="handleEdit(row)">
|
||||
{{ $t('pages.common.edit') }}
|
||||
</ghost-button>
|
||||
<Popconfirm
|
||||
:get-popup-container="getVxePopupContainer"
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<ghost-button
|
||||
danger
|
||||
v-access:code="['property:accessControl:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
<Popconfirm :get-popup-container="getVxePopupContainer" placement="left" title="确认删除?"
|
||||
@confirm="handleDelete(row)">
|
||||
<ghost-button danger v-access:code="['property:accessControl:remove']" @click.stop="">
|
||||
{{ $t('pages.common.delete') }}
|
||||
</ghost-button>
|
||||
</Popconfirm>
|
||||
|
@ -60,6 +60,9 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
isUpdate.value = !!id
|
||||
if (isUpdate.value && id) {
|
||||
const record = await authGroupInfo(id)
|
||||
|
||||
checkedKeys.value = (record.acIds || []).concat(record.floorIds || [])
|
||||
|
||||
await formApi.setValues(record)
|
||||
}
|
||||
await markInitialized()
|
||||
@ -82,9 +85,9 @@ async function handleConfirm() {
|
||||
}
|
||||
|
||||
const data = cloneDeep(await formApi.getValues())
|
||||
data.acIds = acIds.value;
|
||||
data.eleIds = eleIds.value;
|
||||
data.floorIds = floorIds.value;
|
||||
data.acIds = acIds.value
|
||||
data.eleIds = eleIds.value
|
||||
data.floorIds = floorIds.value
|
||||
await (isUpdate.value ? authGroupUpdate(data) : authGroupAdd(data))
|
||||
resetInitialized()
|
||||
emit('reload')
|
||||
@ -98,6 +101,7 @@ async function handleConfirm() {
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm()
|
||||
checkedKeys.value = []
|
||||
resetInitialized()
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,11 @@ export const modalSchema: FormSchemaGetter = () => [
|
||||
component: 'Input',
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
label: '设备位置',
|
||||
fieldName: 'floorId',
|
||||
component: 'TreeSelect',
|
||||
},
|
||||
{
|
||||
label: '设备厂商',
|
||||
fieldName: 'factoryNo',
|
||||
|
@ -1,28 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { cloneDeep } from '@vben/utils';
|
||||
import { useVbenModal } from '@vben/common-ui'
|
||||
import { $t } from '@vben/locales'
|
||||
import { cloneDeep, getPopupContainer, handleNode } from '@vben/utils'
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { useVbenForm } from '#/adapter/form'
|
||||
import {
|
||||
deviceManageAdd,
|
||||
deviceManageInfo,
|
||||
deviceManageUpdate,
|
||||
} from '#/api/sis/deviceManage';
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup';
|
||||
} from '#/api/sis/deviceManage'
|
||||
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup'
|
||||
|
||||
import { modalSchema } from './data';
|
||||
import { getDictOptions } from '#/utils/dict';
|
||||
import { DictEnum } from '@vben/constants';
|
||||
import { modalSchema } from './data'
|
||||
import { communityTree } from '#/api/property/community'
|
||||
import { getDictOptions } from '#/utils/dict'
|
||||
import { DictEnum } from '@vben/constants'
|
||||
|
||||
const emit = defineEmits<{ reload: [] }>();
|
||||
const emit = defineEmits<{ reload: [] }>()
|
||||
|
||||
const isUpdate = ref(false);
|
||||
const isUpdate = ref(false)
|
||||
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({
|
||||
commonConfig: {
|
||||
@ -38,14 +39,14 @@ const [BasicForm, formApi] = useVbenForm({
|
||||
schema: modalSchema(),
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
})
|
||||
|
||||
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
|
||||
{
|
||||
initializedGetter: defaultFormValueGetter(formApi),
|
||||
currentGetter: defaultFormValueGetter(formApi),
|
||||
},
|
||||
);
|
||||
)
|
||||
|
||||
const [BasicModal, modalApi] = useVbenModal({
|
||||
// 在这里更改宽度
|
||||
@ -56,45 +57,88 @@ const [BasicModal, modalApi] = useVbenModal({
|
||||
onConfirm: handleConfirm,
|
||||
onOpenChange: async (isOpen) => {
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
modalApi.modalLoading(true);
|
||||
const { id } = modalApi.getData() as { id?: number | string };
|
||||
isUpdate.value = !!id;
|
||||
|
||||
// 加载社区树
|
||||
setupCommunitySelect()
|
||||
|
||||
modalApi.modalLoading(true)
|
||||
const { id } = modalApi.getData() as { id?: number | string }
|
||||
isUpdate.value = !!id
|
||||
|
||||
if (isUpdate.value && id) {
|
||||
const record = await deviceManageInfo(id);
|
||||
await formApi.setValues(record);
|
||||
const record = await deviceManageInfo(id)
|
||||
await formApi.setValues(record)
|
||||
}
|
||||
await markInitialized();
|
||||
await markInitialized()
|
||||
|
||||
modalApi.modalLoading(false);
|
||||
modalApi.modalLoading(false)
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
async function handleConfirm() {
|
||||
try {
|
||||
modalApi.lock(true);
|
||||
const { valid } = await formApi.validate();
|
||||
modalApi.lock(true)
|
||||
const { valid } = await formApi.validate()
|
||||
if (!valid) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
|
||||
const data = cloneDeep(await formApi.getValues());
|
||||
await (isUpdate.value ? deviceManageUpdate(data) : deviceManageAdd(data));
|
||||
resetInitialized();
|
||||
emit('reload');
|
||||
modalApi.close();
|
||||
const data = cloneDeep(await formApi.getValues())
|
||||
await (isUpdate.value ? deviceManageUpdate(data) : deviceManageAdd(data))
|
||||
resetInitialized()
|
||||
emit('reload')
|
||||
modalApi.close()
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
console.error(error)
|
||||
} finally {
|
||||
modalApi.lock(false);
|
||||
modalApi.lock(false)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化城市
|
||||
*/
|
||||
async function setupCommunitySelect() {
|
||||
const areaList = await communityTree(3)
|
||||
// 选中后显示在输入框的值 即父节点 / 子节点
|
||||
// addFullName(areaList, 'areaName', ' / ');
|
||||
const splitStr = '/'
|
||||
handleNode(areaList, 'label', splitStr, function (node: any) {
|
||||
if (node.level != 3) {
|
||||
node.disabled = true
|
||||
}
|
||||
})
|
||||
formApi.updateSchema([
|
||||
{
|
||||
componentProps: () => ({
|
||||
class: 'w-full',
|
||||
fieldNames: {
|
||||
key: 'id',
|
||||
label: 'label',
|
||||
value: 'code',
|
||||
children: 'children',
|
||||
},
|
||||
getPopupContainer,
|
||||
placeholder: '请选择楼层',
|
||||
showSearch: true,
|
||||
treeData: areaList,
|
||||
treeDefaultExpandAll: true,
|
||||
treeLine: { showLeafIcon: false },
|
||||
// 筛选的字段
|
||||
treeNodeFilterProp: 'label',
|
||||
// 选中后显示在输入框的值
|
||||
treeNodeLabelProp: 'fullName',
|
||||
}),
|
||||
fieldName: 'floorId',
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
async function handleClosed() {
|
||||
await formApi.resetForm();
|
||||
resetInitialized();
|
||||
await formApi.resetForm()
|
||||
resetInitialized()
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user