Merge branch 'master' of http://47.109.37.87:3000/by2025/admin-vben5
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
FLL
2025-07-17 14:10:57 +08:00
21 changed files with 2102 additions and 139 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

@@ -0,0 +1,217 @@
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import {getDictOptions} from "#/utils/dict";
import {renderDict} from "#/utils/render";
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'machineName',
label: '设备名称',
},
{
component: 'Input',
fieldName: 'machineCode',
label: '设备编码',
},
{
component: 'Select',
componentProps:{
options:getDictOptions('wy_sbsyzt')
},
fieldName: 'state',
label: '使用状态',
},
];
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '设备名称',
field: 'machineName',
minWidth:180
},
{
title: '设备编码',
field: 'machineCode',
width:100
},
{
title: '设备品牌',
field: 'machineBrand',
width:100
},
{
title: '设备类型',
field: 'machineTypeId',
width:100
},
{
title: '位置详情',
field: 'locationId',
width:100
},
{
title: '采购价格',
field: 'purchasePrice',
width:100
},
{
title: '启用时间',
field: 'activationTime',
width:100
},
{
title: '保修截至时间',
field: 'deadline',
width:100
},
{
title: '使用年限',
field: 'serviceLife',
width:100
},
{
title: '保修周期',
field: 'maintenanceCycle',
width:100,
slots:{
default: ({row})=>{
return renderDict(row.maintenanceCycle,'wy_sbbxzq')
}
}
},
{
title: '使用状态',
field: 'state',
width:100,
slots:{
default: ({row})=>{
return renderDict(row.state,'wy_sbsyzt')
}
}
},
{
title: '责任人',
field: 'personId',
width:100
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '主键',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '设备名称',
fieldName: 'machineName',
component: 'Input',
rules: 'required',
formItemClass: 'col-span-2',
},
{
label: '设备编码',
fieldName: 'machineCode',
component: 'Input',
rules: 'required',
},
{
label: '设备品牌',
fieldName: 'machineBrand',
component: 'Input',
rules: 'required',
},
{
label: '设备类型',
fieldName: 'machineTypeId',
component: 'TreeSelect',
rules: 'selectRequired',
formItemClass: 'col-span-2',
},
{
label: '位置详情',
fieldName: 'locationId',
component: 'ApiSelect',
rules: 'selectRequired',
formItemClass: 'col-span-2',
},
{
label: '采购价格',
fieldName: 'purchasePrice',
component: 'InputNumber',
componentProps:{
min:0,
precision:2
},
rules: 'required',
},
{
label: '启用时间',
fieldName: 'activationTime',
component: 'DatePicker',
componentProps: {
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
},
rules: 'required',
},
{
label: '保修截至时间',
fieldName: 'deadline',
component: 'DatePicker',
componentProps: {
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
},
rules: 'required',
},
{
label: '使用年限',
fieldName: 'serviceLife',
component: 'InputNumber',
componentProps:{
min:1,
precision:0
},
rules: 'required',
},
{
label: '保修周期',
fieldName: 'maintenanceCycle',
component: 'Select',
componentProps: {
options:getDictOptions('wy_sbbxzq')
},
rules: 'selectRequired',
},
{
label: '使用状态',
fieldName: 'state',
component: 'Select',
componentProps:{
options:getDictOptions('wy_sbsyzt')
},
rules: 'selectRequired',
},
{
label: '责任人',
fieldName: 'personId',
component: 'ApiSelect',
rules: 'selectRequired',
formItemClass: 'col-span-2',
},
];

View File

@@ -0,0 +1,204 @@
<script setup lang="ts">
import {Page, useVbenModal, type VbenFormProps} from '@vben/common-ui';
import {getVxePopupContainer} from '@vben/utils';
import {Modal, Popconfirm, Space} from 'ant-design-vue';
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table';
import {
machineExport,
machineList,
machineRemove,
} from '#/api/property/equipmentManagement/machine';
import type {MachineForm} from '#/api/property/equipmentManagement/machine/model';
import {commonDownloadExcel} from '#/utils/file/download';
import machineModal from './machine-modal.vue';
import {columns, querySchema} from './data';
import MachineTypeTree from '../components/machine-type-tree.vue'
import machineDetail from './machine-detail.vue'
import {ref} from "vue";
const selectTypeId = ref('')
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',
handleReset: async () => {
selectTypeId.value = '';
const { formApi, reload } = tableApi;
await formApi.resetForm();
const formValues = formApi.form.values;
formApi.setLatestSubmissionValues(formValues);
await reload(formValues);
},
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
// 点击行选中
// trigger: 'row',
},
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({page}, formValues = {}) => {
formValues.machineTypeId = selectTypeId.value
return await machineList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'property-machine-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [MachineModal, modalApi] = useVbenModal({
connectedComponent: machineModal,
});
const [MachineDetail, detailApi] = useVbenModal({
connectedComponent: machineDetail,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<MachineForm>) {
modalApi.setData({id: row.id});
modalApi.open();
}
async function handleInfo(row: Required<MachineForm>) {
detailApi.setData({id: row.id});
detailApi.open();
}
async function handleDelete(row: Required<MachineForm>) {
await machineRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<MachineForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await machineRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(machineExport, '设备列表数据', tableApi.formApi.form.values, {
fieldMappingTime: formOptions.fieldMappingTime,
});
}
</script>
<template>
<Page :auto-content-height="true">
<div class="flex h-full gap-[8px]">
<MachineTypeTree
v-model:select-dept-id="selectTypeId"
class="w-[260px]"
@reload="() => tableApi.reload()"
@select="() => tableApi.reload()"
/>
<BasicTable class="flex-1 overflow-hidden" table-title="设备列表列表">
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['property:machine:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['property:machine:remove']"
@click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['property:machine:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['property:machine:info']"
@click.stop="handleInfo(row)"
>
{{ $t('pages.common.info') }}
</ghost-button>
<ghost-button
v-access:code="['property:machine: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:machine:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
</div>
<MachineModal @reload="tableApi.query()"/>
<MachineDetail/>
</Page>
</template>

View File

@@ -0,0 +1,83 @@
<script setup lang="ts">
import {shallowRef} from 'vue';
import {useVbenModal} from '@vben/common-ui';
import {Descriptions, DescriptionsItem} from 'ant-design-vue';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
import {renderDict} from "#/utils/render";
dayjs.extend(duration);
dayjs.extend(relativeTime);
import {CheckboxGroup} from 'ant-design-vue'
import {getDictOptions} from "#/utils/dict";
import {machineInfo} from "#/api/property/equipmentManagement/machine";
import type {MachineVO} from "#/api/property/equipmentManagement/machine/model";
const [BasicModal, modalApi] = useVbenModal({
onOpenChange: handleOpenChange,
onClosed() {
machineDetail.value = null;
},
});
const machineDetail = shallowRef<null | MachineVO>(null);
async function handleOpenChange(open: boolean) {
if (!open) {
return null;
}
modalApi.modalLoading(true);
const {id} = modalApi.getData() as { id: number | string };
machineDetail.value = await machineInfo(id);
modalApi.modalLoading(false);
}
</script>
<template>
<BasicModal :footer="false" :fullscreen-button="false" title="设备详情" class="w-[70%]">
<Descriptions v-if="machineDetail" size="small" :column="2" bordered
:labelStyle="{width:'120px'}">
<DescriptionsItem label="设备名称">
{{ machineDetail.machineName }}
</DescriptionsItem>
<DescriptionsItem label="设备编码">
{{ machineDetail.machineCode }}
</DescriptionsItem>
<DescriptionsItem label="设备品牌">
{{ machineDetail.machineBrand }}
</DescriptionsItem>
<DescriptionsItem label="设备类型">
{{ machineDetail.machineTypeId }}
</DescriptionsItem>
<DescriptionsItem label="位置详情">
{{ machineDetail.locationId }}
</DescriptionsItem>
<DescriptionsItem label="采购价格">
{{ machineDetail.purchasePrice }}
</DescriptionsItem>
<DescriptionsItem label="启用时间">
{{ machineDetail.activationTime }}
</DescriptionsItem>
<DescriptionsItem label="保修截至时间">
{{ machineDetail.deadline }}
</DescriptionsItem>
<DescriptionsItem label="使用年限(年)">
{{ machineDetail.serviceLife }}
</DescriptionsItem>
<DescriptionsItem label="保修周期" v-if="machineDetail.maintenanceCycle!=null">
<component
:is="renderDict(machineDetail.maintenanceCycle,'wy_sbbxzq')"
/>
</DescriptionsItem>
<DescriptionsItem label="使用状态" v-if="machineDetail.state!=null">
<component
:is="renderDict(machineDetail.state,'wy_sbsyzt')"
/>
</DescriptionsItem>
<DescriptionsItem label="责任人" >
{{ machineDetail.personId }}
</DescriptionsItem>
</Descriptions>
</BasicModal>
</template>

View File

@@ -0,0 +1,186 @@
<script setup lang="ts">
import {computed, ref} from 'vue';
import {useVbenModal} from '@vben/common-ui';
import {$t} from '@vben/locales';
import {cloneDeep} from '@vben/utils';
import {useVbenForm} from '#/adapter/form';
import {machineAdd, machineInfo, machineUpdate} from '#/api/property/equipmentManagement/machine';
import {defaultFormValueGetter, useBeforeCloseDiff} from '#/utils/popup';
import {modalSchema} from './data';
import {personList} from "#/api/property/resident/person";
import {renderDictValue} from "#/utils/render";
import {getMachineTypeTree} from "#/api/property/machineType";
import {deviceLocationList} from "#/api/property/equipmentManagement/deviceLocation";
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满一列
formItemClass: 'col-span-1',
// 默认label宽度 px
labelWidth: 110,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
}
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const {onBeforeClose, markInitialized, resetInitialized} = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[70%]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
await queryPersonData()
await setupTypeSelect()
await queryLocationData()
const {id} = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
if (isUpdate.value && id) {
const record = await machineInfo(id);
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const {valid} = await formApi.validate();
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
await (isUpdate.value ? machineUpdate(data) : machineAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
/**
* 查询负责人数据
*/
async function queryPersonData() {
let params = {
pageSize: 1000,
pageNum: 1,
}
const res = await personList(params);
const options = res.rows.map((user) => ({
label: user.userName + '-' + renderDictValue(user.gender, 'sys_user_sex')
+ '-' + user.phone + '-' + user.unitName,
value: user.id,
}));
formApi.updateSchema([{
componentProps: () => ({
options: options,
showSearch: true,
optionFilterProp: 'label',
optionLabelProp: 'label',
}),
fieldName: 'personId',
}])
}
/**
*初始化设别类型数据
*/
async function setupTypeSelect() {
const typeList = await getMachineTypeTree();
formApi.updateSchema([
{
componentProps: () => ({
class: 'w-full',
fieldNames: {
key: 'id',
label: 'machineTypeName',
value: 'id',
children: 'children',
},
placeholder: '请选择',
showSearch: true,
treeData: typeList,
treeDefaultExpandAll: true,
treeLine: {showLeafIcon: false},
// 筛选的字段
treeNodeFilterProp: 'label',
// 选中后显示在输入框的值
treeNodeLabelProp: 'machineTypeName',
}),
fieldName: 'machineTypeId',
},
]);
}
/**
* 查询设备位置数据
*/
async function queryLocationData() {
let params = {
pageSize: 1000,
pageNum: 1,
}
const res = await deviceLocationList(params);
const options = res.rows.map((item) => ({
label: item.locationName + '-' + renderDictValue(item.locationType, 'pro_location_type'),
value: item.id,
}));
formApi.updateSchema([{
componentProps: () => ({
options: options,
showSearch: true,
optionFilterProp: 'label',
optionLabelProp: 'label',
}),
fieldName: 'locationId',
}])
}
</script>
<template>
<BasicModal :title="title">
<BasicForm/>
</BasicModal>
</template>

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',
},
// 需要使用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,25 @@ 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)"
>
<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-button>
</div>
<!-- 详情展示 -->
<a-card v-if="detailData" :title="detailData.machineTypeName">
<p><b>类型名称</b>{{ detailData.machineTypeName }}</p>
<p><b>类型编号</b>{{ detailData.machineTypeCode }}</p>
<p><b>是否启用</b>{{ detailData.isEnable == '1' ? '启用' : '禁用' }}</p>
<p><b>备注</b>{{ detailData.remark || '-' }}</p>
</a-card>
<a-empty v-else description="暂无详情" />
<MachineTypeModal @reload="() => { reloadTree(); loadDetail(); }" />
</div>
</div>
</Page>
</template>

View File

@@ -0,0 +1,209 @@
import type {FormSchemaGetter} from '#/adapter/form';
import type {VxeGridProps} from '#/adapter/vxe-table';
import {getDictOptions} from "#/utils/dict";
import {renderDict} from "#/utils/render";
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'planName',
label: '计划名称',
},
{
component: 'Select',
fieldName: 'state',
label: '状态',
componentProps: {
options: getDictOptions('wy_state')
},
},
];
export const columns: VxeGridProps['columns'] = [
{type: 'checkbox', width: 60},
{
title: '主键',
field: 'id',
},
{
title: '计划名称',
field: 'planName',
},
{
title: '计划编号',
field: 'planNo',
},
{
title: '设备类型',
field: 'machineTypeId',
},
{
title: '保养周期',
field: 'planPeriod',
slots: {
default: ({row}) => {
return renderDict(row.planPeriod,'wy_sbbyzq')
}
}
},
// {
// title: '保养天',
// field: 'maintainDay',
// },
// {
// title: '保养月',
// field: 'maintainMonth',
// },
// {
// title: '固定天',
// field: 'maintainEveryday',
// },
{
title: '开始时间',
field: 'startDate',
},
{
title: '结束时间',
field: 'endDate',
},
{
title: '状态',
field: 'state',
slots:{
default:'state'
}
},
{
field: 'action',
fixed: 'right',
slots: {default: 'action'},
title: '操作',
width: 180,
},
];
export const modalSchema: FormSchemaGetter = () => [
{
label: '主键',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '计划名称',
fieldName: 'planName',
component: 'Input',
rules: 'required',
},
{
label: '计划编号',
fieldName: 'planNo',
component: 'Input',
rules: 'required',
},
{
label: '保养周期',
fieldName: 'planPeriod',
component: 'Select',
componentProps: {
options: getDictOptions('wy_sbbyzq')
},
rules: 'selectRequired',
},
{
label: '设备类型',
fieldName: 'machineTypeId',
component: 'TreeSelect',
rules: 'selectRequired',
},
{
label: '月',
fieldName: 'maintainMonth',
component: 'CheckboxGroup',
dependencies: {
show: (formValue) => formValue.planPeriod=='1',
triggerFields: ['planPeriod'],
},
formItemClass: 'col-span-2',
componentProps: {
options: Array.from({ length: 12 }, (_, i) => ({
label: `${i + 1}`,
value: (i + 1).toString(),
})),
},
rules: 'selectRequired',
},
{
label: '日',
fieldName: 'maintainDay',
component: 'CheckboxGroup',
dependencies: {
show: (formValue) => formValue.planPeriod=='1',
triggerFields: ['planPeriod'],
},
formItemClass: 'col-span-2',
componentProps: {
options: Array.from({ length: 31 }, (_, i) => ({
label: `${i + 1}`,
value: (i + 1).toString(),
})),
},
rules: 'selectRequired',
},
{
label: '固定天数',
fieldName: 'maintainEveryday',
component: 'InputNumber',
dependencies: {
show: (formValue) => formValue.planPeriod=='2',
triggerFields: ['planPeriod'],
},
rules:'required',
componentProps:{
min:0,
precision:2,
placeholder:'请填写多少天后保养一次',
},
},
{
label: '计划日期',
fieldName: 'planDate',
component: 'RangePicker',
componentProps: {
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
},
rules:'required'
},
// {
// label: '开始时间',
// fieldName: 'startDate',
// component: 'DatePicker',
// componentProps: {
// showTime: true,
// format: 'YYYY-MM-DD HH:mm:ss',
// valueFormat: 'YYYY-MM-DD HH:mm:ss',
// },
// rules:'required'
// },
// {
// label: '结束时间',
// fieldName: 'endDate',
// component: 'DatePicker',
// componentProps: {
// showTime: true,
// format: 'YYYY-MM-DD HH:mm:ss',
// valueFormat: 'YYYY-MM-DD HH:mm:ss',
// },
// rules:'required'
// },
// {
// label: '状态(0启用,1停用)',
// fieldName: 'state',
// component: 'Input',
// },
];

View File

@@ -0,0 +1,197 @@
<script setup lang="ts">
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table';
import {
maintainPlanExport,
maintainPlanList,
maintainPlanRemove, maintainPlanUpdate,
} from '#/api/property/equipmentManagement/maintainPlan';
import type { MaintainPlanForm } from '#/api/property/equipmentManagement/maintainPlan/model';
import { commonDownloadExcel } from '#/utils/file/download';
import maintainPlanModal from './maintainPlan-modal.vue';
import { columns, querySchema } from './data';
import planDetail from './plan-detail.vue'
import {TableSwitch} from "#/components/table";
import {useAccess} from "@vben/access";
const { hasAccessByCodes } = useAccess();
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',
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
// 点击行选中
// trigger: 'row',
},
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await maintainPlanList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'property-maintainPlan-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [MaintainPlanModal, modalApi] = useVbenModal({
connectedComponent: maintainPlanModal,
});
const [PlanDetail, detailApi] = useVbenModal({
connectedComponent: planDetail,
});
function handleAdd() {
modalApi.setData({});
modalApi.open();
}
async function handleEdit(row: Required<MaintainPlanForm>) {
modalApi.setData({ id: row.id });
modalApi.open();
}
async function handleInfo(row: Required<MaintainPlanForm>) {
detailApi.setData({ id: row.id });
detailApi.open();
}
async function handleDelete(row: Required<MaintainPlanForm>) {
await maintainPlanRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<MaintainPlanForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await maintainPlanRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(maintainPlanExport, '保养计划数据', tableApi.formApi.form.values, {
fieldMappingTime: formOptions.fieldMappingTime,
});
}
</script>
<template>
<Page :auto-content-height="true">
<BasicTable table-title="保养计划列表">
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['property:maintainPlan:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['property:maintainPlan:remove']"
@click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['property:maintainPlan:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['property:maintainPlan:info']"
@click.stop="handleInfo(row)"
>
{{ $t('pages.common.info') }}
</ghost-button>
<ghost-button
v-access:code="['property:maintainPlan: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:maintainPlan:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
<template #state="{row}">
<TableSwitch
:checkedValue="1"
:unCheckedValue="0"
v-model:value="row.state"
:api="() => maintainPlanUpdate(row)"
:disabled="!hasAccessByCodes(['property:depot:edit'])"
@reload="() => tableApi.query()"
/>
</template>
</BasicTable>
<MaintainPlanModal @reload="tableApi.query()" />
<PlanDetail/>
</Page>
</template>

View File

@@ -0,0 +1,153 @@
<script setup lang="ts">
import {computed, ref} from 'vue';
import {useVbenModal} from '@vben/common-ui';
import {$t} from '@vben/locales';
import {cloneDeep} from '@vben/utils';
import {useVbenForm} from '#/adapter/form';
import {
maintainPlanAdd,
maintainPlanInfo,
maintainPlanUpdate
} from '#/api/property/equipmentManagement/maintainPlan';
import {defaultFormValueGetter, useBeforeCloseDiff} from '#/utils/popup';
import {modalSchema} from './data';
import {getMachineTypeTree} from "#/api/property/machineType";
const emit = defineEmits<{ reload: [] }>();
const isUpdate = ref(false);
const title = computed(() => {
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
});
const [BasicForm, formApi] = useVbenForm({
commonConfig: {
// 默认占满一列
formItemClass: 'col-span-1',
// 默认label宽度 px
labelWidth: 80,
// 通用配置项 会影响到所有表单项
componentProps: {
class: 'w-full',
}
},
schema: modalSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
});
const {onBeforeClose, markInitialized, resetInitialized} = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
);
const [BasicModal, modalApi] = useVbenModal({
// 在这里更改宽度
class: 'w-[70%]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null;
}
modalApi.modalLoading(true);
const {id} = modalApi.getData() as { id?: number | string };
isUpdate.value = !!id;
await setupTypeSelect();
if (isUpdate.value && id) {
const record = await maintainPlanInfo(id);
record.planDate = [record.startDate, record.endDate]
if (record.planPeriod == '1') {
record.maintainanceMonth = record.maintainanceMonth?.split(',')
record.maintainanceDay = record.maintainanceDay?.split(',')
}
await formApi.setValues(record);
}
await markInitialized();
modalApi.modalLoading(false);
},
});
async function handleConfirm() {
try {
modalApi.lock(true);
const {valid} = await formApi.validate();
if (!valid) {
return;
}
// getValues获取为一个readonly的对象 需要修改必须先深拷贝一次
const data = cloneDeep(await formApi.getValues());
if (data.planDate && data.planDate.length) {
data.startDate = data.planDate[0]
data.endDate = data.planDate[1]
}
if (data.planPeriod == '1') {
data.maintainanceMonth = data.maintainanceMonth?.join(',')
data.maintainanceDay = data.maintainanceDay?.join(',')
data.maintainanceEveryday = undefined
} else {
data.maintainanceMonth = undefined
data.maintainanceDay = undefined
}
await (isUpdate.value ? maintainPlanUpdate(data) : maintainPlanAdd(data));
resetInitialized();
emit('reload');
modalApi.close();
} catch (error) {
console.error(error);
} finally {
modalApi.lock(false);
}
}
async function handleClosed() {
await formApi.resetForm();
resetInitialized();
}
/**
*初始化设别类型数据
*/
async function setupTypeSelect() {
const typeList = await getMachineTypeTree();
formApi.updateSchema([
{
componentProps: () => ({
class: 'w-full',
fieldNames: {
key: 'id',
label: 'machineTypeName',
value: 'id',
children: 'children',
},
placeholder: '请选择',
showSearch: true,
treeData: typeList,
treeDefaultExpandAll: true,
treeLine: {showLeafIcon: false},
// 筛选的字段
treeNodeFilterProp: 'label',
// 选中后显示在输入框的值
treeNodeLabelProp: 'machineTypeName',
}),
fieldName: 'machineTypeId',
},
]);
}
</script>
<template>
<BasicModal :title="title">
<BasicForm/>
</BasicModal>
</template>

View File

@@ -0,0 +1,88 @@
<script setup lang="ts">
import {shallowRef} from 'vue';
import {useVbenModal} from '@vben/common-ui';
import {Descriptions, DescriptionsItem} from 'ant-design-vue';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
import {renderDict} from "#/utils/render";
dayjs.extend(duration);
dayjs.extend(relativeTime);
import {CheckboxGroup} from 'ant-design-vue'
import {getDictOptions} from "#/utils/dict";
import {maintainPlanInfo} from "#/api/property/equipmentManagement/maintainPlan";
import type {MaintainPlanVO} from "#/api/property/equipmentManagement/maintainPlan/model";
const [BasicModal, modalApi] = useVbenModal({
onOpenChange: handleOpenChange,
onClosed() {
maintainPlanDetail.value = null;
},
});
const maintainPlanDetail = shallowRef<null | MaintainPlanVO>(null);
async function handleOpenChange(open: boolean) {
if (!open) {
return null;
}
modalApi.modalLoading(true);
const {id} = modalApi.getData() as { id: number | string };
maintainPlanDetail.value = await maintainPlanInfo(id);
if (maintainPlanDetail.value.planPeriod == '1') {
maintainPlanDetail.value.maintainMonth = maintainPlanDetail.value.maintainMonth?.split(',');
maintainPlanDetail.value.maintainDay = maintainPlanDetail.value.maintainDay?.split(',');
}
modalApi.modalLoading(false);
}
const dayArr=Array.from({ length: 31 }, (_, i) => ({
label: `${i + 1}`,
value: (i + 1).toString(),
}));
const monthArr=Array.from({ length: 12 }, (_, i) => ({
label: `${i + 1}`,
value: (i + 1).toString(),
}))
</script>
<template>
<BasicModal :footer="false" :fullscreen-button="false" title="保养计划详情" class="w-[70%]">
<Descriptions v-if="maintainPlanDetail" size="small" :column="2" bordered
:labelStyle="{width:'100px'}">
<DescriptionsItem label="计划名称">
{{ maintainPlanDetail.planName }}
</DescriptionsItem>
<DescriptionsItem label="计划编号">
{{ maintainPlanDetail.planNo }}
</DescriptionsItem>
<DescriptionsItem label="保养周期" v-if="maintainPlanDetail.planPeriod!=null">
<component
:is="renderDict(maintainPlanDetail.planPeriod,'wy_sbbyzq')"
/>
</DescriptionsItem>
<DescriptionsItem label="设备类型">
{{ maintainPlanDetail.machineTypeId }}
</DescriptionsItem>
<DescriptionsItem label="月" :span="2" v-if="maintainPlanDetail.planPeriod=='1'">
<CheckboxGroup v-model:value="maintainPlanDetail.maintainMonth"
:options="monthArr"/>
</DescriptionsItem>
<DescriptionsItem label="日" :span="2" v-if="maintainPlanDetail.planPeriod=='1'">
<CheckboxGroup v-model:value="maintainPlanDetail.maintainDay"
:options="dayArr"/>
</DescriptionsItem>
<DescriptionsItem label="固定天数" v-if="maintainPlanDetail.planPeriod=='2'">
{{maintainPlanDetail.maintainEveryday}}
</DescriptionsItem>
<DescriptionsItem label="计划日期" :span="2">
{{ maintainPlanDetail.startDate + '\xa0至\xa0' + maintainPlanDetail.endDate }}
</DescriptionsItem>
<DescriptionsItem label="状态" v-if="maintainPlanDetail.state!=null">
<component
:is="renderDict(maintainPlanDetail.state,'wy_state')"
/>
</DescriptionsItem>
</Descriptions>
</BasicModal>
</template>

View File

@@ -15,10 +15,10 @@ export const querySchema: FormSchemaGetter = () => [
{
component: 'Select',
componentProps: {
options:getDictOptions('wy_xjqdfs')
options:getDictOptions('wy_xjzt')
},
fieldName: 'taskType',
label: '巡检方式',
fieldName: 'status',
label: '巡检状态',
},
];
@@ -73,7 +73,7 @@ export const columns: VxeGridProps['columns'] = [
width:100,
slots: {
default: ({ row }) => {
return renderDict(row.taskType, 'wy_xjqdfs');
return renderDict(row.taskType, 'wy_xjzt');
},
},
},

View File

@@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales';
import {cloneDeep, getPopupContainer, handleNode} from '@vben/utils';
import {cloneDeep, handleNode} from '@vben/utils';
import { useVbenForm } from '#/adapter/form';
import { resident_unitAdd, resident_unitInfo, resident_unitUpdate } from '#/api/property/resident/unit';
@@ -108,7 +108,6 @@ async function initLocationOptions() {
value: 'code',
children: 'children',
},
getPopupContainer,
placeholder: '请选择入驻位置',
showSearch: true,
treeData: locationList,