fix: 修改同项目登录信息污染

This commit is contained in:
xuziqiang
2024-07-11 15:53:41 +08:00
parent 4d49ef4e42
commit 6137aaa4b6
19 changed files with 188 additions and 116 deletions

View File

@@ -135,7 +135,7 @@ import { log } from 'node:console';
const casData = ref([]);
const treeData = ref([]);
const userAuthList = ref([]);
const orgId = JSON.parse(sessionStorage.getItem('userInfo')).orgId;
const orgId = JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)).orgId;
const dynamicDisabled = computed(() => {
return formRef.value?.validateResult && userAuthList.value?.length;
});

View File

@@ -104,7 +104,7 @@
name: 'EnergyConsumption', // 与页面路由name一致缓存才可生效
});
const orgId = JSON.parse(sessionStorage.getItem('userInfo')).orgId;
const orgId = JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)).orgId;
const fetch = (api, params = { orgId }) => {
return http.post(api, params);
};

View File

@@ -4,10 +4,13 @@ import { http } from '/nerv-lib/util';
import { ref } from 'vue';
import { group } from '/@/api/deviceManage';
import { dict } from '/@/api';
const tableKeyMap = [
import { origanizemanage } from '/@/api/origanizemanage';
const tableCalKeyMap = [
{
title: '来源企业',
dataIndex: 'id',
dataIndex: 'orgName',
// textEllipsis: true,
// textNumber: 4,
},
{
title: '设备id',
@@ -32,20 +35,18 @@ const tableKeyMap = [
dataIndex: 'position',
},
];
const tableCalKeyMap = [
const tableKeyMap = [
{
title: '来源企业',
dataIndex: 'id',
dataIndex: 'orgName',
},
{
title: '节点编号',
dataIndex: 'deviceName',
textNumber: 8,
textEllipsis: true,
dataIndex: 'pointNum',
},
{
title: '节点路径',
dataIndex: 'position',
dataIndex: 'routeName',
},
];
const doWnload = (url) => {
@@ -125,6 +126,26 @@ export const formSchema = [
],
},
];
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 treeConfig = (orgId) => {
return {
defaultExpandAll: true,
@@ -133,15 +154,8 @@ export const treeConfig = (orgId) => {
title: '能耗分组',
},
params: { orgId },
showLine: { showLeafIcon: false },
api: group.queryDeviceGroupTree,
// api: () => {
// return new Promise((resolve) => {
// setTimeout(() => {
// resolve({ data: [{ title: '全部', key: 'all', children: data.data }] });
// }, 100);
// });
// },
transform: (data) => {
return [{ pointName: '全部', id: 'all', selectable: false, children: data }];
},
@@ -176,12 +190,11 @@ export const treeConfig = (orgId) => {
},
};
};
export const tableConfig = (el, elGroup, elFormula) => {
export const tableConfig = (el, elGroup, elFormula, defaultParams) => {
return {
title: '点位信息',
// api: '/carbon_emission/device/getDeviceList',
value: mockData.value,
api: group.queryGroupPage,
params: defaultParams.value,
headerActions: [
{
label: '编辑',
@@ -193,7 +206,7 @@ export const tableConfig = (el, elGroup, elFormula) => {
},
{
label: '批量删除',
name: 'groupTemDownload',
name: 'groupBatDelete',
type: 'primary',
dynamicDisabled: (data: any) => {
return data.list.length === 0;
@@ -244,7 +257,7 @@ export const tableConfig = (el, elGroup, elFormula) => {
{
label: '批量分组',
name: 'groupTemDownload',
name: 'groupBatGroup',
type: 'primary',
handle: () => {
elGroup.value.toggle();
@@ -252,7 +265,7 @@ export const tableConfig = (el, elGroup, elFormula) => {
},
{
label: '公式编辑',
name: 'groupTemDownload',
name: 'groupFormulaEdit',
type: 'primary',
handle: () => {
elFormula.value.toggle();
@@ -265,7 +278,7 @@ export const tableConfig = (el, elGroup, elFormula) => {
actions: [
{
label: '删除',
name: 'FeedBackDetail',
name: 'groupDelete',
dynamicParams: ['uuid', 'appealType'],
confirm: true,
handle: () => {
@@ -341,11 +354,13 @@ export const tableConfig = (el, elGroup, elFormula) => {
};
};
export const tableConfigCal = (el, elGroup, elFormula) => {
export const tableConfigCal = (el, elGroup, elFormula, defaultParams) => {
// 分组节点
return {
title: '点位信息',
// api: '/carbon_emission/device/getDeviceList',
value: mockData.value,
params: defaultParams,
headerActions: [
{
@@ -413,12 +428,12 @@ export const tableConfigCal = (el, elGroup, elFormula) => {
actions: [
{
label: '删除',
name: 'FeedBackDetail',
dynamicParams: ['uuid', 'appealType'],
name: 'groupDelete',
dynamicParams: 'id',
confirm: true,
handle: () => {
mockData.value.splice(0, 1);
},
isReload: true,
isClearCheck: true,
api: group.delGroupList,
},
],
},

View File

@@ -1,53 +1,72 @@
<template>
<ns-drawer
v-model:visible="visible"
size="large"
:width="800"
class="custom-class"
title="编辑"
title=" "
destroyOnClose
:ok="btnClick"
:cancel="() => (visible = false)"
placement="right">
<div class="drawerContainer">
<ns-tree-api v-bind="treeConfig" @select="treeSelect" />
<ns-tree-api v-bind="config" @select="treeSelect" />
<a-transfer
v-model:target-keys="targetKeys"
:data-source="mockData"
:data-source="dataSource"
style="height: 100%; width: 66%"
oneWay
:listStyle="listStyle"
show-search
:render="(item) => item.title"
:filter-option="filterOption"
:render="(item) => item.title" />
@change="handleChange" />
</div>
</ns-drawer>
</template>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { computed, onMounted, ref } from 'vue';
import { NsMessage } from '/nerv-lib/component';
import { treeConfig } from './config';
const visible = ref(false);
const mockData = ref([]);
import { editTreeConfig } from './config';
import { group } from '/@/api/deviceManage';
import { http } from '/nerv-lib/util/http';
const props = defineProps({ params: Object });
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
const config = computed(() => {
return editTreeConfig(result);
});
const visible = ref(true);
const dataSource = ref([]);
const listStyle = {
height: '100%',
width: '100%',
};
const targetKeys = ref<string[]>([]);
const targetKeys = ref([]);
const currentId = ref('');
const toggle = () => {
visible.value = !visible.value;
};
const handleChange = (nextTargetKeys: string[], direction: string, moveKeys: string[]) => {
console.log('targetKeys: ', nextTargetKeys);
console.log('direction: ', direction);
console.log('moveKeys: ', moveKeys);
};
onMounted(() => {
getMock('上海公司');
});
const filterOption = (inputValue: string, option: MockData) => {
return option.description.indexOf(inputValue) > -1;
const filterOption = (inputValue: string, option: any) => {
return option?.title.toLowerCase().indexOf(inputValue.toLowerCase()) > -1;
};
const btnClick = () => {
visible.value = false;
NsMessage.success('编辑成功');
// visible.value = false;
http
.post(group.saveGroupList, {
...props.params,
saveOrgId: currentId.value,
saveGroupIds: targetKeys.value,
})
.then(() => {
NsMessage.success('操作成功');
});
};
function treeSelect(
selectedKeys: never[],
@@ -62,26 +81,27 @@
const {
dataRef: { title },
} = e.node;
getMock(title);
currentId.value = selectedKeys[0];
getData(currentId.value);
}
const getMock = (company) => {
const keys = [];
const mData = [];
for (let i = 0; i < 60; i++) {
const data = {
key: i.toString(),
title: `A00${i + 1}总用电量(${company})`,
description: `description of content${i + 1}`,
chosen: Math.random() * 2 > 1,
};
if (data.chosen) {
keys.push(data.key);
}
mData.push(data);
}
mockData.value = mData;
targetKeys.value = keys;
const getData = (id) => {
http
.post(group.queryEditGroup, {
orgId: result,
queryOrgId: id,
...props.params,
// energyType: props.params.energyType,
})
.then((res) => {
dataSource.value = res.data.groups?.map((item) => {
item['title'] = item.pointName;
item['key'] = item.id.toString();
return item;
});
targetKeys.value = res.data.linkGroups.map((item) => {
return item.id;
});
});
};
defineExpose({
toggle,

View File

@@ -1,5 +1,5 @@
<template>
<editDrawer ref="editDrawerRef" />
<editDrawer ref="editDrawerRef" :params="defaultParams" />
<editGroup ref="editGroupRef" />
<editFormula ref="editFormulaRef" />
@@ -34,8 +34,8 @@
</template>
</ns-tree-api>
</div>
<ns-view-list-table v-show="defaultType" class="table" v-bind="config" />
<ns-view-list-table v-show="!defaultType" class="table" v-bind="configCal" />
<ns-view-list-table v-if="defaultType" class="table" v-bind="config" ref="tableRef" />
<ns-view-list-table v-else class="table" v-bind="configCal" ref="tableCalRef" />
</div>
</template>
<script lang="ts" setup>
@@ -53,14 +53,18 @@
type opType = 'up' | 'down';
const { getParams } = useParams();
const modalFormRef = ref();
const tableRef = ref();
const tableCalRef = ref();
const editDrawerRef = ref();
const editGroupRef = ref();
const editFormulaRef = ref();
const treeRef = ref();
const defaultType = ref(true);
const result = JSON.parse(sessionStorage.getItem('ORGID')!);
const config = tableConfig(editDrawerRef, editGroupRef, editFormulaRef);
const configCal = tableConfigCal(editDrawerRef, editGroupRef, editFormulaRef);
const defaultParams = ref({ orgId: result, energyType: '用电量', id: 19 });
const config = tableConfig(editDrawerRef, editGroupRef, editFormulaRef, defaultParams);
const configCal = tableConfigCal(editDrawerRef, editGroupRef, editFormulaRef, defaultParams);
const tConfig = treeConfig(result);
const nsModalFormConfig = ref({
api: group.creatOrUpdate,
@@ -150,8 +154,17 @@
{ title: '下移', key: 'moveDown', func: (data) => moveNode(data, 'down') },
{ title: '删除', key: 'deleteNode', func: (data) => deleteNode(data) },
];
const handleSelect = () => {
defaultType.value = !defaultType.value;
const handleSelect = (key, record) => {
console.log(record);
const {
node: { pointType, id, energyType },
} = record;
defaultParams.value.energyType = energyType;
defaultParams.value.id = id;
defaultType.value = pointType === '分组节点';
defaultType.value
? tableRef.value?.nsTableRef.reload()
: tableCalRef.value?.nsTableRef.reload();
};
</script>
<style lang="less" scoped>

View File

@@ -194,7 +194,7 @@
const selectRoleRef = ref();
const formSchema = formConfig(disabled as any);
const formSchema2 = formConfig2(roleDisabled as any);
const { orgName, projectId, orgId } = JSON.parse(sessionStorage.getItem('userInfo'));
const { orgName, projectId, orgId } = JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH));
// const orgId = JSON.parse(sessionStorage.getItem('ORGID'));
const roleTreeData = ref([]);
const rolePermissionTreeData = ref([]);

View File

@@ -89,7 +89,7 @@ export const formConfig = (disabled) => {
label: '组织关系',
field: 'orgName',
component: 'NsInput',
defaultValue: JSON.parse(sessionStorage.getItem('userInfo')).orgName,
defaultValue: JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)).orgName,
componentProps: {
disabled: true,
maxLength: 30,

View File

@@ -104,7 +104,7 @@
const treeDataDept = ref([]);
const treeData2 = ref([]);
const userAuthList = ref([]);
// const orgId = JSON.parse(sessionStorage.getItem('userInfo')).orgId;
// const orgId = JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)).orgId;
const orgId = JSON.parse(sessionStorage.getItem('ORGID')!);
const orgTreeConfig = ref({
selectedKeys: ['0-0'],
@@ -291,7 +291,7 @@
setTimeout(() => {
formData.value = {
sex: '男',
orgName: JSON.parse(sessionStorage.getItem('userInfo')).orgName,
orgName: JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)).orgName,
};
userAuthList.value.splice(0);
});