2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
//jqGrid的配置信息
$.jgrid.defaults.width = 1000;
$.jgrid.defaults.responsive = true;
$.jgrid.defaults.styleUI = 'Bootstrap';
 
//工具集合Tools
window.T = {};
 
// 获取请求参数
// 使用示例
// location.href = http://localhost/index.html?id=123
// T.p('id') --> 123;
var url = function (name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
};
T.p = url;
 
//请求前缀 服务器
var restServerBaseURL = "/";   // "http://192.168.0.130:8081/"
//客户端
var baseURL = "/";   // "/lanwebapp/"
 
var portalUrl='http://portal.nmsmpd.nmdis.mnr:8090/';
var lanCatalog='http://portal.nmsmpd.nmdis.mnr:8082';
//上传文件的映射地址
var uploadFileResource = restServerBaseURL + 'uploadFile';
 
//只执行一次getToken()
var hasNewToken = false;
//登录token
var token = localStorage.getItem("token");
if (!token && parent.location.href.indexOf("login.html") == -1) {
  //  parent.location.href = baseURL + 'admin/login.html';
  //单点登陆方式
  //请求T
  getToken();
}
 
//jquery全局配置
$.ajaxSetup({
  dataType: "json",
  cache: false,
  headers: {
    "token": token
  },
  xhrFields: {
    withCredentials: true
  },
  crossDomain: true,
  complete: function (xhr) {
    //无效的token,则跳转到登录页面
    if (!!xhr.responseJSON && xhr.responseJSON.code == 401) {
      // parent.location.href = baseURL + 'admin/login.html';
      getToken();
    }
    //无效的token的另一种情况:ajax请求未完成即返回错误
    if (!!token && !xhr.responseJSON) {
      getToken();
    }
  }
});
 
//jqgrid全局配置
$.extend($.jgrid.defaults, {
  ajaxGridOptions: {
    headers: {
      "token": token
    }
  }
});
 
//获得Token
function getToken() {
  if (hasNewToken) {
    return;
  }
  hasNewToken = true;
  $.ajax({
    // async: false,
    type: "GET",
    url: restServerBaseURL + "sys/caslogin",
    dataType: "json",
    beforeSend: function (xhr) {
    },
    complete: function (xhr) {
    }, //覆盖全局方法
    success: function (r) {
      if (r.code == 0) {//登录成功
        // console.log("\tnewToken:",r.token);
        localStorage.setItem("token", r.token);
        token = r.token;
        parent.location.reload();
      } else {
        alert(r.msg);
      }
    },
    error: function (xhr, err) {
      if (xhr.status == 404) {
        alert("无效的REST服务器:" + restServerBaseURL);
      }
    }
  });
}
 
//权限判断
function hasPermission(permission) {
  if (window.parent.permissions && window.parent.permissions.indexOf(permission) > -1) {
    return true;
  } else {
    //*单独打开页面时不验证权限,方便开发阶段调试
    if (!window.parent.permissions) {
      return true;
    } //*/
    return false;
  }
}
 
//重写alert
window.alert = function (msg, callback) {
  parent.layer.alert(msg, function (index) {
    parent.layer.close(index);
    if (typeof (callback) === "function") {
      callback("ok");
    }
  });
};
 
//重写confirm式样框
window.confirm = function (msg, callback) {
  parent.layer.confirm(msg, { btn: ['确定', '取消'] },
    function () {//确定事件
      if (typeof (callback) === "function") {
        callback("ok");
      }
    });
};
 
//选择一条记录
function getSelectedRow() {
  var grid = $("#jqGrid");
  var rowKey = grid.getGridParam("selrow");
  if (!rowKey) {
    alert("请选择一条记录");
    return;
  }
 
  var selectedIDs = grid.getGridParam("selarrrow");
  if (selectedIDs.length > 1) {
    alert("只能选择一条记录");
    return;
  }
 
  return selectedIDs[0];
}
 
//选择多条记录
function getSelectedRows() {
  var grid = $("#jqGrid");
  var rowKey = grid.getGridParam("selrow");
  if (!rowKey) {
    alert("请选择一条记录");
    return;
  }
 
  return grid.getGridParam("selarrrow");
}
 
//判断是否为空
function isBlank(value) {
  return !value || !/\S/.test(value);
}
 
function openLayer(width, height, title, div) {
  layer.open({
    type: 1,
    skin: 'layui-layer-molv',
    title: title,
    shadeClose: false,
    area: [width, height],
    content: jQuery("#" + div)
  });
}
 
function openLayerOfBtn(width, height, title, div, callback) {
  layer.open({
    type: 1,
    skin: 'layui-layer-molv',
    title: title,
    shadeClose: false,
    area: [width, height],
    content: jQuery("#" + div),
    btn: ['确定', '取消'],
    btn1: function (index) {
      callback();
      layer.close(index);
    }
  });
}
 
//选择附件layer
function openAttachmentLayer(callback, mime_type) {
  var attachment_jqGrid = $("#attachment_layer_jqGrid");
 
  layer.open({
    type: 1,
    skin: 'layui-layer-molv',
    title: '选择附件',
    shadeClose: false,
    area: ['80%', '80%'],
    content: jQuery("#attachment_layer"),
    btn: ['确定', '取消'],
    btn1: function (index) {
      var rowKey = attachment_jqGrid.getGridParam("selrow");
      if (!rowKey) {
        alert("请选择一条记录");
        return;
      }
 
      var rowData = attachment_jqGrid.jqGrid("getRowData", rowKey);
      var path = rowData.path;
      callback(uploadFileResource + path);
 
      layer.close(index);
    }
  });
 
  attachment_jqGrid.jqGrid({
    url: restServerBaseURL + 'sys/attachment/list',
    postData: { mime_type: mime_type },
    datatype: "json",
    colModel: [
      { label: 'id', name: 'id', index: 'id', key: true, hidden: true },
      { label: '标题', name: 'title', width: 100 },
      { label: '地址', name: 'path', width: 100, hidden: true },
      {
        label: '缩略图', name: 'img', width: 100, formatter: function (value, options, row) {
          var mime = row.mimeType;
          var path = row.path;
          if (mime.indexOf('image') >= 0) {
            return '<img style="width: 200px;height: 200px;" src="' + uploadFileResource + path + '" >';
          } else if (mime.indexOf('audio') >= 0) {
            return '<img style="width: 200px;height: 200px;" src="' + restServerBaseURL + 'image/audio.jpg" >';
          } else if (mime.indexOf('video') >= 0) {
            return '<img style="width: 200px;height: 200px;" src="' + restServerBaseURL + 'image/video.jpg" >';
          } else if (mime.indexOf('application') >= 0) {
            return '<img style="width: 200px;height: 200px;" src="' + restServerBaseURL + 'image/file.jpg" >';
          }
        }
      },
      { label: '创建时间', name: 'createTime', width: 90 }
    ],
    viewrecords: true,
    height: "100%",
    rowNum: 10,
    rowList: [10, 20, 30],
    rownumbers: true,
    rownumWidth: 25,
    autowidth: true,
    multiselect: false,
    pager: "#attachment_layer_jqGridPager",
    jsonReader: {
      root: "page.list",
      page: "page.currPage",
      total: "page.totalPage",
      records: "page.totalCount"
    },
    prmNames: {
      page: "page",
      rows: "limit",
      order: "order"
    },
    gridComplete: function () {
      //隐藏grid底部滚动条
      attachment_jqGrid.closest(".ui-jqgrid-bdiv").css({ "overflow-x": "hidden" });
    }
  });
}
 
//创建attachment-layer组件
var attachmentLayerTemplate = Vue.extend({
  template: [
    '<div id="attachment_layer" style="display: none;">',
    '<table id="attachment_layer_jqGrid"></table>',
    '<div id="attachment_layer_jqGridPager"></div>',
    '</div>'
  ].join('')
});
Vue.component('attachment-layer', attachmentLayerTemplate);
 
//文本编辑器
function initTinymce() {
  tinymce.init({
    selector: '#textarea',
    height: 365,
    language: 'zh_CN',
    menubar: false,
    automatic_uploads: true,
    paste_data_images: true,
    convert_urls: false,
    relative_urls: false,
    imagetools_toolbar: "rotateleft rotateright | flipv fliph | editimage imageoptions",
    imagetools_proxy: '',
    images_upload_url: '',
    wordcount_countregex: /[\u4e00-\u9fa5_a-zA-Z0-9]/g,
    file_picker_callback: function (callback, value, meta) {
      openAttachmentLayer(callback);
    },
    font_formats: "宋体=SimSun;新宋体=NSimSun;微软雅黑=Microsoft YaHei;华文黑体=STHeiti;楷体=KaiTi;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;AkrutiKndPadmini=Akpdmi-n",
    fontsize_formats: "12px 14px 16px 18px 20px 24px 32px",
    plugins: [
      "advlist autolink autosave link image media imagetools lists charmap print preview hr anchor pagebreak spellchecker",
      "searchreplace wordcount visualblocks visualchars code codesample fullscreen insertdatetime media nonbreaking",
      "table contextmenu directionality emoticons template textcolor paste fullpage textcolor colorpicker textpattern"],
    toolbar1: '  bold italic underline strikethrough removeformat | blockquote hr table image media codesample | anchor link   unlink | alignleft aligncenter alignright alignjustify | bullist numlist     ',
    toolbar2: '  fontselect | fontsizeselect | formatselect | outdent indent | forecolor backcolor  |  undo redo | code  fullscreen',
  });
}
 
//获取文本编辑器内容
function getTinymceContent() {
  return tinymce.activeEditor.getBody().innerHTML;
}
 
//设置文本编辑器内容
function setTinymceContent(text) {
  tinymce.activeEditor.setContent(text);
}
//点击新增或查看时弹出最大化的新窗口
function openFullWindow(url, title) {
  var height = window.screen.availHeight;
  var width = window.screen.availWidth;
  var top = 0;
  var left = 0;
  var newwin = window.open(url, title, 'height=' + height + ', width=' + width + ',top=' + top + ',left=' + left + ',toolbar=no, menubar=no, resizable=yes,scrollbars=yes,location=no, status=no');
  newwin.resizeTo(window.screen.availWidth, window.screen.availHeight);
  newwin.moveTo(0, 0);
  return false;
}