|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
// 检查全选框是否被选中,并根据状态设置其他复选框的选中状态
|
|
|
|
|
function DoCheck() {
|
|
|
|
|
var ch = document.getElementsByName("ids");
|
|
|
|
|
if (document.getElementById("allSelect").checked == true) {
|
|
|
|
|
@ -11,25 +12,25 @@ function DoCheck() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 确认删除操作,弹出确认对话框,根据用户选择返回true或false
|
|
|
|
|
function confirmDelete() {
|
|
|
|
|
var msg = "您确定要删除吗?";
|
|
|
|
|
if (confirm(msg)==true){
|
|
|
|
|
if (confirm(msg) == true) {
|
|
|
|
|
return true;
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取相对路径
|
|
|
|
|
function getPath(){
|
|
|
|
|
// 获取当前页面的相对路径
|
|
|
|
|
function getPath() {
|
|
|
|
|
var pathName = document.location.pathname;
|
|
|
|
|
var index = pathName.substr(1).indexOf("/");
|
|
|
|
|
var result = pathName.substr(0,index+1);
|
|
|
|
|
var result = pathName.substr(0, index + 1);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//显示和隐藏row-actions
|
|
|
|
|
// 当鼠标进入dashboard-comment-wrap时显示row-actions,离开时隐藏
|
|
|
|
|
$(".dashboard-comment-wrap").mouseenter(function () {
|
|
|
|
|
$(this).find(".row-actions").show();
|
|
|
|
|
})
|
|
|
|
|
@ -37,118 +38,115 @@ $(".dashboard-comment-wrap").mouseleave(function () {
|
|
|
|
|
$(this).find(".row-actions").hide();
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
//删除评论
|
|
|
|
|
// 删除评论,先确认删除,然后发送AJAX请求删除评论,并刷新页面
|
|
|
|
|
function deleteComment(id) {
|
|
|
|
|
if(confirmDelete()==true){
|
|
|
|
|
if (confirmDelete() == true) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "POST",
|
|
|
|
|
url:'/admin/comment/delete/'+id,
|
|
|
|
|
contentType : "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
url: '/admin/comment/delete/' + id,
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
dataType: "text",
|
|
|
|
|
complete:function () {
|
|
|
|
|
complete: function () {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加草稿
|
|
|
|
|
// 添加草稿,检查文章内容和标题是否为空,然后发送AJAX请求添加草稿,并刷新页面
|
|
|
|
|
function insertDraft() {
|
|
|
|
|
if($("#articleContent").val!=""&&$("#articleTitle").val()!="") {
|
|
|
|
|
if ($("#articleContent").val != "" && $("#articleTitle").val() != "") {
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "POST",
|
|
|
|
|
url:'/admin/article/insert',
|
|
|
|
|
contentType : "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
url: '/admin/article/insert',
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
dataType: "text",
|
|
|
|
|
complete:function () {
|
|
|
|
|
complete: function () {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除文章
|
|
|
|
|
// 删除文章,先确认删除,然后发送AJAX请求删除文章,并刷新页面
|
|
|
|
|
function deleteArticle(id) {
|
|
|
|
|
if(confirmDelete()==true){
|
|
|
|
|
if (confirmDelete() == true) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "POST",
|
|
|
|
|
url:'/admin/article/delete/'+id,
|
|
|
|
|
contentType : "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
url: '/admin/article/delete/' + id,
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
dataType: "text",
|
|
|
|
|
complete:function () {
|
|
|
|
|
complete: function () {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询文章
|
|
|
|
|
// 查询文章,提交表单到搜索页面
|
|
|
|
|
function queryArticle() {
|
|
|
|
|
//提交form
|
|
|
|
|
$("#articleForm").attr("action", "/admin/article/search");
|
|
|
|
|
$("#articleForm").submit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//批量删除文章
|
|
|
|
|
// 批量删除文章,先确认删除,然后获取选中的文章ID,发送AJAX请求批量删除,并刷新页面
|
|
|
|
|
function confirmDeleteArticleBatch() {
|
|
|
|
|
if(confirmDelete()==true){
|
|
|
|
|
var text = $("input:checkbox[name='ids']:checked").map(function(index,elem) {
|
|
|
|
|
if (confirmDelete() == true) {
|
|
|
|
|
var text = $("input:checkbox[name='ids']:checked").map(function (index, elem) {
|
|
|
|
|
return $(elem).val();
|
|
|
|
|
}).get().join(',');
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "POST",
|
|
|
|
|
url:'/admin/article/deleteBatch',
|
|
|
|
|
data:{ids:text},
|
|
|
|
|
contentType : "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
url: '/admin/article/deleteBatch',
|
|
|
|
|
data: { ids: text },
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
dataType: "text",
|
|
|
|
|
complete:function () {
|
|
|
|
|
complete: function () {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//退出登录
|
|
|
|
|
// 退出登录,发送AJAX请求退出登录,并刷新页面
|
|
|
|
|
function logout() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,
|
|
|
|
|
type: "POST",
|
|
|
|
|
url:'/admin/logout',
|
|
|
|
|
contentType : "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
url: '/admin/logout',
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
dataType: "text",
|
|
|
|
|
complete:function () {
|
|
|
|
|
complete: function () {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//添加用户检查用户名是否存在
|
|
|
|
|
// 添加用户时检查用户名是否存在
|
|
|
|
|
function checkUserName() {
|
|
|
|
|
var result;
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,//同步,待请求完毕后再执行后面的代码
|
|
|
|
|
async: false, //同步,待请求完毕后再执行后面的代码
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: '/admin/user/checkUserName',
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
data: {"username": $("#userName").val(), "id": $("#userId").val()},
|
|
|
|
|
data: { "username": $("#userName").val(), "id": $("#userId").val() },
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
//用户名存在
|
|
|
|
|
if(data.code==1) {
|
|
|
|
|
if (data.code == 1) {
|
|
|
|
|
$("#userNameTips").html(data.msg);
|
|
|
|
|
result=1;
|
|
|
|
|
result = 1;
|
|
|
|
|
}
|
|
|
|
|
//用户名不存在
|
|
|
|
|
if(data.code==0) {
|
|
|
|
|
if (data.code == 0) {
|
|
|
|
|
$("#userNameTips").html(data.msg);
|
|
|
|
|
result=0;
|
|
|
|
|
result = 0;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
@ -158,26 +156,26 @@ function checkUserName() {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//添加用户检查电子邮箱是否存在
|
|
|
|
|
// 添加用户时检查电子邮箱是否存在
|
|
|
|
|
function checkUserEmail() {
|
|
|
|
|
var result;
|
|
|
|
|
$.ajax({
|
|
|
|
|
async: false,//同步,待请求完毕后再执行后面的代码
|
|
|
|
|
async: false, //同步,待请求完毕后再执行后面的代码
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: '/admin/user/checkUserEmail',
|
|
|
|
|
contentType: "application/x-www-form-urlencoded; charset=utf-8",
|
|
|
|
|
data: {"email": $("#userEmail").val(), "id": $("#userId").val()},
|
|
|
|
|
data: { "email": $("#userEmail").val(), "id": $("#userId").val() },
|
|
|
|
|
dataType: "json",
|
|
|
|
|
success: function (data) {
|
|
|
|
|
//用户名存在
|
|
|
|
|
if(data.code==1) {
|
|
|
|
|
//电子邮箱存在
|
|
|
|
|
if (data.code == 1) {
|
|
|
|
|
$("#userEmailTips").html(data.msg);
|
|
|
|
|
result=1;
|
|
|
|
|
result = 1;
|
|
|
|
|
}
|
|
|
|
|
//用户名不存在
|
|
|
|
|
if(data.code==0) {
|
|
|
|
|
//电子邮箱不存在
|
|
|
|
|
if (data.code == 0) {
|
|
|
|
|
$("#userEmailTips").html(data.msg);
|
|
|
|
|
result=0;
|
|
|
|
|
result = 0;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function () {
|
|
|
|
|
@ -187,29 +185,28 @@ function checkUserEmail() {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//添加用户验证和编辑用户验证
|
|
|
|
|
// 使用layui框架进行表单验证
|
|
|
|
|
layui.use(['form', 'layedit', 'laydate'], function () {
|
|
|
|
|
var form = layui.form, layer = layui.layer;
|
|
|
|
|
form.verify({
|
|
|
|
|
|
|
|
|
|
// 用户名验证规则
|
|
|
|
|
userName: function (value) {
|
|
|
|
|
if (value.length > 12 || value.length < 4) {
|
|
|
|
|
return "用户名必须4到12位";
|
|
|
|
|
}
|
|
|
|
|
if(checkUserName()==1) {
|
|
|
|
|
if (checkUserName() == 1) {
|
|
|
|
|
return "用户名已存在";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 电子邮箱验证规则
|
|
|
|
|
userEmail: function () {
|
|
|
|
|
if(checkUserEmail()==1) {
|
|
|
|
|
if (checkUserEmail() == 1) {
|
|
|
|
|
return "电子邮箱已存在";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 表单提交事件
|
|
|
|
|
form.on('submit(demo1)', function (data) {
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
|