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

View File

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