allocatr/public/assets/js/backend/auth/admin.js
2025-04-02 22:43:14 +08:00

180 lines
7.8 KiB
JavaScript
Executable File

define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'],
function ($, undefined, Backend, Table, Form) {
$.jstree.core.prototype.get_all_checked = function (full) {
var obj = this.get_selected(), i, j;
for (i = 0, j = obj.length; i < j; i++) {
obj = obj.concat(this.get_node(obj[i]).parents);
}
obj = $.grep(obj, function (v, i, a) {
return v != '#';
});
obj = obj.filter(function (itm, i, a) {
return i == a.indexOf(itm);
});
return full ? $.map(obj, $.proxy(function (i) {
return this.get_node(i);
}, this)) : obj;
};
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'auth/admin/index',
add_url: 'auth/admin/add',
edit_url: 'auth/admin/edit',
del_url: 'auth/admin/del',
multi_url: 'auth/admin/multi',
area_url: 'auth/admin/setArea',
}
});
var table = $("#table");
//在表格内容渲染完成后回调的事件
table.on('post-body.bs.table', function (e, json) {
$("tbody tr[data-index]", this).each(function () {
if (parseInt($("td:eq(1)", this).text()) == Config.admin.id) {
$("input[type=checkbox]", this).prop("disabled", true);
}
});
});
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
columns: [
[
{field: 'state', checkbox: true,},
{field: 'id', title: 'ID'},
{field: 'username', title: __('Username')},
{field: 'nickname', title: __('Nickname')},
{
field: 'groups_text',
title: __('Group'),
operate: false,
formatter: Table.api.formatter.label
},
{field: 'email', title: __('Email')},
{field: 'mobile', title: __('Mobile')},
{
field: 'status',
title: __("Status"),
searchList: {"normal": __('Normal'), "hidden": __('Hidden')},
formatter: Table.api.formatter.status
},
{
field: 'logintime',
title: __('Login time'),
formatter: Table.api.formatter.datetime,
operate: 'RANGE',
addclass: 'datetimerange',
sortable: true
},
{
field: 'operate', title: __('Operate'), table: table,
events: Table.api.events.operate, formatter: function (value, row, index) {
// if (row.id == Config.admin.id) {
// return '';
// }
return Table.api.formatter.operate.call(this, value, row, index);
},
buttons: [
{
name: "setArea",
text: "配置管理区域",
title: "区域",
url: 'auth/admin/area',
extend: 'data-toggle="tooltip" data-container="body"',
classname: 'btn btn-xs btn-warning btn-dialog',
//classname:"btn-view btn-dialog",
icon: 'fa fa-add',
refresh: true,
},
],
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Form.api.bindevent($("form[role=form]"));
},
edit: function () {
Form.api.bindevent($("form[role=form]"));
},
area: function () {
Form.api.bindevent($("form[role=form]"), null, null, function () {
if ($("#treeview").length > 0) {
var r = $("#treeview").jstree("get_all_checked");
$("input[name='row[area_ids]']").val(r.join(','));
}
return true;
});
//渲染权限节点树
//销毁已有的节点树
$("#treeview").jstree("destroy");
$.ajax({
url: "auth/admin/areaget", // 你的 API 地址
type: "GET",
dataType: "json",
data: {
user_id:$('#user_id').val()
},
success: function (data) {
// console.log(data);
Controller.api.rendertree(data);
},
error: function () {
console.error("请求失败");
}
});
//全选和展开
$(document).on("click", "#checkall", function () {
$("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
});
$(document).on("click", "#expandall", function () {
$("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
});
$("select[name='row[pid]']").trigger("change");
},
api: {
rendertree: function (content) {
$("#treeview")
.on('redraw.jstree', function (e) {
$(".layer-footer").attr("domrefresh", Math.random());
})
.jstree({
"themes": {"stripes": true},
"checkbox": {
"keep_selected_style": false,
},
"types": {
"root": {
"icon": "fa fa-folder-open",
},
"menu": {
"icon": "fa fa-folder-open",
},
"file": {
"icon": "fa fa-file-o",
}
},
"plugins": ["checkbox", "types"],
"core": {
'check_callback': true,
"data": content
}
});
}
}
};
return Controller;
});