From a637cdb04ab7e0954196ad0d8e7cc24ae22ee93a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 10 三月 2026 13:22:22 +0800
Subject: [PATCH] #
---
src/main/webapp/static/js/role/role.js | 950 ++++++++++++++++++++++++++++++++++------------------------
1 files changed, 556 insertions(+), 394 deletions(-)
diff --git a/src/main/webapp/static/js/role/role.js b/src/main/webapp/static/js/role/role.js
index 3bdce29..8d6f6ec 100644
--- a/src/main/webapp/static/js/role/role.js
+++ b/src/main/webapp/static/js/role/role.js
@@ -1,410 +1,572 @@
-var pageCurr;
-var roleId;
-var powerTreeData;
-$(function (){
- $.ajax({
- url: baseUrl+"/power/list/auth",
- headers: {'token': localStorage.getItem('token')},
- method: 'GET',
- success: function (res) {
- if (res.code === 200){
- powerTreeData = res.data;
- } else if (res.code === 403){
- top.location.href = baseUrl+"/";
- } else {
- layer.msg(res.msg)
- }
- }
- })
-});
-
-layui.use(['table','laydate', 'form'], function(){
- var table = layui.table;
- var $ = layui.jquery;
- var layer = layui.layer;
- var layDate = layui.laydate;
- var form = layui.form;
-
- // 鏁版嵁娓叉煋
- tableIns = table.render({
- elem: '#role',
- headers: {token: localStorage.getItem('token')},
- url: baseUrl+'/role/list/auth',
- page: true,
- limit: 16,
- limits: [16, 30, 50, 100, 200, 500],
- toolbar: '#toolbar',
- cellMinWidth: 50,
- cols: [[
- {type: 'checkbox', fixed: 'left'}
- ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
- ,{field: 'code', align: 'center',title: '缂栫爜'}
- ,{field: 'name', align: 'center',title: '鍚嶇О'}
- ,{field: 'leader$', align: 'center',title: '涓婄骇'}
- // ,{field: 'level$', align: 'center',title: '瑙掕壊绛夌骇'}
-
- ,{fixed: 'right', title:'鎿嶄綔', align: 'center', toolbar: '#operate', width:150}
- ]],
- request: {
- pageName: 'curr',
- pageSize: 'limit'
- },
- parseData: function (res) {
- return {
- 'code': res.code,
- 'msg': res.msg,
- 'count': res.data.total,
- 'data': res.data.records
- }
- },
- response: {
- statusCode: 200
- },
- done: function(res, curr, count) {
- if (res.code === 403) {
- top.location.href = baseUrl+"/";
- }
- pageCurr=curr;
- limit();
- }
- });
-
- // 鐩戝惉鎺掑簭浜嬩欢
- table.on('sort(role)', function (obj) {
- var searchData = {};
- $.each($('#search-box [name]').serializeArray(), function() {
- searchData[this.name] = this.value;
- });
- searchData['orderByField'] = obj.field;
- searchData['orderByType'] = obj.type;
- tableIns.reload({
- where: searchData,
- page: {
- curr: 1
- },
- done: function (res, curr, count) {
- if (res.code === 403) {
- top.location.href = baseUrl+"/";
- }
- pageCurr=curr;
- limit();
- }
- });
- });
-
- // 鐩戝惉澶村伐鍏锋爮浜嬩欢
- table.on('toolbar(role)', function (obj) {
- var checkStatus = table.checkStatus(obj.config.id);
- switch(obj.event) {
- case 'addData':
- layer.open({
- type: 2,
- title: '鏂板',
- maxmin: true,
- area: [top.detailWidth, top.detailHeight],
- shadeClose: false,
- content: 'role_detail.html',
- success: function(layero, index){
- clearFormVal(layer.getChildFrame('#detail', index));
- layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
- }
- });
- break;
- case 'refreshData':
- tableIns.reload({
- page: {
- curr: pageCurr
- }
- });
- limit();
- break;
- case 'deleteData':
- var data = checkStatus.data;
- var ids=[];
- data.map(function (track) {
- ids.push(track.id);
- });
- if (ids.length === 0){
- layer.msg('璇烽�夋嫨鏁版嵁');
- } else {
- layer.confirm('纭畾鍒犻櫎'+(ids.length===1?'姝�':ids.length)+'鏉℃暟鎹悧', function(){
- $.ajax({
- url: baseUrl+"/role/delete/auth",
- headers: {'token': localStorage.getItem('token')},
- data: {ids: ids},
- method: 'POST',
- traditional:true,
- success: function (res) {
- if (res.code === 200){
- layer.closeAll();
- tableReload(false);
- } else if (res.code === 403){
- top.location.href = baseUrl+"/";
- } else {
- layer.msg(res.msg)
- }
- }
- })
- });
- }
- break;
- case 'exportData':
- layer.confirm('纭畾瀵煎嚭Excel鍚�', {shadeClose: true}, function(){
- var titles=[];
- var fields=[];
- obj.config.cols[0].map(function (col) {
- if (col.type === 'normal' && col.hide === false && col.toolbar == null) {
- titles.push(col.title);
- fields.push(col.field);
- }
- });
- var exportData = {};
- $.each($('#search-box [name]').serializeArray(), function() {
- exportData[this.name] = this.value;
- });
- var param = {
- 'role': exportData,
- 'fields': fields
- };
- $.ajax({
- url: baseUrl+"/role/export/auth",
- headers: {'token': localStorage.getItem('token')},
- data: JSON.stringify(param),
- dataType:'json',
- contentType:'application/json;charset=UTF-8',
- method: 'POST',
- success: function (res) {
- layer.closeAll();
- if (res.code === 200) {
- table.exportFile(titles,res.data,'xls');
- } else if (res.code === 403) {
- top.location.href = baseUrl+"/";
- } else {
- layer.msg(res.msg)
- }
- }
- });
- });
- break;
- }
- });
-
- // 鐩戝惉琛屽伐鍏蜂簨浠�
- table.on('tool(role)', function(obj){
- var data = obj.data;
- switch (obj.event) {
- // 璇︽儏
- case 'detail':
- layer.open({
- type: 2,
- title: '璇︽儏',
- maxmin: true,
- area: [top.detailWidth, top.detailHeight],
- shadeClose: false,
- content: 'role_detail.html',
- success: function(layero, index){
- setFormVal(layer.getChildFrame('#detail', index), data, true);
- top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
- layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
- layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
- layero.find('iframe')[0].contentWindow.layui.form.render('select');
- }
- });
- break;
- // 缂栬緫
- case 'edit':
- layer.open({
- type: 2,
- title: '淇敼',
- maxmin: true,
- area: [top.detailWidth, top.detailHeight],
- shadeClose: false,
- content: 'role_detail.html',
- success: function(layero, index){
- setFormVal(layer.getChildFrame('#detail', index), data, false);
- top.convertDisabled(layer.getChildFrame('#data-detail :input', index), false);
- layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
- layero.find('iframe')[0].contentWindow.layui.form.render('select');
- }
- });
- break;
- case 'leader':
- var param = top.reObject(data).leader;
- if (param === undefined) {
- layer.msg("鏃犳暟鎹�");
- } else {
- layer.open({
- type: 2,
- title: '璇︽儏',
- maxmin: true,
- area: [top.detailHeight, top.detailWidth],
- shadeClose: false,
- content: '../role/role_detail.html',
- success: function(layero, index){
- $.ajax({
- url: baseUrl+"/role/"+ param +"/auth",
- headers: {'token': localStorage.getItem('token')},
- method: 'GET',
- success: function (res) {
- if (res.code === 200){
- setFormVal(layer.getChildFrame('#detail', index), res.data, true);
- top.convertDisabled(layer.getChildFrame('#data-detail :input', index), true);
- layer.getChildFrame('#data-detail-submit,#prompt', index).hide();
- layer.iframeAuto(index);layer.style(index, {top: (($(window).height()-layer.getChildFrame('#data-detail', index).height())/3)+"px"});
- layero.find('iframe')[0].contentWindow.layui.form.render('select');
- } else if (res.code === 403){
- parent.location.href = "/";
- }else {
- layer.msg(res.msg)
- }
- }
- })
- }
- });
- }
- break;
- case 'power':
- roleId = data.id;
- layer.open({
- type: 2,
- title: data.name + ' 鏉冮檺鍒嗛厤',
- maxmin: true,
- area: [top.detailWidth/2, '85%'],
- shadeClose: false,
- content: 'role_power_detail.html',
- success: function(layero, index){
- }
- });
- break;
- }
- });
-
- // 鏁版嵁淇敼鍔ㄤ綔
- form.on('submit(edit)', function () {
- var index = layer.load(1, {
- shade: [0.5,'#000'] //0.1閫忔槑搴︾殑鑳屾櫙
- });
- var data = {
- id: $('#id').val(),
- code: $('#code').val(),
- name: $('#name').val(),
- leader: $('#leader').val(),
- level: $('#level').val(),
-
+(function () {
+ function authHeaders() {
+ return {
+ token: localStorage.getItem('token') || ''
};
- $.ajax({
- url: baseUrl+"/role/edit/auth",
- headers: {'token': localStorage.getItem('token')},
- data: top.reObject(data),
- method: 'POST',
- success: function (res) {
- if (res.code === 200){
- parent.layer.closeAll();
- tableReload(true);
- $("#data-detail :input").each(function () {
- $(this).val("");
- });
- } else if (res.code === 403){
- top.location.href = baseUrl+"/";
- }else {
- layer.msg(res.msg)
- }
- layer.close(index);
- }
- })
- });
+ }
- // 鎼滅储鏍忔悳绱簨浠�
- form.on('submit(search)', function (data) {
- pageCurr = 1;
- tableReload(false);
- });
+ function isForbidden(res) {
+ return res && Number(res.code) === 403;
+ }
- // 鎼滅储鏍忛噸缃簨浠�
- form.on('submit(reset)', function (data) {
- pageCurr = 1;
- clearFormVal($('#search-box'));
- tableReload(false);
- });
+ function isOk(res) {
+ return res && Number(res.code) === 200;
+ }
- // 鏃堕棿閫夋嫨鍣�
+ function normalizeId(value) {
+ if (value === null || value === undefined || value === '') {
+ return null;
+ }
+ var numberValue = Number(value);
+ return isNaN(numberValue) ? value : numberValue;
+ }
+ function createRoleForm() {
+ return {
+ id: null,
+ code: '',
+ name: '',
+ leader: null
+ };
+ }
-});
+ function escapeHtml(value) {
+ return String(value == null ? '' : value)
+ .replace(/&/g, '&')
+ .replace(/</g, '<')
+ .replace(/>/g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+ }
-// 鍏抽棴鍔ㄤ綔
-$(document).on('click','#data-detail-close', function () {
- parent.layer.closeAll();
-});
+ function downloadExcel(filename, headers, rows) {
+ var headHtml = headers.map(function (title) {
+ return '<th style="mso-number-format:\\@;">' + escapeHtml(title) + '</th>';
+ }).join('');
+ var bodyHtml = rows.map(function (row) {
+ return '<tr>' + row.map(function (cell) {
+ return '<td style="mso-number-format:\\@;">' + escapeHtml(cell) + '</td>';
+ }).join('') + '</tr>';
+ }).join('');
+ var workbook = [
+ '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel">',
+ '<head><meta charset="UTF-8"></head>',
+ '<body><table border="1"><tr>',
+ headHtml,
+ '</tr>',
+ bodyHtml,
+ '</table></body></html>'
+ ].join('');
+ var blob = new Blob([workbook], {type: 'application/vnd.ms-excel;charset=utf-8;'});
+ var link = document.createElement('a');
+ link.href = URL.createObjectURL(blob);
+ link.download = filename;
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ URL.revokeObjectURL(link.href);
+ }
-function tableReload(child) {
- var searchData = {};
- $.each($('#search-box [name]').serializeArray(), function() {
- searchData[this.name] = this.value;
- });
- (child ? parent.tableIns : tableIns).reload({
- where: searchData,
- page: {
- curr: pageCurr
+ new Vue({
+ el: '#app',
+ data: function () {
+ return {
+ loading: false,
+ exportLoading: false,
+ leaderSearchLoading: false,
+ dialogLeaderLoading: false,
+ tableHeight: Math.max(window.innerHeight - 220, 360),
+ tableData: [],
+ selection: [],
+ pagination: {
+ curr: 1,
+ limit: 16,
+ total: 0
+ },
+ searchForm: {
+ leader: null
+ },
+ leaderSearchOptions: [],
+ roleDialog: {
+ visible: false,
+ mode: 'create',
+ submitting: false
+ },
+ roleForm: createRoleForm(),
+ roleRules: {
+ code: [
+ {required: true, message: '璇疯緭鍏ョ紪鐮�', trigger: 'blur'}
+ ],
+ name: [
+ {required: true, message: '璇疯緭鍏ュ悕绉�', trigger: 'blur'}
+ ]
+ },
+ dialogLeaderOptions: [],
+ powerDialog: {
+ visible: false,
+ roleId: null,
+ roleName: '',
+ loading: false,
+ submitting: false
+ },
+ powerTreeData: [],
+ powerExpandedKeys: []
+ };
},
- done: function (res, curr, count) {
- if (res.code === 403) {
- top.location.href = baseUrl+"/";
- }
- pageCurr=curr;
- if (res.data.length === 0 && count !== 0) {
- tableIns.reload({
- where: searchData,
- page: {
- curr: pageCurr-1
+ created: function () {
+ this.loadList();
+ },
+ mounted: function () {
+ window.addEventListener('resize', this.handleResize);
+ },
+ beforeDestroy: function () {
+ window.removeEventListener('resize', this.handleResize);
+ },
+ methods: {
+ handleResize: function () {
+ this.tableHeight = Math.max(window.innerHeight - 220, 360);
+ this.refreshTableLayout();
+ },
+ handleForbidden: function (res) {
+ if (isForbidden(res)) {
+ top.location.href = baseUrl + '/';
+ return true;
+ }
+ return false;
+ },
+ refreshTableLayout: function () {
+ var vm = this;
+ this.$nextTick(function () {
+ if (vm.$refs.dataTable && vm.$refs.dataTable.doLayout) {
+ vm.$refs.dataTable.doLayout();
}
});
- pageCurr -= 1;
+ },
+ currentQuery: function () {
+ return {
+ curr: this.pagination.curr,
+ limit: this.pagination.limit,
+ leader: this.searchForm.leader
+ };
+ },
+ loadList: function () {
+ var vm = this;
+ vm.loading = true;
+ $.ajax({
+ url: baseUrl + '/role/list/auth',
+ method: 'GET',
+ headers: authHeaders(),
+ data: vm.currentQuery(),
+ success: function (res) {
+ vm.loading = false;
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '瑙掕壊鍔犺浇澶辫触');
+ return;
+ }
+ var data = res.data || {};
+ vm.tableData = data.records || [];
+ vm.pagination.total = data.total || 0;
+ vm.selection = [];
+ vm.refreshTableLayout();
+ },
+ error: function () {
+ vm.loading = false;
+ vm.$message.error('瑙掕壊鍔犺浇澶辫触');
+ }
+ });
+ },
+ fetchRoleOptions: function (keyword, target) {
+ var vm = this;
+ var loadingKey = target === 'search' ? 'leaderSearchLoading' : 'dialogLeaderLoading';
+ vm[loadingKey] = true;
+ $.ajax({
+ url: baseUrl + '/roleQuery/auth',
+ method: 'GET',
+ headers: authHeaders(),
+ data: {
+ condition: keyword || ''
+ },
+ success: function (res) {
+ vm[loadingKey] = false;
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '瑙掕壊鏌ヨ澶辫触');
+ return;
+ }
+ if (target === 'search') {
+ vm.leaderSearchOptions = res.data || [];
+ } else {
+ vm.dialogLeaderOptions = res.data || [];
+ }
+ },
+ error: function () {
+ vm[loadingKey] = false;
+ vm.$message.error('瑙掕壊鏌ヨ澶辫触');
+ }
+ });
+ },
+ searchLeaderOptions: function (keyword) {
+ this.fetchRoleOptions(keyword, 'search');
+ },
+ searchDialogLeaderOptions: function (keyword) {
+ this.fetchRoleOptions(keyword, 'dialog');
+ },
+ ensureDialogLeaderOption: function (id, label) {
+ if (!id || !label) {
+ return;
+ }
+ var exists = this.dialogLeaderOptions.some(function (item) {
+ return normalizeId(item.id) === normalizeId(id);
+ });
+ if (!exists) {
+ this.dialogLeaderOptions = [{
+ id: normalizeId(id),
+ value: label
+ }].concat(this.dialogLeaderOptions);
+ }
+ },
+ handleSelectionChange: function (rows) {
+ this.selection = rows || [];
+ },
+ handleSearch: function () {
+ this.pagination.curr = 1;
+ this.loadList();
+ },
+ handleReset: function () {
+ this.searchForm.leader = null;
+ this.leaderSearchOptions = [];
+ this.pagination.curr = 1;
+ this.loadList();
+ },
+ handleCurrentChange: function (page) {
+ this.pagination.curr = page;
+ this.loadList();
+ },
+ handleSizeChange: function (size) {
+ this.pagination.limit = size;
+ this.pagination.curr = 1;
+ this.loadList();
+ },
+ resetRoleDialog: function () {
+ this.roleForm = createRoleForm();
+ this.dialogLeaderOptions = [];
+ var vm = this;
+ this.$nextTick(function () {
+ if (vm.$refs.roleForm) {
+ vm.$refs.roleForm.clearValidate();
+ }
+ });
+ },
+ openCreateDialog: function () {
+ this.roleDialog.mode = 'create';
+ this.roleDialog.visible = true;
+ this.resetRoleDialog();
+ },
+ openEditDialog: function (row) {
+ this.roleDialog.mode = 'edit';
+ this.roleDialog.visible = true;
+ this.roleForm = {
+ id: normalizeId(row.id),
+ code: row.code || '',
+ name: row.name || '',
+ leader: normalizeId(row.leader)
+ };
+ this.dialogLeaderOptions = [];
+ this.ensureDialogLeaderOption(row.leader, row['leader$']);
+ var vm = this;
+ this.$nextTick(function () {
+ if (vm.$refs.roleForm) {
+ vm.$refs.roleForm.clearValidate();
+ }
+ });
+ },
+ submitRole: function () {
+ var vm = this;
+ if (!vm.$refs.roleForm) {
+ return;
+ }
+ vm.$refs.roleForm.validate(function (valid) {
+ if (!valid) {
+ return false;
+ }
+ vm.roleDialog.submitting = true;
+ $.ajax({
+ url: baseUrl + '/role/' + (vm.roleDialog.mode === 'create' ? 'add' : 'update') + '/auth',
+ method: 'POST',
+ headers: authHeaders(),
+ data: {
+ id: vm.roleDialog.mode === 'edit' ? normalizeId(vm.roleForm.id) : null,
+ code: $.trim(vm.roleForm.code),
+ name: $.trim(vm.roleForm.name),
+ leader: normalizeId(vm.roleForm.leader)
+ },
+ success: function (res) {
+ vm.roleDialog.submitting = false;
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '淇濆瓨澶辫触');
+ return;
+ }
+ vm.$message.success(res.msg || '淇濆瓨鎴愬姛');
+ vm.roleDialog.visible = false;
+ vm.loadList();
+ },
+ error: function () {
+ vm.roleDialog.submitting = false;
+ vm.$message.error('淇濆瓨澶辫触');
+ }
+ });
+ return true;
+ });
+ },
+ removeSelection: function () {
+ var vm = this;
+ if (!vm.selection.length) {
+ vm.$message.warning('璇烽�夋嫨鏁版嵁');
+ return;
+ }
+ var ids = vm.selection.map(function (row) {
+ return normalizeId(row.id);
+ }).filter(function (id) {
+ return id !== null;
+ });
+ vm.$confirm('纭畾鍒犻櫎閫変腑瑙掕壊鍚楋紵', '鎻愮ず', {
+ confirmButtonText: '纭畾',
+ cancelButtonText: '鍙栨秷',
+ type: 'warning'
+ }).then(function () {
+ $.ajax({
+ url: baseUrl + '/role/delete/auth',
+ method: 'POST',
+ headers: authHeaders(),
+ traditional: true,
+ data: {
+ ids: ids
+ },
+ success: function (res) {
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '鍒犻櫎澶辫触');
+ return;
+ }
+ vm.$message.success(res.msg || '鍒犻櫎鎴愬姛');
+ if (vm.tableData.length === ids.length && vm.pagination.curr > 1) {
+ vm.pagination.curr -= 1;
+ }
+ vm.loadList();
+ },
+ error: function () {
+ vm.$message.error('鍒犻櫎澶辫触');
+ }
+ });
+ }).catch(function () {
+ });
+ },
+ exportRows: function () {
+ var vm = this;
+ vm.exportLoading = true;
+ $.ajax({
+ url: baseUrl + '/role/export/auth',
+ method: 'POST',
+ headers: authHeaders(),
+ dataType: 'json',
+ contentType: 'application/json;charset=UTF-8',
+ data: JSON.stringify({
+ role: {
+ leader: vm.searchForm.leader
+ },
+ fields: ['id', 'code', 'name', 'leader$']
+ }),
+ success: function (res) {
+ vm.exportLoading = false;
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '瀵煎嚭澶辫触');
+ return;
+ }
+ downloadExcel('瑙掕壊绠$悊.xls', ['ID', '缂栫爜', '鍚嶇О', '涓婄骇'], res.data || []);
+ },
+ error: function () {
+ vm.exportLoading = false;
+ vm.$message.error('瀵煎嚭澶辫触');
+ }
+ });
+ },
+ ensurePowerTree: function (callback) {
+ var vm = this;
+ if (vm.powerTreeData.length) {
+ if (callback) {
+ callback();
+ }
+ return;
+ }
+ $.ajax({
+ url: baseUrl + '/power/list/auth',
+ method: 'GET',
+ headers: authHeaders(),
+ success: function (res) {
+ if (vm.handleForbidden(res)) {
+ vm.powerDialog.loading = false;
+ return;
+ }
+ if (!isOk(res)) {
+ vm.powerDialog.loading = false;
+ vm.$message.error(res && res.msg ? res.msg : '鏉冮檺鏍戝姞杞藉け璐�');
+ return;
+ }
+ vm.powerTreeData = res.data || [];
+ vm.powerExpandedKeys = [];
+ if (callback) {
+ callback();
+ }
+ },
+ error: function () {
+ vm.powerDialog.loading = false;
+ vm.$message.error('鏉冮檺鏍戝姞杞藉け璐�');
+ }
+ });
+ },
+ loadRolePower: function () {
+ var vm = this;
+ vm.powerDialog.loading = true;
+ $.ajax({
+ url: baseUrl + '/power/' + vm.powerDialog.roleId + '/auth',
+ method: 'GET',
+ headers: authHeaders(),
+ success: function (res) {
+ vm.powerDialog.loading = false;
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '鏉冮檺鍥炴樉澶辫触');
+ return;
+ }
+ vm.$nextTick(function () {
+ if (vm.$refs.powerTree) {
+ vm.$refs.powerTree.setCheckedKeys(res.data || []);
+ }
+ });
+ },
+ error: function () {
+ vm.powerDialog.loading = false;
+ vm.$message.error('鏉冮檺鍥炴樉澶辫触');
+ }
+ });
+ },
+ openPowerDialog: function (row) {
+ var vm = this;
+ vm.powerDialog.visible = true;
+ vm.powerDialog.roleId = normalizeId(row.id);
+ vm.powerDialog.roleName = row.name || '';
+ vm.powerDialog.loading = true;
+ vm.ensurePowerTree(function () {
+ vm.$nextTick(function () {
+ if (vm.$refs.powerTree) {
+ vm.$refs.powerTree.setCheckedKeys([]);
+ }
+ vm.loadRolePower();
+ });
+ });
+ },
+ collectPowerPayload: function () {
+ var tree = this.$refs.powerTree;
+ if (!tree) {
+ return [];
+ }
+ var selected = tree.getCheckedKeys().concat(tree.getHalfCheckedKeys());
+ var selectedMap = {};
+ selected.forEach(function (key) {
+ selectedMap[key] = true;
+ });
+ var payload = [];
+ this.powerTreeData.forEach(function (top) {
+ (top.children || []).forEach(function (node) {
+ var childList = node.children || [];
+ var checkedChildren = childList.filter(function (child) {
+ return !!selectedMap[child.id];
+ }).map(function (child) {
+ return String(child.id);
+ });
+ if (childList.length === 0) {
+ if (selectedMap[node.id]) {
+ payload.push({
+ two: node.id,
+ three: []
+ });
+ }
+ return;
+ }
+ if (selectedMap[node.id] || checkedChildren.length > 0) {
+ payload.push({
+ two: node.id,
+ three: checkedChildren
+ });
+ }
+ });
+ });
+ return payload;
+ },
+ submitPower: function () {
+ var vm = this;
+ vm.powerDialog.submitting = true;
+ $.ajax({
+ url: baseUrl + '/power/auth',
+ method: 'POST',
+ headers: authHeaders(),
+ traditional: true,
+ data: {
+ roleId: vm.powerDialog.roleId,
+ powers: JSON.stringify(vm.collectPowerPayload())
+ },
+ success: function (res) {
+ vm.powerDialog.submitting = false;
+ if (vm.handleForbidden(res)) {
+ return;
+ }
+ if (!isOk(res)) {
+ vm.$message.error(res && res.msg ? res.msg : '鏉冮檺淇濆瓨澶辫触');
+ return;
+ }
+ vm.$message.success(res.msg || '淇濆瓨鎴愬姛');
+ vm.powerDialog.visible = false;
+ },
+ error: function () {
+ vm.powerDialog.submitting = false;
+ vm.$message.error('鏉冮檺淇濆瓨澶辫触');
+ }
+ });
}
- limit(child);
- }
- });
-}
-
-function setFormVal(el, data, showImg) {
- for (var val in data) {
- var find = el.find(":input[id='" + val + "']");
- find.val(data[val]);
- if (showImg){
- var next = find.next();
- if (next.get(0)){
- if (next.get(0).localName === "img") {
- find.hide();
- next.attr("src", data[val]);
- next.show();
+ },
+ watch: {
+ 'roleDialog.visible': function (visible) {
+ if (!visible) {
+ this.resetRoleDialog();
+ this.roleDialog.submitting = false;
+ }
+ },
+ 'powerDialog.visible': function (visible) {
+ if (!visible) {
+ this.powerDialog.roleId = null;
+ this.powerDialog.roleName = '';
+ this.powerDialog.loading = false;
+ this.powerDialog.submitting = false;
+ if (this.$refs.powerTree) {
+ this.$refs.powerTree.setCheckedKeys([]);
+ }
}
}
}
- }
-}
-
-function clearFormVal(el) {
- $(':input', el)
- .val('')
- .removeAttr('checked')
- .removeAttr('selected');
-}
-
-function detailScreen(index) {
- var detail = layer.getChildFrame('#data-detail', index);
- var height = detail.height()+60;
- if (height > ($(window).height()*0.9)) {
- height = ($(window).height()*0.9);
- }
- layer.style(index, {
- top: (($(window).height()-height)/3)+"px",
- height: height+'px'
});
- $(".layui-layer-shade").remove();
-}
-
-$('body').keydown(function () {
- if (event.keyCode === 13) {
- $("#search").click();
- }
-});
+})();
--
Gitblit v1.9.1