فهرست منبع

账号添加受限控制

laiguoran 3 سال پیش
والد
کامیت
8ba33da869
2فایلهای تغییر یافته به همراه98 افزوده شده و 1 حذف شده
  1. 97 0
      app/controller/setting_controller.js
  2. 1 1
      app/view/setting/user_permission.ejs

+ 97 - 0
app/controller/setting_controller.js

@@ -243,6 +243,7 @@ module.exports = app => {
                     permission,
                     permissionStr: JSON.stringify(permission),
                     pageInfo,
+                    user_total: total,
                     // rule: JSON.stringify(frontRule),
                 };
                 await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');
@@ -847,6 +848,102 @@ module.exports = app => {
                 this.ajaxErrorBody(error, '保存数据失败');
             }
         }
+
+        async dataCollect(ctx) {
+            try {
+                const projectId = ctx.session.sessionProject.id;
+                await this._checkMenu(projectId);
+                const projectData = await ctx.service.project.getDataById(projectId);
+                if (projectData === null) throw '没有对应的项目数据';
+                if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';
+                const dataCollectAudits = await ctx.service.datacollectAudit.getList(projectId);
+                // 获取所有项目参与者
+                const accountList = await ctx.service.projectAccount.getAllDataByCondition({
+                    where: { project_id: ctx.session.sessionProject.id, enable: 1 },
+                    columns: ['id', 'name', 'company', 'role', 'enable', 'is_admin', 'account_group', 'mobile'],
+                });
+                const accountGroupList = accountGroup.map((item, idx) => {
+                    const groupList = accountList.filter(item => item.account_group === idx);
+                    return { groupName: item, groupList };
+                });
+                const categoryData = await ctx.service.category.getAllCategory(ctx.session.sessionProject.id);
+                await this.layout('setting/datacollect.ejs', {
+                    projectData,
+                    dataCollectAudits,
+                    accountList,
+                    accountGroup: accountGroupList,
+                    categoryData,
+                }, 'setting/datacollect_modal.ejs');
+            } catch (error) {
+                ctx.helper.log(error);
+                ctx.redirect('/dashboard');
+            }
+        }
+
+        async dataCollectSave(ctx) {
+            try {
+                if (ctx.session.sessionUser.is_admin === 0) throw '没有设置权限';
+                const projectId = ctx.session.sessionProject.id;
+                const responseData = {
+                    err: 0, msg: '', data: null,
+                };
+
+                const data = JSON.parse(ctx.request.body.data);
+                if (!data.type) {
+                    throw '提交数据错误';
+                }
+                switch (data.type) {
+                    case 'show':
+                        responseData.data = await ctx.service.project.update({ data_collect: data.data_collect }, { id: projectId });
+                        ctx.session.sessionProject.dataCollect = data.data_collect;
+                        ctx.session.sessionProject.showDataCollect = data.data_collect ? 1 : 0;
+                        break;
+                    case 'add-audit':
+                        // 判断该用户的组是否已加入到表中,已加入则提示无需添加
+                        const auditInfo = await ctx.service.datacollectAudit.getDataByCondition({ pid: projectId, uid: data.id });
+                        if (auditInfo) {
+                            throw '该用户已存在权限中,无需重复添加';
+                        }
+                        const accountInfo = await ctx.service.projectAccount.getDataById(data.id);
+                        const groupInfo = await ctx.service.datacollectAudit.getGroupInfo(projectId, accountInfo.account_group);
+                        if (groupInfo) {
+                            throw '该用户所在单位已存在权限中,无需单独添加';
+                        }
+                        await ctx.service.datacollectAudit.saveAudit(projectId, accountInfo.account_group, data.id);
+                        responseData.data = await ctx.service.datacollectAudit.getList(projectId);
+                        break;
+                    case 'add-group':
+                        const groupInfo2 = await ctx.service.datacollectAudit.getGroupInfo(projectId, data.id);
+                        if (groupInfo2) {
+                            throw '该单位已存在权限中,无需重复添加';
+                        }
+                        await ctx.service.datacollectAudit.saveGroup(projectId, data.id);
+                        responseData.data = await ctx.service.datacollectAudit.getList(projectId);
+                        break;
+                    case 'del-audit':
+                        const auditInfo2 = await ctx.service.datacollectAudit.getDataById(data.id);
+                        if (!auditInfo2) {
+                            throw '该用户已不存在权限中,移除失败';
+                        }
+                        await ctx.service.datacollectAudit.delAudit(data.id);
+                        responseData.data = await ctx.service.datacollectAudit.getList(projectId);
+                        break;
+                    case 'del-group':
+                        const groupInfo3 = await ctx.service.datacollectAudit.getDataById(data.id);
+                        if (!groupInfo3) {
+                            throw '该单位已不存在权限中,移除失败';
+                        }
+                        await ctx.service.datacollectAudit.delAudit(data.id);
+                        responseData.data = await ctx.service.datacollectAudit.getList(projectId);
+                        break;
+                    default: throw '参数有误';
+                }
+                ctx.body = responseData;
+            } catch (err) {
+                this.log(err);
+                ctx.body = { err: 1, msg: err.toString(), data: null };
+            }
+        }
     }
 
     return SettingController;

+ 1 - 1
app/view/setting/user_permission.ejs

@@ -3,7 +3,7 @@
     <div class="panel-title">
         <div class="title-main">
             <h2>账号管理
-                <% if (projectData.max_user !== accountData.length) { %>
+                <% if (projectData.max_user > user_total) { %>
                 <a href="#ver" data-toggle="modal" data-target="#add-user" class="btn btn-primary btn-sm pull-right">添加账号</a>
                 <% } else { %>
                 <a href="#add-unpass" data-toggle="modal" data-target="#add-unpass" class="btn btn-primary btn-sm pull-right">添加账号(受限)</a>