瀏覽代碼

管理员修改,默认创建管理员

lrf 3 年之前
父節點
當前提交
3ca62546b1
共有 4 個文件被更改,包括 17 次插入21 次删除
  1. 9 9
      app.js
  2. 2 3
      app/controller/user/config/.admin.js
  3. 0 2
      app/model/user/admin.js
  4. 6 7
      app/service/user/admin.js

+ 9 - 9
app.js

@@ -5,15 +5,15 @@ class AppBootHook {
   }
 
   async willReady() {
-    // const data = await this.app.model.Admin.findOne();
-    // if (!data) {
-    //   // 没有管理员,初始化一个
-    //   const data = {
-    //     account: 'admin',
-    //     password: { secret: '1qaz2wsx' },
-    //   };
-    //   await this.app.model.Admin.create(data);
-    // }
+    const data = await this.app.model.User.Admin.findOne();
+    if (!data) {
+      // 没有管理员,初始化一个
+      const data = {
+        phone: 'admin',
+        password: { secret: '1qaz2wsx' },
+      };
+      await this.app.model.User.Admin.create(data);
+    }
   }
 
   async serverDidReady() {

+ 2 - 3
app/controller/user/config/.admin.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['!name', '!phone', '!password', 'openid', '!role', 'menus', '!pid', 'deptname', 'code', 'isdel', 'remark', 'role_id'],
+    requestBody: ['name', 'phone', 'password', 'openid', 'role', 'pid', 'deptname', 'code', 'remark', 'role_id'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['name', 'phone', 'openid', 'role', 'menus', 'pid', 'deptname', 'code', 'isdel', 'remark', 'role_id'],
+    requestBody: ['name', 'phone', 'openid', 'role', 'pid', 'deptname', 'code', 'remark', 'role_id'],
   },
   show: {
     parameters: {
@@ -25,7 +25,6 @@ module.exports = {
         pid: 'pid',
         deptname: '%deptname%',
         code: 'code',
-        isdel: 'isdel',
         role_id: 'role_id',
         'create_time@start': 'create_time@start',
         'create_time@end': 'create_time@end',

+ 0 - 2
app/model/user/admin.js

@@ -11,11 +11,9 @@ const admin = {
   password: { type: Secret, select: false }, // 注册密码
   openid: { type: String }, // 微信openid
   role: { type: String }, // 角色: 0:超级管理员;1:管理员;2:机构管理员;3:业务管理员
-  menus: { type: [ String ] }, // 菜单
   pid: { type: String }, // 上级id
   deptname: { type: String }, // 机构名称
   code: { type: String }, // 邀请码
-  isdel: { type: Boolean, default: false }, // 是否删除
   remark: { type: String, maxLength: 200 },
   role_id: { type: String }, // 关联角色id
 };

+ 6 - 7
app/service/user/admin.js

@@ -17,15 +17,14 @@ class AdminService extends CrudService {
 
   async query(query, { skip = 0, limit = 0, ...other } = {}) {
     query = this.util.turnDateRangeQuery(this.util.turnFilter(query));
-    console.log(this.model);
     let data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit));
     if (data.length > 0) data = JSON.parse(JSON.stringify(data));
-    const menus = await this.ctx.model.System.Menu.find();
-    data = data.map(i => {
-      const um = menus.filter(f => i.menus.find(mf => ObjectId(mf).equals(f._id)));
-      i.menus = um;
-      return i;
-    });
+    // const menus = await this.ctx.model.System.Menu.find();
+    // data = data.map(i => {
+    //   const um = menus.filter(f => i.menus.find(mf => ObjectId(mf).equals(f._id)));
+    //   i.menus = um;
+    //   return i;
+    // });
     return data;
   }