import { message } from 'antd' import { config } from '../../config' import { wait } from '../../utils/common' import { httpget, httppost, xyt_httpget2 } from '../../utils/request' import { MenuItem } from '../_' import { apiPaths } from '../_/apipath' import apiurl from '../../service/apiurl' import { store } from '../store' // @ts-ignore import cookie from 'react-cookies' export type LoginUser = { id: number loginName: string name: string roleList: string[] tokenInfo: { tokenValue: string } } export type AuthState = { user: LoginUser | null | -1 menu: MenuItem[] roleObj: any, role: any } export const USER_SESSION_KEY = '__usereinfo__' export function removeLoginInfo() { let keysToKeep = ["checked", "loginNamePwd"]; let keysToRemove = []; // 遍历 localStorage for (let i = 0; i < localStorage.length; i++) { let key: any = localStorage.key(i); if (!keysToKeep.includes(key)) { keysToRemove.push(key); } } for (let i = 0; i < keysToRemove.length; i++) { localStorage.removeItem(keysToRemove[i]); } /*localStorage.removeItem(USER_SESSION_KEY); localStorage.removeItem('TOKEN');*/ // localStorage.clear() sessionStorage.clear() cookie.remove('Admin-Token') } export function setLoginInfo(userInfo: string, token: string) { sessionStorage.setItem(USER_SESSION_KEY, userInfo) localStorage.setItem('TOKEN', token) } export function getUserFromSession(): LoginUser | null { const strUser = sessionStorage.getItem(USER_SESSION_KEY) if (!strUser) { return null } try { const obj: LoginUser = JSON.parse(strUser) if (obj.id && obj.tokenInfo.tokenValue) { return obj } } catch (e) { } return null } export async function regByToken( token: string ): Promise { const result: LoginUser | null = await httppost( apiPaths.auth.registerByToken, { token } ) if (!result) { message.error('登陆失败') return } setLoginInfo(JSON.stringify(result), result.tokenInfo?.tokenValue) return result } //user: string, pw: string, captcha: string /*export async function login(form: { user: string, pw: string }): Promise { const result = await httppost('/shzh/'+store.getState().systemSwitch.address+apiurl.upgramurl.login.authOld, { user: form.user, pw: form.pw, //captcha: form.captcha }); if(result.code === 200){ localStorage.setItem('TOKEN', result.data.token); localStorage.setItem('account', result.data.name); }else{ message.error('登陆失败'); //return; } //setLoginInfo(JSON.stringify(result), result.data.token?.token); return result; }*/ function idgen() { let id = 1 return () => `${id++}` } const handelTreeData = (data: any, id: any) => { if (data.length > 0) { data.forEach((item: any) => { item.id = id() item.title = item.menuName; item.icon = item.icon; if (item.menuType === 'M' && item.children && item.children.length > 0) {//目录 item.redirect = item.path; delete item.path handelTreeData(item.children, id); } if (item.menuType === 'C') {//菜单 item.rule = item.children; delete item.children } }); } } const buildTree = (data: any, parentId: any) => { let tree: any = []; data.forEach((node: any) => { if (node.parentId === parentId) { let children = buildTree(data, node.menuId); if (children.length) { node.children = children; } tree.push(node); } }); return tree; } export function loadRole(data: any) { const roleObj: any = {} const handelTreeData2 = (data: any) => { if (data.length > 0) { data.forEach((item: any) => { if (item.children && item.children.length > 0) { //是目录 handelTreeData2(item.children); } else { //是菜单 roleObj[item.path] = item } }); } } handelTreeData2(data) return roleObj } export async function loadMenu(): Promise { // await wait(200) // const { code, data } = await xyt_httpget2(apiurl.xytlogin.role) // if( code!== 200){ // message.error('获取用户权限失败') // return [] // } // //获取到菜单后遍历 // const id = idgen() // // handelTreeData(data,id) // const tree = buildTree(data,0) // const tree2 = tree?.filter((item:any) =>(item.menuId != "1" && item.menuId != "2" && item.menuId != "3")) // handelTreeData(tree2,id) // return tree2 const id = idgen() return [ { id: id(), title: '水库一张图', path: '/mgr/home', icon: 'jbqk' }, { id: id(), title: '四全', redirect: '/mgr/sq/qfg/zcdjxx', icon: 'fxzb', children: [ { id: id(), title: '全覆盖', redirect: '/mgr/sq/qfg/zcdjxx', children: [ { id: id(), title: '注册登记信息', path: '/mgr/sq/qfg/zcdjxx' }, ] }, { id: id(), title: '全要素', redirect: '/mgr/sq/qys/kqys', children: [ { id: id(), title: '库区要素', path: '/mgr/sq/qys/kqys' }, { id: id(), title: '工程要素', path: '/mgr/sq/qys/gcys' }, { id: id(), title: '下游要素', path: '/mgr/sq/qys/xyys' }, ] }, { id: id(), title: '全周期', redirect: '/mgr/sq/qzq/gcdsj', children: [ { id: id(), title: '工程大事记', path: '/mgr/sq/qzq/gcdsj'}, { id: id(), title: '全周期档案', path: '/mgr/sq/qys/qzqda'}, ] }, { id: id(), title: '全天候', redirect: '/mgr/sq/qth/sksq', children: [ { id: id(), title: '水库水情', path: '/mgr/sq/qth/sksq'}, { id: id(), title: '河道水情', path: '/mgr/sq/qth/hdsq'}, { id: id(), title: '实时雨情', path: '/mgr/sq/qth/ssyq'}, { id: id(), title: '大坝安全监测', path: '/mgr/sq/qth/dbaqjc'}, { id: id(), title: '视频监控', path: '/mgr/sq/qth/spjk'}, ] }, ] }, { id: id(), title: '四制', redirect: '/mgr/sz/gltx/zzjgck', icon: 'jbqk', children: [ { id: id(), title: '管理体系', redirect: '/mgr/sz/gltx/zzjgck', children: [ { id: id(), title: '管理体系', path: '/mgr/sz/gltx/zzjgck', }, { id: id(), title: '责任人管理', path: '/mgr/sz/gltx/zrrgl', } ] }, { id: id(), title: '培训管理', redirect: '/mgr/sz/pxgl/pxjhgl', children: [ { id: id(), title: '培训计划管理', path: '/mgr/sz/pxgl/pxjhgl', }, { id: id(), title: '培训记录管理', path: '/mgr/sz/pxgl/pxjlgl', }, ] }, { id: id(), title: '水政执法', redirect: '/mgr/sz/szzf/ajdj', children: [ { id: id(), title: '案件登记', path: '/mgr/sz/szzf/ajdj', }, { id: id(), title: '案件统计', path: '/mgr/sz/szzf/ajtj', }, { id: id(), title: '处理依据', path: '/mgr/sz/szzf/clyj', } ] }, { id: id(), title: '监督考核', redirect: '/mgr/sz/jdkh/khtj', children: [ { id: id(), title: '考核统计', path: '/mgr/sz/jdkh/khtj', }, { id: id(), title: '考核任务管理', path: '/mgr/sz/jdkh/khrwgl', }, { id: id(), title: '考核问题整改', path: '/mgr/sz/jdkh/khwtzg', }, { id: id(), title: '考核指标管理', path: '/mgr/sz/jdkh/khzbgl', }, { id: id(), title: '考核模板管理', path: '/mgr/sz/jdkh/khmbgl', } ] }, { id: id(), title: '法律法规', path: '/mgr/sz/flfg' }, { id: id(), title: '制度管理', path: '/mgr/sz/zdgl' }, ] }, { id: id(), title: '四预', redirect: '/mgr/sy/fhxzfx', icon: 'fxzb', children: [ { id: id(), title: '防洪形势', path: '/mgr/sy/fhxzfx' }, { id: id(), title: '天气预报', path: '/mgr/sy/tqyb' }, { id: id(), title: '洪水预报', redirect: '/mgr/sy/hsyb/hyybjs', children: [ { id: id(), title: '洪水预报计算', path: '/mgr/sy/hsyb/hyybjs' }, { id: id(), title: '预报方案管理', path: '/mgr/sy/hsyb/ybfagl' }, { id: id(), title: '参数管理', path: '/mgr/sy/hsyb/csgl' }, ] }, { id: id(), title: '防汛预案', path: '/mgr/sy/fxya' }, { id: id(), title: '调度规程', path: '/mgr/sy/ddgc' }, { id: id(), title: '抢险物料', path: '/mgr/sy/qxwl', }, { id: id(), title: '抢险队伍', path: '/mgr/sy/qxdw', }, ], }, { id: id(), title: '四管', redirect: '/mgr/sg/xcxj/xcrw', icon: 'fxzb', children: [ { id: id(), title: '巡查巡检', redirect: '/mgr/sg/xcxj/xcrw', children: [ { id: id(), title: '巡检任务', path: '/mgr/sg/xcxj/xcrw' }, { id: id(), title: '巡检问题处理', path: '/mgr/sg/xcxj/xjwtcl' }, { id: id(), title: '巡检项配置', path: '/mgr/sg/xcxj/xjxpz' }, ] }, { id: id(), title: '安全管理', redirect: '/mgr/sg/aqgl/fxgkqd', children: [ { id: id(), title: '风险管控清单', path: '/mgr/sg/aqgl/fxgkqd' }, { id: id(), title: '安全隐患排查', path: '/mgr/sg/aqgl/aqyhpc' }, { id: id(), title: '安全检查管理', path: '/mgr/sg/aqgl/aqjcgl' }, { id: id(), title: '安全事故登记', path: '/mgr/sg/aqgl/aqsgdj' }, { id: id(), title: '安全鉴定台帐', path: '/mgr/sg/aqgl/aqjdtz' }, { id: id(), title: '除险加固台帐', path: '/mgr/sg/aqgl/cxjgtz' }, ] }, { id: id(), title: '白蚁防治', redirect: '/mgr/sg/byfz/bypc', children: [ { id: id(), title: '白蚁普查', path: '/mgr/sg/byfz/bypc' }, { id: id(), title: '防治宣传', path: '/mgr/sg/byfz/byxc' }, ] }, { id: id(), title: '闸门监控', path: '/mgr/sg/zmjk', }, { id: id(), title: '维修养护', path: '/mgr/sg/wxyh', }, { id: id(), title: '库容管理', path: '/mgr/sg/krgl', }, { id: id(), title: '值班管理', redirect: '/mgr/sg/zbgl/zbb', children: [ { id: id(), title: '值班表', path: '/mgr/sg/zbgl/zbb' }, { id: id(), title: '值班日志', path: '/mgr/sg/zbgl/zbrz' }, ] }, { id: id(), title: '报表管理', redirect: '/mgr/sg/btbb/sdjyrbb', children: [ { id: id(), title: '时段降雨日报表', path: '/mgr/sg/btbb/sdjyrbb' }, { id: id(), title: '日降雨量年报表', path: '/mgr/sg/btbb/rjylnbb' }, { id: id(), title: '时段水位日报表', path: '/mgr/sg/btbb/sdswbb' }, { id: id(), title: '日均水位年报表', path: '/mgr/sg/btbb/rjswbb' }, ] }, { id: id(), title: '告警管理', redirect: '/mgr/sg/gjgl/aigj', children: [ { id: id(), title: 'AI告警', path: '/mgr/sg/gjgl/aigj' }, { id: id(), title: '广播预警', path: '/mgr/sg/gjgl/gbyj' }, ] }, ], }, { id: id(), title: '工程安全监测', redirect: '/mgr/gcaqjc/gcaqyj/bzt', icon: 'fxzb', children: [ { id: id(), title: '布置图', path: '/mgr/gcaqjc/gcaqyj/bzt', }, { id: id(), title: '工程安全分析', redirect: '/mgr/gcaqjc/gcaqfx/jrx', children: [ { id: id(), title: '浸润线', path: '/mgr/gcaqjc/gcaqfx/jrx' }, ] }, { id: id(), title: '工程安全预警', redirect: '/mgr/gcaqjc/gcaqyj/yhyj', children: [ { id: id(), title: '隐患预警', path: '/mgr/gcaqjc/gcaqyj/yhyj' }, { id: id(), title: '预警规则配置', path: '/mgr/gcaqjc/gcaqyj/yjgzpz' }, ] }, { id: id(), title: '数据统计查询', redirect: '/mgr/gcaqjc/sjtjcx/czcx', children: [ { id: id(), title: '测值查询', path: '/mgr/gcaqjc/sjtjcx/czcx' }, { id: id(), title: '渗压监测', path: '/mgr/gcaqjc/sjtjcx/syjx' }, { id: id(), title: '渗流监测 ', path: '/mgr/gcaqjc/sjtjcx/sljx' }, { id: id(), title: '位移监测 ', path: '/mgr/gcaqjc/sjtjcx/wyjx' }, { id: id(), title: '年度渗压统计表', path: '/mgr/gcaqjc/sjtjcx/ndsytjb' }, { id: id(), title: '年度渗流统计表', path: '/mgr/gcaqjc/sjtjcx/ndsltjb' }, ] }, ], }, // { id: id(), title: '基本情况', path: '/mgr/home', icon: 'jbqk' }, // { // id: id(), // title: '防汛调度', // redirect: '/mgr/fxzb/fhxs', // icon: 'fxzb', // children: [ // { id: id(), title: '防洪形势', path: '/mgr/fxzb/fhxs'}, // { id: id(), title: '天气预报', path: '/mgr/fxzb/tqyb'}, // { // id: id(), title: '洪水预报', redirect: '/mgr/fxzb/hsyb/hyybjs', // children: [ // { id: id(), title: '洪水预报计算', path: '/mgr/fxzb/hsyb/hyybjs' }, // { id: id(), title: '预报方案管理', path: '/mgr/fxzb/hsyb/ybfagl' }, // { id: id(), title: '参数管理', path: '/mgr/fxzb/hsyb/csgl' }, // ] // }, // { id: id(), title: '调度规程', path: '/mgr/fxzb/ddgc'}, // { id: id(), title: '防汛预案', path: '/mgr/fxzb/fxya'}, // { // id: id(), // title: '抢险物料', // path: '/mgr/fxzb/qxwl', // }, // { // id: id(), // title: '抢险队伍', // path: '/mgr/fxzb/qxdw', // }, // ], // }, // { // id: id(), // title: '工程安全监测', // redirect: '/mgr/gcaqjc/gcaqyj/bzt', // icon: 'fxzb', // children: [ // { id: id(), title: '布置图', path: '/mgr/gcaqjc/gcaqyj/bzt' }, // { // id: id(), title: '工程安全预警', redirect: '/mgr/gcaqjc/gcaqyj/yhyj', // children: [ // { id: id(), title: '隐患预警', path: '/mgr/gcaqjc/gcaqyj/yhyj' }, // { id: id(), title: '预警规则配置', path: '/mgr/gcaqjc/gcaqyj/yjgzpz' }, // ] // }, // { // id: id(), title: '工程安全分析', redirect: '/mgr/gcaqjc/gcaqfx/jrx', // children: [ // { id: id(), title: '浸润线', path: '/mgr/gcaqjc/gcaqfx/jrx' }, // ] // }, // { // id: id(), title: '数据统计查询', redirect: '/mgr/gcaqjc/sjtjcx/sljx', // children: [ // { id: id(), title: '测值查询', path: '/mgr/gcaqjc/sjtjcx/czcx' }, // { id: id(), title: '渗压监测', path: '/mgr/gcaqjc/sjtjcx/syjx' }, // { id: id(), title: '渗流监测', path: '/mgr/gcaqjc/sjtjcx/sljx' }, // { id: id(), title: '位移监测', path: '/mgr/gcaqjc/sjtjcx/wyjx' }, // { id: id(), title: '年度渗压统计表', path: '/mgr/gcaqjc/sjtjcx/ndsytjb' }, // { id: id(), title: '年度渗流统计表', path: '/mgr/gcaqjc/sjtjcx/ndsltjb' }, // { id: id(), title: '年度位移统计表', path: '/mgr/gcaqjc/sjtjcx/ndwytjb' }, // ] // }, // ], // }, // { // id: id(), // title: '日常管理', // redirect: '/mgr/rcgl/gcdsj', // icon: 'fxzb', // children: [ // { // id: id(), // title: '工程大事件', // path: '/mgr/rcgl/gcdsj', // }, // { // id: id(), title: '值班管理', redirect: '/mgr/rcgl/zbgl/zbb', // children: [ // { id: id(), title: '值班表', path: '/mgr/rcgl/zbgl/zbb' }, // { id: id(), title: '值班日志', path: '/mgr/rcgl/zbgl/zbrz' }, // ] // }, // { // id: id(), // title: '水质整编', // path: '/mgr/rcgl/szzb', // }, // { // id: id(), // title: '生态流量监控', // path: '/mgr/rcgl/stlljc', // }, // ], // }, { // id: id(), // title: '供水兴利', // redirect: '/mgr/gsxl/zfzl', // icon: 'fxzb', // children: [ // { // id: id(), // title: '闸阀总览', // path: '/mgr/gsxl/zfzl', // }, // { // id: id(), // title: '闸阀监控', // path: '/mgr/gsxl/zfjk', // }, // { // id: id(), // title: '供水统计分析', // path: '/mgr/gsxl/gstjfx', // }, // { // id: id(), // title: '典型年降雨资料', // path: '/mgr/gsxl/dxnjyzl', // }, // ], // }, // { // id: id(), // title: '视频监控', // redirect: '/mgr/spjk/spjk', // icon: 'spjk', // children: [ // { // id: id(), // title: '视频监控', // path: '/mgr/spjk/spjk', // }, // { // id: id(), // title: 'AI告警', // path: '/mgr/spjk/aiWarn', // }, // ], // }, // { // id: id(), // title: '数字孪生大屏', // path: '/', // icon: 'spjk' // }, ] } export function defaultHomePage() { return '/mgr/home' } export async function currentBreadcrumbs() { let url = window.location.href let index = url.lastIndexOf('/') let str = url.substring(index + 1, url.length) let menuData: any = await loadMenu() //console.log("menuData",menuData); let breadcrumbsArray: any = [] menuData.map(function (item: any) { if (item.children && item.children.length > 0) { item.children.map(function (item1: any) { if (item1.children && item1.children.length > 0) { item1.children.map(function (item2: any) { let index = item2.path.lastIndexOf('/') if (str === item2.path.substring(index + 1, url.length)) { breadcrumbsArray = [item.title, item1.title, item2.title] } }) } else { let index = item1.path.lastIndexOf('/') if (str === item1.path.substring(index + 1, url.length)) { breadcrumbsArray = [item.title, item1.title] } } }) } }) return breadcrumbsArray }