//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;
|
}
|