reloaded 5 سال پیش
والد
کامیت
2d1a650c88

+ 31 - 0
.github/workflows/nodejs.yml

@@ -0,0 +1,31 @@
+# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
+# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
+
+name: Node.js CI
+
+on:
+  push:
+    branches: [ master ]
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  build:
+
+    runs-on: ${{ matrix.os }}
+
+    strategy:
+      matrix:
+        node-version: [10.x]
+        os: [ubuntu-latest, windows-latest, macos-latest]
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Use Node.js ${{ matrix.node-version }}
+      uses: actions/setup-node@v1
+      with:
+        node-version: ${{ matrix.node-version }}
+    - run: npm i -g npminstall && npminstall
+    - run: npm run ci
+      env:
+        CI: true

+ 12 - 0
.travis.yml

@@ -0,0 +1,12 @@
+
+language: node_js
+node_js:
+  - '10'
+before_install:
+  - npm i npminstall -g
+install:
+  - npminstall
+script:
+  - npm run ci
+after_script:
+  - npminstall codecov && codecov

+ 36 - 0
app/controller/.department.js

@@ -0,0 +1,36 @@
+module.exports = {
+  create: {
+    requestBody: ["!name", "unit", "!duty", "phone"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["name", "unit", "!duty", "phone"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        unit: "unit",
+        duty: "duty",
+        phone: "phone",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 34 - 0
app/controller/.level.js

@@ -0,0 +1,34 @@
+module.exports = {
+  create: {
+    requestBody: ["!dept_id", "!name"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["dept_id", "name"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        dept_id: "dept_id",
+        name: "name",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 73 - 0
app/controller/.news.js

@@ -0,0 +1,73 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!col_name",
+      "!title",
+      "!introduction",
+      "content",
+      "publish_time",
+      "publish_unit",
+      "publisher",
+      "type",
+      "url",
+      "img_url",
+      "is_top",
+      "view_times",
+      "status",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "col_name",
+      "title",
+      "introduction",
+      "content",
+      "publish_time",
+      "publish_unit",
+      "publisher",
+      "type",
+      "url",
+      "img_url",
+      "is_top",
+      "view_times",
+      "status",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        col_name: "col_name",
+        title: "title",
+        introduction: "introduction",
+        content: "content",
+        publish_time: "publish_time",
+        publish_unit: "publish_unit",
+        publisher: "publisher",
+        type: "type",
+        url: "url",
+        img_url: "img_url",
+        is_top: "is_top",
+        view_times: "view_times",
+        status: "status",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 34 - 0
app/controller/.roles.js

@@ -0,0 +1,34 @@
+module.exports = {
+  create: {
+    requestBody: ["code", "!name"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["code", "name"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        code: "code",
+        name: "name",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 61 - 0
app/controller/.staff.js

@@ -0,0 +1,61 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!gender",
+      "self_tel",
+      "address",
+      "birthday",
+      "id_number",
+      "dept_id",
+      "level_id",
+      "sort",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "name",
+      "gender",
+      "self_tel",
+      "address",
+      "birthday",
+      "id_number",
+      "dept_id",
+      "level_id",
+      "sort",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        gender: "gender",
+        self_tel: "self_tel",
+        address: "address",
+        birthday: "birthday",
+        id_number: "id_number",
+        dept_id: "dept_id",
+        level_id: "level_id",
+        sort: "sort",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 38 - 0
app/controller/.user.js

@@ -0,0 +1,38 @@
+module.exports = {
+  create: {
+    requestBody: ["uid", "openid", "!passwd", "role_id", "name", "phone"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["uid", "openid", "passwd", "role_id", "name", "phone"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        uid: "uid",
+        openid: "openid",
+        passwd: "passwd",
+        role_id: "role_id",
+        name: "name",
+        phone: "phone",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 18 - 0
app/controller/department.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.department.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 部门表管理
+class DepartmentController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.department;
+  }
+
+}
+
+module.exports = CrudController(DepartmentController, meta);

+ 0 - 12
app/controller/home.js

@@ -1,12 +0,0 @@
-'use strict';
-
-const Controller = require('egg').Controller;
-
-class HomeController extends Controller {
-  async index() {
-    const { ctx } = this;
-    ctx.body = 'hi, egg';
-  }
-}
-
-module.exports = HomeController;

+ 18 - 0
app/controller/level.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.level.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 信息表管理
+class LevelController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.level;
+  }
+
+}
+
+module.exports = CrudController(LevelController, meta);

+ 18 - 0
app/controller/news.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.news.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 信息表管理
+class NewsController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.news;
+  }
+
+}
+
+module.exports = CrudController(NewsController, meta);

+ 18 - 0
app/controller/roles.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.roles.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 信息表管理
+class RolesController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.roles;
+  }
+
+}
+
+module.exports = CrudController(RolesController, meta);

+ 18 - 0
app/controller/staff.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.staff.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 人员表管理
+class StaffController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.staff;
+  }
+
+}
+
+module.exports = CrudController(StaffController, meta);

+ 26 - 0
app/controller/user.js

@@ -0,0 +1,26 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.user.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 用户表管理
+class UserController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.user;
+  }
+
+  async login() {
+    const res = await this.service.login(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+
+  async uppasswd() {
+    const res = await this.service.uppasswd(this.ctx.request.body);
+    this.ctx.ok({ data: res });
+  }
+}
+
+module.exports = CrudController(UserController, meta);

+ 21 - 0
app/model/department.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 部门表
+const DepartmentSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 部门名称
+  unit: { type: String, required: false, maxLength: 200 }, // 所属单位
+  duty: { type: String, required: false, maxLength: 200 }, // 部门职责
+  phone: { type: String, required: false, maxLength: 200 }, // 部门电话
+};
+
+
+const schema = new Schema(DepartmentSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Department', schema, 'department');
+};

+ 19 - 0
app/model/level.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 职务表
+const LevelSchema = {
+  dept_id: { type: String, required: true, maxLength: 200 }, // 部门id
+  name: { type: String, required: true, maxLength: 200 }, // 职务名称
+};
+
+
+const schema = new Schema(LevelSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Level', schema, 'level');
+};

+ 30 - 0
app/model/news.js

@@ -0,0 +1,30 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 信息表
+const NewsSchema = {
+  col_name: { type: String, required: true, maxLength: 200 }, // 栏目名称
+  title: { type: String, required: true, maxLength: 200 }, // 标题
+  introduction: { type: String, required: true, maxLength: 200 }, // 简介
+  content: { type: String, required: false }, // 内容
+  publish_time: { type: String, required: false, maxLength: 200 }, // 发布时间
+  publish_unit: { type: String, required: false, maxLength: 200 }, // 发布单位
+  publisher: { type: String, required: false, maxLength: 200 }, // 发布人
+  type: { type: String, required: false, maxLength: 200 }, // 0-自有,1-外链
+  url: { type: String, required: false, maxLength: 200 }, // 链接地址
+  img_url: { type: String, required: false, maxLength: 200 }, // 图片路径
+  is_top: { type: String, required: false, maxLength: 200, default: '0' }, // 是否推荐,0-不推荐,1-推荐
+  view_times: { type: String, required: false, maxLength: 200 }, // 浏览次数
+  status: { type: String, required: false, maxLength: 200, default: '0' }, // 状态,0-草稿,1-未审核,2-已审核
+};
+
+
+const schema = new Schema(NewsSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('News', schema, 'news');
+};

+ 19 - 0
app/model/roles.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 用户权限表
+const RolesSchema = {
+  code: { type: String, required: true, maxLength: 200 }, // 权限code
+  name: { type: String, required: true, maxLength: 200 }, // 权限名称
+};
+
+
+const schema = new Schema(RolesSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Roles', schema, 'roles');
+};

+ 26 - 0
app/model/staff.js

@@ -0,0 +1,26 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 人员表
+const StaffSchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 姓名
+  gender: { type: String, required: true, maxLength: 200 }, // 性别,0-女,1-男
+  self_tel: { type: String, required: false, maxLength: 200 }, // 个人电话
+  address: { type: String, required: false, maxLength: 200 }, // 家庭住址
+  birthday: { type: String, required: false, maxLength: 200 }, // 出生日期
+  id_number: { type: String, required: false, maxLength: 200 }, // 身份证号
+  dept_id: { type: String, required: false, maxLength: 200 }, // 部门id
+  level_id: { type: String, required: false, maxLength: 200 }, // 职务id
+  sort: { type: String, required: false, maxLength: 200 }, // 排序号
+};
+
+
+const schema = new Schema(StaffSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Staff', schema, 'staff');
+};

+ 24 - 0
app/model/user.js

@@ -0,0 +1,24 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+const { Secret } = require('naf-framework-mongoose/lib/model/schema');
+
+// 用户表
+const UserSchema = {
+  uid: { type: String, required: false, maxLength: 200 }, // 用户信息表id
+  openid: { type: String, required: false, maxLength: 200 }, // 用户微信openid
+  passwd: { type: { Secret }, required: true, select: false, maxLength: 200 }, // 用户密码
+  role_id: { type: String, required: false, maxLength: 200 }, // 用户权限id
+  name: { type: String, required: false, maxLength: 200 }, // 用户名
+  phone: { type: String, required: true, maxLength: 64 }, // 手机号
+};
+
+
+const schema = new Schema(UserSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('User', schema, 'user');
+};

+ 26 - 1
app/router.js

@@ -5,5 +5,30 @@
  */
  */
 module.exports = app => {
 module.exports = app => {
   const { router, controller } = app;
   const { router, controller } = app;
-  router.get('/', controller.home.index);
+
+  // 信息表设置路由
+  router.resources('news', '/api/count/news', controller.news); // index、create、show、destroy
+  router.post('news', '/api/count/news/update/:id', controller.news.update);
+
+  // 权限表设置路由
+  router.resources('roles', '/api/count/roles', controller.roles); // index、create、show、destroy
+  router.post('roles', '/api/count/roles/update/:id', controller.roles.update);
+
+  // 用户表设置路由
+  router.resources('user', '/api/count/user', controller.user); // index、create、show、destroy
+  router.post('user', '/api/count/user/update/:id', controller.user.update);
+  router.post('user', '/api/count/user/uppasswd', controller.user.uppasswd);
+  router.post('user', '/api/count/user/login', controller.user.login);
+
+  // 职务表设置路由
+  router.resources('level', '/api/count/level', controller.level); // index、create、show、destroy
+  router.post('level', '/api/count/level/update/:id', controller.level.update);
+
+  // 部门表设置路由
+  router.resources('department', '/api/count/department', controller.department); // index、create、show、destroy
+  router.post('department', '/api/count/department/update/:id', controller.department.update);
+
+  // 人员表设置路由
+  router.resources('staff', '/api/count/staff', controller.staff); // index、create、show、destroy
+  router.post('staff', '/api/count/staff/update/:id', controller.staff.update);
 };
 };

+ 18 - 0
app/service/department.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class DepartmentService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'department');
+    this.model = this.ctx.model.Department;
+  }
+
+}
+
+module.exports = DepartmentService;

+ 18 - 0
app/service/level.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class LevelService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'news');
+    this.model = this.ctx.model.Level;
+  }
+
+}
+
+module.exports = LevelService;

+ 18 - 0
app/service/news.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class NewsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'news');
+    this.model = this.ctx.model.News;
+  }
+
+}
+
+module.exports = NewsService;

+ 18 - 0
app/service/roles.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class RolesService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'roles');
+    this.model = this.ctx.model.Roles;
+  }
+
+}
+
+module.exports = RolesService;

+ 18 - 0
app/service/staff.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class StaffService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'staff');
+    this.model = this.ctx.model.Staff;
+  }
+
+}
+
+module.exports = StaffService;

+ 91 - 0
app/service/user.js

@@ -0,0 +1,91 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const jwt = require('jsonwebtoken');
+
+class UserService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'user');
+    this.model = this.ctx.model.User;
+  }
+
+  // 重写创建方法
+  async create(data) {
+    const { uid, openid, passwd, role_id, name, phone } = data;
+    // console.log(data);
+    assert(name && phone && passwd, '缺少部分信息项');
+    assert(/^\d{11}$/i.test(phone), '无效的手机号');
+    const user = await this.model.findOne({ phone });
+    if (user) {
+      throw new BusinessError(ErrorCode.DATA_EXISTED);
+    }
+    const newdata = data;
+    const pas = await this.createJwtPwd(passwd);
+    newdata.passwd = pas;
+    const res = await this.model.create(newdata);
+    return res;
+  }
+
+  // 用户修改密码
+  async uppasswd(data) {
+    const { userid, oldpasswd, newpasswd } = data;
+    assert(userid && oldpasswd && newpasswd, '缺少部分信息项');
+    // 根据用户id查询其他用户表中是否存在相应数据
+    const user = await this.model.findById(userid, '+passwd');
+    // 如果用户不存在抛出异常
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
+    const _oldpasswd = await this.createJwtPwd(oldpasswd);
+    // 如果两个密码不一致抛出异常
+    if (_oldpasswd !== user.passwd) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    const _newpasswd = await this.createJwtPwd(newpasswd);
+    user.passwd = _newpasswd;
+    await user.save();
+  }
+
+  async login(data) {
+    const { phone, passwd } = data;
+    // 根据用户输入的手机号查询其他用户表中是否存在相应数据
+    const user = await this.model.findOne({ phone });
+    // 如果用户不存在抛出异常
+    if (!user) {
+      throw new BusinessError(ErrorCode.USER_NOT_EXIST);
+    }
+    const _user = await this.model.findOne({ phone }, '+passwd');
+    // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
+    const pas = await this.createJwtPwd(passwd);
+    // 如果两个密码不一致抛出异常
+    if (pas !== _user.passwd) {
+      throw new BusinessError(ErrorCode.BAD_PASSWORD);
+    }
+    // 取出用户的类型,根据用户类型返回相应信息
+    return await this.createJwt(user);
+  }
+
+  async createJwtPwd(password) {
+    const { secret, expiresIn, issuer } = this.config.jwt;
+    const token = await jwt.sign(password, secret);
+    return token;
+  }
+
+  // 创建登录Token
+  async createJwt({ id, uid, openid, role_id, name, phone }) {
+    const { secret, expiresIn = '1d', issuer } = this.config.jwt;
+    const subject = phone;
+    const _userid = id;
+    const res = { userid: _userid, uid, openid, role_id, name, phone };
+    const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
+    return token;
+  }
+}
+
+module.exports = UserService;

+ 14 - 0
appveyor.yml

@@ -0,0 +1,14 @@
+environment:
+  matrix:
+    - nodejs_version: '10'
+
+install:
+  - ps: Install-Product node $env:nodejs_version
+  - npm i npminstall && node_modules\.bin\npminstall
+
+test_script:
+  - node --version
+  - npm --version
+  - npm run test
+
+build: off

+ 21 - 0
config/config.default.js

@@ -2,6 +2,8 @@
 
 
 'use strict';
 'use strict';
 
 
+const { jwt } = require('./config.secret');
+
 /**
 /**
  * @param {Egg.EggAppInfo} appInfo app info
  * @param {Egg.EggAppInfo} appInfo app info
  */
  */
@@ -23,6 +25,25 @@ module.exports = appInfo => {
     // myAppName: 'egg',
     // myAppName: 'egg',
   };
   };
 
 
+  // mongoose config
+  config.mongoose = {
+    url: 'mongodb://127.0.0.1:27017/count',
+    // options: {
+    //   user: 'admin',
+    //   pass: 'admin',
+    //   authSource: 'admin',
+    //   useNewUrlParser: true,
+    //   useCreateIndex: true,
+    // },
+  };
+
+  // // JWT config
+  config.jwt = {
+    ...jwt,
+    expiresIn: '1d',
+    issuer: 'count',
+  };
+
   return {
   return {
     ...config,
     ...config,
     ...userConfig,
     ...userConfig,

+ 7 - 0
config/config.secret.js

@@ -0,0 +1,7 @@
+'use strict';
+
+module.exports = {
+  jwt: {
+    secret: 'Ziyouyanfa!@#',
+  },
+};

+ 5 - 0
jsconfig.json

@@ -0,0 +1,5 @@
+{
+  "include": [
+    "**/*"
+  ]
+}

+ 5 - 2
package.json

@@ -4,11 +4,14 @@
   "description": "",
   "description": "",
   "private": true,
   "private": true,
   "egg": {
   "egg": {
-    "declarations": true
+    "framework": "naf-framework-mongoose"
   },
   },
   "dependencies": {
   "dependencies": {
     "egg": "^2.15.1",
     "egg": "^2.15.1",
-    "egg-scripts": "^2.11.0"
+    "egg-scripts": "^2.11.0",
+    "jsonwebtoken": "^8.5.1",
+    "lodash": "^4.17.15",
+    "naf-framework-mongoose": "^0.6.12"
   },
   },
   "devDependencies": {
   "devDependencies": {
     "autod": "^3.0.1",
     "autod": "^3.0.1",