mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 07:22:49 +08:00
290 lines
9.9 KiB
PHP
290 lines
9.9 KiB
PHP
|
||
(function () {
|
||
|
||
window.onInitElemStyle = function () {
|
||
miniTheme.renderElemStyle();
|
||
|
||
$('iframe').each(function (index, iframe) {
|
||
|
||
if (typeof iframe.contentWindow.onInitElemStyle == "function") {
|
||
iframe.contentWindow.onInitElemStyle();
|
||
}
|
||
});
|
||
|
||
};
|
||
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 };
|
||
},
|
||
|
||
checkAuth: function (node, elem) {
|
||
if (node === '1') {
|
||
return true;
|
||
}
|
||
if (CONFIG.IS_SUPER_ADMIN) {
|
||
return true;
|
||
}
|
||
if ($(elem).attr('data-auth-' + node) === '1') {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
},
|
||
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;
|
||
})();
|