优化后台UI
完善表单上传组件
This commit is contained in:
+114
-78
@@ -1,16 +1,18 @@
|
||||
define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
define(['jquery', 'layer', 'message'], function ($, layer) {
|
||||
var sent = {
|
||||
config: {
|
||||
keyName: 'sent_'
|
||||
},
|
||||
init: function(){
|
||||
init: function () {
|
||||
if ($("form[role=form]").length > 0) {
|
||||
require(['form'], function(form){
|
||||
require(['form'], function (form) {
|
||||
form.api.bindevent($("form[role=form]"));
|
||||
})
|
||||
}
|
||||
sent.api.bindGet(); //绑定get请求
|
||||
sent.api.bindPost(); //绑定post请求
|
||||
},
|
||||
msg: function(text, type){
|
||||
msg: function (text, type) {
|
||||
text = (type == 'success') ? text + ' 页面即将自动跳转~' : text;
|
||||
if (typeof type != 'undefined') {
|
||||
var message = $.messager.show(text, {
|
||||
@@ -40,8 +42,12 @@ define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
return obj;
|
||||
},
|
||||
store: {
|
||||
set: function(params = {}){
|
||||
var { name, content, type} = params;
|
||||
set: function (params = {}) {
|
||||
var {
|
||||
name,
|
||||
content,
|
||||
type
|
||||
} = params;
|
||||
name = sent.config.keyName + name
|
||||
var obj = {
|
||||
dataType: typeof (content),
|
||||
@@ -52,8 +58,11 @@ define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
if (type) window.sessionStorage.setItem(name, JSON.stringify(obj));
|
||||
else window.localStorage.setItem(name, JSON.stringify(obj));
|
||||
},
|
||||
get: function(params = {}){
|
||||
var { name, debug } = params;
|
||||
get: function (params = {}) {
|
||||
var {
|
||||
name,
|
||||
debug
|
||||
} = params;
|
||||
name = sent.config.keyName + name
|
||||
var obj = {},
|
||||
content;
|
||||
@@ -79,8 +88,11 @@ define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
}
|
||||
return content;
|
||||
},
|
||||
remove: function(params = {}){
|
||||
let { name, type } = params;
|
||||
remove: function (params = {}) {
|
||||
let {
|
||||
name,
|
||||
type
|
||||
} = params;
|
||||
name = sent.config.keyName + name
|
||||
if (type) {
|
||||
window.sessionStorage.removeItem(name);
|
||||
@@ -88,9 +100,11 @@ define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
window.localStorage.removeItem(name);
|
||||
}
|
||||
},
|
||||
all: function(params = {}){
|
||||
all: function (params = {}) {
|
||||
let list = [];
|
||||
let { type } = params;
|
||||
let {
|
||||
type
|
||||
} = params;
|
||||
if (type) {
|
||||
for (let i = 0; i <= window.sessionStorage.length; i++) {
|
||||
list.push({
|
||||
@@ -109,13 +123,15 @@ define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
name: window.localStorage.key(i),
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return list;
|
||||
},
|
||||
clear: function(params = {}){
|
||||
let { type } = params;
|
||||
clear: function (params = {}) {
|
||||
let {
|
||||
type
|
||||
} = params;
|
||||
if (type) {
|
||||
window.sessionStorage.clear();
|
||||
} else {
|
||||
@@ -124,72 +140,92 @@ define(['jquery', 'layer', 'message'], function($, layer) {
|
||||
}
|
||||
},
|
||||
events: {
|
||||
//请求成功的回调
|
||||
onAjaxSuccess: function (ret, onAjaxSuccess) {
|
||||
var data = typeof ret.data !== 'undefined' ? ret.data : null;
|
||||
var msg = typeof ret.msg !== 'undefined' && ret.msg ? ret.msg : __('Operation completed');
|
||||
//请求成功的回调
|
||||
onAjaxSuccess: function (ret, onAjaxSuccess) {
|
||||
var data = typeof ret.data !== 'undefined' ? ret.data : null;
|
||||
var msg = typeof ret.msg !== 'undefined' && ret.msg ? ret.msg : __('Operation completed');
|
||||
|
||||
if (typeof onAjaxSuccess === 'function') {
|
||||
var result = onAjaxSuccess.call(this, data, ret);
|
||||
if (result === false)
|
||||
return;
|
||||
}
|
||||
sent.msg(msg, 'success');
|
||||
},
|
||||
//请求错误的回调
|
||||
onAjaxError: function (ret, onAjaxError) {
|
||||
var data = typeof ret.data !== 'undefined' ? ret.data : null;
|
||||
if (typeof onAjaxError === 'function') {
|
||||
var result = onAjaxError.call(this, data, ret);
|
||||
if (result === false) {
|
||||
return;
|
||||
}
|
||||
if (typeof onAjaxSuccess === 'function') {
|
||||
var result = onAjaxSuccess.call(this, data, ret);
|
||||
if (result === false)
|
||||
return;
|
||||
}
|
||||
sent.msg(ret.msg, 'error');
|
||||
},
|
||||
//服务器响应数据后
|
||||
onAjaxResponse: function (response) {
|
||||
try {
|
||||
var ret = typeof response === 'object' ? response : JSON.parse(response);
|
||||
if (!ret.hasOwnProperty('code')) {
|
||||
$.extend(ret, {code: -2, msg: response, data: null});
|
||||
}
|
||||
} catch (e) {
|
||||
var ret = {code: -1, msg: e.message, data: null};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
api:{
|
||||
//发送Ajax请求
|
||||
ajax: function (options, success, error) {
|
||||
options = typeof options === 'string' ? {url: options} : options;
|
||||
var index;
|
||||
if (typeof options.loading === 'undefined' || options.loading) {
|
||||
index = layer.load(options.loading || 0);
|
||||
}
|
||||
options = $.extend({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function (ret) {
|
||||
index && layer.close(index);
|
||||
ret = sent.events.onAjaxResponse(ret);
|
||||
if (ret.code === 1) {
|
||||
sent.events.onAjaxSuccess(ret, success);
|
||||
} else {
|
||||
sent.events.onAjaxError(ret, error);
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
index && layer.close(index);
|
||||
var ret = {code: xhr.status, msg: xhr.statusText, data: null};
|
||||
sent.events.onAjaxError(ret, error);
|
||||
}
|
||||
}, options);
|
||||
return $.ajax(options);
|
||||
},
|
||||
sent.msg(msg, 'success');
|
||||
},
|
||||
//请求错误的回调
|
||||
onAjaxError: function (ret, onAjaxError) {
|
||||
var data = typeof ret.data !== 'undefined' ? ret.data : null;
|
||||
if (typeof onAjaxError === 'function') {
|
||||
var result = onAjaxError.call(this, data, ret);
|
||||
if (result === false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
sent.msg(ret.msg, 'error');
|
||||
},
|
||||
//服务器响应数据后
|
||||
onAjaxResponse: function (response) {
|
||||
try {
|
||||
var ret = typeof response === 'object' ? response : JSON.parse(response);
|
||||
if (!ret.hasOwnProperty('code')) {
|
||||
$.extend(ret, {
|
||||
code: -2,
|
||||
msg: response,
|
||||
data: null
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
var ret = {
|
||||
code: -1,
|
||||
msg: e.message,
|
||||
data: null
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
validatenull: function(val){
|
||||
api: {
|
||||
//发送Ajax请求
|
||||
ajax: function (options, success, error) {
|
||||
options = typeof options === 'string' ? {
|
||||
url: options
|
||||
} : options;
|
||||
var index;
|
||||
if (typeof options.loading === 'undefined' || options.loading) {
|
||||
index = layer.load(options.loading || 0);
|
||||
}
|
||||
options = $.extend({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
success: function (ret) {
|
||||
index && layer.close(index);
|
||||
ret = sent.events.onAjaxResponse(ret);
|
||||
if (ret.code === 1) {
|
||||
sent.events.onAjaxSuccess(ret, success);
|
||||
} else {
|
||||
sent.events.onAjaxError(ret, error);
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
index && layer.close(index);
|
||||
var ret = {
|
||||
code: xhr.status,
|
||||
msg: xhr.statusText,
|
||||
data: null
|
||||
};
|
||||
sent.events.onAjaxError(ret, error);
|
||||
}
|
||||
}, options);
|
||||
return $.ajax(options);
|
||||
},
|
||||
bindGet: function(){
|
||||
|
||||
},
|
||||
bindPost: function(){
|
||||
|
||||
}
|
||||
},
|
||||
validatenull: function (val) {
|
||||
if (typeof val == 'boolean') {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user