Skip to content

Commit

Permalink
🦄 fix some bug and optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Feb 26, 2017
1 parent 8207ddb commit ecd6d8a
Show file tree
Hide file tree
Showing 16 changed files with 365 additions and 308 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/tale/init/TaleJdbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,12 @@ public static void testConn() {
Connection con = DriverManager.getConnection(jdbc_prop.getProperty("url"), jdbc_prop.getProperty("username"), jdbc_prop.getProperty("password"));
ScriptRunner runner = new ScriptRunner(con, false, true);
String cp = TaleJdbc.class.getClassLoader().getResource("").getPath();

InputStreamReader isr = new InputStreamReader(new FileInputStream(cp + "schema.sql"), "UTF-8");
BufferedReader read = new BufferedReader(isr);
runner.runScript(read);
con.close();
} catch (Exception e) {
e.printStackTrace();
throw new TipException("数据库连接失败, 请检查数据库配置");
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/tale/service/impl/ContentsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public void publish(Contents contents) {
throw new TipException("请登录后发布文章");

if (StringKit.isNotBlank(contents.getSlug())) {
if(contents.getSlug().length() < 5){
throw new TipException("路径太短了");
}
if (!TaleUtils.isPath(contents.getSlug())) throw new TipException("您输入的路径不合法");

int count = activeRecord.count(new Take(Contents.class).eq("type", contents.getType()).eq("slug", contents.getSlug()));
Expand Down
35 changes: 20 additions & 15 deletions src/main/resources/static/admin/js/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ $(".select2").select2({
width: '100%'
});

var tale = new $.tale();

/**
* 保存文章
* @param status
Expand All @@ -28,31 +30,34 @@ function subArticle(status) {
var title = $('#articleForm input[name=title]').val();
var content = $('#text').val();
if (title == '') {
swal('提示信息', '请输入文章标题', 'warning');
tale.alertWarn('请输入文章标题');
return;
}
if (content == '') {
swal('提示信息', '请输入文章内容', 'warning');
tale.alertWarn('请输入文章内容');
return;
}
$('#content-editor').val(content);
$("#articleForm #status").val(status);
$("#articleForm #categories").val($('#multiple-sel').val());
var params = $("#articleForm").serialize();
var url = $('#articleForm #cid').val() != '' ? '/admin/article/modify' : '/admin/article/publish';
$.post(url, params, function (result) {
if (result && result.success) {
swal({
title: "提示信息",
text: "文章保存成功",
timer: 2000,
type: 'success'
});
setTimeout(function () {
window.location.href = '/admin/article';
}, 2000);
} else {
swal("提示消息", result.msg, 'error');
tale.post({
url:url,
data:params,
success: function (result) {
if (result && result.success) {
tale.alertOk({
text:'文章保存成功',
then: function () {
setTimeout(function () {
window.location.href = '/admin/article';
}, 500);
}
});
} else {
tale.alertError(result.msg || '保存文章失败');
}
}
});
}
Expand Down
226 changes: 114 additions & 112 deletions src/main/resources/static/admin/js/base.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,152 @@

/**
* Tale全局函数对象 var tale = new $.tale();
*/
$.extend({
tale: function () {}
tale: function () {
}
});

/**
* tale alert删除 // todo: 减少耦合度,链式操作替代 2017-02-27
* @param options
*/
$.tale.prototype.alert_del = function (options) {
swal({
title: options.title || '警告信息',
text: options.text || "确定删除吗?",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(function () {
$.post(options.url, options.parame, function (result) {
if (result && result.success) {
swal('提示信息', '删除成功', 'success');
setTimeout(function () {
window.location.reload();
}, 2000);
} else {
swal("提示消息", result.msg, 'error');
}
});
}).catch(swal.noop);
// $.tale.prototype.alert_del = function (options) {
// swal({
// title: options.title || '警告信息',
// text: options.text || "确定删除吗?",
// type: 'warning',
// showCancelButton: true,
// confirmButtonColor: '#3085d6',
// cancelButtonColor: '#d33',
// confirmButtonText: '确定',
// cancelButtonText: '取消'
// }).then(function () {
// $.post(options.url, options.parame, function (result) {
// if (result && result.success) {
// swal('提示信息', '删除成功', 'success');
// setTimeout(function () {
// window.location.reload();
// }, 2000);
// } else {
// swal("提示消息", result.msg, 'error');
// }
// });
// }).catch(swal.noop);
// };

/**
* 成功弹框
* @param options
*/
$.tale.prototype.alertOk = function (options) {
options = options.length ? {text:options} : ( options || {} );
options.title = options.title || '操作成功';
options.text = options.text;
options.showCancelButton = false;
options.showCloseButton = false;
options.type = 'success';
this.alertBox(options);
};

/**
*
* 弹出成功,并在500毫秒后刷新页面
* @param text
*/
$.tale.prototype.alertOkAndReload = function (text) {
this.alertOk({text:text, then:function () {
setTimeout(function () {
window.location.reload();
}, 500);
}});
};

/**
* 警告弹框
* @param options
*/
$.tale.prototype.alert_ok = function (options){
swal(option.title || '提示信息', options.text, 'success');
$.tale.prototype.alertWarn = function (options) {
options = options.length ? {text:options} : ( options || {} );
options.title = options.title || '警告信息';
options.text = options.text;
options.timer = 3000;
options.type = 'warning';
this.alertBox(options);
};

$.tale.prototype.alert_error = function(options){
swal(option.title || '提示信息', options.text, 'error');
/**
* 询问确认弹框,这里会传入then函数进来
* @param options
*/
$.tale.prototype.alertConfirm = function (options) {
options = options || {};
options.title = options.title || '确定要删除吗?';
options.text = options.text;
options.showCancelButton = true;
options.type = 'question';
this.alertBox(options);
};

/**
* 错误提示
* @param options
*/
$.tale.prototype.alertError = function (options) {
options = options.length ? {text:options} : ( options || {} );
options.title = options.title || '错误信息';
options.text = options.text;
options.type = 'error';
this.alertBox(options);
};

/**
* 公共弹框
* @param options
*/
$.tale.prototype.alertBox = function (options) {
swal({
title: options.title,
text: options.text,
type: options.type,
timer: options.timer || 9999,
showCloseButton: options.showCloseButton,
showCancelButton: options.showCancelButton,
showLoaderOnConfirm: options.showLoaderOnConfirm || false,
confirmButtonColor: options.confirmButtonColor || '#3085d6',
cancelButtonColor: options.cancelButtonColor || '#d33',
confirmButtonText: options.confirmButtonText || '确定',
cancelButtonText: options.cancelButtonText || '取消'
}).then(function (e) {
options.then && options.then(e);
}).catch(swal.noop);
};

/**
* 全局post函数
*
* @param options 参数
* @param callback 成功后调用的函数
*/
$.tale.prototype.post = function(options, callback){
$.tale.prototype.post = function (options) {
var self = this;
$.ajax({
type: 'POST',
url: options.url,
data: options.data || {},
async: options.async || false,
dataType: 'json',
success: function (result) {
if (result && result.success) {
callback && callback();
} else {
swal("提示消息", result.msg, 'error');
}
self.hideLoading();
options.success && options.success(result);
},
error: function () {
//
}
});
};

/**
* 显示动画
*/
$.tale.prototype.showLoading = function(){
$.tale.prototype.showLoading = function () {
if ($('#tale-loading').length == 0) {
$('body').append('<div id="tale-loading"></div>');
}
Expand All @@ -82,78 +156,6 @@ $.tale.prototype.showLoading = function(){
/**
* 隐藏动画
*/
$.tale.prototype.hideLoading = function(){
$('#tale-loading').hide();
};

//
///**
// * Tale全局函数对象
// * @type {{}}
// */
//var tale = {};
//

//
///**
// * 弹出确认对话框
// * @param options
// */
//tale.alertQA = function (options) {
// options = options || {};
// options.title = options.title || '确定要删除吗?';
// options.text = options.text;
// options.showCancelButton = true;
// options.type = 'question';
// this.alertBox(options);
//};

///**
// * 弹出警告对话框
// * @param options
// */
//tale.alertWarn = function (options) {
// options = options || {};
// options.title = options.title || '警告信息';
// options.text = options.text;
// options.type = 'warning';
// this.alertBox(options);
//};
///**
// * 公共对话框
// * @param options
// */
//tale.alertBox = function (options) {
// swal({
// title: options.title,
// text: options.text,
// type: options.type,
// showCloseButton: options.showCloseButton,
// showCancelButton: options.showCancelButton,
// showLoaderOnConfirm: options.showLoaderOnConfirm || false,
// confirmButtonColor: options.confirmButtonColor || '#3085d6',
// cancelButtonColor: options.cancelButtonColor || '#d33',
// confirmButtonText: options.confirmButtonText || '确定',
// cancelButtonText: options.cancelButtonText || '取消'
// }).then(function (e) {
// options.then(e);
// }).catch(swal.noop);
//};

///**
// * 显示loading动画
// */
//tale.showLoading = function () {
// if ($('#tale-loading').length == 0) {
// $('body').append('<div id="tale-loading"></div>');
// }
// $('#tale-loading').show();
//};
///**
// * 隐藏loading动画
// */
//tale.hideLoading = function () {
// $('#tale-loading').hide();
//};


$.tale.prototype.hideLoading = function () {
$('#tale-loading') && $('#tale-loading').hide();
};
Loading

0 comments on commit ecd6d8a

Please sign in to comment.