3
13693261870
2022-09-16 63ba114e70e380442fcbed4a5157ee52c9491216
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
//jqGrid的配置信息
if($.jgrid){
    $.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;
 
//只执行一次getToken()
var hasNewToken = false;
//登录token
var token = localStorage.getItem("token"); //localStorage sessionStorage
if(!token){
//    parent.location.href = baseURL + 'admin/login.html';
//根据参数是否带有username和validatenumber来判断请求来源是否是办公自动化系统,若是则进行反向验证登录\
    if(T.p("username")&&T.p("validateNumber")){
        ValidLoginUser(T.p("validateNumber"));
    }
    
   if(iisRun) getToken();
}
 
 
function ValidLoginUser(validateNumber){
 
    $.ajax({
           type: "get",
           async:false,
        url:restServerBaseURL + "sys/portallogin" ,
           dataType: "json",
           timeout: 10000,
           data: "",
           error:function(){
                alert('读取数据错误');
                 },
           success:function(data){
               //debugger
              if(data.result.validateResult==true){
                  console.log('调用成功');
                  
              }         
       }
     });
}
//jquery全局配置
$.ajaxSetup({
    // beforeSend: function(xhr) {
    //     console.log("beforeSend:token is [%s]",token);
    // },
    dataType: "json",
    cache: false,
    headers: {
        "token": token
    },
    xhrFields: {
        withCredentials: true
    },
    crossDomain: true,
    complete: function(xhr) {
        // console.log("complete:token is [%s], xhr.responseJSON:",token,xhr.responseJSON);
        //无效的token,则跳转到登录页面
        if(!!xhr.responseJSON && xhr.responseJSON.code == 401){
            //localStorage.setItem("token", "");
            //alert("无效的token,请刷新页面或重新登陆系统!");
            //parent.location.href = baseURL + 'admin/login.html';
            //debugger;
            //getToken();
        }
        //无效的token的另一种情况:ajax请求未完成即返回错误
//        if(!!token && !xhr.responseJSON){
//            debugger;
//            getToken();
//        }
    }
});
 
//jqgrid全局配置
if($.jgrid){
    $.extend($.jgrid.defaults, {
        ajaxGridOptions : {
                headers: {
                "token": token
            }
        }
    });
}
 
//获得Token
function getToken() {
    // console.log("getToken:");
    if(hasNewToken){
        return;
    }
    hasNewToken = true;
    //debugger
    $.ajax({
        // async: false,
        type: "GET",
        url: restServerBaseURL + "sys/caslogin2",
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback: "casloginCallback",
        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) {  //alert ykm 2019-01-18 修改因门户点击进运维监控,没有权限的用户进到(//弹出窗口的权限判断)出现错误
    if (window.parent.permissions != undefined) {
        if(window.parent.permissions.indexOf(permission) > -1) {
            return true;
        }
        else {
            return false;
        }
    } else if(window.opener != undefined && window.opener.parent != undefined && window.opener.parent != null &&  window.opener.parent.permissions != undefined && window.opener.parent.permissions != null  && window.opener.parent.permissions.indexOf(permission) > -1){ //弹出窗口的权限判断
        return true;
    } else if(window.opener != undefined && window.opener.opener != undefined && window.opener.opener.parent.permissions != undefined && window.opener.opener.parent.permissions.indexOf(permission) > -1){
        return true;//窗口里再弹窗口 (单位管理)
    }else{
        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 resetForm(formId) {
    document.getElementById(formId).reset();
}
 
//获取appId
function getAppId(){
    if (window.parent.appId != undefined) {
        return window.parent.appId;
    } else if(window.opener != undefined && window.opener.parent.appId != undefined){
        return window.opener.parent.appId;
    }else{
        return null
    }
}