feat: 修改设备类型展示方式

This commit is contained in:
fyy 2025-07-16 17:45:30 +08:00
parent 37324d04e6
commit 26ba202977
2 changed files with 153 additions and 131 deletions

View File

@ -45,7 +45,7 @@ const showTreeSkeleton = ref<boolean>(true);
async function loadTree() { async function loadTree() {
showTreeSkeleton.value = true; showTreeSkeleton.value = true;
searchValue.value = ''; searchValue.value = '';
selectDeptId.value = []; // selectDeptId.value = []; //
const ret = await getMachineTypeTree(); const ret = await getMachineTypeTree();
deptTreeArray.value = convertTreeLabel(ret); deptTreeArray.value = convertTreeLabel(ret);
showTreeSkeleton.value = false; showTreeSkeleton.value = false;
@ -55,7 +55,9 @@ async function handleReload() {
await loadTree(); await loadTree();
emit('reload'); emit('reload');
} }
defineExpose({
handleReload,
});
onMounted(loadTree); onMounted(loadTree);
</script> </script>

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Recordable } from '@vben/types'; import type { Recordable } from '@vben/types';
import { ref } from 'vue'; import { ref, onMounted, watch } from 'vue';
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui'; import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils'; import { getVxePopupContainer } from '@vben/utils';
@ -18,86 +18,63 @@ import {
import { import {
machineTypeExport, machineTypeExport,
machineTypeList, machineTypeList,
machineTypeInfo,
getMachineTypeTree,
machineTypeRemove, machineTypeRemove,
} from '#/api/property/machineType'; } from '#/api/property/machineType';
import type { MachineTypeForm } from '#/api/property/machineType/model'; import type { MachineTypeForm } from '#/api/property/machineType/model';
import { commonDownloadExcel } from '#/utils/file/download'; import { commonDownloadExcel } from '#/utils/file/download';
import machineTypeModal from './machineType-modal.vue'; import machineTypeModal from './machineType-modal.vue';
import { columns, querySchema } from './data'; import { columns } from './data';
const selectDeptId = ref<string[]>([]); const selectDeptId = ref<string[]>([]);
const formOptions: VbenFormProps = { //
commonConfig: { const detailData = ref<any>(null);
labelWidth: 80, interface MachineTypeTree {
componentProps: { id: number;
allowClear: true, /**
}, * antd组件必须要这个属性 实际是没有这个属性的
}, */
schema: querySchema(), key: string;
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4', parentId: number;
// RangePicker / label: string;
// weight: number;
// fieldMappingTime: [ children?: MachineTypeTree[];
// [ }
// 'createTime', interface MachineTypeTreeData {
// ['params[beginTime]', 'params[endTime]'], id: number;
// ['YYYY-MM-DD 00:00:00', 'YYYY-MM-DD 23:59:59'], label: string;
// ], children?: MachineTypeTreeData[];
// ], }
handleReset: async () => { async function loadDetail() {
selectDeptId.value = []; // selectDeptId
let id:any = selectDeptId.value[0];
if (!id) {
//
const res:MachineTypeTree[] = await getMachineTypeTree();
if (res.length > 0 && res[0]) {
id = res[0].id;
}
}
if (id) {
//
const { machineTypeInfo } = await import('#/api/property/machineType');
detailData.value = await machineTypeInfo(id);
} else {
detailData.value = null;
}
}
const { formApi, reload } = tableApi; onMounted(loadDetail);
await formApi.resetForm();
const formValues = formApi.form.values;
formApi.setLatestSubmissionValues(formValues);
await reload(formValues);
},
};
const gridOptions: VxeGridProps = { watch(selectDeptId, loadDetail);
checkboxConfig: {
//
highlight: true,
//
reserve: true,
//
// trigger: 'row',
},
// 使i18ngetter
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
if (selectDeptId.value.length === 1) {
formValues.parentTypeId = selectDeptId.value[0];
} else {
Reflect.deleteProperty(formValues, 'parentTypeId');
}
return await machineTypeList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
//
id: 'property-machineType-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({ const treeRef = ref();
formOptions,
gridOptions, function reloadTree() {
}); treeRef.value?.handleReload?.();
}
const [MachineTypeModal, modalApi] = useVbenModal({ const [MachineTypeModal, modalApi] = useVbenModal({
connectedComponent: machineTypeModal, connectedComponent: machineTypeModal,
@ -108,33 +85,71 @@ function handleAdd() {
modalApi.open(); modalApi.open();
} }
async function handleEdit(row: Required<MachineTypeForm>) { async function handleEdit() {
modalApi.setData({ id: row.id }); if (detailData.value && detailData.value.id) {
modalApi.open(); modalApi.setData({ id: detailData.value.id });
modalApi.open();
}
} }
async function handleDelete(row: Required<MachineTypeForm>) { async function handleDelete() {
await machineTypeRemove(row.id); if (detailData.value && detailData.value.id) {
await tableApi.query(); await machineTypeRemove(detailData.value.id);
reloadTree();
await loadDetail();
}
} }
// async function handleDelete() {
// if (detailData.value && detailData.value.id) {
// const currentId = detailData.value.id;
// // 1.
// const tree = await getMachineTypeTree();
function handleMultiDelete() { // // 2.
const rows = tableApi.grid.getCheckboxRecords(); // function findParentAndSiblings(list:any, targetId:any, parent:any = null) {
const ids = rows.map((row: Required<MachineTypeForm>) => row.id); // for (const node of list) {
Modal.confirm({ // if (node.id === targetId) {
title: '提示', // return { parent, siblings: list };
okType: 'danger', // }
content: `确认删除选中的${ids.length}条记录吗?`, // if (node.children && node.children.length) {
onOk: async () => { // const res:any = findParentAndSiblings(node.children, targetId, node);
await machineTypeRemove(ids); // if (res) return res;
await tableApi.query(); // }
}, // }
}); // return null;
} // }
// const found = findParentAndSiblings(tree, currentId);
// // 3.
// await machineTypeRemove(currentId);
// // 4.
// let nextId = null;
// if (found) {
// //
// const sameLevel = found.siblings.filter((n:any) => n.id !== currentId);
// if (sameLevel.length > 0) {
// nextId = sameLevel[0].id;
// } else if (found.parent) {
// nextId = found.parent.id;
// }
// }
// // 5.
// if (nextId) {
// selectDeptId.value = [nextId];
// } else {
// selectDeptId.value = [];
// }
// // 6.
// reloadTree();
// await loadDetail();
// }
// }
function handleDownloadExcel() { function handleDownloadExcel() {
commonDownloadExcel(machineTypeExport, '设备类型数据', tableApi.formApi.form.values, { commonDownloadExcel(machineTypeExport, '设备类型数据', {}, {
fieldMappingTime: formOptions.fieldMappingTime, fieldMappingTime: [],
}); });
} }
</script> </script>
@ -142,27 +157,23 @@ function handleDownloadExcel() {
<template> <template>
<Page :auto-content-height="true"> <Page :auto-content-height="true">
<div class="flex h-full gap-[8px]"> <div class="flex h-full gap-[8px]">
<MachineTypeTree <MachineTypeTree
ref="treeRef"
v-model:select-dept-id="selectDeptId" v-model:select-dept-id="selectDeptId"
class="w-[260px]" class="w-[260px]"
@reload="() => tableApi.reload()" @reload="loadDetail"
@select="() => tableApi.reload()" @select="loadDetail"
/> />
<BasicTable table-title="设备类型列表"> <div class="flex-1">
<template #toolbar-tools> <!-- 顶部操作按钮 -->
<Space> <div class="mb-4 flex gap-2">
<a-button <a-button
v-access:code="['property:machineType:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger danger
type="primary" type="primary"
v-access:code="['property:machineType:remove']" v-access:code="['property:machineType:remove']"
@click="handleMultiDelete"> @click="handleDelete"
:disabled="!detailData || !detailData.id"
>
{{ $t('pages.common.delete') }} {{ $t('pages.common.delete') }}
</a-button> </a-button>
<a-button <a-button
@ -172,34 +183,43 @@ function handleDownloadExcel() {
> >
{{ $t('pages.common.add') }} {{ $t('pages.common.add') }}
</a-button> </a-button>
</Space> <a-button
</template> v-if="detailData && detailData.id"
<template #action="{ row }"> type="default"
<Space>
<ghost-button
v-access:code="['property:machineType:edit']" v-access:code="['property:machineType:edit']"
@click.stop="handleEdit(row)" @click="handleEdit"
> >
{{ $t('pages.common.edit') }} {{ $t('pages.common.edit') }}
</ghost-button> </a-button>
<Popconfirm </div>
:get-popup-container="getVxePopupContainer" <!-- 详情展示 -->
placement="left" <a-card v-if="detailData" :title="detailData.machineTypeName">
title="确认删除?" <a-descriptions
@confirm="handleDelete(row)" bordered
:column="2"
size="middle"
title="设备类型详情"
class="mb-2"
> >
<ghost-button <a-descriptions-item label="类型名称">
danger {{ detailData.machineTypeName }}
v-access:code="['property:machineType:remove']" </a-descriptions-item>
@click.stop="" <a-descriptions-item label="类型编号">
> {{ detailData.machineTypeCode }}
{{ $t('pages.common.delete') }} </a-descriptions-item>
</ghost-button> <a-descriptions-item label="是否启用">
</Popconfirm> <a-tag :color="detailData.isEnable == '1' ? 'green' : 'red'">
</Space> {{ detailData.isEnable == '1' ? '启用' : '禁用' }}
</template> </a-tag>
</BasicTable> </a-descriptions-item>
<MachineTypeModal @reload="tableApi.query()" /> <a-descriptions-item label="备注">
{{ detailData.remark || '-' }}
</a-descriptions-item>
</a-descriptions>
</a-card>
<a-empty v-else description="暂无详情" />
<MachineTypeModal @reload="() => { reloadTree(); loadDetail(); }" />
</div>
</div> </div>
</Page> </Page>
</template> </template>