初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||||
|
||||
//设置弹窗宽高
|
||||
Fast.config.openArea = ['80%', '80%'];
|
||||
|
||||
var Controller = {
|
||||
index: function () {
|
||||
// 初始化表格参数配置
|
||||
Table.api.init({
|
||||
extend: {
|
||||
index_url: 'cms/page/index',
|
||||
add_url: 'cms/page/add',
|
||||
edit_url: 'cms/page/edit',
|
||||
del_url: 'cms/page/del',
|
||||
multi_url: 'cms/page/multi',
|
||||
table: 'cms_page',
|
||||
}
|
||||
});
|
||||
|
||||
var table = $("#table");
|
||||
|
||||
// 初始化表格
|
||||
table.bootstrapTable({
|
||||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||||
pk: 'id',
|
||||
sortName: 'weigh',
|
||||
columns: [
|
||||
[
|
||||
{checkbox: true},
|
||||
{field: 'id', sortable: true, title: __('Id')},
|
||||
{field: 'type', title: __('Type'), formatter: Table.api.formatter.search, searchList: Config.typeList},
|
||||
{field: 'title', title: __('Title'), operate: 'like'},
|
||||
{field: 'flag', title: __('Flag'), searchList: Config.flagList, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label},
|
||||
{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
|
||||
{field: 'views', sortable: true, title: __('Views'), operate: 'BETWEEN'},
|
||||
{
|
||||
field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true, formatter: function (value, row, index) {
|
||||
return '<a href="javascript:" data-url="cms/comment/index?type=page&aid=' + row['id'] + '" title="评论列表" class="dialogit">' + value + '</a>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'url', title: __('Url'), operate: false, formatter: function (value, row, index) {
|
||||
return '<a href="' + value + '" target="_blank" class="btn btn-default btn-xs"><i class="fa fa-link"></i></a>';
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'spiders', title: __('Spiders'), visible: Config.spiderRecord || false, operate: false, formatter: function (value, row, index) {
|
||||
if (!$.isArray(value) || value.length === 0) {
|
||||
return '-';
|
||||
}
|
||||
var html = [];
|
||||
$.each(value, function (i, j) {
|
||||
var color = 'default', title = '暂无来访记录';
|
||||
if (j.status === 'today') {
|
||||
color = 'danger';
|
||||
title = "今天有来访记录";
|
||||
} else if (j.status === 'pass') {
|
||||
color = 'success';
|
||||
title = "最后来访日期:" + j.date;
|
||||
}
|
||||
html.push('<span class="label label-' + color + '" data-toggle="tooltip" data-title="' + j.title + ' ' + title + '">' + j.title.substr(0, 1) + '</span>');
|
||||
});
|
||||
return html.join(" ");
|
||||
}
|
||||
},
|
||||
{field: 'createtime', sortable: true, title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
|
||||
{field: 'updatetime', sortable: true, visible: false, title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
|
||||
{field: 'weigh', operate: false, sortable: true, title: __('Weigh')},
|
||||
{field: 'status', title: __('Status'), searchList: {"normal": __('Normal'), "hidden": __('Hidden')}, formatter: Table.api.formatter.status},
|
||||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
},
|
||||
recyclebin: function () {
|
||||
// 初始化表格参数配置
|
||||
Table.api.init({
|
||||
extend: {
|
||||
'dragsort_url': ''
|
||||
}
|
||||
});
|
||||
|
||||
var table = $("#table");
|
||||
|
||||
// 初始化表格
|
||||
table.bootstrapTable({
|
||||
url: 'cms/page/recyclebin',
|
||||
pk: 'id',
|
||||
sortName: 'id',
|
||||
columns: [
|
||||
[
|
||||
{checkbox: true},
|
||||
{field: 'id', title: __('Id')},
|
||||
{field: 'title', title: __('Title'), formatter: Table.api.formatter.search},
|
||||
{
|
||||
field: 'deletetime',
|
||||
title: __('Deletetime'),
|
||||
operate: 'RANGE',
|
||||
addclass: 'datetimerange',
|
||||
formatter: Table.api.formatter.datetime
|
||||
},
|
||||
{
|
||||
field: 'operate',
|
||||
width: '130px',
|
||||
title: __('Operate'),
|
||||
table: table,
|
||||
events: Table.api.events.operate,
|
||||
buttons: [
|
||||
{
|
||||
name: 'Restore',
|
||||
text: __('Restore'),
|
||||
classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
|
||||
icon: 'fa fa-rotate-left',
|
||||
url: 'cms/page/restore',
|
||||
refresh: true
|
||||
},
|
||||
{
|
||||
name: 'Destroy',
|
||||
text: __('Destroy'),
|
||||
classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
|
||||
icon: 'fa fa-times',
|
||||
url: 'cms/page/destroy',
|
||||
refresh: true
|
||||
}
|
||||
],
|
||||
formatter: Table.api.formatter.operate
|
||||
}
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
},
|
||||
select: function () {
|
||||
// 初始化表格参数配置
|
||||
Table.api.init({
|
||||
extend: {
|
||||
index_url: 'cms/page/select',
|
||||
add_url: 'cms/page/add',
|
||||
edit_url: 'cms/page/edit',
|
||||
table: 'page',
|
||||
}
|
||||
});
|
||||
|
||||
var table = $("#table");
|
||||
|
||||
// 初始化表格
|
||||
table.bootstrapTable({
|
||||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||||
pk: 'id',
|
||||
sortName: 'weigh',
|
||||
columns: [
|
||||
[
|
||||
{checkbox: true},
|
||||
{field: 'id', sortable: true, title: __('Id')},
|
||||
{field: 'title', title: __('Title')},
|
||||
{field: 'image', title: __('Image'), formatter: Table.api.formatter.image},
|
||||
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
|
||||
{
|
||||
field: 'select', title: __('Operate'), table: table, formatter: Table.api.formatter.buttons,
|
||||
events: {
|
||||
'click .btn-select-one': function (e, value, row) {
|
||||
Fast.api.close(row);
|
||||
}
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
name: "select",
|
||||
text: __("Select"),
|
||||
classname: "btn btn-xs btn-success btn-select-one"
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
]
|
||||
});
|
||||
|
||||
// 为表格绑定事件
|
||||
Table.api.bindevent(table);
|
||||
},
|
||||
add: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
edit: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
api: {
|
||||
bindevent: function () {
|
||||
//获取标题拼音
|
||||
var si;
|
||||
$(document).on("keyup", "#c-title", function () {
|
||||
var value = $(this).val();
|
||||
if (value != '' && !value.match(/\n/)) {
|
||||
clearTimeout(si);
|
||||
si = setTimeout(function () {
|
||||
Fast.api.ajax({
|
||||
loading: false,
|
||||
url: "cms/ajax/get_title_pinyin",
|
||||
data: {title: value}
|
||||
}, function (data, ret) {
|
||||
$("#c-diyname").val(data.pinyin.substr(0, 100));
|
||||
return false;
|
||||
}, function (data, ret) {
|
||||
return false;
|
||||
});
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
$(document).on("click", ".btn-legal", function (a) {
|
||||
Fast.api.ajax({
|
||||
url: "cms/ajax/check_content_islegal",
|
||||
data: {content: $("#c-content").val()}
|
||||
}, function (data, ret) {
|
||||
|
||||
}, function (data, ret) {
|
||||
if ($.isArray(data)) {
|
||||
Layer.alert(__('Banned words') + ":" + data.join(","));
|
||||
}
|
||||
});
|
||||
});
|
||||
$(document).on("click", ".btn-keywords", function (a) {
|
||||
Fast.api.ajax({
|
||||
url: "cms/ajax/get_content_keywords",
|
||||
data: {title: $("#c-title").val(), content: $("#c-content").val()}
|
||||
}, function (data, ret) {
|
||||
$("#c-keywords").val(data.keywords);
|
||||
$("#c-description").val(data.description);
|
||||
});
|
||||
});
|
||||
$(document).on("keyup", "#c-type_text", function () {
|
||||
$("#c-type").val($(this).val());
|
||||
});
|
||||
|
||||
$.validator.config({
|
||||
rules: {
|
||||
diyname: function (element) {
|
||||
if (element.value.toString().match(/^\d+$/)) {
|
||||
return __('Can not be only digital');
|
||||
}
|
||||
if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
|
||||
return __('Please input character or digital');
|
||||
}
|
||||
return $.ajax({
|
||||
url: 'cms/page/check_element_available',
|
||||
type: 'POST',
|
||||
data: {id: $("#page-id").val(), name: element.name, value: element.value},
|
||||
dataType: 'json'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Form.api.bindevent($("form[role=form]"));
|
||||
}
|
||||
}
|
||||
};
|
||||
return Controller;
|
||||
});
|
||||
Reference in New Issue
Block a user