Kaynağa Gözat

接口设置菜单,是否可见控制

MaiXinRong 4 yıl önce
ebeveyn
işleme
cb13f5045b

+ 10 - 10
app/controller/setting_controller.js

@@ -33,10 +33,10 @@ module.exports = app => {
             ctx.subMenu = settingMenu;
         }
 
-        _checkMenu(pid) {
+        async _checkMenu(pid) {
             const s2bData = new S2b(this.ctx);
-            const s2bProj = s2bData.getS2bProj(pid);
-            this.ctx.subMenu.s2b.display = s2bProj.gxby || s2bProj.dagl;
+            const s2bProj = await s2bData.getS2bProj(pid);
+            this.ctx.subMenu.s2b.display = !!s2bProj && (!!s2bProj.gxby || !!s2bProj.dagl);
             return s2bProj;
         }
 
@@ -50,7 +50,7 @@ module.exports = app => {
             try {
                 // 获取项目数据
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 if (projectData === null) {
                     throw '没有对应的项目数据';
@@ -95,7 +95,7 @@ module.exports = app => {
             try {
                 // 获取项目数据
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 if (projectData === null) {
                     throw '没有对应的项目数据';
@@ -421,7 +421,7 @@ module.exports = app => {
             try {
                 // 获取项目数据
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 if (projectData === null) {
                     throw '没有对应的项目数据';
@@ -638,7 +638,7 @@ module.exports = app => {
             try {
                 // 获取项目数据
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 if (!projectData) {
                     throw '没有对应的项目数据';
@@ -679,7 +679,7 @@ module.exports = app => {
             try {
                 // 获取项目数据
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 if (projectData === null) {
                     throw '没有对应的项目数据';
@@ -706,7 +706,7 @@ module.exports = app => {
         async fun(ctx) {
             try {
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 const funRela = await ctx.service.project.getFunRela(projectId);
                 if (projectData === null) {
@@ -760,7 +760,7 @@ module.exports = app => {
         async s2b (ctx) {
             try {
                 const projectId = ctx.session.sessionProject.id;
-                this._checkMenu(projectId);
+                await this._checkMenu(projectId);
                 const projectData = await ctx.service.project.getDataById(projectId);
                 if (projectData === null) throw '没有对应的项目数据';
                 if (ctx.session.sessionUser.is_admin === 0) throw '没有访问权限';

+ 1 - 0
app/view/setting/sub_menu.ejs

@@ -7,6 +7,7 @@
             <ul class="nav-list list-unstyled">
                 <% if (projectData.user_account === ctx.session.sessionUser.account) { %>
                 <% for (const index in ctx.subMenu) { %>
+                <% if (!ctx.subMenu[index].display) continue; %>
                 <li <% if (ctx.url.indexOf(ctx.subMenu[index].url) !== -1) { %>class="active"<% } %>>
                     <a href="<%- ctx.subMenu[index].url %>">
                         <span><%- ctx.subMenu[index].caption %></span>