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"; @@ -9,24 +9,24 @@ const domainName = "http://127.0.0.1:8183";
9 var global = {}; 9 var global = {};
10 10
11 global.common = { 11 global.common = {
12 - domainName: domainName,  
13 - tokenKey: 'access_token', // 存放token的key  
14 - refreshToken: 'refresh_token', // 存放token的key  
15 - hasEnter: false // 登陆状态 12 + domainName: domainName,
  13 + tokenKey: 'access_token', // 存放token的key
  14 + refreshToken: 'refresh_token', // 存放token的key
  15 + hasEnter: false // 登陆状态
16 }; 16 };
17 17
18 global.showLoading = (callback) => { 18 global.showLoading = (callback) => {
19 - const loading = ElementPlus.ElLoading.service({  
20 - lock: true,  
21 - text: '',  
22 - spinner: ' ',  
23 - background: 'rgba(0, 0, 0, 0.7)',  
24 - });  
25 -  
26 - if (callback) {  
27 - callback(loading);  
28 - }  
29 - return loading; 19 + const loading = ElementPlus.ElLoading.service({
  20 + lock: true,
  21 + text: '',
  22 + spinner: ' ',
  23 + background: 'rgba(0, 0, 0, 0.7)',
  24 + });
  25 +
  26 + if (callback) {
  27 + callback(loading);
  28 + }
  29 + return loading;
30 } 30 }
31 31
32 /** 32 /**
@@ -35,56 +35,56 @@ global.showLoading = (callback) => { @@ -35,56 +35,56 @@ global.showLoading = (callback) => {
35 * @param type "success", "warning", "info", "error" 35 * @param type "success", "warning", "info", "error"
36 */ 36 */
37 global.showMsg = (msg, type) => { 37 global.showMsg = (msg, type) => {
38 - if(!type){  
39 - type = 'success';  
40 - }  
41 -  
42 - if(type == 'success'){  
43 - ElementPlus.ElMessage.success({  
44 - showClose: true,  
45 - message: msg,  
46 - type: type,  
47 - })  
48 - } else if(type == 'warning'){  
49 - ElementPlus.ElMessage.warning({  
50 - showClose: true,  
51 - message: msg,  
52 - type: type,  
53 - })  
54 - } else if(type == 'info'){  
55 - ElementPlus.ElMessage.info({  
56 - showClose: true,  
57 - message: msg,  
58 - type: type,  
59 - })  
60 - }else if(type == 'error'){  
61 - ElementPlus.ElMessage.error({  
62 - showClose: true,  
63 - message: msg,  
64 - type: type,  
65 - })  
66 - } 38 + if (!type) {
  39 + type = 'success';
  40 + }
  41 +
  42 + if (type == 'success') {
  43 + ElementPlus.ElMessage.success({
  44 + showClose: true,
  45 + message: msg,
  46 + type: type,
  47 + })
  48 + } else if (type == 'warning') {
  49 + ElementPlus.ElMessage.warning({
  50 + showClose: true,
  51 + message: msg,
  52 + type: type,
  53 + })
  54 + } else if (type == 'info') {
  55 + ElementPlus.ElMessage.info({
  56 + showClose: true,
  57 + message: msg,
  58 + type: type,
  59 + })
  60 + } else if (type == 'error') {
  61 + ElementPlus.ElMessage.error({
  62 + showClose: true,
  63 + message: msg,
  64 + type: type,
  65 + })
  66 + }
67 67
68 } 68 }
69 -global.confirm = (msg,okFunc,cancelFunc) =>{  
70 - ElementPlus.ElMessageBox.confirm(  
71 - msg,  
72 - '提示',  
73 - {  
74 - confirmButtonText: '确认',  
75 - cancelButtonText: '取消',  
76 - type: 'warning',  
77 - }  
78 - ).then(() => {  
79 - if(typeof(okFunc) == 'function'){  
80 - okFunc();  
81 - }  
82 -  
83 - }).catch(() => {  
84 - if(typeof(cancelFunc) == 'function'){  
85 - cancelFunc();  
86 - }  
87 - }) 69 +global.confirm = (msg, okFunc, cancelFunc) => {
  70 + ElementPlus.ElMessageBox.confirm(
  71 + msg,
  72 + '提示',
  73 + {
  74 + confirmButtonText: '确认',
  75 + cancelButtonText: '取消',
  76 + type: 'warning',
  77 + }
  78 + ).then(() => {
  79 + if (typeof (okFunc) == 'function') {
  80 + okFunc();
  81 + }
  82 +
  83 + }).catch(() => {
  84 + if (typeof (cancelFunc) == 'function') {
  85 + cancelFunc();
  86 + }
  87 + })
88 } 88 }
89 89
90 /** 90 /**
@@ -93,55 +93,72 @@ global.confirm = (msg,okFunc,cancelFunc) =>{ @@ -93,55 +93,72 @@ global.confirm = (msg,okFunc,cancelFunc) =>{
93 * @returns {string|boolean} 93 * @returns {string|boolean}
94 */ 94 */
95 global.getQueryVariable = (variable) => { 95 global.getQueryVariable = (variable) => {
96 - var query = window.location.search.substring(1);  
97 - if(query == ''){  
98 - query = document.location.href  
99 - let args = query.split('?');  
100 - let arr = [];  
101 - if(args && args.length > 1){  
102 - arr = args[1].split('&')  
103 - }  
104 - for (var i = 0; i < arr.length; i++) {  
105 - var pair = arr[i].split("=");  
106 - if (pair[0] == variable) {  
107 - return pair[1];  
108 - }  
109 - }  
110 - return (false);  
111 - }  
112 - var vars = query.split("&");  
113 - for (var i = 0; i < vars.length; i++) {  
114 - var pair = vars[i].split("=");  
115 - if (pair[0] == variable) {  
116 - return pair[1];  
117 - }  
118 - }  
119 - return (false); 96 + var query = window.location.search.substring(1);
  97 + if (query == '') {
  98 + query = document.location.href
  99 + let args = query.split('?');
  100 + let arr = [];
  101 + if (args && args.length > 1) {
  102 + arr = args[1].split('&')
  103 + }
  104 + for (var i = 0; i < arr.length; i++) {
  105 + var pair = arr[i].split("=");
  106 + if (pair[0] == variable) {
  107 + return pair[1];
  108 + }
  109 + }
  110 + return (false);
  111 + }
  112 + var vars = query.split("&");
  113 + for (var i = 0; i < vars.length; i++) {
  114 + var pair = vars[i].split("=");
  115 + if (pair[0] == variable) {
  116 + return pair[1];
  117 + }
  118 + }
  119 + return (false);
  120 +}
  121 +global.openBlankWindow = (url, width, height) => {
  122 + // width = window.innerWidth;
  123 + // height = window.innerHeight;
  124 + var features = "toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no";
  125 + if (width) {
  126 + features += "width=" + width;
  127 + }
  128 +
  129 + if (height) {
  130 + features += "height=" + height;
  131 + }
  132 +
  133 + if (url) {
  134 + window.open(url, "_blank", features);
  135 + }
120 } 136 }
121 137
122 /** 138 /**
123 * 文件预览 139 * 文件预览
124 * @param path 140 * @param path
125 */ 141 */
126 -global.viewer = (path,proxy) =>{  
127 - proxy.$http.get(`/api-web/openoffice/convertPdf/?path=${encodeURIComponent(path)}`, {}, function (res) {  
128 - if (res && res.success) {  
129 - window.open("/src/lib/extend/pdfjs/web/viewer.html?test=" + encodeURIComponent(res.str));  
130 - } else {  
131 - global.showMsg((res.msg == undefined || res.msg == '' || res.msg == null) ? "该文档不支持预览!" : res.msg,"error")  
132 - }  
133 - }) 142 +global.viewer = (path, proxy) => {
  143 + proxy.$http.get(`/api-web/openoffice/convertPdf/?path=${encodeURIComponent(path)}`, {}, function (res) {
  144 + if (res && res.success) {
  145 + global.openBlankWindow("/src/lib/extend/pdfjs/web/viewer.html?test=" + encodeURIComponent(res.str));
  146 + } else {
  147 + global.showMsg((res.msg == undefined || res.msg == '' || res.msg == null) ? "该文档不支持预览!" : res.msg, "error")
  148 + }
  149 + })
134 } 150 }
135 151
136 /** 152 /**
137 * 拓扑 153 * 拓扑
138 * @param path 154 * @param path
139 */ 155 */
140 -global.openGraphEditor = (topoId) =>{  
141 - let url = `${sessionStorage.getItem('graphEditorOrigin')}/jgraph/grapheditor/index.html?access_token=${localStorage.getItem('access_token')}&id=${topoId}`;  
142 - let height = window.innerHeight;  
143 - let width = window.innerWidth;  
144 - window.open(url,"_blank",`toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no, width=${width}, height=${height}`); 156 +global.openGraphEditor = (topoId) => {
  157 + let url = `${sessionStorage.getItem('graphEditorOrigin')}/jgraph/grapheditor/index.html?access_token=${localStorage.getItem('access_token')}&id=${topoId}`;
  158 + let height = window.innerHeight;
  159 + let width = window.innerWidth;
  160 + //window.open(url,"_blank",`toolbar=no, location=no, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=no, width=${width}, height=${height}`);
  161 + global.openBlankWindow(url, width, height);
145 } 162 }
146 163
147 /** 164 /**
@@ -150,27 +167,33 @@ global.openGraphEditor = (topoId) =>{ @@ -150,27 +167,33 @@ global.openGraphEditor = (topoId) =>{
150 */ 167 */
151 global.openCmdbAssets = (resTypeId, resId, proxy) => { 168 global.openCmdbAssets = (resTypeId, resId, proxy) => {
152 169
153 - let preUrl = sessionStorage.getItem('cmdbWeb');  
154 - if(!preUrl){  
155 - global.showMsg("获取CMDB系统地址失败,请配置!","error");  
156 - return;  
157 - }  
158 -  
159 - let height = window.innerHeight;  
160 - let width = window.innerWidth;  
161 - // 获取资源类型对应的cmddb的资源类型  
162 - proxy.$http.get(`/api-web/v32/res/cmdb/${resTypeId}`, {}, function (res) {  
163 - if (res && res.success) {  
164 - let obj = res.object;  
165 - let cmdVal = obj.cmdbValue;  
166 -  
167 - let url =`${preUrl}/#/CI/configuration-item/detail?objId=${cmdVal}&id=${resId}`  
168 -  
169 - 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}`);  
170 - } else {  
171 - proxy.$global.showMsg('没有查询到关联数据,请配置!', "error");  
172 - }  
173 - }); 170 + let preUrl = sessionStorage.getItem('cmdbWeb');
  171 + if (!preUrl) {
  172 + global.showMsg("获取CMDB系统地址失败,请配置!", "error");
  173 + return;
  174 + }
  175 +
  176 + let height = window.innerHeight;
  177 + let width = window.innerWidth;
  178 + // 获取资源类型对应的cmddb的资源类型
  179 + proxy.$http.get(`/api-web/v32/res/cmdb/${resTypeId}`, {}, function (res) {
  180 + if (res && res.success) {
  181 + let obj = res.object;
  182 + let cmdVal = obj.cmdbValue;
  183 +
  184 + let url = `${preUrl}/#/CI/configuration-item/detail?objId=${cmdVal}&id=${resId}`
  185 +
  186 + //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}`);
  187 + global.openBlankWindow(url, width, height);
  188 + } else {
  189 + proxy.$global.showMsg('没有查询到关联数据,请配置!', "error");
  190 + }
  191 + });
  192 +}
  193 +
  194 +global.openDetail = (resId, resType, title) => {
  195 + let url = window.top.location.href.split('/#')[0] + `/#/res/resDetail/resId=${resId}/resType=${resType}/title=${title}`;
  196 + global.openBlankWindow(url);
174 } 197 }
175 198
176 /** 199 /**
@@ -178,25 +201,24 @@ global.openCmdbAssets = (resTypeId, resId, proxy) => { @@ -178,25 +201,24 @@ global.openCmdbAssets = (resTypeId, resId, proxy) => {
178 * @param file 201 * @param file
179 * @returns {Promise<String>} 202 * @returns {Promise<String>}
180 */ 203 */
181 -global.getBase64 = (file) =>{  
182 - return new Promise(function(resolve, reject) {  
183 - let reader = new FileReader();  
184 - let imgResult = "";  
185 - reader.readAsDataURL(file);  
186 - reader.onload = function() {  
187 - imgResult = reader.result;  
188 - };  
189 - reader.onerror = function(error) {  
190 - reject(error);  
191 - };  
192 - reader.onloadend = function() {  
193 - resolve(imgResult);  
194 - };  
195 - }); 204 +global.getBase64 = (file) => {
  205 + return new Promise(function (resolve, reject) {
  206 + let reader = new FileReader();
  207 + let imgResult = "";
  208 + reader.readAsDataURL(file);
  209 + reader.onload = function () {
  210 + imgResult = reader.result;
  211 + };
  212 + reader.onerror = function (error) {
  213 + reject(error);
  214 + };
  215 + reader.onloadend = function () {
  216 + resolve(imgResult);
  217 + };
  218 + });
196 } 219 }
197 220
198 221
199 -  
200 // 组件默认大小 medium / small / mini 222 // 组件默认大小 medium / small / mini
201 global.elementSize = ''; 223 global.elementSize = '';
202 global.height = window.innerHeight - 20; 224 global.height = window.innerHeight - 20;
  1 +<script type="text/javascript">
  2 + //资源指标列表
  3 + layui.define(['table', 'form','sessions','common'], function (exports) {
  4 + var commonDetail = layui.commonDetail;
  5 +
  6 + //对外暴露的接口
  7 + commonDetail.openDetail(resId,resType,"详情页",true,function(data){
  8 + if(data){
  9 + console.log(111);
  10 + }
  11 + });
  12 + });
  13 +</script>