|
@@ -194,216 +194,22 @@ export default{
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- getApsURL: function (apiName) {
|
|
|
|
|
- var apsBaseUrl = localStorage.getItem('apsBaseUrl');
|
|
|
|
|
- if (apsBaseUrl == undefined) {
|
|
|
|
|
- Notify.error('错误', '系统参数"apsBaseUrl"未设置,请联系系统管理员设置参数', false);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- return apsBaseUrl + apiName;
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- getActivitiURL: function (apiName) {
|
|
|
|
|
- var apsBaseUrl = localStorage.getItem('activitiUrl');
|
|
|
|
|
- if (apsBaseUrl == undefined) {
|
|
|
|
|
- Notify.error('错误', '系统参数"activitiUrl"未设置,请联系系统管理员设置参数', false);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- return apsBaseUrl + apiName;
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- getSchedulingURL: function (apiName) {
|
|
|
|
|
- var _self = this;
|
|
|
|
|
- var apsBaseUrl = localStorage.getItem('schedulingUrl');
|
|
|
|
|
- if (apsBaseUrl == undefined) {
|
|
|
|
|
- _self.loadSystemParam('schedulingUrl', function () {
|
|
|
|
|
- apsBaseUrl = localStorage.getItem('schedulingUrl');
|
|
|
|
|
- if (apsBaseUrl == undefined) {
|
|
|
|
|
- Notify.error('错误', '系统参数"schedulingUrl"未设置,请联系系统管理员设置参数', false);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- return apsBaseUrl + apiName;
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- getCameraURL: function (apiName) {
|
|
|
|
|
- var apsBaseUrl = localStorage.getItem('cameraBaseURL');
|
|
|
|
|
- if (apsBaseUrl == undefined) {
|
|
|
|
|
- Notify.error('错误', '系统参数"cameraBaseURL"未设置,请联系系统管理员设置参数', false);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- return apsBaseUrl + apiName;
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- //设置路径到localStorage
|
|
|
|
|
- setHref: function () {
|
|
|
|
|
- var href = window.location.href;
|
|
|
|
|
- if (href.indexOf('http') == 0) {
|
|
|
|
|
- href = href.substring(0, href.indexOf('#') + 2);
|
|
|
|
|
- localStorage.setItem('href', href);
|
|
|
|
|
- } else {
|
|
|
|
|
- var hostPageBaseURL = localStorage.getItem('hostPageBaseURL');
|
|
|
|
|
- if (hostPageBaseURL == undefined) {
|
|
|
|
|
- let href = window.location.href;
|
|
|
|
|
- href = href.substring(0, href.indexOf('#') + 2);
|
|
|
|
|
- localStorage.setItem('href', href);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- //加载系统参数到localStorage
|
|
|
|
|
- loadSystemParam: function (systemParamName, success) {
|
|
|
|
|
- var that = this;
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- url: that.getApiURL('SystemParamResource/loadSystemParam'),
|
|
|
|
|
- type: 'GET',
|
|
|
|
|
- dataType: 'text',
|
|
|
|
|
- data: {
|
|
|
|
|
- 'systemParamName': systemParamName,
|
|
|
|
|
- },
|
|
|
|
|
- beforeSend: function (request) {
|
|
|
|
|
- that.addTokenToRequest(request);
|
|
|
|
|
- },
|
|
|
|
|
- success: function (data) {
|
|
|
|
|
- localStorage.setItem(systemParamName, data);
|
|
|
|
|
- success();
|
|
|
|
|
- },
|
|
|
|
|
- error: function (XMLHttpRequest, textStatus, errorThrown) {
|
|
|
|
|
- that.processException(XMLHttpRequest, textStatus, errorThrown);
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
// 给请求头中加上account和token信息
|
|
// 给请求头中加上account和token信息
|
|
|
addTokenToRequest: function (request) {
|
|
addTokenToRequest: function (request) {
|
|
|
- var token = $.cookie('token');
|
|
|
|
|
- var account = $.cookie('account');
|
|
|
|
|
- if (token == undefined) {
|
|
|
|
|
- var localStorageToken = localStorage.getItem('#token');
|
|
|
|
|
- if (localStorageToken != undefined) {
|
|
|
|
|
- token = localStorageToken;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (account == undefined) {
|
|
|
|
|
- var localStorageAccount = localStorage.getItem('#accountId');
|
|
|
|
|
- if (localStorageAccount != undefined) {
|
|
|
|
|
- account = localStorageAccount;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var token = localStorage.getItem('#token');
|
|
|
|
|
+ var account = localStorage.getItem('#accountId');
|
|
|
request.setRequestHeader('account', account);
|
|
request.setRequestHeader('account', account);
|
|
|
request.setRequestHeader('token', token);
|
|
request.setRequestHeader('token', token);
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 获取Token
|
|
|
|
|
- */
|
|
|
|
|
- getToken: function () {
|
|
|
|
|
- return $.cookie('token');
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- // 获取新建对象的Id
|
|
|
|
|
- getNewRecordId: function () {
|
|
|
|
|
- window.CRUDId++;
|
|
|
|
|
- return window.CRUDId;
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- // 清空 Cookie
|
|
|
|
|
- clearCookie: function () {
|
|
|
|
|
- var keys = document.cookie.match(/[^ =;]+(?==)/g);
|
|
|
|
|
- if (keys) {
|
|
|
|
|
- for (var i = keys.length; i--;) {
|
|
|
|
|
- // 清除当前域名路径的有限日期
|
|
|
|
|
- document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString();
|
|
|
|
|
- // Domain Name域名 清除当前域名的
|
|
|
|
|
- document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString();
|
|
|
|
|
- // 清除一级域名下的或指定的
|
|
|
|
|
- document.cookie = keys[i] + '=0;path=/;domain=baidu.com;expires=' + new Date(0).toUTCString();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
-
|
|
|
|
|
- clearLocalStorage: function () {
|
|
|
|
|
- // 清理localStorage时需要保留的参数列表
|
|
|
|
|
- var reserveParams = ['hostPageBaseURL', 'workShopId', 'resourceInstanceId',
|
|
|
|
|
- 'resourceInstanceName', 'apsBaseUrl', 'cameraBaseURL'];
|
|
|
|
|
- //存放的信息
|
|
|
|
|
- var reserveParamValues = [];
|
|
|
|
|
-
|
|
|
|
|
- //获取参数信息
|
|
|
|
|
- var len = reserveParams.length;
|
|
|
|
|
- for (var i = 0; i < len; i++) {
|
|
|
|
|
- var reserveParam = reserveParams[i];
|
|
|
|
|
- var reserveParamValue = '';
|
|
|
|
|
- if (localStorage.getItem(reserveParam) != undefined) {
|
|
|
|
|
- reserveParamValue = localStorage.getItem(reserveParam);
|
|
|
|
|
- }
|
|
|
|
|
- reserveParamValues.push(reserveParamValue);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //清理localStorage
|
|
|
|
|
- window.localStorage.clear();
|
|
|
|
|
-
|
|
|
|
|
- //还原参数信息
|
|
|
|
|
- for (let i = 0; i < len; i++) {
|
|
|
|
|
- localStorage.setItem(reserveParams[i], reserveParamValues[i]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- showDialog: function (title, content, type) {
|
|
|
|
|
- if (type == 'success') {
|
|
|
|
|
- Notify.success(title, content, 4000);
|
|
|
|
|
- }
|
|
|
|
|
- else if (type == 'error') {
|
|
|
|
|
- Notify.error(title, content, -1);
|
|
|
|
|
- }
|
|
|
|
|
- else if (type == 'info') {
|
|
|
|
|
- Notify.info(title, content, 2000);
|
|
|
|
|
- }
|
|
|
|
|
- else if (type == 'notice') {
|
|
|
|
|
- Notify.notice(title, content, 2000);
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
- //合并路由数组
|
|
|
|
|
- mergeArray: function (arr1, arr2) {
|
|
|
|
|
- var arr = [];
|
|
|
|
|
- for (var k = 0, len = arr1.length; k < len; k++) {
|
|
|
|
|
- arr.push(arr1[k]);
|
|
|
|
|
- }
|
|
|
|
|
- for (var i = 0, len2 = arr2.length; i < len2; i++) {
|
|
|
|
|
- //是否添加该元素
|
|
|
|
|
- var flag = true;
|
|
|
|
|
- for (var j = 0, len1 = arr.length; j < len1; j++) {
|
|
|
|
|
- //如果path相同,则合并children;如果children不存在,则不合并;
|
|
|
|
|
- if (arr[j].path == arr2[i].path) {
|
|
|
|
|
- flag = false;
|
|
|
|
|
- if (arr[j].children instanceof Array && arr2[i].children instanceof Array) {
|
|
|
|
|
- arr[j].children = this.mergeArray(arr[j].children, arr2[i].children);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (flag) {
|
|
|
|
|
- arr.push(arr2[i]);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- //将path为"*"的项移到最后
|
|
|
|
|
- var temp;
|
|
|
|
|
- var index;
|
|
|
|
|
- for (var n = 0, len3 = arr.length; n < len3; n++) {
|
|
|
|
|
- if (arr[n].path == '*' || arr[n].path == '/*') {
|
|
|
|
|
- index = n;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (index != undefined) {
|
|
|
|
|
- temp = arr[index];
|
|
|
|
|
- arr[index] = arr[len3 - 1];
|
|
|
|
|
- arr[len3 - 1] = temp;
|
|
|
|
|
- }
|
|
|
|
|
- return arr;
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
// 获取路由中的参数
|
|
// 获取路由中的参数
|
|
|
getRouteParam: function (name) {
|
|
getRouteParam: function (name) {
|
|
@@ -425,30 +231,6 @@ export default{
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 可以修改url的参数
|
|
|
|
|
- * 例如将
|
|
|
|
|
- * www.baidu.com
|
|
|
|
|
- * 修改为
|
|
|
|
|
- * www.baidu.com?name=123
|
|
|
|
|
- * 操作为
|
|
|
|
|
- * window.location.href = changeURLArg(window.location.href,'name',123)
|
|
|
|
|
- */
|
|
|
|
|
- changeURLArg: function (url, arg, value) {
|
|
|
|
|
- var pattern = arg + '=([^&]*)';
|
|
|
|
|
- var replaceText = arg + '=' + value;
|
|
|
|
|
- if (url.match(pattern)) {
|
|
|
|
|
- var tmp = '/(' + arg + '=)([^&]*)/gi';
|
|
|
|
|
- tmp = url.replace(eval(tmp), replaceText);
|
|
|
|
|
- return tmp;
|
|
|
|
|
- } else {
|
|
|
|
|
- if (url.match('[?]')) {
|
|
|
|
|
- return url + '&' + replaceText;
|
|
|
|
|
- } else {
|
|
|
|
|
- return url + '?' + replaceText;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|