Browse Source

账号设置添加分页

laiguoran 5 years ago
parent
commit
d7f8873da8

+ 38 - 9
app/controller/setting_controller.js

@@ -91,21 +91,37 @@ module.exports = app => {
                     throw '没有访问权限';
                 }
 
+                const page = ctx.page;
+
                 // 获取数据规则
                 // const rule = ctx.service.projectAccount.rule('updateUser');
                 // const frontRule = ctx.helper.validateConvert(rule);
 
+                const total = await ctx.service.projectAccount.count({ project_id: projectId });
+
                 // 获取项目用户列表
-                const accountData = await ctx.service.projectAccount.getAllDataByCondition({
-                    where: { project_id: projectId },
-                    columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
-                });
+                // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
+                //     where: { project_id: projectId },
+                //     columns: ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'],
+                //     limit: (app.config.pageSize * (page - 1)),
+                //     offset: app.config.pageSize,
+                // });
+                const columns = ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'];
+                const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
+
+                // 分页相关
+                const pageInfo = {
+                    page,
+                    total: Math.ceil(total / app.config.pageSize),
+                    queryData: JSON.stringify(ctx.urlInfo.query),
+                };
 
                 const renderData = {
                     projectData,
                     accountData,
                     accountGroup,
                     permission,
+                    pageInfo,
                     // rule: JSON.stringify(frontRule),
                 };
                 await this.layout('setting/user.ejs', renderData, 'setting/user_modal.ejs');
@@ -135,12 +151,24 @@ module.exports = app => {
                 // 获取数据规则
                 // const rule = ctx.service.projectAccount.rule('updateUser');
                 // const frontRule = ctx.helper.validateConvert(rule);
-
+                const page = ctx.page;
+                const total = await ctx.service.projectAccount.count({ project_id: projectId });
                 // 获取项目用户列表
-                const accountData = await ctx.service.projectAccount.getAllDataByCondition({
-                    where: { project_id: projectId },
-                    columns: ['id', 'account', 'name', 'company', 'role', 'is_admin', 'account_group', 'permission', 'cooperation'],
-                });
+                // const accountData = await ctx.service.projectAccount.getAllDataByCondition({
+                //     where: { project_id: projectId },
+                //     columns: ['id', 'account', 'name', 'company', 'role', 'is_admin', 'account_group', 'permission', 'cooperation'],
+                // });
+
+                const columns = ['id', 'account', 'name', 'company', 'role', 'is_admin', 'account_group', 'permission', 'cooperation'];
+
+                const accountData = await ctx.service.projectAccount.getListByProjectId(columns, projectId);
+
+                // 分页相关
+                const pageInfo = {
+                    page,
+                    total: Math.ceil(total / app.config.pageSize),
+                    queryData: JSON.stringify(ctx.urlInfo.query),
+                };
 
                 const renderData = {
                     projectData,
@@ -148,6 +176,7 @@ module.exports = app => {
                     accountGroup,
                     permission,
                     permissionStr: JSON.stringify(permission),
+                    pageInfo,
                     // rule: JSON.stringify(frontRule),
                 };
                 await this.layout('setting/user_permission.ejs', renderData, 'setting/user_permission_modal.ejs');

+ 11 - 0
app/service/project_account.js

@@ -314,6 +314,17 @@ module.exports = app => {
             return info;
         }
 
+        async getListByProjectId(columns = '', pid) {
+            this.initSqlBuilder();
+            this.sqlBuilder.columns = columns !== '' ? columns : ['id', 'account', 'name', 'company', 'role', 'mobile', 'auth_mobile', 'telephone', 'enable', 'is_admin', 'account_group'];
+            this.sqlBuilder.setAndWhere('project_id', {
+                value: pid,
+                operate: '=',
+            });
+
+            return await this.getListWithBuilder();
+        }
+
         /**
          * 修改用户数据
          *

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

@@ -53,6 +53,7 @@
                             <% } %>
                             </tbody>
                         </table>
+                        <% include ../layout/page.ejs %>
                     </div>
                 </div>
             </div>

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

@@ -60,6 +60,7 @@
                             <% } %>
                             </tbody>
                         </table>
+                        <% include ../layout/page.ejs %>
                     </div>
                 </div>
             </div>