|
@@ -11,60 +11,30 @@ class InstallService extends CrudService {
|
|
|
super(ctx, 'install');
|
|
|
this.dataIndex = path.resolve('app', 'public', 'defaultData');
|
|
|
}
|
|
|
+
|
|
|
async init() {
|
|
|
- await this.initRole();
|
|
|
- await this.initAdmin();
|
|
|
- await this.initTestBasic();
|
|
|
- }
|
|
|
- /**
|
|
|
- * 初始化角色数据
|
|
|
- */
|
|
|
- async initRole() {
|
|
|
- const model = this.ctx.model.System.Role;
|
|
|
- const num = await model.count();
|
|
|
- if (num > 0) return;
|
|
|
- const dataPath = path.resolve(this.dataIndex, 'role.js');
|
|
|
- const list = require(dataPath);
|
|
|
- await model.insertMany(list);
|
|
|
- }
|
|
|
- /**
|
|
|
- * 初始化管理员
|
|
|
- */
|
|
|
- async initAdmin() {
|
|
|
- const model = this.ctx.model.System.User;
|
|
|
- const roleModel = this.ctx.model.System.Role;
|
|
|
- const num = await model.count();
|
|
|
- if (num > 0) return;
|
|
|
- // 需要将role中menu的mode为all的数据取出来,这是超级管理员的角色信息
|
|
|
- const roleData = await roleModel.findOne({ code: 'sadmin' });
|
|
|
- if (!roleData) return;
|
|
|
- const { _id: role } = roleData;
|
|
|
- const dataPath = path.resolve(this.dataIndex, 'user.js');
|
|
|
- let list = require(dataPath);
|
|
|
- list = list.map(i => ({ ...i, role }));
|
|
|
- await model.insertMany(list);
|
|
|
+ await this.initDict();
|
|
|
+ // await this.initSelfShop();
|
|
|
+ // await this.initTestCustomer();
|
|
|
+ // await this.initTestGoods();
|
|
|
+ // await this.initServiceContact();
|
|
|
}
|
|
|
/**
|
|
|
- * 初始化测试用户
|
|
|
+ * 初始化字典
|
|
|
*/
|
|
|
- async initTestBasic() {
|
|
|
- const model = this.ctx.model.Basic;
|
|
|
- const roleModel = this.ctx.model.System.Role;
|
|
|
- const userModel = this.ctx.model.System.User;
|
|
|
- const num = await model.count();
|
|
|
- if (num > 0) return;
|
|
|
- const roleData = await roleModel.findOne({ code: 'user' });
|
|
|
- if (!roleData) return;
|
|
|
- const { _id: role } = roleData;
|
|
|
- const dataPath = path.resolve(this.dataIndex, 'basic.js');
|
|
|
- const list = require(dataPath);
|
|
|
- const basicList = await model.insertMany(list);
|
|
|
- const users = basicList.map(i => {
|
|
|
- const { _id: basic, name, phone } = i;
|
|
|
- const obj = { role, basic, phone, name, account: name, password: { secret: '111111' } };
|
|
|
- return obj;
|
|
|
- });
|
|
|
- await userModel.insertMany(users);
|
|
|
+ async initDict() {
|
|
|
+ const indexModel = this.ctx.model.Dev.DictIndex;
|
|
|
+ const dataModel = this.ctx.model.Dev.DictData;
|
|
|
+ const p = path.resolve(this.dataIndex, 'dict.js');
|
|
|
+ const data = require(p);
|
|
|
+ for (const i of data) {
|
|
|
+ const { children, ...others } = i;
|
|
|
+ const num = await indexModel.count({ code: others.code });
|
|
|
+ if (num > 0) continue;
|
|
|
+ await indexModel.create(others);
|
|
|
+ const newChildren = children.map(i => ({ ...i, code: others.code }));
|
|
|
+ await dataModel.insertMany(newChildren);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|