feat: 修改设备类型展示方式
This commit is contained in:
parent
37324d04e6
commit
26ba202977
@ -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>
|
||||
|
||||
|
@ -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',
|
||||
},
|
||||
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
||||
// 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>
|
||||
|
Loading…
Reference in New Issue
Block a user