Files
ulthon_admin/public/static/plugs/ulthon-admin/admin-core.js

322 lines
12 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function () {
window.onInitElemStyle = function () {
miniTheme.renderElemStyle();
$('iframe').each(function (index, iframe) {
if (typeof iframe.contentWindow.onInitElemStyle == "function") {
iframe.contentWindow.onInitElemStyle();
}
});
};
// body 解析完成后才执行打类:本脚本位于 head,立即执行时 $('body') 为空集合导致类未打上;
// 仅框架页(pageType=index)及其 iframe 内容页(parent.pageType=index)执行,
// 登录页等独立顶层页面不打皮肤类,维持既有视觉
$(function () {
var in_frame = window.parent && window.parent != window;
if (window.pageType == 'index' || (in_frame && window.parent.pageType == 'index')) {
window.onInitElemStyle();
}
});
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate,
upload = layui.upload,
element = layui.element,
laytpl = layui.laytpl,
util = layui.util;
layer.config({
skin: 'layui-layer-easy'
});
var init = {
tableElem: '#currentTable',
tableRenderId: 'currentTableRenderId',
uploadUrl: 'ajax/upload',
uploadExts: '',
extGroup: {}
};
var table;
table = layui.table;
var extGroup = {
// 图片扩展名数组
'image': ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico', 'webp', 'svg'],
// word扩展名数组
'word': ['doc', 'docx'],
// excel扩展名数组
'excel': ['xls', 'xlsx'],
// ppt扩展名数组
'ppt': ['ppt', 'pptx'],
// pdf扩展名数组
'pdf': ['pdf'],
// 压缩文件扩展名数组
'zip': ['zip', 'rar', '7z'],
// 文本文件扩展名数组
'txt': ['txt'],
// 音乐文件扩展名数组
'music': ['mp3', 'wma', 'wav', 'mid', 'm4a'],
// 视频文件扩展名数组
'video': ['mp4', 'avi', 'wmv', '3gp', 'flv'],
// visio扩展名数组
'visio': ['vsd', 'vsdx'],
'file': []
};
var allExtGroup = [];
for (const extGroupName in extGroup) {
if (Object.hasOwnProperty.call(extGroup, extGroupName)) {
const extGroupList = extGroup[extGroupName];
allExtGroup = allExtGroup.concat(extGroupList);
}
}
extGroup['office'] = [].concat(extGroup['word'], extGroup['excel'], extGroup['ppt'], extGroup['pdf']);
extGroup['media'] = [].concat(extGroup['image'], extGroup['music'], extGroup['video']);
init.uploadExts += allExtGroup.join('|');
init.extGroup = extGroup;
var ua = {
init: init,
config: {
shade: [0.02, '#000'],
},
url: function (url) {
var urlPrefixCheck = ['/', 'http://', 'https://'];
for (const index in urlPrefixCheck) {
if (Object.hasOwnProperty.call(urlPrefixCheck, index)) {
const prefix = urlPrefixCheck[index];
if (url.indexOf(prefix) === 0) {
return url;
}
}
}
return '/' + CONFIG.ADMIN + '/' + url;
},
headers: function () {
return { 'X-CSRF-TOKEN': window.CONFIG.CSRF_TOKEN };
},
// 全局权限判定:读服务端注入的权限集合 window.UA_AUTH({all, controller, nodes})。
// 无有效载荷(undefined/false,旧服务端渲染或异常)返回 undefined,由 checkAuth 落回 data-auth 属性判定;
// 前端不做 snake/驼峰规范化转换,全节点字符串必须与注册节点逐字一致
auth: function (node) {
var payload = window.UA_AUTH;
if (typeof payload !== 'object' || payload === null) {
return undefined;
}
if (payload.all) {
return true;
}
var controller, action;
if (node.indexOf('/') === -1) {
controller = payload.controller;
action = node;
} else {
// 按第一个 '/' 拆解;禁止 split('/', 2):JS 的 limit 是丢弃余段语义,多段节点会静默截断
var i = node.indexOf('/');
controller = node.slice(0, i);
action = node.slice(i + 1);
}
var actions = payload.nodes ? payload.nodes[controller] : undefined;
return actions ? actions.indexOf(action) !== -1 : false;
},
checkAuth: function (node, elem) {
if (node === '1') {
return true;
}
if (CONFIG.IS_SUPER_ADMIN) {
return true;
}
if (ua.auth(node) === true) {
return true;
}
return !!(elem && $(elem).attr('data-auth-' + node) === '1');
},
parame: function (param, defaultParam) {
return param !== undefined ? param : defaultParam;
},
request: {
post: function (option, ok, no, ex, complete) {
return ua.request.ajax('post', option, ok, no, ex, complete);
},
get: function (option, ok, no, ex, complete) {
return ua.request.ajax('get', option, ok, no, ex, complete);
},
ajax: function (type, option, ok, no, ex, complete) {
type = type || 'get';
option.url = option.url || '';
option.data = option.data || {};
option.prefix = option.prefix || false;
option.statusName = option.statusName || 'code';
option.statusCode = option.statusCode || 0;
ok = ok || function (res) {};
var originalOk = ok;
ok = function (res) {
originalOk(res);
complete()
}
complete = complete || function () {
};
if (no) {
var originalNo = no;
no = function (res) {
originalNo(res);
complete();
};
} else {
no = function (res) {
var msg = res.msg == undefined ? '返回数据格式有误' : res.msg;
ua.msg.error(msg);
complete();
return false;
};
}
if (ex) {
var originalEx = ex;
ex = function (res) {
originalEx(res);
complete();
};
} else {
ex = function (res) {
complete();
};
}
if (option.url == '') {
ua.msg.error('请求地址不能为空');
return false;
}
if (option.prefix == true) {
option.url = ua.url(option.url);
}
loading.show();
$.ajax({
url: option.url,
type: type,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "json",
headers: ua.headers(),
data: option.data,
timeout: 60000,
success: function (res) {
loading.hide();
if (eval('res.' + option.statusName) == option.statusCode) {
return ok(res);
} else {
return no(res);
}
},
error: function (xhr, textstatus, thrown) {
var errorMsg = '';
if (xhr.responseJSON.message) {
errorMsg = xhr.responseJSON.message;
}
loading.hide();
ua.msg.error('Status:' + xhr.status + ',' + xhr.statusText + ',请稍后再试!<br/>' + errorMsg, function () {
ex(this);
});
return false;
},
});
}
},
common: {
parseNodeStr: function (node) {
var array = node.split('/');
$.each(array, function (key, val) {
if (key === 0) {
val = val.split('.');
$.each(val, function (i, v) {
val[i] = ua.common.humpToLine(v.replace(v[0], v[0].toLowerCase()));
});
val = val.join(".");
array[key] = val;
}
});
node = array.join("/");
return node;
},
lineToHump: function (name) {
return name.replace(/\_(\w)/g, function (all, letter) {
return letter.toUpperCase();
});
},
humpToLine: function (name) {
return name.replace(/([A-Z])/g, "_$1").toLowerCase();
},
},
msg: {
// 成功消息
success: function (msg, callback) {
if (callback === undefined) {
callback = function () {
};
}
var index = layer.msg(msg, { icon: 1, shade: ua.config.shade, scrollbar: false, time: 800, shadeClose: true }, callback);
return index;
},
// 失败消息
error: function (msg, callback) {
if (callback === undefined) {
callback = function () {
};
}
var index = layer.msg(msg, { icon: 2, shade: ua.config.shade, scrollbar: false, time: -1, shadeClose: true }, callback);
return index;
},
// 警告消息框
alert: function (msg, callback) {
var index = layer.alert(msg, { end: callback, scrollbar: false });
return index;
},
// 对话框
confirm: function (msg, ok, no) {
var index = layer.confirm(msg, { title: '操作确认', btn: ['确认', '取消'] }, function () {
typeof ok === 'function' && ok.call(this);
}, function () {
typeof no === 'function' && no.call(this);
});
return index;
},
// 消息提示
tips: function (msg, time, callback) {
var index = layer.msg(msg, { time: (time || 0.8) * 1000, shade: this.shade, end: callback, shadeClose: true });
return index;
},
// 加载中提示
loading: function (msg, callback) {
var index = msg ? layer.msg(msg, { icon: 16, scrollbar: false, shade: this.shade, time: 0, end: callback }) : layer.load(2, { time: 0, scrollbar: false, shade: this.shade, end: callback });
return index;
},
// 关闭消息框
close: function (index) {
return layer.close(index);
}
}
};
window.UA_CORE = { form: form, layer: layer, laydate: laydate, upload: upload, element: element, laytpl: laytpl, util: util, table: table };
window.UA_SHARED = { init: init, extGroup: extGroup };
window.UA_ADMIN = ua;
})();