diff --git a/hx-ai-intelligent/public/asset/file/emissionSource.xlsx b/hx-ai-intelligent/public/asset/file/emissionSource.xlsx index 306414b..57d82b0 100644 Binary files a/hx-ai-intelligent/public/asset/file/emissionSource.xlsx and b/hx-ai-intelligent/public/asset/file/emissionSource.xlsx differ diff --git a/hx-ai-intelligent/public/asset/file/energyConsumption.xlsx b/hx-ai-intelligent/public/asset/file/energyConsumption.xlsx index a9eae6e..5edee96 100644 Binary files a/hx-ai-intelligent/public/asset/file/energyConsumption.xlsx and b/hx-ai-intelligent/public/asset/file/energyConsumption.xlsx differ diff --git a/hx-ai-intelligent/src/config/app.config.ts b/hx-ai-intelligent/src/config/app.config.ts index 2a80768..41bd1f6 100644 --- a/hx-ai-intelligent/src/config/app.config.ts +++ b/hx-ai-intelligent/src/config/app.config.ts @@ -3,14 +3,19 @@ import { permission } from '/@/api/origanizemanage'; import { appConfigStore } from '/nerv-lib/saas/store/modules/app-config'; import { authorizationService } from '/nerv-base/store/modules/authorization-service'; import { get } from 'lodash-es'; -import { computed, ref, toRef } from 'vue'; +import { computed, ref, toRef} from 'vue'; -const ORGID = sessionStorage.getItem('ORGID') ? Number(sessionStorage.getItem('ORGID')) : ''; -const isAdmin = sessionStorage.getItem('ISADMIN') - ? Boolean(sessionStorage.getItem('ISADMIN')) - : false; -const selectDefaultValue = ref(ORGID); -const selectDefaultDisabled = ref(isAdmin); +import { router } from '/nerv-lib/saas/router'; +import { replyRoutesButton } from '/@/util/dynamicRoutes'; +import { replyDynamRoutesPath } from '/nerv-lib/util/dynamicRoutesss'; +import { useTags } from '/nerv-base/store/modules/tags'; + +const ROLEID = sessionStorage.getItem('ROLEID') ? Number(sessionStorage.getItem('ROLEID')) : ''; +// const isAdmin = sessionStorage.getItem('ISADMIN') +// ? Boolean(sessionStorage.getItem('ISADMIN')) +// : false; +const selectDefaultValue = ref(ROLEID); +// const selectDefaultDisabled = ref(isAdmin); const transform = (data, map) => { return Object.keys(map).reduce((pre, cur) => { pre[cur] = data[map[cur]]; @@ -46,22 +51,25 @@ export const appConfig = { api: '/carbon-smart/user/login/logInInfo', size: 'large', defaultValue: selectDefaultValue, - disabled: selectDefaultDisabled, + disabled:false, + // disabled: selectDefaultDisabled, // autoSelectFirst: true, placeholder: '请选择', - onSelect: async (cur, record) => { - console.log(cur, record); + onSelect: async (cur:any, record:any) => { const configStore = appConfigStore(); const useAuthorization = authorizationService(); sessionStorage.setItem('ORGID', record.orgId); + sessionStorage.setItem('ROLEID', record.roleId); const res = await configStore.userResource({ data: record }); useAuthorization.updateUserResource(res.data); - window.location.reload(); + setTimeout(() => { + window.location.reload(); + }, 200); // value.value = cur; }, - resultField: 'data.linkList', + resultField: 'data.userRoles', labelField: 'orgName', - valueField: 'orgId', + valueField: 'roleId', immediate: true, dropdownReload: true, }, @@ -71,15 +79,33 @@ export const appConfig = { return http.post('/carbon-smart/user/login', { ...params }); }, userResourceApi: (params) => { - const { orgId } = get(params, 'data') || { orgId: '' }; - const finalId = orgId || ORGID; + const { roleId } = get(params, 'data') || { roleId: '' }; + const finalId = roleId || ROLEID; // 解决初始化登录select无初始值的问题 selectDefaultValue.value = finalId; - const userInfo = JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)!); - const ownOrgInfo = userInfo.linkList?.filter(({ orgId: id }) => id === finalId)[0]; - - return http.post('/carbon-smart/user/login/logInPermission', ownOrgInfo).then((res) => { + // const userInfo = JSON.parse(sessionStorage.getItem(import.meta.env.VITE_PUBLIC_PATH)!); + // const ownOrgInfo = userInfo.userRoles?.filter(({ roleId: id }) => id === finalId)[0]; + // return http.post('/carbon-smart/user/login/logInPermission', ownOrgInfo).then((res) => { + // return res; + // }); + // 切换角色时获取新的权限菜单 + return http.post('/carbon-smart/user/login/role/permission/'+finalId).then((res) => { + //切换后重新处理动态菜单数据 + let resetDynamicRouteList = replyRoutesButton(res.data); + sessionStorage.setItem("dynamicRouteList",JSON.stringify(resetDynamicRouteList)); + if(resetDynamicRouteList && resetDynamicRouteList.length>0){ + let addDynamicRoutes = replyDynamRoutesPath(resetDynamicRouteList); + addDynamicRoutes.forEach(item => { + if (item.children && !item.component) { + item.component = () => import('/nerv-lib/saas/view/system/application.vue');//hx-ai-intelligent项目下的首页 + } + router.addRoute(item); + }) + } + //删除所有已经打开的tag标签 + useTags().clearTags(); + router.replace({ name: 'home' }); return res; }); }, @@ -96,16 +122,25 @@ export const appConfig = { linkList: 'linkList', permissionVos: 'permissionVos', adminFlag: 'adminFlag', + userRoles:'userRoles', }); 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; - return { data: { ...trD } }; - }); + // 头部“企业角色”切换暂不需要以下屏蔽的两个参数 + // sessionStorage.setItem('ISADMIN', trD?.adminFlag === '1'); + // selectDefaultDisabled.value = info?.adminFlag === '1'; + if(info.userRoles && info.userRoles.length>0){ + sessionStorage.setItem('ROLEID', info.userRoles[0].roleId); + sessionStorage.setItem('USERROLES', JSON.stringify(info.userRoles)); + selectDefaultValue.value = info.userRoles[0].roleId; + //路由接口数据暂时组装 + let getRoutesList = replyRoutesButton(info.userRoles[0].routes); + sessionStorage.setItem("dynamicRouteList",JSON.stringify(getRoutesList)) + sessionStorage.setItem("isRefrech",'1') + } + return { data: { ...trD } }; + }); }, - useHistoryTag: false, // 修改密码配置 updatePassWordInfo: { diff --git a/hx-ai-intelligent/src/router/dynamicRoute.ts b/hx-ai-intelligent/src/router/dynamicRoute.ts new file mode 100644 index 0000000..99f34a3 --- /dev/null +++ b/hx-ai-intelligent/src/router/dynamicRoute.ts @@ -0,0 +1,44 @@ +const sessionStoreRoute = sessionStorage.getItem("dynamicRouteList"); +let getDynamicRouteList = sessionStoreRoute?JSON.parse(sessionStoreRoute):[]; +let dynamicRoute:any = []; +// getDynamicRouteList.map(itemRouter => { +// if(itemRouter.children && itemRouter.children.length > 0){ +// itemRouter.children.map(childRoute => { +// let modulePath0 = childRoute.component; +// childRoute.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)();///nerv-lib/saas/view/ +// if(childRoute.children && childRoute.children.length > 0){ +// childRoute.children.map(child2=>{ +// let modulePath = child2.component; +// child2.component = () => new Function(`return import('/@/view/${modulePath}')`)();///@/view/ +// }) +// }else{//如没有下一级菜单代表是一级,重新处理一级菜单路由 +// childRoute.component = () => new Function(`return import('/@/view/${modulePath0}')`)(); +// } +// }) +// } +// dynamicRoute.push(itemRouter) +// }) +getDynamicRouteList.forEach(itemRouter => { + if (itemRouter.children && itemRouter.children.length > 0) { + itemRouter.children.forEach(childRoute => { + const modulePath0 = childRoute.component; + // 修改 component 属性 + // childRoute.component = () => import(`/nerv-lib/saas/view/${modulePath0}`).then(mod => mod.default); + childRoute.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)(); + + if (childRoute.children && childRoute.children.length > 0) { + childRoute.children.forEach(child2 => { + const modulePath = child2.component; + // 修改 component 属性 + // child2.component = /* @vite-ignore */ () => import(`/@/view/${modulePath}`).then(mod => mod.default); + child2.component = () => new Function(`return import('/@/view/${modulePath}')`)(); + }); + } else { // 如果没有下一级菜单代表是一级,重新处理一级菜单路由 + // childRoute.component = /* @vite-ignore */ () => import(`/@/view/${modulePath0}`).then(mod => mod.default); + childRoute.component = () => new Function(`return import('/@/view/${modulePath0}')`)(); + } + }); + } + dynamicRoute.push(itemRouter); +}); +export default dynamicRoute; \ No newline at end of file diff --git a/hx-ai-intelligent/src/util/dynamicRoutes.ts b/hx-ai-intelligent/src/util/dynamicRoutes.ts new file mode 100644 index 0000000..fea4dbb --- /dev/null +++ b/hx-ai-intelligent/src/util/dynamicRoutes.ts @@ -0,0 +1,98 @@ +/***公共方法==>处理动态路由数据 将“按钮”部分的数据追加到meta中*/ +//处理路由按钮,存放在meta中 +export const replyRoutesButton = (data:any) => { + if(!data) return; + return data.map(item => { + if(item.children && item.children.length > 0){ + item.meta.operates = []; + item.children.map(itemChild => { + if(itemChild.type=="3"){ + let operateObj = {title:'',code:''}; + operateObj.title = itemChild.meta.title; + operateObj.code = itemChild.name; + item.meta.operates.push(operateObj); + item.children = item.children.filter(its => its.name != itemChild.name); + } + }) + if(item.meta.operates.length == 0){ + delete item.meta.operates; + } + return { + ...item, + children: replyRoutesButton(item.children), + }; + } + + return item; + }); +}; +// //处理路由compontent路径 +// export const replyRoutesPath = (itemRouter:any) => { +// if (itemRouter.children && itemRouter.children.length > 0) { +// itemRouter.children.forEach(childRoute => { +// const modulePath0 = childRoute.component; +// // 修改 component 属性 +// // childRoute.component = () => import(`/nerv-lib/saas/view/${modulePath0}`).then(mod => mod.default); +// childRoute.component = () => new Function(`return import('/nerv-lib/saas/view/${modulePath0}')`)(); + +// if (childRoute.children && childRoute.children.length > 0) { +// childRoute.children.forEach(child2 => { +// const modulePath = child2.component; +// // 修改 component 属性 +// // child2.component = /* @vite-ignore */ () => import(`/@/view/${modulePath}`).then(mod => mod.default); +// child2.component = () => new Function(`return import('/@/view/${modulePath}')`)(); +// }); +// } else { // 如果没有下一级菜单代表是一级,重新处理一级菜单路由 +// // childRoute.component = /* @vite-ignore */ () => import(`/@/view/${modulePath0}`).then(mod => mod.default); +// childRoute.component = () => new Function(`return import('/@/view/${modulePath0}')`)(); +// } +// }); +// } +// return itemRouter; +// } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hx-ai-intelligent/src/view/carbonEmissionManage/carbonAssets/carbonAssetsDetail/index.vue b/hx-ai-intelligent/src/view/carbonEmissionManage/carbonAssets/carbonAssetsDetail/index.vue index fcc3dab..fe7571b 100644 --- a/hx-ai-intelligent/src/view/carbonEmissionManage/carbonAssets/carbonAssetsDetail/index.vue +++ b/hx-ai-intelligent/src/view/carbonEmissionManage/carbonAssets/carbonAssetsDetail/index.vue @@ -48,7 +48,7 @@ -