Authored by 鲁尚清

Merge branch 'master' of http://192.168.1.136:82/monitor_v3/hg-monitor-web into …

…master-v32-lushangqing
... ... @@ -9,24 +9,24 @@ const domainName = "http://127.0.0.1:8183";
var global = {};
global.common = {
domainName: domainName,
tokenKey: 'access_token', // 存放token的key
refreshToken: 'refresh_token', // 存放token的key
hasEnter: false // 登陆状态
domainName: domainName,
tokenKey: 'access_token', // 存放token的key
refreshToken: 'refresh_token', // 存放token的key
hasEnter: false // 登陆状态
};
global.showLoading = (callback) => {
const loading = ElementPlus.ElLoading.service({
lock: true,
text: '',
spinner: ' ',
background: 'rgba(0, 0, 0, 0.7)',
});
if (callback) {
callback(loading);
}
return loading;
const loading = ElementPlus.ElLoading.service({
lock: true,
text: '',
spinner: ' ',
background: 'rgba(0, 0, 0, 0.7)',
});
if (callback) {
callback(loading);
}
return loading;
}
/**
... ... @@ -35,56 +35,56 @@ global.showLoading = (callback) => {
* @param type "success", "warning", "info", "error"
*/
global.showMsg = (msg, type) => {
if(!type){
type = 'success';
}
if(type == 'success'){
ElementPlus.ElMessage.success({
showClose: true,
message: msg,
type: type,
})
} else if(type == 'warning'){
ElementPlus.ElMessage.warning({
showClose: true,
message: msg,
type: type,
})
} else if(type == 'info'){
ElementPlus.ElMessage.info({
showClose: true,
message: msg,
type: type,
})
}else if(type == 'error'){
ElementPlus.ElMessage.error({
showClose: true,
message: msg,
type: type,
})
}
if (!type) {
type = 'success';
}
if (type == 'success') {
ElementPlus.ElMessage.success({
showClose: true,
message: msg,
type: type,
})
} else if (type == 'warning') {
ElementPlus.ElMessage.warning({
showClose: true,
message: msg,
type: type,
})
} else if (type == 'info') {
ElementPlus.ElMessage.info({
showClose: true,
message: msg,
type: type,
})
} else if (type == 'error') {
ElementPlus.ElMessage.error({
showClose: true,
message: msg,
type: type,
})
}
}
global.confirm = (msg,okFunc,cancelFunc) =>{
ElementPlus.ElMessageBox.confirm(
msg,
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
if(typeof(okFunc) == 'function'){
okFunc();
}
}).catch(() => {
if(typeof(cancelFunc) == 'function'){
cancelFunc();
}
})
global.confirm = (msg, okFunc, cancelFunc) => {
ElementPlus.ElMessageBox.confirm(
msg,
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
if (typeof (okFunc) == 'function') {
okFunc();
}
}).catch(() => {
if (typeof (cancelFunc) == 'function') {
cancelFunc();
}
})
}
/**
... ... @@ -93,55 +93,72 @@ global.confirm = (msg,okFunc,cancelFunc) =>{
* @returns {string|boolean}
*/
global.getQueryVariable = (variable) => {
var query = window.location.search.substring(1);
if(query == ''){
query = document.location.href
let args = query.split('?');
let arr = [];
if(args && args.length > 1){
arr = args[1].split('&')
}
for (var i = 0; i < arr.length; i++) {
var pair = arr[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return (false);
}
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return (false);
var query = window.location.search.substring(1);
if (query == '') {
query = document.location.href
let args = query.split('?');
let arr = [];
if (args && args.length > 1) {
arr = args[1].split('&')
}
for (var i = 0; i < arr.length; i++) {
var pair = arr[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return (false);
}
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return (false);
}
global.openBlankWindow = (url, width, height) => {
// width = window.innerWidth;
// height = window.innerHeight;
var features = "toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no";
if (width) {
features += "width=" + width;
}
if (height) {
features += "height=" + height;
}
if (url) {
window.open(url, "_blank", features);
}
}
/**
* 文件预览
* @param path
*/
global.viewer = (path,proxy) =>{
proxy.$http.get(`/api-web/openoffice/convertPdf/?path=${encodeURIComponent(path)}`, {}, function (res) {
if (res && res.success) {
window.open("/src/lib/extend/pdfjs/web/viewer.html?test=" + encodeURIComponent(res.str));
} else {
global.showMsg((res.msg == undefined || res.msg == '' || res.msg == null) ? "该文档不支持预览!" : res.msg,"error")
}
})
global.viewer = (path, proxy) => {
proxy.$http.get(`/api-web/openoffice/convertPdf/?path=${encodeURIComponent(path)}`, {}, function (res) {
if (res && res.success) {
global.openBlankWindow("/src/lib/extend/pdfjs/web/viewer.html?test=" + encodeURIComponent(res.str));
} else {
global.showMsg((res.msg == undefined || res.msg == '' || res.msg == null) ? "该文档不支持预览!" : res.msg, "error")
}
})
}
/**
* 拓扑
* @param path
*/
global.openGraphEditor = (topoId) =>{
let url = `${sessionStorage.getItem('graphEditorOrigin')}/jgraph/grapheditor/index.html?access_token=${localStorage.getItem('access_token')}&id=${topoId}`;
let height = window.innerHeight;
let width = window.innerWidth;
window.open(url,"_blank",`toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no, width=${width}, height=${height}`);
global.openGraphEditor = (topoId) => {
let url = `${sessionStorage.getItem('graphEditorOrigin')}/jgraph/grapheditor/index.html?access_token=${localStorage.getItem('access_token')}&id=${topoId}`;
let height = window.innerHeight;
let width = window.innerWidth;
//window.open(url,"_blank",`toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no, width=${width}, height=${height}`);
global.openBlankWindow(url, width, height);
}
/**
... ... @@ -150,27 +167,33 @@ global.openGraphEditor = (topoId) =>{
*/
global.openCmdbAssets = (resTypeId, resId, proxy) => {
let preUrl = sessionStorage.getItem('cmdbWeb');
if(!preUrl){
global.showMsg("获取CMDB系统地址失败,请配置!","error");
return;
}
let height = window.innerHeight;
let width = window.innerWidth;
// 获取资源类型对应的cmddb的资源类型
proxy.$http.get(`/api-web/v32/res/cmdb/${resTypeId}`, {}, function (res) {
if (res && res.success) {
let obj = res.object;
let cmdVal = obj.cmdbValue;
let url =`${preUrl}/#/CI/configuration-item/detail?objId=${cmdVal}&id=${resId}`
window.open(url,"_blank",`left=100,fullscreen,toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=${width}, height=${height}`);
} else {
proxy.$global.showMsg('没有查询到关联数据,请配置!', "error");
}
});
let preUrl = sessionStorage.getItem('cmdbWeb');
if (!preUrl) {
global.showMsg("获取CMDB系统地址失败,请配置!", "error");
return;
}
let height = window.innerHeight;
let width = window.innerWidth;
// 获取资源类型对应的cmddb的资源类型
proxy.$http.get(`/api-web/v32/res/cmdb/${resTypeId}`, {}, function (res) {
if (res && res.success) {
let obj = res.object;
let cmdVal = obj.cmdbValue;
let url = `${preUrl}/#/CI/configuration-item/detail?objId=${cmdVal}&id=${resId}`
//window.open(url, "_blank", `left=100,fullscreen,toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=${width}, height=${height}`);
global.openBlankWindow(url, width, height);
} else {
proxy.$global.showMsg('没有查询到关联数据,请配置!', "error");
}
});
}
global.openDetail = (resId, resType, title) => {
let url = window.top.location.href.split('/#')[0] + `/#/res/resDetail/resId=${resId}/resType=${resType}/title=${title}`;
global.openBlankWindow(url);
}
/**
... ... @@ -178,25 +201,24 @@ global.openCmdbAssets = (resTypeId, resId, proxy) => {
* @param file
* @returns {Promise<String>}
*/
global.getBase64 = (file) =>{
return new Promise(function(resolve, reject) {
let reader = new FileReader();
let imgResult = "";
reader.readAsDataURL(file);
reader.onload = function() {
imgResult = reader.result;
};
reader.onerror = function(error) {
reject(error);
};
reader.onloadend = function() {
resolve(imgResult);
};
});
global.getBase64 = (file) => {
return new Promise(function (resolve, reject) {
let reader = new FileReader();
let imgResult = "";
reader.readAsDataURL(file);
reader.onload = function () {
imgResult = reader.result;
};
reader.onerror = function (error) {
reject(error);
};
reader.onloadend = function () {
resolve(imgResult);
};
});
}
// 组件默认大小 medium / small / mini
global.elementSize = '';
global.height = window.innerHeight - 20;
... ...
<script type="text/javascript">
//资源指标列表
layui.define(['table', 'form','sessions','common'], function (exports) {
var commonDetail = layui.commonDetail;
//对外暴露的接口
commonDetail.openDetail(resId,resType,"详情页",true,function(data){
if(data){
console.log(111);
}
});
});
</script>
... ...