refactor(property): 重构能源管理相关页面布局

This commit is contained in:
2025-08-25 15:46:05 +08:00
parent a43cb1b390
commit 84ff3d21b4
31 changed files with 904 additions and 1027 deletions

View File

@@ -0,0 +1,203 @@
import type { FormSchemaGetter } from '#/adapter/form'
import type { VxeGridProps } from '#/adapter/vxe-table'
import { getDictOptions } from '#/utils/dict'
import { renderDict } from '#/utils/render'
export function initMoalForm(type: number) {
const modalSchema: FormSchemaGetter = () => [
{
label: '仪表名称',
fieldName: 'meterName',
component: 'Input',
rules: 'selectRequired',
},
{
label: '仪表编码',
fieldName: 'meterCode',
component: 'Input',
},
{
label: '设备厂商',
fieldName: 'factoryNo',
component: 'Input',
},
{
label: type === 1 ? '设备类型(电表)' : type === 2 ? '设备类型(水表)' : '设备类型(气表)',
fieldName: 'meterType',
component: 'Select',
defaultValue: type.toString(),
disabled: true,
componentProps: {
// 可选从DictEnum中获取 DictEnum.METER_TYPE 便于维护
options: getDictOptions('meter_type'),
},
rules: 'selectRequired',
},
{
label: type === 1 ? '计量单位(度)' : type === 2 ? '计量单位(吨)' : '计量单位(立方米)',
fieldName: 'meterUnit',
component: 'Select',
defaultValue: type.toString(),
disabled: true,
componentProps: {
// 可选从DictEnum中获取 DictEnum.METER_UNIT 便于维护
options: getDictOptions('meter_unit'),
},
rules: 'selectRequired',
},
{
label: '安装位置',
fieldName: 'installLocation',
component: 'Input',
},
{
label: '初始读数',
fieldName: 'initReading',
component: 'Input',
},
{
label: '最大量程',
fieldName: 'maxRang',
component: 'Input',
},
{
label: '通信状态',
fieldName: 'communicationState',
component: 'Select',
componentProps: {
// 可选从DictEnum中获取 DictEnum.SIS_DEVICE_STATUS 便于维护
options: getDictOptions('sis_device_status'),
},
},
{
label: '运行状态',
fieldName: 'runningState',
component: 'Select',
componentProps: {
// 可选从DictEnum中获取 DictEnum.SIS_DEVICE_STATUS 便于维护
options: getDictOptions('sis_device_status'),
},
},
{
label: '备注',
fieldName: 'remark',
component: 'Textarea',
},
]
return modalSchema
}
export function initQuerySchema(type: number) {
const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'meterName',
label: '仪表名称',
},
{
component: 'Input',
fieldName: 'meterCode',
label: '仪表编码',
},
{
component: 'Select',
disabled: true,
componentProps: {
// 可选从DictEnum中获取 DictEnum.METER_TYPE 便于维护
options: getDictOptions('meter_type'),
},
defaultValue: type.toString(),
fieldName: 'meterType',
label: '设备类型',
}
]
return querySchema
}
export function initColumns(type: number) {
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
{
title: '仪表名称',
field: 'meterName',
},
{
title: '仪表编码',
field: 'meterCode',
},
{
title: '设备厂商',
field: 'factoryNo',
},
{
title: type === 1 ? '设备类型(电表)' : type === 2 ? '设备类型(水表)' : '设备类型(气表)',
field: 'meterType',
slots: {
default: ({ row }) => {
// 可选从DictEnum中获取 DictEnum.METER_TYPE 便于维护
return renderDict(row.meterType, 'meter_type')
},
},
},
{
title: type === 1 ? '计量单位(度)' : type === 2 ? '计量单位(吨)' : '计量单位(立方米)',
field: 'meterUnit',
slots: {
default: ({ row }) => {
// 可选从DictEnum中获取 DictEnum.METER_UNIT 便于维护
return renderDict(row.meterUnit, 'meter_unit')
},
},
},
{
title: '安装位置',
field: 'installLocation',
},
{
title: '初始读数',
field: 'initReading',
},
{
title: '最大量程',
field: 'maxRang',
},
{
title: '通信状态',
field: 'communicationState',
slots: {
default: ({ row }) => {
// 可选从DictEnum中获取 DictEnum.SIS_DEVICE_STATUS 便于维护
return renderDict(row.communicationState, 'sis_device_status')
},
},
},
{
title: '运行状态',
field: 'runningState',
slots: {
default: ({ row }) => {
// 可选从DictEnum中获取 DictEnum.SIS_DEVICE_STATUS 便于维护
return renderDict(row.runningState, 'sis_device_status')
},
},
},
{
title: '备注',
field: 'remark',
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
]
return columns
}

View File

@@ -0,0 +1,117 @@
<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 {
meterInfoAdd,
meterInfoInfo,
meterInfoUpdate,
} from "#/api/property/energyManagement/meterInfo"
import { defaultFormValueGetter, useBeforeCloseDiff } from "#/utils/popup"
const props = defineProps({
meterType: {
type: Number,
required: true,
},
})
import { initMoalForm } from "./data"
const modalSchema = initMoalForm(props.meterType)
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: 120,
// 通用配置项 会影响到所有表单项
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-[900px]",
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
if (isUpdate.value && id) {
const record = await meterInfoInfo(id)
record.meterType = record.meterType.toString()
record.meterUnit = record.meterUnit.toString()
record.runningState = record.runningState.toString()
record.communicationState = record.communicationState.toString()
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 ? meterInfoUpdate(data) : meterInfoAdd(data))
resetInitialized()
emit("reload")
modalApi.close()
} catch (error) {
console.error(error)
} finally {
modalApi.lock(false)
}
}
async function handleClosed() {
await formApi.resetForm()
resetInitialized()
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>

View File

@@ -0,0 +1,167 @@
<script setup lang="ts">
import type { Recordable } from "@vben/types"
import { ref } from "vue"
import { Page, useVbenModal, type VbenFormProps } from "@vben/common-ui"
import { getVxePopupContainer } from "@vben/utils"
import { Modal, Popconfirm, Space } from "ant-design-vue"
import dayjs from "dayjs"
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps,
} from "#/adapter/vxe-table"
import {
meterInfoExport,
meterInfoList,
meterInfoRemove,
} from "#/api/property/energyManagement/meterInfo"
import type { MeterInfoForm } from "#/api/property/meterInfo/model"
import { commonDownloadExcel } from "#/utils/file/download"
import meterInfoModal from "../components/meterInfo-modal.vue"
import { initQuerySchema, initColumns } from "../components/data"
const columns = initColumns(3)
const querySchema = initQuerySchema(3)
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'],
// ],
// ],
}
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 = {}) => {
return await meterInfoList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
})
},
},
},
rowConfig: {
keyField: "id",
},
// 表格全局唯一表示 保存列配置需要用到
id: "property-meterInfo-index",
}
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
})
const [MeterInfoModal, modalApi] = useVbenModal({
connectedComponent: meterInfoModal,
})
function handleAdd() {
modalApi.setData({})
modalApi.open()
}
async function handleEdit(row: Required<MeterInfoForm>) {
modalApi.setData({ id: row.id })
modalApi.open()
}
async function handleDelete(row: Required<MeterInfoForm>) {
await meterInfoRemove(row.id)
await tableApi.query()
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords()
const ids = rows.map((row: Required<MeterInfoForm>) => row.id)
Modal.confirm({
title: "提示",
okType: "danger",
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await meterInfoRemove(ids)
await tableApi.query()
},
})
}
function handleDownloadExcel() {
commonDownloadExcel(
meterInfoExport,
"水电气数据",
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:meterInfo:export']" @click="handleDownloadExcel">
{{ $t('pages.common.export') }}
</a-button>
<a-button :disabled="!vxeCheckboxChecked(tableApi)" danger type="primary"
v-access:code="['property:meterInfo:remove']" @click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button type="primary" v-access:code="['property:meterInfo:add']" @click="handleAdd">
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button v-access:code="['property:meterInfo: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:meterInfo:remove']" @click.stop="">
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<MeterInfoModal @reload="tableApi.query()" :meterType="3" />
</Page>
</template>

View File

@@ -0,0 +1,162 @@
<script setup lang="ts">
import type { Recordable } from '@vben/types'
import { ref } from 'vue'
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui'
import { getVxePopupContainer } from '@vben/utils'
import { Modal, Popconfirm, Space } from 'ant-design-vue'
import dayjs from 'dayjs'
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table'
import {
meterInfoExport,
meterInfoList,
meterInfoRemove,
} from '#/api/property/energyManagement/meterInfo'
import type { MeterInfoForm } from '#/api/property/meterInfo/model'
import { commonDownloadExcel } from '#/utils/file/download'
import meterInfoModal from "../components/meterInfo-modal.vue"
import { initQuerySchema, initColumns } from "../components/data"
const columns = initColumns(1)
const querySchema = initQuerySchema(1)
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'],
// ],
// ],
}
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 = {}) => {
return await meterInfoList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
})
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'property-meterInfo-index'
}
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
})
const [MeterInfoModal, modalApi] = useVbenModal({
connectedComponent: meterInfoModal,
})
function handleAdd() {
modalApi.setData({})
modalApi.open()
}
async function handleEdit(row: Required<MeterInfoForm>) {
modalApi.setData({ id: row.id })
modalApi.open()
}
async function handleDelete(row: Required<MeterInfoForm>) {
await meterInfoRemove(row.id)
await tableApi.query()
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords()
const ids = rows.map((row: Required<MeterInfoForm>) => row.id)
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await meterInfoRemove(ids)
await tableApi.query()
},
})
}
function handleDownloadExcel() {
commonDownloadExcel(meterInfoExport, '水电气数据', 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:meterInfo:export']" @click="handleDownloadExcel">
{{ $t('pages.common.export') }}
</a-button>
<a-button :disabled="!vxeCheckboxChecked(tableApi)" danger type="primary"
v-access:code="['property:meterInfo:remove']" @click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button type="primary" v-access:code="['property:meterInfo:add']" @click="handleAdd">
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button v-access:code="['property:meterInfo: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:meterInfo:remove']" @click.stop="">
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<MeterInfoModal @reload="tableApi.query()" :meterType="1" />
</Page>
</template>

View File

@@ -0,0 +1,162 @@
<script setup lang="ts">
import type { Recordable } from '@vben/types'
import { ref } from 'vue'
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui'
import { getVxePopupContainer } from '@vben/utils'
import { Modal, Popconfirm, Space } from 'ant-design-vue'
import dayjs from 'dayjs'
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table'
import {
meterInfoExport,
meterInfoList,
meterInfoRemove,
} from '#/api/property/energyManagement/meterInfo'
import type { MeterInfoForm } from '#/api/property/meterInfo/model'
import { commonDownloadExcel } from '#/utils/file/download'
import meterInfoModal from "../components/meterInfo-modal.vue"
import { initQuerySchema, initColumns } from "../components/data"
const columns = initColumns(2)
const querySchema = initQuerySchema(2)
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'],
// ],
// ],
}
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 = {}) => {
return await meterInfoList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
})
},
},
},
rowConfig: {
keyField: 'id',
},
// 表格全局唯一表示 保存列配置需要用到
id: 'property-meterInfo-index'
}
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
})
const [MeterInfoModal, modalApi] = useVbenModal({
connectedComponent: meterInfoModal,
})
function handleAdd() {
modalApi.setData({})
modalApi.open()
}
async function handleEdit(row: Required<MeterInfoForm>) {
modalApi.setData({ id: row.id })
modalApi.open()
}
async function handleDelete(row: Required<MeterInfoForm>) {
await meterInfoRemove(row.id)
await tableApi.query()
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords()
const ids = rows.map((row: Required<MeterInfoForm>) => row.id)
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await meterInfoRemove(ids)
await tableApi.query()
},
})
}
function handleDownloadExcel() {
commonDownloadExcel(meterInfoExport, '水电气数据', 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:meterInfo:export']" @click="handleDownloadExcel">
{{ $t('pages.common.export') }}
</a-button>
<a-button :disabled="!vxeCheckboxChecked(tableApi)" danger type="primary"
v-access:code="['property:meterInfo:remove']" @click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button type="primary" v-access:code="['property:meterInfo:add']" @click="handleAdd">
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button v-access:code="['property:meterInfo: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:meterInfo:remove']" @click.stop="">
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
</BasicTable>
<MeterInfoModal @reload="tableApi.query()" :meterType="2" />
</Page>
</template>