2025-06-27 10:04:22 +08:00

184 lines
11 KiB
JavaScript
Raw Permalink 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.

//这个是头部获取的菜单
app.controller('headerCtrl', ['$rootScope', '$scope', '$sessionStorage', '$state', "$uibModal", '$http', function ($rootScope, $scope, $sessionStorage, $state, $uibModal, $http) {
//正确用法
console.log(document.cookie)
var token = document.cookie
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].split('=');
if (cookie[0] == "Admin-Token") {
// var token2 = decodeURIComponent(cookie[1]);
var token2 = cookie[1];
}
}
//是否开启sso登录 还有一个地方需要修改 loginCtrl.js 的7行
var sso = false;
//如果菜单信息为空,则再去查一次信息 和 开启了sso
if ($sessionStorage.user == null && sso) {
debugger
$http({
method: 'GET',
url: Gaddress + '/loginSSO'
}).success(function (mydata) {
console.log(mydata);
// debugger;
if (mydata == "") {
$rootScope.user = {};
debugger;
console.log(mydata);
$scope.isLoading = false;
$scope.loginForm2 = true;
window.location.href = 'https://10.86.138.22/dsp/';
} else {
$scope.isLoading = true;
$scope.loginForm2 = false;
$sessionStorage.user = mydata;
sessionStorage.setItem('userName', mydata.username);
$state.go("app.main");
// $sessionStorage.user = { "name": "宇盛好", "type": 1, "username": "yushenghao", "userpwd": "yushenghao", "quJson": [{ "QX": [{ "id": 1, "name": "基础信息管理", "xiao": [{ "floor": [], "cid": 1, "url": "app.YBLB", "isshow": true, "name": "样品类别管理" }, { "floor": [], "cid": 2, "url": "app.JCXM", "isshow": true, "name": "检测项目管理" }, { "floor": [], "cid": 3, "url": "app.JCBZ", "isshow": true, "name": "检测标准管理" }, { "floor": [], "cid": 4, "url": "app.PJBZ", "isshow": true, "name": "评价标准管理" }, { "floor": [], "cid": 5, "url": "app.JLDW", "isshow": true, "name": "计量单位管理" }, { "floor": [], "cid": 6, "url": "app.DWHS", "isshow": true, "name": "单位换算管理" }, { "floor": [], "cid": 7, "url": "app.CYDD", "isshow": false, "name": "采样地点管理" }, { "floor": [], "cid": 8, "url": "app.JZJG", "isshow": true, "name": "检测机构管理" }, { "floor": [], "cid": 10, "url": "app.XFLDB", "isshow": true, "name": "消费量数据管理" }, { "floor": [], "cid": 11, "url": "app.JKZDZ", "isshow": true, "name": "健康指导值管理" }, { "floor": [], "cid": 47, "url": "app.XLZ", "isshow": true, "name": "限量值基础库" }, { "floor": [], "cid": 100, "url": "app.QGCJ", "isshow": false, "name": "全国抽检信息" }] }, { "id": 2, "name": "计划任务管理", "xiao": [{ "floor": [], "cid": 10, "url": "app.PlanCustomize", "isshow": true, "name": "计划任务定制" }, { "floor": [], "cid": 11, "url": "app.PlanControl", "isshow": true, "name": "计划任务监控" }, { "floor": [], "cid": 12, "url": "app.PlanCheck({id:0})", "isshow": true, "name": "计划任务查看" }] }, { "id": 3, "name": "检测任务管理", "xiao": [{ "floor": [], "cid": 13, "url": "app.SampleRegister({id:0})", "isshow": true, "name": "样品登记管理" }, { "floor": [], "cid": 14, "url": "app.SampleControl", "isshow": true, "name": "样品检验管理" }, { "floor": [], "cid": 15, "url": "app.SampleAutio", "isshow": true, "name": "样品审核管理" }, { "floor": [], "cid": 16, "url": "app.SampleApprove", "isshow": true, "name": "样品批准管理" }] }, { "id": 4, "name": "综合查询", "xiao": [{ "floor": [], "cid": 22, "url": "app.DetectionCost", "isshow": false, "name": "检测费用" }, { "floor": [], "cid": 17, "url": "app.CustomQuery2", "isshow": true, "name": "MGO查询" }, { "floor": [], "cid": 24, "url": "app.CustomQuery2", "isshow": true, "name": "SQL查询" }, { "floor": [], "cid": 100, "url": "app.HLZH", "isshow": false, "name": "行列转换" }, { "floor": [], "cid": 101, "url": "app.SHDT", "isshow": false, "name": "上海地图" }, { "floor": [], "cid": 102, "url": "app.QGDT", "isshow": false, "name": "全国地图" }, { "floor": [], "cid": 103, "url": "app.QQDT", "isshow": false, "name": "全球地图" }, { "floor": [], "cid": 104, "url": "app.OperateLog", "isshow": true, "name": "操作日志" }, { "floor": [], "cid": 105, "url": "app.BackLog", "isshow": false, "name": "备份记录" }, { "floor": [], "cid": 105, "url": "app.CJHuiLuoNew", "isshow": false, "name": "抽检监测数据回落库" }] }, { "id": 5, "name": "统计分析", "xiao": [{ "floor": [], "cid": 30, "url": "app.Sample", "isshow": true, "name": "不合格率" }, { "floor": [], "cid": 31, "url": "app.Overproof", "isshow": true, "name": "覆盖率" }] }, { "id": 6, "name": "风险评估", "xiao": [{ "floor": [], "cid": 37, "url": "app.JianCeXiangMu4", "isshow": true, "name": "大类评估" }, { "floor": [], "cid": 36, "url": "app.JianCeXiangMu3", "isshow": true, "name": "亚类评估" }, { "floor": [], "cid": 35, "url": "app.JianCeXiangMu2", "isshow": true, "name": "品种评估" }, { "floor": [], "cid": 34, "url": "app.JianCeXiangMu", "isshow": true, "name": "细类评估" }, { "floor": [], "cid": 30, "url": "app.FengXianPingGu", "isshow": false, "name": "评估(2018)" }, { "floor": [], "cid": 30, "url": "app.nianfenzhanshi", "isshow": false, "name": "年份风险评估展示" }, { "floor": [], "cid": 30, "url": "app.ShiPinLeiBiePingGuZhanShi", "isshow": false, "name": "食品类别评估展示" }, { "floor": [], "cid": 30, "url": "app.ShiPinFengXianMapZhanShi", "isshow": false, "name": "风险评估地图展示(上海)" }, { "floor": [], "cid": 30, "url": "app.ShiPinFengXianMap_QuanGuoZhanShi", "isshow": false, "name": "风险评估地图展示(全国)" }] }, { "id": 7, "name": "风险预警", "xiao": [{ "floor": [], "cid": 56, "url": "app.dataBuhegelv", "isshow": true, "name": "首页预警" }, { "floor": [{ "cid": 44, "url": "app.Buhegelv", "isshow": true, "name": "首次不合格预警" }], "cid": 57, "url": "", "isshow": true, "name": "首发预警" }, { "floor": [{ "cid": 45, "url": "app.Buhegelv2", "isshow": true, "name": "不合格率上升预警" }, { "cid": 48, "url": "app.Buhegelv4", "isshow": true, "name": "被抽样单位多件不合格预警" }, { "cid": 57, "url": "app.Buhegelv7", "isshow": true, "name": "被抽样单位多次不合格预警" }, { "cid": 50, "url": "app.Buhegelv6", "isshow": true, "name": "生产企业多件不合格预警" }], "cid": 58, "url": "", "isshow": true, "name": "频发预警" }, { "floor": [{ "cid": 46, "url": "app.Buhegelv3", "isshow": true, "name": "不合格率偏高预警" }, { "cid": 52, "url": "app.Buhegelv8", "isshow": true, "name": "产地省份不合格率预警" }, { "cid": 53, "url": "app.Buhegelv9", "isshow": true, "name": "进口食品不合格率预警" }, { "cid": 51, "url": "app.Buhegelv12", "isshow": true, "name": "网络平台不合格率预警" }], "cid": 59, "url": "", "isshow": true, "name": "高发预警" }, { "floor": [{ "cid": 49, "url": "app.Buhegelv5", "isshow": true, "name": "检测值异常预警" }], "cid": 60, "url": "", "isshow": true, "name": "污染预警" }, { "floor": [{ "floor": [], "cid": 55, "url": "app.Buhegelv11", "isshow": true, "name": "污染物总膳食暴露量预警" }], "cid": 61, "url": "", "isshow": true, "name": "风险评估预警" }] }, { "id": 8, "name": "用户管理", "xiao": [{ "floor": [], "cid": 29, "url": "app.user", "isshow": true, "name": "用户管理" }] }], "Sel": [24, 25, 26, 27, 1, 2, 3, 4, 5, 6, 7, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 29, 9, 8, 10, 30, 31, 32, 33, 34, 35, 36, 37, 44, 100, 47] }], "id": "6937a40a-b079-47cf-84b7-5671ce30f1dc" };
console.log(angular.toJson($sessionStorage.user));
}
console.log(mydata);
});
}
$scope.userName = $sessionStorage.user.name
//$scope.logFun = function () {
// var Cur = confirm("是否退出!");
// if (Cur == true) {
// $sessionStorage.user = null;
// $state.go("login");
// }
//}
$scope.logFun = function () {
//退出的话,先将用户信息设置为空
$sessionStorage.user = null
console.log('user信息',$sessionStorage.user)
$http({
method: 'GET',
url: Gaddress + '/logout'
}).success(function (data) {
console.log(data);
if (sso){
// 1. 删除 Cookie
document.cookie = "Admin-Token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; Secure; SameSite=Strict";
document.cookie = "Admin-Token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/shp; Secure; SameSite=Strict";
//sso登录地址
window.location.href = "https://10.86.138.22/dsp/"
} else {
//登录地址
$state.go("login");
}
});
// var modalInstance = $uibModal.open({
// animation: true,
// backdrop: false, // 不让点击背景关闭系统
// templateUrl: 'app/login/view/loginModel.html',
// controller: 'LoginModelCtrl',
// size: 'sm',
// //windowTopClass:'dialog'
// resolve: {
// items: function () {
// return $scope.items;
// }
// }
// });
modalInstance.result.then(
function (nclose) {
$scope.returnData = nclose
},
function (ndismiss) {
$scope.returnData = ndismiss
}
)
}
}])
app.controller("LoginModelCtrl", ['$scope', '$uibModalInstance', '$state', '$sessionStorage', '$http', function ($scope, $uibModalInstance, $state, $sessionStorage, $http) {
$uibModalInstance.dismiss("退出");
$sessionStorage.user = null;
$scope.loginOut = function () {
$http({
method: 'GET',
url: Gaddress + 'logout'
}).success(function (data) {
console.log(data);
var headers = new Headers();
// headers.append("Authorization", data);
// window.location.href = new Request("https://10.86.138.22/dsp/")
window.location.href = "https://10.86.138.22/dsp/"
});
// window.location.href='/index.html#/app/main';
// window.location.href='/index.html#/app/main';
// $state.go('login');
}
$scope.goHome = function () {
$uibModalInstance.dismiss("返回主页");
$state.go('app.main');
}
$scope.Close = function () {
$uibModalInstance.dismiss("返回");
}
}])
//这个是头部获取的菜单
app.controller('LeftCtrl', ['$rootScope', '$scope', '$sessionStorage', '$state', 'Login', function ($rootScope, $scope, $sessionStorage, $state, Login) {
//菜单权限
$scope.mueu = $sessionStorage.user.quJson[0].QX;
layui.use('element', function () {
var element = layui.element; //导航的hover效果、二级菜单等功能需要依赖element模块
//监听导航点击
element.on('nav(demo)', function (elem) {
//console.log(elem)
//layer.msg(elem.text());
});
});
// console.log(angular.toJson($scope.mueu));
}])