12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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' },
- { name: '平台设置', parent_id: smId.toString(), order_num: 5, path: '/system/config', component: '/system/config/index', type: '1' },
- { name: '模块设置', parent_id: smId.toString(), order_num: 6, path: '/system/module', component: '/system/module/index', type: '1' },
- ];
- // 用户管理
- 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: 5, path: '/personnel', component: '/personnel/index', type: '1' },
- { name: '申办流程管理', order_num: 6, path: '/path', component: '/path/index', type: '1' },
- { name: '业务管理', order_num: 7, path: '/business', component: '/business/index', type: '1' },
- { name: '申请记录管理', order_num: 8, path: '/apply', component: '/apply/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);
- }
- }
|