| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- /**
- * 路由管理工具类
- * 支持动态路由跳转,无需在pages.json中预先配置
- */
- // 服务路由映射配置
- const SERVICE_ROUTES = {
- // 学工管理
- 'student:info': '/pages/xg/xsjcxx/xsjcxx/index',
- 'student:pwdreset': '/pages/xg/xsjcxx/studentPwdReset/index',
- 'student:dorm': '/pages/student/dorm/index',
- 'student:leave': '/pages/xg/xsjcxx/xsqj/leave/index',
- 'student:psychology': '/pages/student/psychology/index',
- 'student:club': '/pages/student/club/index',
- 'student:counsel': '/pages/student/counsel/index',
- // 后勤管理
- 'logistics:repair': '/pages/logistics/repair/index',
- 'logistics:venue': '/pages/logistics/venue/index',
- 'logistics:hall': '/pages/logistics/hall/index',
- 'logistics:survey': '/pages/logistics/survey/index',
- 'logistics:canteen': '/pages/logistics/canteen/index',
- 'logistics:property': '/pages/logistics/property/index',
- // 招生就业
- 'recruitment:student': '/pages/recruitment/student/index',
- 'recruitment:graduate': '/pages/recruitment/graduate/index',
- 'recruitment:job': '/pages/recruitment/job/index',
- // 人事管理
- 'hr:staff': '/pages/hr/staff/index',
- 'hr:abroad': '/pages/hr/abroad/index',
- 'hr:training': '/pages/hr/training/index',
- // 财务管理
- 'finance:budget': '/pages/finance/budget/index',
- 'finance:expense': '/pages/finance/expense/index',
- 'finance:invoice': '/pages/finance/invoice/index',
- // 系统管理
- 'system:user': '/pages/system/user/index',
- 'system:role': '/pages/system/role/index',
- 'system:menu': '/pages/system/menu/index',
- 'system:dept': '/pages/system/dept/index',
- 'system:config': '/pages/system/config/index',
- 'monitor:online': '/pages/monitor/online/index',
- };
- // 服务名称映射
- const SERVICE_NAMES = {
- 学生信息: 'student:info',
- 重置学生密码: 'student:pwdreset',
- 宿舍管理: 'student:dorm',
- 学生请假: 'student:leave',
- 心理健康: 'student:psychology',
- 社团管理: 'student:club',
- 心理咨询: 'student:counsel',
- 物业报修: 'logistics:repair',
- 场地预约: 'logistics:venue',
- 报告厅预约: 'logistics:hall',
- 满意度调查: 'logistics:survey',
- 食堂管理: 'logistics:canteen',
- 物业管理: 'logistics:property',
- 学生管理: 'recruitment:student',
- 毕业生信息: 'recruitment:graduate',
- 就业信息: 'recruitment:job',
- 员工管理: 'hr:staff',
- 出国申请: 'hr:abroad',
- 培训管理: 'hr:training',
- 预算管理: 'finance:budget',
- 费用报销: 'finance:expense',
- 发票管理: 'finance:invoice',
- 用户管理: 'system:user',
- 角色管理: 'system:role',
- 菜单管理: 'system:menu',
- 部门管理: 'system:dept',
- 参数设置: 'system:config',
- 在线用户: 'monitor:online',
- };
- /**
- * 路由管理类
- */
- class RouterManager {
- /**
- * 根据服务名称跳转到对应页面
- * @param {string} serviceName - 服务名称
- * @param {object} options - 跳转选项
- */
- static navigateToService(serviceName, options = {}) {
- const serviceKey = SERVICE_NAMES[serviceName];
- if (!serviceKey) {
- this.showServiceNotConfigured(serviceName);
- return;
- }
- const route = SERVICE_ROUTES[serviceKey];
- if (!route) {
- this.showServiceNotConfigured(serviceName);
- return;
- }
- // 构建完整URL(支持参数传递)
- let url = route;
- if (options.params) {
- const queryString = Object.keys(options.params)
- .map((key) => `${key}=${encodeURIComponent(options.params[key])}`)
- .join('&');
- url += `?${queryString}`;
- }
- // 执行跳转
- uni.navigateTo({
- url,
- success: () => {
- console.log(`✅ 成功跳转到: ${url}`);
- if (options.onSuccess) {
- options.onSuccess();
- }
- },
- fail: (error) => {
- console.warn(`⚠️ 页面跳转失败: ${url}`, error);
- this.handlePageNotExist(serviceName, route, options);
- },
- });
- }
- /**
- * 处理页面不存在的情况
- * @param {string} serviceName - 服务名称
- * @param {string} route - 路由路径
- * @param {object} options - 选项
- */
- static handlePageNotExist(serviceName, route, options = {}) {
- uni.showModal({
- title: '页面不存在',
- content: `${serviceName}页面尚未创建,是否创建该页面?`,
- confirmText: '创建页面',
- cancelText: '取消',
- success: (res) => {
- if (res.confirm) {
- this.createPageTemplate(serviceName, route, options);
- } else {
- this.showServiceNotImplemented(serviceName);
- }
- },
- });
- }
- /**
- * 创建页面模板
- * @param {string} serviceName - 服务名称
- * @param {string} route - 路由路径
- * @param {object} options - 选项
- */
- static createPageTemplate(serviceName, route, options = {}) {
- // 这里可以实现页面创建逻辑
- // 1. 调用后端API创建页面文件
- // 2. 跳转到页面创建向导
- // 3. 生成标准页面模板
- console.log(`📝 需要创建页面: ${route} - ${serviceName}`);
- // 临时提示
- uni.showToast({
- title: '页面创建功能开发中',
- icon: 'none',
- duration: 2000,
- });
- // 可以在这里添加实际的页面创建逻辑
- if (options.onCreatePage) {
- options.onCreatePage(serviceName, route);
- }
- }
- /**
- * 显示服务未配置提示
- * @param {string} serviceName - 服务名称
- */
- static showServiceNotConfigured(serviceName) {
- uni.showToast({
- title: `服务未配置: ${serviceName}`,
- icon: 'none',
- duration: 2000,
- });
- }
- /**
- * 显示服务未实现提示
- * @param {string} serviceName - 服务名称
- */
- static showServiceNotImplemented(serviceName) {
- uni.showToast({
- title: `功能开发中: ${serviceName}`,
- icon: 'none',
- duration: 2000,
- });
- }
- /**
- * 检查页面是否存在
- * @param {string} route - 路由路径
- * @returns {Promise<boolean>}
- */
- static async checkPageExists(route) {
- return new Promise((resolve) => {
- // 尝试跳转但不实际跳转,用于检查页面是否存在
- uni.navigateTo({
- url: route,
- success: () => {
- // 立即返回,避免实际跳转
- uni.navigateBack();
- resolve(true);
- },
- fail: () => {
- resolve(false);
- },
- });
- });
- }
- /**
- * 获取所有可用的服务路由
- * @returns {object}
- */
- static getAvailableRoutes() {
- return { ...SERVICE_ROUTES };
- }
- /**
- * 获取服务名称映射
- * @returns {object}
- */
- static getServiceNames() {
- return { ...SERVICE_NAMES };
- }
- }
- export default RouterManager;
|