-
-
-
-
-
-
+ {% include 'admin/common/header.html' %}
+
+
+
-
+
-{% block models_script %}
-
-
-
+
+
-{% endblock %}
+ },
+ {
+ field: 'enable', title: '是否可用', templet: (d) => {
+ // TODO 修改禁用启动逻辑
+ return `
`;
+ },
+ },
+ {field: 'sort', title: '排序'},
+ {title: '操作', templet: '#tool', width: 150, align: 'center'},
+ ],
+ ];
+
+ treetable.render({
+ treeColIndex: 1,
+ treeSpid: 0,
+ treeIdName: 'powerId',
+ treePidName: 'parentId',
+ skin: 'line',
+ method: 'post',
+ treeDefaultClose: true,
+ toolbar: '#toolbar',
+ elem: '#tables',
+ url: '/api/v1/rights/rights',
+ page: false,
+ cols: get_columns(),
+ });
+
+ form.on('submit(power_query)', function(data) {
+ var keyword = data.field.powerName;
+ var $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td');
+ if (!keyword) {
+ $tds.css('background-color', 'transparent');
+ layer.msg('请输入关键字', {icon: 5});
+ return;
+ }
+ var searchCount = 0;
+ $tds.each(function() {
+ $(this).css('background-color', 'transparent');
+ if ($(this).text().indexOf(keyword) >= 0) {
+ $(this).css('background-color', 'rgba(250,230,160,0.5)');
+ if (searchCount === 0) {
+ $('body,html').stop(true);
+ $('body,html').animate({scrollTop: $(this).offset().top - 150}, 500);
+ }
+ searchCount++;
+ }
+ });
+ if (searchCount === 0) {
+ layer.msg('没有匹配结果', {icon: 5});
+ } else {
+ treetable.expandAll('#tables');
+ }
+ return false;
+ });
+
+ table.on('tool(tables)', function(obj) {
+ if (obj.event === 'tool-remove') {
+ window.tool_remove(obj);
+ } else if (obj.event === 'tool-edit') {
+ window.tool_edit(obj);
+ }
+ });
+
+ table.on('toolbar(tables)', function(obj) {
+ if (obj.event === 'toolbar-add') {
+ window.toolbar_add();
+ } else if (obj.event === 'refresh') {
+ window.refresh();
+ } else if (obj.event === 'toolbar-remove') {
+ window.toolbar_remove(obj);
+ }
+ });
+
+ form.on('switch(tool-switch)', function(obj) {
+ let operate;
+ if (obj.elem.checked) {
+ operate = 1; /*启用*/
+ } else {
+ operate = 0; /*禁用*/
+ }
+ let loading = layer.load();
+ $.ajax({
+ url: '/api/v1/rights/power/' + this.value + '/status',
+ data: JSON.stringify({powerId: this.value, operate: operate}),
+ dataType: 'json',
+ contentType: 'application/json',
+ type: 'put',
+ success: function(result) {
+ layer.close(loading);
+ if (result.success) {
+ popup.success(result.message);
+ } else {
+ popup.failure(result.message);
+ }
+ },
+ });
+ });
+
+ window.toolbar_add = function() {
+ layer.open({
+ type: 2,
+ title: '新增',
+ shade: 0.1,
+ area: ['450px', '500px'],
+ content: '/rights/add',
+ });
+ };
+
+ window.tool_edit = function(obj) {
+ layer.open({
+ type: 2,
+ title: '修改',
+ shade: 0.1,
+ area: ['450px', '500px'],
+ content: '/rights/power/' + obj.data['powerId'],
+ });
+ };
+ window.tool_remove = function(obj) {
+ layer.confirm('确定要删除该权限', {icon: 3, title: '提示'}, function(index) {
+ layer.close(index);
+ let loading = layer.load();
+ $.ajax({
+ url: '/api/v1/rights/power/' + obj.data['powerId'],
+ dataType: 'json',
+ type: 'delete',
+ success: function(result) {
+ layer.close(loading);
+ if (result.success) {
+ popup.success(result.message, function() {
+ console.log(obj);
+ obj.del();
+ });
+ } else {
+ popup.failure(result.message);
+ }
+ },
+ });
+ });
+ };
+
+ window.toolbar_remove = function(obj) {
+ let data = table.checkStatus(obj.config.id).data;
+ if (data.length === 0) {
+ layer.msg('未选中数据', {
+ icon: 3,
+ time: 1000,
+ });
+ return false;
+ }
+ var ids = [];
+ var hasCheck = table.checkStatus('tables');
+ var hasCheckData = hasCheck.data;
+ if (hasCheckData.length > 0) {
+ $.each(hasCheckData, function(index, element) {
+ ids.push(element.id);
+ });
+ }
+ layer.confirm('确定要删除选中权限', {
+ icon: 3,
+ title: '提示',
+ }, function(index) {
+ layer.close(index);
+ let loading = layer.load();
+ $.ajax({
+ url: '/api/v1/rights/rights',
+ data: {ids: ids},
+ dataType: 'json',
+ type: 'delete',
+ success: function(result) {
+ layer.close(loading);
+ if (result.success) {
+ popup.success(result.msg, function() {
+ console.log(obj);
+ obj.del();
+ });
+ } else {
+ popup.failure(result.msg);
+ }
+ },
+ });
+ });
+ };
+
+ iconPicker.render({
+ // 选择器,推荐使用input
+ elem: '#add_icon',
+ // 数据类型:fontClass/unicode,推荐使用fontClass
+ type: 'fontClass',
+ // 是否开启搜索:true/false
+ search: true,
+ // 是否开启分页
+ page: true,
+ // 每页显示数量,默认12
+ limit: 12,
+ // 点击回调
+ click: function(data) {
+ console.log(data);
+ },
+ });
+ });
+
+
+
\ No newline at end of file
diff --git a/templates/admin/rights/rights_add.html b/templates/admin/rights/rights_add.html
index 4b7169b..c6846b0 100644
--- a/templates/admin/rights/rights_add.html
+++ b/templates/admin/rights/rights_add.html
@@ -1,170 +1,171 @@
-{% extends 'admin/base.html' %}
-
-{% block title %}
+
+
+
权限
-{% endblock %}
-
-{% block body %}
-