You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
6.4 KiB
138 lines
6.4 KiB
2 years ago
|
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
|
||
|
|
||
|
var Controller = {
|
||
|
index: function () {
|
||
|
// 初始化表格参数配置
|
||
|
Table.api.init({
|
||
|
extend: {
|
||
|
index_url: 'wx/category/index' + location.search,
|
||
|
add_url: 'wx/category/add',
|
||
|
edit_url: 'wx/category/edit',
|
||
|
del_url: 'wx/category/del',
|
||
|
multi_url: 'wx/category/multi',
|
||
|
import_url: 'wx/category/import',
|
||
|
dragsort_url: 'ajax/weigh2',
|
||
|
table: 'wx_category',
|
||
|
}
|
||
|
});
|
||
|
|
||
|
var table = $("#table");
|
||
|
|
||
|
// 初始化表格
|
||
|
table.bootstrapTable({
|
||
|
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||
|
pk: 'id',
|
||
|
sortName: 'weigh',
|
||
|
columns: [
|
||
|
[
|
||
|
{checkbox: true},
|
||
|
{field: 'id', title: __('Id')},
|
||
|
// {field: 'wx_menu_id', title: __('Wx_menu_id')},
|
||
|
{field: 'menu_name', title: "所属菜单"},
|
||
|
//{field: 'name', title: __('Name'), operate: 'LIKE'},
|
||
|
{field: 'name', title: __('Name'), align: 'left', formatter:function (value, row, index) {
|
||
|
return value.toString().replace(/(&|&)nbsp;/g, ' ');
|
||
|
}
|
||
|
},
|
||
|
// {field: 'wx_category_id', title: __('Wx_category_id')},
|
||
|
{field: 'weigh', title: __('Weigh'), operate: false},
|
||
|
{field: 'catedata', title: __('Catedata'), searchList: {"0":__('Catedata 0'),"1":__('Catedata 1')}, formatter: Table.api.formatter.normal},
|
||
|
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
|
||
|
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
|
||
|
{field: 'id', title: '展开', operate: false, formatter: Controller.api.formatter.subnode},
|
||
|
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
|
||
|
]
|
||
|
],
|
||
|
pagination: false,//隐藏分页
|
||
|
search: false,//隐藏搜索框
|
||
|
commonSearch: false,//隐藏搜索按钮
|
||
|
showToggle: false,//表格视图两种模式
|
||
|
showColumns: false,//隐藏列
|
||
|
showExport: false,//隐藏导出
|
||
|
});
|
||
|
|
||
|
// 为表格绑定事件
|
||
|
Table.api.bindevent(table);
|
||
|
//当内容渲染完成后
|
||
|
table.on('post-body.bs.table', function (e, settings, json, xhr) {
|
||
|
//默认隐藏所有子节点
|
||
|
$("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide();
|
||
|
// $(".btn-node-sub.disabled").closest("tr").hide();
|
||
|
//显示隐藏子节点
|
||
|
$(".btn-node-sub").off("click").on("click", function (e) {
|
||
|
var status = $(this).data("shown") ? true : false;
|
||
|
$("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
|
||
|
$(this).closest("tr").toggle(!status);
|
||
|
});
|
||
|
$(this).data("shown", !status);
|
||
|
return false;
|
||
|
});
|
||
|
//点击切换/排序/删除操作后刷新左侧菜单
|
||
|
$(".btn-change[data-id],.btn-delone,.btn-dragsort").data("success", function (data, ret) {
|
||
|
Fast.api.refreshmenu();
|
||
|
return false;
|
||
|
});
|
||
|
|
||
|
});
|
||
|
//批量删除后的回调
|
||
|
$(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) {
|
||
|
Fast.api.refreshmenu();
|
||
|
});
|
||
|
//展开隐藏一级
|
||
|
$(document.body).on("click", ".btn-toggle", function (e) {
|
||
|
$("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
|
||
|
var that = this;
|
||
|
var show = $("i", that).hasClass("fa-chevron-down");
|
||
|
$("i", that).toggleClass("fa-chevron-down", !show);
|
||
|
$("i", that).toggleClass("fa-chevron-up", show);
|
||
|
$("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
|
||
|
$(".btn-node-sub[data-pid=0]").data("shown", show);
|
||
|
});
|
||
|
//展开隐藏全部
|
||
|
$(document.body).on("click", ".btn-toggle-all", function (e) {
|
||
|
var that = this;
|
||
|
var show = $("i", that).hasClass("fa-plus");
|
||
|
$("i", that).toggleClass("fa-plus", !show);
|
||
|
$("i", that).toggleClass("fa-minus", show);
|
||
|
$(".btn-node-sub.disabled").closest("tr").toggle(show);
|
||
|
$(".btn-node-sub").data("shown", show);
|
||
|
});
|
||
|
|
||
|
},
|
||
|
add: function () {
|
||
|
Controller.api.bindevent();
|
||
|
setTimeout(function () {
|
||
|
$("#c-wx_menu_id").trigger("change");
|
||
|
}, 100);
|
||
|
},
|
||
|
edit: function () {
|
||
|
Controller.api.bindevent();
|
||
|
},
|
||
|
api: {
|
||
|
formatter: {
|
||
|
subnode: function (value, row, index) {
|
||
|
return '<a href="javascript:;" data-toggle="tooltip" title="展开子菜单" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
|
||
|
+ (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
|
||
|
}
|
||
|
},
|
||
|
bindevent: function () {
|
||
|
|
||
|
$("#c-wx_category_id").data("params", function (obj) {
|
||
|
|
||
|
return {custom: {wx_menu_id: $("#c-wx_menu_id").val()}};
|
||
|
});
|
||
|
|
||
|
$(document).on("change", "#c-wx_menu_id", function(){
|
||
|
|
||
|
$("#c-wx_category_id_text").val('');
|
||
|
|
||
|
});
|
||
|
|
||
|
|
||
|
Form.api.bindevent($("form[role=form]"));
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
return Controller;
|
||
|
});
|