const { request } = require('../../utils/request'); const DEFAULT_MODULES = [ { name: '功能控制台', path: '/pages/console/console' }, { name: '提示词库', path: '/pages/prompt/prompt' } ]; const TAB_PAGES = new Set([ '/pages/home/home', '/pages/console/console', '/pages/prompt/prompt' ]); Page({ data: { modules: DEFAULT_MODULES }, onLoad() { this.loadModules(); }, async loadModules() { try { const result = await request({ url: '/portal/api/modules' }); if (Array.isArray(result) && result.length) { const defaultMap = new Map(DEFAULT_MODULES.map((item) => [item.path, item])); const merged = DEFAULT_MODULES.map((item) => { const remote = result.find((entry) => entry && entry.path === item.path); return remote ? { ...item, ...remote } : item; }); if (merged.length) { this.setData({ modules: merged }); } } } catch (e) {} }, goModule(e) { const path = e.currentTarget.dataset.path; if (!path) return; if (TAB_PAGES.has(path)) { wx.switchTab({ url: path }); return; } wx.navigateTo({ url: path }); } });