Merge branch 'master' of http://47.109.37.87:3000/by2025/admin-vben5
Some checks failed
/ Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
FLL 2025-08-20 14:25:59 +08:00
commit fc08c5525c
6 changed files with 600 additions and 1 deletions

View File

@ -0,0 +1,61 @@
import type { LightInfoVO, LightInfoForm, LightInfoQuery } from './model';
import type { ID, IDS } from '#/api/common';
import type { PageResult } from '#/api/common';
import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';
/**
*
* @param params
* @returns
*/
export function lightInfoList(params?: LightInfoQuery) {
return requestClient.get<PageResult<LightInfoVO>>('/property/lightInfo/list', { params });
}
/**
*
* @param params
* @returns
*/
export function lightInfoExport(params?: LightInfoQuery) {
return commonExport('/property/lightInfo/export', params ?? {});
}
/**
*
* @param id id
* @returns
*/
export function lightInfoInfo(id: ID) {
return requestClient.get<LightInfoVO>(`/property/lightInfo/${id}`);
}
/**
*
* @param data
* @returns void
*/
export function lightInfoAdd(data: LightInfoForm) {
return requestClient.postWithMsg<void>('/property/lightInfo', data);
}
/**
*
* @param data
* @returns void
*/
export function lightInfoUpdate(data: LightInfoForm) {
return requestClient.putWithMsg<void>('/property/lightInfo', data);
}
/**
*
* @param id id
* @returns void
*/
export function lightInfoRemove(id: ID | IDS) {
return requestClient.deleteWithMsg<void>(`/property/lightInfo/${id}`);
}

View File

@ -0,0 +1,134 @@
import type { PageQuery, BaseEntity } from '#/api/common';
export interface LightInfoVO {
/**
* id
*/
id: string | number;
/**
*
*/
locationRemark: string;
/**
* 01
*/
isOn: number;
/**
*
*/
code: number;
/**
*
*/
communityId: string | number;
/**
*
*/
buildingId: string | number;
/**
*
*/
unitId: string | number;
/**
* ID
*/
floorId: string | number;
/**
*
*/
floorName: string;
}
export interface LightInfoForm extends BaseEntity {
/**
* id
*/
id?: string | number;
/**
*
*/
locationRemark?: string;
/**
* 01
*/
isOn?: number;
/**
*
*/
code?: number;
/**
*
*/
communityId?: string | number;
/**
*
*/
buildingId?: string | number;
/**
*
*/
unitId?: string | number;
/**
* ID
*/
floorId?: string | number;
}
export interface LightInfoQuery extends PageQuery {
/**
*
*/
locationRemark?: string;
/**
* 01
*/
isOn?: number;
/**
*
*/
code?: number;
/**
*
*/
communityId?: string | number;
/**
*
*/
buildingId?: string | number;
/**
*
*/
unitId?: string | number;
/**
* ID
*/
floorId?: string | number;
/**
*
*/
params?: any;
}

View File

@ -0,0 +1,84 @@
import type { FormSchemaGetter } from '#/adapter/form'
import type { VxeGridProps } from '#/adapter/vxe-table'
export const querySchema: FormSchemaGetter = () => [
{
component: 'Input',
fieldName: 'locationRemark',
label: '位置描述',
},
]
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
{ type: 'checkbox', width: 60 },
// {
// title: '主键id',
// field: 'id',
// },
{
title: '位置描述',
field: 'locationRemark',
},
{
title: '楼 层',
field: 'floorName',
},
{
title: '开关状态',
field: 'isOn',
slots: { default: 'isOn' },
},
{
field: 'action',
fixed: 'right',
slots: { default: 'action' },
title: '操作',
width: 180,
},
]
export const drawerSchema: FormSchemaGetter = () => [
{
label: '主键id',
fieldName: 'id',
component: 'Input',
dependencies: {
show: () => false,
triggerFields: [''],
},
},
{
label: '楼层',
fieldName: 'floorId',
component: 'TreeSelect',
defaultValue: undefined,
rules: 'required',
},
{
label: '位置描述',
fieldName: 'locationRemark',
component: 'Input',
rules: 'required',
},
{
label: '开关状态',
fieldName: 'isOn',
component: 'Switch',
rules: 'required',
defaultValue: false,
componentProps: {
class: 'w-auto',
},
},
{
label: '灯控模块编码',
fieldName: 'code',
component: 'Input',
rules: 'required',
},
]

View File

@ -0,0 +1,181 @@
<script setup lang="ts">
import { TableSwitch } from "#/components/table"
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import {
useVbenVxeGrid,
vxeCheckboxChecked,
type VxeGridProps
} from '#/adapter/vxe-table';
import {
lightInfoExport,
lightInfoList,
lightInfoRemove,
} from '#/api/property/meter/lightInfo';
import type { LightInfoForm } from '#/api/property/meter/lightInfo/model';
import { commonDownloadExcel } from '#/utils/file/download';
import lightInfoDrawer from './lightInfo-drawer.vue';
import { columns, querySchema } from './data';
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',
},
// 使i18ngetter
// columns: columns(),
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
query: async ({ page }, formValues = {}) => {
return await lightInfoList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
keyField: 'id',
},
//
id: 'property-lightInfo-index'
};
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
});
const [LightInfoDrawer, drawerApi] = useVbenDrawer({
connectedComponent: lightInfoDrawer,
});
function handleAdd() {
drawerApi.setData({});
drawerApi.open();
}
async function handleEdit(row: Required<LightInfoForm>) {
drawerApi.setData({ id: row.id });
drawerApi.open();
}
async function handleDelete(row: Required<LightInfoForm>) {
await lightInfoRemove(row.id);
await tableApi.query();
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: Required<LightInfoForm>) => row.id);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await lightInfoRemove(ids);
await tableApi.query();
},
});
}
function handleDownloadExcel() {
commonDownloadExcel(lightInfoExport, '灯控开关信息数据', 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:lightInfo:export']"
@click="handleDownloadExcel"
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
:disabled="!vxeCheckboxChecked(tableApi)"
danger
type="primary"
v-access:code="['property:lightInfo:remove']"
@click="handleMultiDelete">
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['property:lightInfo:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
<Space>
<ghost-button
v-access:code="['property:lightInfo: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:lightInfo:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</ghost-button>
</Popconfirm>
</Space>
</template>
<template #isOn="{ row }">
<TableSwitch :checkedValue=true :unCheckedValue=false :value="row.isOn" @reload="() => tableApi.query()" />
</template>
</BasicTable>
<LightInfoDrawer @reload="tableApi.query()" />
</Page>
</template>

View File

@ -0,0 +1,140 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useVbenDrawer } from '@vben/common-ui'
import { $t } from '@vben/locales'
import { cloneDeep, getPopupContainer, handleNode } from '@vben/utils'
import { useVbenForm } from '#/adapter/form'
import { communityTree } from '#/api/property/community'
import { lightInfoAdd, lightInfoInfo, lightInfoUpdate } from '#/api/property/meter/lightInfo'
import { defaultFormValueGetter, useBeforeCloseDiff } from '#/utils/popup'
import { drawerSchema } from './data';
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-2',
// label px
labelWidth: 100,
//
componentProps: {
class: 'w-full',
}
},
schema: drawerSchema(),
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
})
const { onBeforeClose, markInitialized, resetInitialized } = useBeforeCloseDiff(
{
initializedGetter: defaultFormValueGetter(formApi),
currentGetter: defaultFormValueGetter(formApi),
},
)
const [BasicModal, modalApi] = useVbenDrawer({
//
class: 'w-[550px]',
fullscreenButton: false,
onBeforeClose,
onClosed: handleClosed,
onConfirm: handleConfirm,
onOpenChange: async (isOpen) => {
if (!isOpen) {
return null
}
modalApi.drawerLoading(true)
const { id } = modalApi.getData() as { id?: number | string }
isUpdate.value = !!id
setupCommunitySelect()
if (isUpdate.value && id) {
const record = await lightInfoInfo(id)
await formApi.setValues(record)
}
await markInitialized()
modalApi.drawerLoading(false)
},
})
async function handleConfirm() {
try {
modalApi.lock(true)
const { valid } = await formApi.validate()
if (!valid) {
return
}
// getValuesreadonly
const data = cloneDeep(await formApi.getValues())
await (isUpdate.value ? lightInfoUpdate(data) : lightInfoAdd(data))
resetInitialized()
emit('reload')
modalApi.close()
} catch (error) {
console.error(error)
} finally {
modalApi.lock(false)
}
}
/**
* 初始化城市
*/
async function setupCommunitySelect() {
const areaList = await communityTree(3)
// /
// addFullName(areaList, 'areaName', ' / ');
const splitStr = '/'
handleNode(areaList, 'label', splitStr, function (node: any) {
if (node.level != 3) {
node.disabled = true
}
})
formApi.updateSchema([
{
componentProps: () => ({
fieldNames: {
key: 'id',
label: 'label',
value: 'code',
children: 'children',
},
getPopupContainer,
placeholder: '请选择建筑',
showSearch: true,
treeData: areaList,
treeDefaultExpandAll: true,
treeLine: { showLeafIcon: false },
//
treeNodeFilterProp: 'label',
//
treeNodeLabelProp: 'fullName',
}),
fieldName: 'floorId',
},
])
}
async function handleClosed() {
await formApi.resetForm()
resetInitialized()
}
</script>
<template>
<BasicModal :title="title">
<BasicForm />
</BasicModal>
</template>

View File

@ -76,7 +76,6 @@ async function handleConfirm() {
//
const data = {
...cloneDeep(formValues),
facePictures: 1,
visitingBeginTime: formValues.visitingTimeRange?.[0],
visitingEndTime: formValues.visitingTimeRange?.[1],
visitingTimeRange: undefined