更新功能
This commit is contained in:
@@ -23,8 +23,8 @@ require.config({
|
||||
"nanoscroller":"/static/libs/nanoscroller/jquery.nanoscroller.min",
|
||||
"slimscroll":"/static/js/jquery.slimscroll.min",
|
||||
"bootstrap":"/static/libs/bootstrap/js/bootstrap.min",
|
||||
'bootstrap-table-commonsearch': 'bootstrap-table-commonsearch',
|
||||
'bootstrap-table-template': 'bootstrap-table-template',
|
||||
'bootstrap-table-commonsearch': '/static/js/bootstrap-table-commonsearch',
|
||||
'bootstrap-table-template': '/static/js/bootstrap-table-template',
|
||||
//
|
||||
// 以下的包从bower的libs目录加载
|
||||
'jquery': '/static/libs/jquery/dist/jquery.min',
|
||||
@@ -129,7 +129,7 @@ require.config({
|
||||
|
||||
require(['jquery', 'sent'], function($, Sent){
|
||||
$(function($) {
|
||||
require(['backend', 'backend-init', 'addons'], function (Backend, undefined, Addons) {
|
||||
require(['backend', 'addons'], function (Backend, Addons) {
|
||||
// 避免目录冲突
|
||||
require.config({baseUrl: '/static/admin/js/module/'});
|
||||
|
||||
|
||||
@@ -23,12 +23,45 @@ define(['jquery', 'toastr','layer'], function($, Toastr, Layer){
|
||||
|
||||
init: function () {
|
||||
|
||||
//绑定表单提交事件
|
||||
if($('form[role=ajax]').length > 0){
|
||||
require(['form'], function(Form){
|
||||
Form.api.bindevent($("form"));
|
||||
})
|
||||
}
|
||||
|
||||
//绑定ajax请求事件
|
||||
if($('.ajax-post').length > 0){
|
||||
$('.ajax-post').on('click', function(e){
|
||||
Sent.events.onAjaxRequest(this, e, 'post');
|
||||
})
|
||||
}
|
||||
|
||||
if($('.ajax-get').length > 0){
|
||||
$('.ajax-post').on('click', function(e){
|
||||
Sent.events.onAjaxRequest(this, e, 'get');
|
||||
})
|
||||
}
|
||||
|
||||
//公共代码
|
||||
//配置Toastr的参数
|
||||
Toastr.options = Sent.config.toastr;
|
||||
},
|
||||
|
||||
events: {
|
||||
//ajax请求
|
||||
onAjaxRequest: function(obj, event, type){
|
||||
event.preventDefault();
|
||||
var url = $(obj).attr('href') ? $(obj).attr('href') : $(obj).attr('url');
|
||||
if ($(obj).hasClass('confirm')) {
|
||||
Layer.confirm('您确定需要'+$(obj).text()+'?', function(index){
|
||||
Sent.api.ajax({type:type, url: url});
|
||||
layer.close(index);
|
||||
})
|
||||
}else{
|
||||
Sent.api.ajax({type:type, url: url});
|
||||
}
|
||||
},
|
||||
//请求成功的回调
|
||||
onAjaxSuccess: function (ret, onAjaxSuccess) {
|
||||
var data = typeof ret.data !== 'undefined' ? ret.data : null;
|
||||
@@ -85,6 +118,11 @@ define(['jquery', 'toastr','layer'], function($, Toastr, Layer){
|
||||
} else {
|
||||
Sent.events.onAjaxError(ret, error);
|
||||
}
|
||||
if (ret.url) {
|
||||
setTimeout(function(){
|
||||
window.location.href = ret.url;
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
index && Layer.close(index);
|
||||
@@ -249,19 +287,60 @@ define(['jquery', 'toastr','layer'], function($, Toastr, Layer){
|
||||
},
|
||||
toastr: Toastr,
|
||||
layer: Layer
|
||||
}
|
||||
},
|
||||
lang: function () {
|
||||
var args = arguments,
|
||||
string = args[0],
|
||||
i = 1;
|
||||
string = string.toLowerCase();
|
||||
//string = typeof Lang[string] != 'undefined' ? Lang[string] : string;
|
||||
if (typeof Lang !== 'undefined' && typeof Lang[string] !== 'undefined') {
|
||||
if (typeof Lang[string] == 'object')
|
||||
return Lang[string];
|
||||
string = Lang[string];
|
||||
} else if (string.indexOf('.') !== -1 && false) {
|
||||
var arr = string.split('.');
|
||||
var current = Lang[arr[0]];
|
||||
for (var i = 1; i < arr.length; i++) {
|
||||
current = typeof current[arr[i]] != 'undefined' ? current[arr[i]] : '';
|
||||
if (typeof current != 'object')
|
||||
break;
|
||||
}
|
||||
if (typeof current == 'object')
|
||||
return current;
|
||||
string = current;
|
||||
} else {
|
||||
string = args[0];
|
||||
}
|
||||
return string.replace(/%((%)|s|d)/g, function (m) {
|
||||
// m is the matched format, e.g. %s, %d
|
||||
var val = null;
|
||||
if (m[2]) {
|
||||
val = m[2];
|
||||
} else {
|
||||
val = args[i];
|
||||
// A switch statement so that the formatter can be extended. Default is %s
|
||||
switch (m) {
|
||||
case '%d':
|
||||
val = parseFloat(val);
|
||||
if (isNaN(val)) {
|
||||
val = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return val;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if($('form').length > 0){
|
||||
require(['form'], function(Form){
|
||||
Form.api.bindevent($("form"));
|
||||
})
|
||||
}
|
||||
//将Layer暴露到全局中去
|
||||
window.Layer = Layer;
|
||||
//将Toastr暴露到全局中去
|
||||
window.Toastr = Toastr;
|
||||
//将Fast渲染至全局
|
||||
//将语言方法暴露到全局中去
|
||||
window.__ = Sent.lang;
|
||||
//将Sent渲染至全局
|
||||
window.Sent = Sent;
|
||||
|
||||
Sent.init(); //默认初始化执行的代码
|
||||
|
||||
Reference in New Issue
Block a user