|
@@ -0,0 +1,87 @@
|
|
|
|
+import { Provide } from '@midwayjs/decorator';
|
|
|
|
+import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
|
+import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
|
+import { Admin } from '../entity/system/admin.entity';
|
|
|
|
+import { Role } from '../entity/system/role.entity';
|
|
|
|
+import { Menus } from '../entity/system/menus.entity';
|
|
|
|
+import { DictData } from '../entity/system/dictData.entity';
|
|
|
|
+import { DictType } from '../entity/system/dictType.entity';
|
|
|
|
+import { Types } from 'mongoose';
|
|
|
|
+const ObjectId = Types.ObjectId;
|
|
|
|
+@Provide()
|
|
|
|
+export class InitService {
|
|
|
|
+ @InjectEntityModel(Admin)
|
|
|
|
+ adminModel: ReturnModelType<typeof Admin>;
|
|
|
|
+ @InjectEntityModel(Role)
|
|
|
|
+ roleModel: ReturnModelType<typeof Role>;
|
|
|
|
+ @InjectEntityModel(Menus)
|
|
|
|
+ menusModel: ReturnModelType<typeof Menus>;
|
|
|
|
+ @InjectEntityModel(DictType)
|
|
|
|
+ dictTypeModel: ReturnModelType<typeof DictType>;
|
|
|
|
+ @InjectEntityModel(DictData)
|
|
|
|
+ dictDataModel: ReturnModelType<typeof DictData>;
|
|
|
|
+
|
|
|
|
+ async adminUser() {
|
|
|
|
+ const data = {
|
|
|
|
+ account: 'admin',
|
|
|
|
+ password: '1qaz2wsx',
|
|
|
|
+ nick_name: '系统管理员',
|
|
|
|
+ is_super: '0',
|
|
|
|
+ };
|
|
|
|
+ const is_exist = await this.adminModel.count({ is_super: '0' });
|
|
|
|
+ if (!is_exist) return await this.adminModel.create(data);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async initRole() {
|
|
|
|
+ const num = await this.roleModel.count();
|
|
|
|
+ if (num > 0) return;
|
|
|
|
+ const datas = [{ name: '管理员', code: 'admin' }];
|
|
|
|
+ await this.roleModel.insertMany(datas);
|
|
|
|
+ }
|
|
|
|
+ async initMenus() {
|
|
|
|
+ const num = await this.menusModel.count();
|
|
|
|
+ if (num > 0) return;
|
|
|
|
+ const datas: any = [{ name: '首页', order_num: 1, path: '/homeIndex', component: '/home/index', type: '1' }];
|
|
|
|
+ // 系统设置
|
|
|
|
+ const smId = new ObjectId();
|
|
|
|
+ const systemMenus = [
|
|
|
|
+ { _id: smId, name: '系统设置', order_num: 2, type: '0' },
|
|
|
|
+ { name: '菜单设置', parent_id: smId.toString(), order_num: 1, path: '/system/menus', component: '/system/menus/index', type: '1' },
|
|
|
|
+ { name: '角色管理', parent_id: smId.toString(), order_num: 2, path: '/system/role', component: '/system/role/index', type: '1' },
|
|
|
|
+ { name: '字典管理', parent_id: smId.toString(), order_num: 3, path: '/system/dict', component: '/system/dict/index', type: '1' },
|
|
|
|
+ { name: '字典数据', parent_id: smId.toString(), order_num: 4, path: '/system/dictData', component: '/system/dictData/index', type: '2' },
|
|
|
|
+ ];
|
|
|
|
+ // 用户管理
|
|
|
|
+ const umId = new ObjectId();
|
|
|
|
+ const userMenus = [
|
|
|
|
+ { _id: umId, name: '用户管理', order_num: 3, type: '0' },
|
|
|
|
+ { name: '管理员用户', parent_id: umId.toString(), order_num: 1, path: '/user/admin', component: '/user/admin/index', type: '1' },
|
|
|
|
+ { name: '平台用户', parent_id: umId.toString(), order_num: 2, path: '/user/user', component: '/user/user/index', type: '1' },
|
|
|
|
+ ];
|
|
|
|
+ const password = { name: '修改密码', order_num: 999, path: '/acccount/updatepd', component: '/acccount/updatepd/index', type: '1' };
|
|
|
|
+
|
|
|
|
+ datas.push(...systemMenus, ...userMenus, password);
|
|
|
|
+ // 项目业务菜单
|
|
|
|
+ const busMenus = [
|
|
|
|
+ { name: '相关设置', order_num: 4, path: '/config', component: '/config/index', type: '1' },
|
|
|
|
+ { name: '菜品管理', order_num: 5, path: '/menu', component: '/menu/index', type: '1' },
|
|
|
|
+ { name: '安排管理', order_num: 6, path: '/arrange', component: '/arrange/index', type: '1' },
|
|
|
|
+ { name: '订单管理', order_num: 7, path: '/order', component: '/order/index', type: '1' },
|
|
|
|
+ { name: '新闻管理', order_num: 8, path: '/news', component: '/news/index', type: '1' },
|
|
|
|
+ ];
|
|
|
|
+ datas.push(...busMenus);
|
|
|
|
+ await this.menusModel.insertMany(datas);
|
|
|
|
+ }
|
|
|
|
+ async initRoleMenu(admin: Admin) {}
|
|
|
|
+
|
|
|
|
+ async initDict() {
|
|
|
|
+ const isUseType = [{ title: '是否使用', code: 'isUse', is_use: '0' }];
|
|
|
|
+ const isUseData = [
|
|
|
|
+ { code: 'isUse', label: '使用', value: '0', sort: 1, is_use: '0' },
|
|
|
|
+ { code: 'isUse', label: '禁用', value: '1', sort: 2, is_use: '0' },
|
|
|
|
+ ];
|
|
|
|
+ await this.dictTypeModel.insertMany(isUseType);
|
|
|
|
+ await this.dictDataModel.insertMany(isUseData);
|
|
|
|
+ }
|
|
|
|
+}
|