Files
SaaS-lib/hx-ai-intelligent/src/view/equipmentManage/group/config.ts
2024-07-15 15:53:54 +08:00

533 lines
13 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NsSelect } from './../../../../../lib/component/form/select/index';
import { dateUtil } from '/nerv-lib/util/date-util';
import data from './mock.json';
import { http } from '/nerv-lib/util';
import { ref } from 'vue';
import { device, group } from '/@/api/deviceManage';
import { dict } from '/@/api';
import { origanizemanage } from '/@/api/origanizemanage';
const tableCalKeyMap = [
{
title: '来源企业',
dataIndex: 'linkOrgName',
textEllipsis: true,
textNumber: 10,
},
{
title: '设备id',
textNumber: 10,
dataIndex: 'deviceCode',
textEllipsis: true,
},
{
title: '设备编号',
dataIndex: 'deviceNum',
textNumber: 10,
},
{
textNumber: 10,
title: '分组名称',
dataIndex: 'groupName',
},
{
title: '设备品牌/型号',
textNumber: 10,
dataIndex: 'deviceNameType',
},
{
textNumber: 10,
title: '设备状态',
dataIndex: 'deviceStatus',
customRender: ({ value }) => {
return value === '0' ? '启用' : '停用';
},
},
];
const tableKeyMap = [
{
title: '来源企业',
dataIndex: 'orgName',
},
{
title: '节点编号',
dataIndex: 'pointNum',
},
{
title: '节点路径',
dataIndex: 'routeName',
},
];
const doWnload = (url) => {
const a = document.createElement('a');
document.body.appendChild(a);
a.href = encodeURI(url);
//设置下载的文件名
// a.download = fileName.value;
//触发a标签的点击事件进行下载
a.click();
};
export const formSchema = [
{
field: 'isCreate',
component: 'NsCheck',
show: false,
},
{
field: 'isCreatSon',
component: 'NsCheck',
show: false,
},
{
field: 'orgId',
component: 'NsInput',
show: false,
},
{
field: 'energyType',
component: 'NsInput',
show: false,
},
{
field: 'id',
component: 'NsInput',
show: false,
},
{
field: 'pid',
component: 'NsInput',
show: false,
},
{
label: '节点名称',
field: 'pointName',
component: 'NsInput',
componentProps: {
placeholder: '请输入节点名称(必填)',
},
rules: [
{
required: true,
message: '请输入节点名称',
},
],
},
{
label: '节点类型',
field: 'pointType',
component: 'NsSelectApi',
componentProps: {
placeholder: '请选择节点类型(必填)',
api: () => dict({ params: { dicKey: 'COUNT_POINT' } }),
// params: { dicKey: 'COUNT_POINT' },
immediate: true,
// resultField: 'data.COUNT_POINT',
labelField: 'cnValue',
valueField: 'dicKey',
},
rules: [
{
required: true,
message: '请输入节点类型',
},
],
},
];
export const editTreeConfig = (orgId) => ({
selectedKeys: ['0-0'],
defaultExpandAll: true,
api: group.queryEditGroup,
params: { orgId },
resultField: 'data.orgInfos',
fieldNames: { title: 'orgName', key: 'orgId' },
formConfig: {
schemas: [
{
field: 'orgName',
component: 'NsInput',
autoSubmit: true,
componentProps: {
placeholder: '请输入企业名称',
},
},
],
},
});
export const editCalTreeConfig = (orgId) => ({
selectedKeys: ['0-0'],
defaultExpandAll: true,
api: group.queryEditCompute,
params: { orgId },
resultField: 'data.orgInfos',
fieldNames: { title: 'orgName', key: 'orgId' },
formConfig: {
schemas: [
{
field: 'orgName',
component: 'NsInput',
autoSubmit: true,
componentProps: {
placeholder: '请输入企业名称',
},
},
],
},
});
export const treeConfig = (orgId) => {
return {
defaultExpandAll: true,
header: {
icon: 'orgLink',
title: '能耗分组',
},
params: { orgId },
api: group.queryDeviceGroupTree,
transform: (data) => {
return [{ pointName: '全部', id: 'all', selectable: false, children: data }];
},
formConfig: {
schemas: [
{
field: 'energyType',
label: '',
component: 'NsSelectApi',
autoSubmit: true,
componentProps: {
api: () => dict({ params: { dicKey: 'ENERGY_TYPE' } }),
// params: { dicKey: 'ENERGY_TYPE' },
immediate: true,
// resultField: 'data.ENERGY_TYPE',
labelField: 'cnValue',
valueField: 'dicKey',
placeholder: '请选择能耗种类',
autoSelectFirst: true,
},
},
{
field: 'pointName',
label: '',
component: 'NsInput',
autoSubmit: true,
componentProps: {
placeholder: '请输入节点名称',
},
},
],
},
};
};
export const tableConfig = (el, elGroup, elFormula, defaultParams) => {
return {
title: '点位信息',
api: group.queryGroupPage,
params: defaultParams.value,
headerActions: [
{
label: '编辑',
name: 'groupEdit',
type: 'primary',
handle: (a, b) => {
el.value.toggle();
},
},
{
label: '批量删除',
name: 'groupBatDelete',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
dynamicParams: { linkIds: 'linkId[]' },
confirm: true,
isClearCheck: true,
isReload: true,
api: group.delGroupList,
},
{
label: '批量导出',
name: 'groupExports',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
extra: {
xlsxMap: tableKeyMap,
xlsxName: '分组信息YYYY-MM-DD',
},
},
{
label: '批量导入',
name: 'groupImport',
type: 'primary',
extra: {
// api: props.postImportApi, // 导入接口名
title: '设备信息', // 弹窗title
templateName: 'whiteListUser', // 所使用的文件名称
indexName: '设备id', // 匹配类型字段
message: [
{ label: '1、若必填项未填写则不能进行导入操作' },
{ label: `2、当重复时则更新数据。` },
{ label: '3、数据将从模版的第五行进行导入。' },
{ label: '4、文件导入勿超过5MB。' },
],
},
},
{
label: '模板下载',
name: 'groupTemDownload',
type: 'primary',
handle: () => {
// http.get('/asset/file/whiteListUser.xlsx');
doWnload('/hx-ai-intelligent/asset/file/whiteListUser.xlsx');
},
},
],
columns: tableKeyMap,
columnActions: {
title: '操作',
actions: [
{
label: '删除',
name: 'groupDelete',
dynamicParams: { linkIds: 'linkId[]' },
confirm: true,
isClearCheck: true,
isReload: true,
api: group.delGroupList,
},
],
},
formConfig: {
schemas: [
{
field: 'orgName',
component: 'NsSelectApi',
defaultParams: defaultParams.value,
componentProps: {
placeholder: '请选择公司',
mode: 'multiple',
api: group.dropGroupFilter,
resultField: 'data',
params: { filterField: 'ORG' },
labelField: 'orgName',
valueField: 'orgId',
filterOption: (input: string, option: any) => {
return option.deviceName.toLowerCase().indexOf(input.toLowerCase()) >= 0;
},
showSearch: true,
dropdownReload: true,
allowClear: true,
},
},
{
field: 'pointNum',
component: 'NsInput',
componentProps: {
placeholder: '请输入节点编号',
},
},
],
},
// pagination: { pageSizeOptions: false },
rowKey: 'id',
};
};
export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
// 计算节点
return {
title: '点位信息',
api: group.queryGroupInfoPage,
params: defaultParams.value,
headerActions: [
{
label: '编辑',
name: 'groupEdit',
type: 'primary',
handle: (a, b) => {
el.value.toggle();
},
},
{
label: '批量删除',
name: 'groupTemDownload',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
dynamicParams: { ids: 'id[]' },
confirm: true,
isReload: true,
isClearCheck: true,
api: group.delComputeList,
},
{
label: '批量导出',
name: 'groupExports',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
extra: {
xlsxMap: tableKeyMap,
xlsxName: '分组信息YYYY-MM-DD',
},
},
{
label: '批量导入',
name: 'groupImport',
type: 'primary',
extra: {
// api: props.postImportApi, // 导入接口名
title: '设备信息', // 弹窗title
templateName: 'whiteListUser', // 所使用的文件名称
indexName: '设备id', // 匹配类型字段
message: [
{ label: '1、若必填项未填写则不能进行导入操作' },
{ label: `2、当重复时则更新数据。` },
{ label: '3、数据将从模版的第五行进行导入。' },
{ label: '4、文件导入勿超过5MB。' },
],
},
},
{
label: '模板下载',
name: 'groupTemDownload',
type: 'primary',
handle: () => {
// http.get('/asset/file/whiteListUser.xlsx');
doWnload('/hx-ai-intelligent/asset/file/whiteListUser.xlsx');
},
},
{
label: '批量分组',
name: 'groupBatGroup',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
handle: ({ list }) => {
const ids = list.map(({ id }) => id);
defaultParams.value['saveDeviceInfoIds'] = ids;
elGroup.value.toggle();
},
},
{
label: '公式编辑',
name: 'groupFormulaEdit',
type: 'primary',
handle: () => {
elFormula.value.toggle();
},
},
],
scroll: { x: 1400 },
columns: tableCalKeyMap,
columnActions: {
title: '操作',
actions: [
{
label: '删除',
name: 'groupDelete',
dynamicParams: { ids: 'id[]' },
confirm: true,
isReload: true,
isClearCheck: true,
api: group.delComputeList,
},
],
},
formConfig: {
schemas: [
{
field: 'orgIds',
component: 'NsSelectApi',
defaultParams: defaultParams.value,
componentProps: {
placeholder: '请选择公司',
mode: 'multiple',
api: group.dropGroupInfoFilter,
resultField: 'data',
params: { filterField: 'ORG' },
labelField: 'orgName',
valueField: 'orgId',
filterOption: (input: string, option: any) => {
return option.deviceName.toLowerCase().indexOf(input.toLowerCase()) >= 0;
},
showSearch: true,
dropdownReload: true,
allowClear: true,
},
},
{
field: 'deviceCode',
component: 'NsInput',
componentProps: {
placeholder: '请输入设备id',
},
},
{
field: 'deviceNum',
component: 'NsInput',
componentProps: {
placeholder: '请输入设备编号',
},
},
{
field: 'deviceStatus',
component: 'NsSelectApi',
componentProps: {
placeholder: '请选择设备状态',
api: () => dict({ params: { dicKey: 'DEVICE_STATUS' } }),
immediate: true,
labelField: 'cnValue',
valueField: 'dicKey',
},
},
{
field: 'deviceNameType',
component: 'NsSelectApi',
defaultParams: defaultParams.value,
componentProps: {
placeholder: '请选择设备型号',
mode: 'multiple',
api: (params: any) => {
return http.post(group.dropGroupInfoFilter, params).then((res: any) => {
const result = [...new Set(res.data)];
return { data: result };
});
},
resultField: 'data',
params: { filterField: 'DEVICE_TYPE' },
// labelField: 'orgName',
// valueField: 'orgId',
filterOption: (input: string, option: any) => {
return option.deviceName.toLowerCase().indexOf(input.toLowerCase()) >= 0;
},
showSearch: true,
dropdownReload: true,
allowClear: true,
},
},
{
field: 'provider',
component: 'NsInput',
componentProps: {
placeholder: '请输入分组名称',
},
},
],
},
// pagination: { pageSizeOptions: false },
rowKey: 'id',
};
};