Browse Source

碳排分组设置前台页面

temp
fks-yangshouda 4 months ago
parent
commit
d583acfb2d
  1. 5
      hx-ai-intelligent/src/api/deviceManage.ts
  2. 1
      hx-ai-intelligent/src/config/app.config.ts
  3. 457
      hx-ai-intelligent/src/view/equipmentManage/group/config.ts
  4. 123
      hx-ai-intelligent/src/view/equipmentManage/group/editCarbonEquipment.vue
  5. 56
      hx-ai-intelligent/src/view/equipmentManage/group/index.vue
  6. 77
      hx-ai-intelligent/src/view/equipmentManage/group/setFactor.vue

5
hx-ai-intelligent/src/api/deviceManage.ts

@ -29,4 +29,9 @@ export enum group {
dropGroupFilter = `${BASE_URL}/deviceGroup/dropGroupFilter`, // 分组列表查询
dropGroupInfoFilter = `${BASE_URL}/deviceGroup/dropGroupInfoFilter`, // 计算列表查询
queryDeviceToEnergy = `${BASE_URL}/deviceGroup/queryDeviceToEnergy`, // 能耗监测用查询设备(能耗监测设备树)
getCarbonGroupList = `${BASE_URL}/deviceGroup/carbonEmissions/getGroupList`, // 分组管理-碳排放-分组查询设备
deleteCarbonDevice = `${BASE_URL}/deviceGroup/carbonEmissions/deleteDevice`, // 分组管理-碳排放-删除设备
addCarbonDevice = `${BASE_URL}/deviceGroup/carbonEmissions/addDevice`, // 分组管理-碳排放-添加设备
updateCarbonFactor = `${BASE_URL}/deviceGroup/carbonEmissions/updateFactor`, // 分组管理-碳排放-设置因子
}

1
hx-ai-intelligent/src/config/app.config.ts

@ -98,6 +98,7 @@ export const appConfig = {
adminFlag: 'adminFlag',
});
sessionStorage.setItem('ORGID', info.orgId);
sessionStorage.setItem('LINKLIST', JSON.stringify(info.linkList));
sessionStorage.setItem('ISADMIN', trD?.adminFlag === '1');
selectDefaultDisabled.value = info?.adminFlag === '1';
selectDefaultValue.value = info.orgId;

457
hx-ai-intelligent/src/view/equipmentManage/group/config.ts

@ -1,6 +1,8 @@
import { http } from '/nerv-lib/util';
import { group } from '/@/api/deviceManage';
import { group, device } from '/@/api/deviceManage';
import { carbonEmissionFactorLibrary, quickCalculation } from '/@/api/carbonEmissionFactorLibrary';
import { dict } from '/@/api';
import { ref } from 'vue';
const tableCalKeyMap = [
{
title: '来源企业',
@ -38,6 +40,54 @@ const tableCalKeyMap = [
},
},
];
const tableCarbonKeyMap = [
{
title: '能源类型',
dataIndex: 'energyTypeName',
// textEllipsis: true,
textNumber: 5,
},
{
title: '设备名称',
textNumber: 10,
dataIndex: 'deviceName',
// textEllipsis: true,
},
{
title: '设备id',
dataIndex: 'deviceInfoCode',
textNumber: 10,
},
{
textNumber: 5,
title: '碳排因子值',
dataIndex: 'emissionFactor',
},
{
title: '设备品牌/型号',
textNumber: 10,
dataIndex: 'deviceModel',
},
{
title: '来源企业',
textNumber: 10,
dataIndex: 'manufacturer',
},
{
title: '分组名称',
textNumber: 10,
dataIndex: 'deviceNameType',
},
{
textNumber: 5,
title: '设备状态',
dataIndex: 'status',
customRender: ({ value }) => {
return value === '0' ? '启用' : '停用';
},
},
];
const tableKeyMap = [
{
title: '来源企业',
@ -333,11 +383,19 @@ export const tableConfig = (el, elGroup, elFormula, defaultParams) => {
};
};
export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
export const tableConfigCal = (
el,
elGroup,
elFormula,
defaultParams,
isCarbon,
editCarbonEquipmentRef,
setFactorRef,
) => {
// 计算节点
return {
title: '点位信息',
api: group.queryGroupInfoPage,
api: isCarbon ? group.getCarbonGroupList : group.queryGroupInfoPage,
params: defaultParams.value,
headerActions: [
{
@ -345,9 +403,32 @@ export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
name: 'GroupPointEdit',
type: 'primary',
handle: (a, b) => {
if (isCarbon) {
editCarbonEquipmentRef.value.toggle();
} else {
el.value.toggle();
}
},
},
isCarbon
? {
label: '关联因子值',
name: 'SetFactor',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
handle: ({ list }) => {
// 过滤出 id 大于 0 的项
const filteredList = list.filter(({ id }) => id > 0);
// 提取出 id 值
const ids = filteredList.map(({ id }) => id);
setFactorRef.value.toggle(ids);
},
}
: {},
{
label: '批量删除',
name: 'GroupPointDelete',
@ -355,11 +436,17 @@ export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
dynamicDisabled: (data: any) => {
return data.list.length === 0;
},
dynamicParams: { ids: 'id[]' },
dynamicParams: isCarbon
? {
deviceInfoCodeList: 'id[]',
}
: {
ids: 'id[]',
},
confirm: true,
isReload: true,
isClearCheck: true,
api: group.delComputeList,
api: isCarbon ? group.deleteCarbonDevice : group.delComputeList,
},
{
label: '批量导出',
@ -425,18 +512,39 @@ export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
},
],
scroll: { x: 1400 },
columns: tableCalKeyMap,
columns: isCarbon ? tableCarbonKeyMap : tableCalKeyMap,
columnActions: {
title: '操作',
actions: [
{
label: '关联因子',
name: 'SetFactor',
dynamicDisabled: (record) => {
// 这里根据record的某个字段值判断是否禁用删除按钮
return record.id < 0;
},
handle: (row) => {
setFactorRef.value.toggle([row.id]);
},
},
{
label: '删除',
name: 'GroupPointDelete',
dynamicParams: { ids: 'id[]' },
dynamicDisabled: (record) => {
// 这里根据record的某个字段值判断是否禁用删除按钮
return record.id < 0;
},
dynamicParams: isCarbon
? {
deviceInfoCodeList: 'id[]',
}
: {
ids: 'id[]',
},
confirm: true,
isReload: true,
isClearCheck: true,
api: group.delComputeList,
api: isCarbon ? group.deleteCarbonDevice : group.delComputeList,
},
],
},
@ -522,7 +630,338 @@ export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
},
],
},
// pagination: { pageSizeOptions: false },
pagination: isCarbon ? false : true,
rowKey: 'id',
rowSelection: { checkStrictly: false },
};
};
export const editCarbonEquipmentConfig = (orgId) => {
return ref({
title: '设备信息',
api: device.queryDevicePage,
params: { orgId },
treeConfig: {
header: {
icon: 'deviceType',
title: '设备类别',
},
params: { orgId },
dynamicParams: { deviceCode: 'code' },
defaultExpandAll: true,
api: device.queryDeviceTree,
fieldNames: { title: 'deviceType', key: 'code' },
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: 'deviceType',
label: '设备名称',
component: 'NsInput',
autoSubmit: true,
componentProps: {
placeholder: '请输入设备类型',
},
},
],
},
},
// rowSelection: null,
rowSelection: true,
// scroll: { x: 2000 },
columns: [
{
title: '设备名称',
dataIndex: 'deviceName',
},
{
title: '设备型号',
dataIndex: 'deviceModel',
},
{
title: 'SN码',
dataIndex: 'snCode',
textNumber: 5,
textEllipsis: true,
},
{
title: '设备一级区域',
dataIndex: 'device1Area',
textWidth: 88,
// width: 130,
textEllipsis: true,
},
{
title: '设备二级区域',
dataIndex: 'device2Area',
textWidth: 88,
// width: 130,
textEllipsis: true,
},
{
title: '设备详细位置',
dataIndex: 'deviceAddress',
textNumber: 5,
textEllipsis: true,
},
],
formConfig: {
schemas: [
{
field: 'areas',
label: '设备区域',
component: 'NsCascader',
format: (record) => {
console.log(record);
return record?.reduce(
(pre, cur) => {
const len = cur?.length - 1;
pre[len].push(cur[len]);
return pre;
},
[[], []],
);
},
fieldMap: ['area1', 'area2'],
componentProps: {
placeholder: '请选择设备区域',
multiple: true,
loadData: (selectedOptions, options) => {
const targetOption = selectedOptions[selectedOptions.length - 1];
if (!selectedOptions.length) {
http.post(device.dropArea, { orgId, filterField: 'DEVICE_AREA' }).then((res) => {
options.value = res.data?.map((item) => {
return { label: item, value: item, children: [], isLeaf: false };
});
});
}
const value = targetOption?.value;
if (targetOption) {
targetOption.loading = true;
http
.post(device.dropArea, { device1Area: value, orgId, filterField: 'DEVICE_AREA' })
.then((res) => {
targetOption.loading = false;
targetOption.children = res.data?.map((item) => {
return { label: item, value: item, children: [], isLeaf: true };
});
});
}
},
},
},
{
field: 'deviceName',
label: '设备名称',
component: 'NsSelectApi',
componentProps: {
placeholder: '请选择设备名称',
api: (params) => {
return http.post(device.dropArea, params).then((res) => {
const result = res.data?.reduce((pre, cur) => {
!pre.includes(cur.deviceName) && pre.push(cur.deviceName);
return pre;
}, []);
return { data: result };
});
},
resultField: 'data',
params: { orgId, filterField: 'DEVICE_NAME_FACTORY' },
// labelField: 'deviceName',
// valueField: 'deviceName',
filterOption: (input: string, option: any) => {
return option.deviceName?.toLowerCase().indexOf(input.toLowerCase()) >= 0;
},
showSearch: true,
immediate: true,
dropdownReload: true,
allowClear: true,
},
},
],
params: {},
},
// pagination: { pageSizeOptions: false },
rowKey: 'deviceInfoCode',
});
};
export const setFactorConfig = (orgId) => {
return ref({
title: '排放因子库',
// api: carbonEmissionFactorLibrary.getTableList,
api: quickCalculation.queryCarbonEmissionPage,
params: { orgId, pageNum: 1, pageSize: 9999 },
treeConfig: {
header: {
icon: 'deviceType',
title: '因子分类',
},
params: { orgId },
dynamicParams: { energyType: 'id' },
defaultExpandAll: true,
// api: carbonEmissionFactorLibrary.getCarbonFactorTree,
api: quickCalculation.carbonQuickTree,
fieldNames: { title: 'energyType', key: 'id' },
formConfig: {
schemas: [
{
field: 'deviceType',
label: '设备名称',
component: 'NsInput',
autoSubmit: true,
componentProps: {
placeholder: '请输入关键字',
},
},
],
},
},
// rowSelection: null,
rowSelection: { type: 'radio' },
// scroll: { x: 2000 },
columns: [
{
title: '序号',
textNumber: 2,
dataIndex: 'address',
customRender: (text: any) => {
return text.index + 1;
},
},
{
title: '因子值',
dataIndex: 'emissionFactors',
textNumber: 3,
},
{
title: '计量单位',
dataIndex: 'carbonEmissionSuffix',
textNumber: 4,
textEllipsis: true,
},
{
title: '更新时间',
dataIndex: 'updateTime',
textWidth: 88,
// width: 130,
textEllipsis: true,
},
{
title: '启用时间',
dataIndex: 'startTime',
textWidth: 88,
// width: 130,
textEllipsis: true,
},
{
title: '结束时间',
dataIndex: 'endTime',
textNumber: 5,
textEllipsis: true,
},
{
title: '数据来源',
dataIndex: 'dataSources',
textNumber: 5,
textEllipsis: true,
},
],
// formConfig: {
// schemas: [
// {
// field: 'areas',
// label: '设备区域',
// component: 'NsCascader',
// format: (record) => {
// console.log(record);
// return record?.reduce(
// (pre, cur) => {
// const len = cur?.length - 1;
// pre[len].push(cur[len]);
// return pre;
// },
// [[], []],
// );
// },
// fieldMap: ['area1', 'area2'],
// componentProps: {
// placeholder: '请选择设备区域',
// multiple: true,
// loadData: (selectedOptions, options) => {
// const targetOption = selectedOptions[selectedOptions.length - 1];
// if (!selectedOptions.length) {
// http.post(device.dropArea, { orgId, filterField: 'DEVICE_AREA' }).then((res) => {
// options.value = res.data?.map((item) => {
// return { label: item, value: item, children: [], isLeaf: false };
// });
// });
// }
// const value = targetOption?.value;
// if (targetOption) {
// targetOption.loading = true;
// http
// .post(device.dropArea, { device1Area: value, orgId, filterField: 'DEVICE_AREA' })
// .then((res) => {
// targetOption.loading = false;
// targetOption.children = res.data?.map((item) => {
// return { label: item, value: item, children: [], isLeaf: true };
// });
// });
// }
// },
// },
// },
// {
// field: 'deviceName',
// label: '设备名称',
// component: 'NsSelectApi',
// componentProps: {
// placeholder: '请选择设备名称',
// api: (params) => {
// return http.post(device.dropArea, params).then((res) => {
// const result = res.data?.reduce((pre, cur) => {
// !pre.includes(cur.deviceName) && pre.push(cur.deviceName);
// return pre;
// }, []);
// return { data: result };
// });
// },
// resultField: 'data',
// params: { orgId, filterField: 'DEVICE_NAME_FACTORY' },
// // labelField: 'deviceName',
// // valueField: 'deviceName',
// filterOption: (input: string, option: any) => {
// return option.deviceName?.toLowerCase().indexOf(input.toLowerCase()) >= 0;
// },
// showSearch: true,
// immediate: true,
// dropdownReload: true,
// allowClear: true,
// },
// },
// ],
// params: {},
// },
// pagination: { pageSizeOptions: false },
rowKey: 'id',
});
};

123
hx-ai-intelligent/src/view/equipmentManage/group/editCarbonEquipment.vue

@ -0,0 +1,123 @@
<template>
<a-modal
v-model:visible="visible"
width="60%"
class="custom-class"
title="添加设备"
destroyOnClose
@ok="btnClick"
:cancel="() => (visible = false)"
placement="right">
<template #header>
<div class="custom-header">
<!-- 这里可以放置任何你想要的内容或组件 -->
<h2>自定义标题</h2>
</div>
</template>
<!-- <template #header>
<div class="modal-header">
<span>Modal Title</span>
<a-select placeholder="Select an option" style="width: 150px">
<a-select-option value="option1">Option 1</a-select-option>
<a-select-option value="option2">Option 2</a-select-option>
<a-select-option value="option3">Option 3</a-select-option>
</a-select>
</div>
</template> -->
<div class="custom-select-wrapper">
<a-select
placeholder="请选择"
style="width: 200px"
:options="linkList"
:field-names="{ label: 'orgName', value: 'orgId' }"
@change="handleChange" />
</div>
<div class="drawerContainer">
<ns-view-list-table v-bind="config" ref="carbonEquipment" style="height: 500px" :key="key" />
</div>
</a-modal>
</template>
<script lang="ts" setup>
import { editCarbonEquipmentConfig } from './config';
import { computed, nextTick, ref } from 'vue';
import { NsMessage } from '/nerv-lib/saas';
import { http } from '/nerv-lib/util';
import { group, device } from '/@/api/deviceManage';
const orgId = ref('');
const key = ref(Date.now());
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
// const selectOrgId = ref(orgId.value);
const linkList = JSON.parse(sessionStorage.getItem('LINKLIST')!);
let config = editCarbonEquipmentConfig(orgId.value);
const visible = ref(false);
const carbonEquipment = ref();
// defineOptions({
// name: 'LedgerIndex', // name
// });
const handleChange = (value: string) => {
// selectOrgId.value = value;
config = editCarbonEquipmentConfig(value);
debugger;
key.value = Date.now();
// carbonEquipment.value?.nsTableRef.reload();
// carbonEquipment.value?.nsTableRef.treeReload();
};
const props = defineProps({ params: Object });
const emit = defineEmits(['sure']);
const toggle = () => {
visible.value = !visible.value;
// clearData();
// visible.value && getData(currentId.value);
};
const btnClick = () => {
let selectedRowKeys = carbonEquipment.value?.nsTableRef.tableState.selectedRowKeys;
if (!selectedRowKeys || selectedRowKeys.lenght == 0) {
NsMessage.warn('请选择设备');
return;
}
if (!props.params?.hxDeviceGroupId) {
NsMessage.warn('请选择分组');
return;
}
let params = [];
for (let i = 0; i < selectedRowKeys.length; i++) {
params.push({
orgId: props.params?.orgId,
groupId: props.params?.hxDeviceGroupId,
deviceInfoCode: selectedRowKeys[i],
});
}
http.post(group.addCarbonDevice, params).then(() => {
emit('sure');
NsMessage.success('操作成功');
toggle();
});
};
defineExpose({
toggle,
});
</script>
<style lang="less" scoped>
:deep(.ns-table-search),
:deep(.ns-part-tree),
:deep(.ns-table-main) {
box-shadow: @ns-content-box-shadow;
}
.drawerContainer {
height: 100%;
display: flex;
justify-content: space-between;
}
.custom-select-wrapper {
position: absolute;
top: 10px; /* Adjust based on your modal's positioning */
right: 50px; /* Adjust based on your modal's positioning */
// z-index: 1050; /* Ensure it's above the modal's backdrop */
}
</style>

56
hx-ai-intelligent/src/view/equipmentManage/group/index.vue

@ -4,6 +4,8 @@
<editCalDrawer ref="editDrawerCalRef" :params="defaultParams" @sure="handleOk" />
<editGroup ref="editGroupRef" :params="defaultParams" @sure="handleOk" />
<editFormula ref="editFormulaRef" :params="defaultParams" @sure="handleOk" />
<editCarbonEquipment ref="editCarbonEquipmentRef" :params="defaultParams" @sure="handleOk" />
<setFactor ref="setFactorRef" :params="defaultParams" @sure="handleOk" />
<NsModalFrom ref="modalFormRef" v-bind="nsModalFormConfig" />
<div class="groupContainer">
@ -41,7 +43,24 @@
</ns-tree-api>
</div>
<ns-view-list-table v-show="defaultType" class="table" v-bind="config" ref="tableRef" />
<ns-view-list-table v-show="!defaultType" class="table" v-bind="configCal" ref="tableCalRef" />
<ns-view-list-table
v-show="!defaultType && !isCarbon"
class="table"
v-bind="configCal"
ref="tableCalRef" />
<ns-view-list-table
v-show="!defaultType && isCarbon"
class="table"
v-bind="configCarbon"
ref="tableCalRef">
<!-- <template #bodyCell="{ column, record }">
<template v-if="column.title === '操作'">
<a-button type="link" @click="setStandard(record)" v-if="record.id != selectedKey[0]"
>设为目标值</a-button
>
</template>
</template> -->
</ns-view-list-table>
</div>
</template>
<script lang="ts" setup>
@ -52,6 +71,9 @@
import editCalDrawer from './editCal.vue';
import editGroup from './editGroup.vue';
import editFormula from './editFormula.vue';
import editCarbonEquipment from './editCarbonEquipment.vue';
import setFactor from './setFactor.vue';
import { NsMessage, NsModal } from '/nerv-lib/component';
import NsModalFrom from '/@/components/ns-modal-form.vue';
import { group } from '/@/api/deviceManage';
@ -68,8 +90,12 @@
const editDrawerCalRef = ref();
const editGroupRef = ref();
const editFormulaRef = ref();
const editCarbonEquipmentRef = ref();
const setFactorRef = ref();
const treeRef = ref();
const defaultType = ref(true);
const isCarbon = ref(true);
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
const defaultParams = ref({
orgId: result,
@ -79,7 +105,26 @@
});
const config = tableConfig(editDrawerRef, editGroupRef, editFormulaRef, defaultParams);
const configCal = tableConfigCal(editDrawerCalRef, editGroupRef, editFormulaRef, defaultParams);
const configCal = tableConfigCal(
editDrawerCalRef,
editGroupRef,
editFormulaRef,
defaultParams,
false,
editCarbonEquipmentRef,
setFactorRef,
);
const configCarbon = tableConfigCal(
editDrawerCalRef,
editGroupRef,
editFormulaRef,
defaultParams,
true,
editCarbonEquipmentRef,
setFactorRef,
);
const tConfig = treeConfig(result);
const nsModalFormConfig = ref({
api: group.creatOrUpdate,
@ -120,7 +165,6 @@
modalFormRef.value?.toggle();
};
const moveNode = (data, type: opType) => {
debugger
const flag = type === 'up';
http.post(group.move, { ...data, isUp: flag }).then(() => {
treeRef.value?.treeReload();
@ -185,6 +229,12 @@
defaultType.value
? tableRef.value?.nsTableRef.reload()
: tableCalRef.value?.nsTableRef.reload();
if (energyType == 'CARBON_EMISSIONS') {
isCarbon.value = true;
} else {
isCarbon.value = false;
}
};
const handleOk = () => {

77
hx-ai-intelligent/src/view/equipmentManage/group/setFactor.vue

@ -0,0 +1,77 @@
<template>
<a-modal
v-model:visible="visible"
width="60%"
class="custom-class"
title="关联因子值"
destroyOnClose
@ok="btnClick"
:cancel="() => (visible = false)"
placement="right">
<div class="drawerContainer">
<ns-view-list-table v-bind="config" ref="setFactorRef" style="height: 500px" />
</div>
</a-modal>
</template>
<script lang="ts" setup>
import { setFactorConfig } from './config';
import { computed, nextTick, ref } from 'vue';
import { NsMessage } from '/nerv-lib/saas';
import { http } from '/nerv-lib/util';
import { group, device } from '/@/api/deviceManage';
const orgId = ref('');
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
orgId.value = result;
const config = setFactorConfig(orgId.value);
const visible = ref(false);
const setFactorRef = ref();
const ids = ref();
// defineOptions({
// name: 'LedgerIndex', // name
// });
const props = defineProps({ params: Object });
const emit = defineEmits(['sure']);
const toggle = (idlist) => {
ids.value = idlist;
visible.value = !visible.value;
// clearData();
// visible.value && getData(currentId.value);
};
const btnClick = () => {
let selectedRowKeys = setFactorRef.value?.nsTableRef.tableState.selectedRowKeys;
if (!selectedRowKeys) {
NsMessage.warn('请选择因子');
return;
}
if (!ids.value) {
NsMessage.warn('请选择分组');
return;
}
http
.post(group.updateCarbonFactor, {
deviceInfoCodeList: ids.value,
factorId: selectedRowKeys[0],
})
.then(() => {
emit('sure');
NsMessage.success('操作成功');
toggle([]);
});
};
defineExpose({
toggle,
});
</script>
<style lang="less" scoped>
:deep(.ns-table-search),
:deep(.ns-part-tree),
:deep(.ns-table-main) {
box-shadow: @ns-content-box-shadow;
}
.drawerContainer {
height: 100%;
display: flex;
justify-content: space-between;
}
</style>
Loading…
Cancel
Save