|
@@ -0,0 +1,162 @@
|
|
|
+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: '/', component: '/home/index', type: '1', i18n_code: 'menus.home', route_name: 'home' }];
|
|
|
+ // 系统设置
|
|
|
+ const smId = new ObjectId();
|
|
|
+ const systemMenus = [
|
|
|
+ { _id: smId, name: '系统设置', path: '/system', order_num: 2, type: '0', i18n_code: 'menus.system', route_name: 'system', is_default: '0' },
|
|
|
+ {
|
|
|
+ name: '菜单设置',
|
|
|
+ parent_id: smId.toString(),
|
|
|
+ order_num: 1,
|
|
|
+ path: '/system/menus',
|
|
|
+ component: '/system/menus/index',
|
|
|
+ type: '1',
|
|
|
+ route_name: 'system_menus',
|
|
|
+ i18n_code: 'menus.system_menus',
|
|
|
+ config: [
|
|
|
+ {
|
|
|
+ zh: '添加',
|
|
|
+ code: 'add',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '修改',
|
|
|
+ code: 'update',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '添加下一级',
|
|
|
+ code: 'addNext',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '删除',
|
|
|
+ code: 'delete',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ is_default: '0',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '角色管理',
|
|
|
+ parent_id: smId.toString(),
|
|
|
+ order_num: 2,
|
|
|
+ path: '/system/role',
|
|
|
+ component: '/system/role/index',
|
|
|
+ type: '1',
|
|
|
+ route_name: 'system_role',
|
|
|
+ i18n_code: 'menus.system_role',
|
|
|
+ is_default: '0',
|
|
|
+ config: [
|
|
|
+ {
|
|
|
+ zh: '添加',
|
|
|
+ code: 'add',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '修改',
|
|
|
+ code: 'update',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '使用',
|
|
|
+ code: 'toAbled',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '禁用',
|
|
|
+ code: 'toDisabled',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ zh: '删除',
|
|
|
+ code: 'delete',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ { name: '字典管理', parent_id: smId.toString(), order_num: 3, path: '/system/dict', component: '/system/dict/index', type: '1', i18n_code: 'menus.system_dict', route_name: 'system_dict', is_default: '0' },
|
|
|
+ { name: '字典数据', parent_id: smId.toString(), order_num: 4, path: '/system/dictData', component: '/system/dictData/index', type: '2', route_name: 'system_dict_data', i18n_code: 'menus.system_dict_data', is_default: '0' },
|
|
|
+ { name: '网址设置', route_name: 'system_config', i18n_code: 'menus.system_config', parent_id: smId.toString(), order_num: 5, path: '/system/config', component: '/system/config/index', type: '1', is_default: '0', parent_name: '系统设置' },
|
|
|
+ ];
|
|
|
+ // 用户管理
|
|
|
+ const umId = new ObjectId();
|
|
|
+ const userMenus = [
|
|
|
+ { _id: umId, name: '用户管理', order_num: 3, path: '/user', type: '0', i18n_code: 'menus.user', route_name: 'user', is_default: '1' },
|
|
|
+ { name: '管理员用户', parent_id: umId.toString(), order_num: 1, path: '/user/admin', component: '/user/admin/index', type: '1', i18n_code: 'menus.user_admin', route_name: 'user_admin' },
|
|
|
+ { name: '教师用户', parent_id: umId.toString(), order_num: 2, path: '/user/teacher', component: '/user/teacher/index', type: '1', i18n_code: 'menus.user_teacher', route_name: 'user_teacher' },
|
|
|
+ { name: '学生用户', parent_id: umId.toString(), order_num: 2, path: '/user/student', component: '/user/student/index', type: '1', i18n_code: 'menus.user_student', route_name: 'user_student' },
|
|
|
+ ];
|
|
|
+ const course = { name: '课程管理', route_name: 'course', i18n_code: 'menus.course', order_num: 4, path: '/core/course', component: '/core/course/index', type: '1', is_default: '1', is_use: '0' };
|
|
|
+ const order = { name: '订单管理', order_num: 5, path: '/core/order', component: '/core/order/index', type: '1', is_default: '1', is_use: '0', route_name: 'order', i18n_code: 'menus.order' };
|
|
|
+ const opinion = { name: '意见反馈管理', route_name: 'opinion', i18n_code: 'menus.opinion', order_num: 5, path: '/core/opinion', component: '/core/opinion/index', type: '1', is_default: '1', is_use: '0' };
|
|
|
+ datas.push(...systemMenus, ...userMenus, course, order, opinion);
|
|
|
+ // 项目业务菜单
|
|
|
+ const busMenus = [];
|
|
|
+ datas.push(...busMenus);
|
|
|
+ await this.menusModel.insertMany(datas);
|
|
|
+ }
|
|
|
+ async initDict() {
|
|
|
+ const isUseType = [
|
|
|
+ { title: '是否使用', code: 'isUse', is_use: '0' },
|
|
|
+ { title: '审核状态', code: 'examStatus', is_use: '0' },
|
|
|
+ { title: '性别', code: 'gender', is_use: '0' },
|
|
|
+ { title: '图标', code: 'icon', 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' },
|
|
|
+ { code: 'examStatus', label: '待审核', value: '0', sort: 1, is_use: '0' },
|
|
|
+ { code: 'examStatus', label: '已通过', value: '1', sort: 2, is_use: '0' },
|
|
|
+ { code: 'examStatus', label: '未通过', value: '-1', sort: 2, is_use: '0' },
|
|
|
+ { code: 'gender', label: '男', value: '0', sort: 1, is_use: '0' },
|
|
|
+ { code: 'gender', label: '女', value: '1', sort: 2, is_use: '0' },
|
|
|
+ { code: 'gender', label: '未知', value: '2', sort: 3, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'House', value: 'House', sort: 1, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'User', value: 'User', sort: 2, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'Setting', value: 'Setting', sort: 3, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'ScaleToOriginal', value: 'ScaleToOriginal', sort: 4, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'Management', value: 'Management', sort: 5, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'DataLine', value: 'DataLine', sort: 6, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'Film', value: 'Film', sort: 7, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'SwitchFilled', value: 'SwitchFilled', sort: 8, is_use: '0' },
|
|
|
+ { code: 'icon', label: 'VideoPlay', value: 'VideoPlay', sort: 9, is_use: '0' },
|
|
|
+ ];
|
|
|
+ await this.dictTypeModel.insertMany(isUseType);
|
|
|
+ await this.dictDataModel.insertMany(isUseData);
|
|
|
+ }
|
|
|
+}
|