123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- $(document).ready(() => {
- autoFlashHeight();
- // 选择账号
- const refreshUnitUsersHtml = function () {
- const select = $('#sel-batch-unit').val();
- const selectGroup = accountGroup.find(x => { return x.name === select; });
- const html = [];
- if (selectGroup) {
- for (const u of selectGroup.groupList) {
- html.push(`<tr class="text-center">`);
- html.push(`<td><input type="checkbox" name="sel-batch-check" id="${u.id}" unit="${selectGroup.name}" ${(u.select ? 'checked' : '')} ${u.sp_exist ? 'disabled' : ''}></td>`);
- html.push(`<td>${u.name}</td>`);
- html.push(`<td>${u.role}</td>`);
- html.push('<tr>');
- }
- }
- $('#sel-batch-users').html(html.join(''));
- };
- $('#sel-batch').on('show.bs.modal', function() {
- accountGroup.forEach(ag => {
- ag.groupList.forEach(u => { u.select = false; });
- });
- refreshUnitUsersHtml();
- });
- $('#sel-batch-unit').change(function() {
- refreshUnitUsersHtml();
- });
- $('body').on('click', '[name=sel-batch-check]', function() {
- const select = $('#sel-batch-unit').val();
- const selectGroup = accountGroup.find(x => { return x.name === select; });
- const user = selectGroup.groupList.find(x => { return x.id === parseInt(this.getAttribute('id')); });
- user.select = this.checked;
- });
- $('#sel-batch-all').change(function() {
- const select = $('#sel-batch-unit').val();
- const selectGroup = accountGroup.find(x => { return x.name === select; });
- selectGroup.groupList.forEach(x => {
- x.select = x.sp_exist ? false : this.checked;
- });
- refreshUnitUsersHtml();
- });
- $('#sel-batch-ok').click(() => {
- const select = [];
- for (const ag of accountGroup) {
- for (const u of ag.groupList) {
- if (u.select && !u.sp_exist) select.push(u.id);
- }
- }
- postData(`/sp/${spid}/setting/user/permission/update`, { add: select }, function() {
- window.location.reload();
- });
- });
- // 移除账号
- $('[name=remove-user]').click(function() {
- const id = this.getAttribute('data-id');
- postData(`/sp/${spid}/setting/user/permission/update`, { del: id }, function() {
- window.location.reload();
- });
- });
- $('[name=set-permission]').click(function() {
- const data = JSON.parse(this.getAttribute('data-account'));
- const permissionCheck = $('[name="permission-check"]');
- for (const pc of permissionCheck) {
- const ptype = pc.getAttribute('ptype');
- const pvalue = pc.getAttribute('pvalue');
- const typePermission = (data[ptype + '_permission'] || '').split(',');
- pc.checked = typePermission.indexOf(pvalue) >= 0;
- }
- $('#permission-uid').val(data.permission_id);
- $('#permission').modal('show');
- });
- $('#permission-ok').click(function() {
- const data = { id: $('#permission-uid').val() };
- const updatePermission = [];
- const permissionCheck = $('[name="permission-check"]');
- for (const pc of permissionCheck) {
- const ptype = pc.getAttribute('ptype');
- const pvalue = pc.getAttribute('pvalue');
- let up = updatePermission.find(x => { return x.key === ptype; });
- if (!up) {
- up = { key: ptype, value: [] };
- updatePermission.push(up);
- }
- if (pc.checked) up.value.push(pvalue);
- }
- updatePermission.forEach(x => {
- data[x.key + '_permission'] = x.value.join(',');
- });
- postData(`/sp/${spid}/setting/user/permission/update`, { update: data }, function() {
- window.location.reload();
- });
- });
- $('#filter-valid').change(function() {
- const filter = this.checked;
- const users = $('[name=user-permission]');
- for (const user of users) {
- if (filter) {
- const checked = $(':checked', user);
- if (checked.length > 0) {
- $(user).show();
- } else {
- $(user).hide();
- }
- } else {
- $(user).show();
- }
- }
- });
- $('#save-permission').click(function() {
- const updateData = [];
- const users = $('[name=user-permission]');
- for (const user of users) {
- const data = { id: user.getAttribute('pid') };
- const permissionKey = [], permission = {};
- const check = $('[type=checkbox]', user);
- for (const c of check) {
- const ptype = c.getAttribute('ptype');
- const pvalue = c.getAttribute('pvalue');
- if (permissionKey.indexOf(ptype) < 0) {
- permissionKey.push(ptype);
- permission[ptype] = [];
- }
- if (c.checked) permission[ptype].push(pvalue);
- }
- permissionKey.forEach(x => {
- data[x + '_permission'] = permission[x].join(',');
- });
- updateData.push(data);
- }
- postData(`/sp/${spid}/setting/user/permission/update`, { update: updateData }, function() {
- window.location.reload();
- })
- });
- });
|