Layout.vue 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. <template>
  2. <el-container class="layout-container">
  3. <!-- Mobile overlay -->
  4. <div v-if="isMobile && sidebarVisible" class="sidebar-overlay" @click="sidebarVisible = false"></div>
  5. <el-aside :class="['el-aside', { 'sidebar-mobile': isMobile, 'sidebar-open': isMobile && sidebarVisible, 'sidebar-closed': isMobile && !sidebarVisible }]" :width="isMobile ? '200px' : '200px'">
  6. <div class="logo">浠艾福</div>
  7. <el-scrollbar wrap-class="sidebar-scrollbar-wrap">
  8. <div v-if="menuLoadFailed && effectiveMenuItems.length === 0" class="menu-load-failed">
  9. <i class="el-icon-warning-outline"></i>
  10. <p class="menu-load-failed-title">菜单加载失败</p>
  11. <p class="menu-load-failed-sub">请刷新页面重试</p>
  12. </div>
  13. <el-menu
  14. :default-active="activeMenu"
  15. class="sidebar-menu"
  16. background-color="transparent"
  17. text-color="#64748B"
  18. active-text-color="#1677FF"
  19. @select="handleMenuSelect"
  20. >
  21. <template v-for="item in effectiveMenuItems">
  22. <el-submenu v-if="item.children && item.children.length > 0 && hasPerm(item.perm)" :key="item.title || item.path" :index="item.title || item.path">
  23. <template slot="title">
  24. <i :class="item.icon"></i>
  25. <span>{{ item.title || item.label }}</span>
  26. </template>
  27. <template v-for="child in item.children">
  28. <!-- 子项有 children = 三级菜单 -->
  29. <el-submenu v-if="child.children && child.children.length > 0 && hasPerm(child.perm)" :key="child.title" :index="child.title">
  30. <template slot="title">
  31. <i :class="child.icon"></i>
  32. <span>{{ child.title || child.label }}</span>
  33. </template>
  34. <el-menu-item
  35. v-for="grandson in child.children"
  36. :key="grandson.path || grandson.id"
  37. :index="grandson.path"
  38. >
  39. <i :class="grandson.icon"></i>
  40. <span slot="title">{{ grandson.label }}</span>
  41. </el-menu-item>
  42. </el-submenu>
  43. <!-- 普通二级菜单项 -->
  44. <el-menu-item v-else-if="hasPerm(child.perm)" :key="child.path || child.id" :index="getMenuIndex(child)">
  45. <i :class="child.icon"></i>
  46. <span slot="title">{{ child.label }}</span>
  47. </el-menu-item>
  48. </template>
  49. </el-submenu>
  50. <el-menu-item v-else-if="hasPerm(item.perm)" :key="item.path || item.id" :index="getMenuIndex(item)">
  51. <i :class="item.icon"></i>
  52. <span slot="title">{{ item.label }}</span>
  53. </el-menu-item>
  54. </template>
  55. </el-menu>
  56. </el-scrollbar>
  57. </el-aside>
  58. <el-container>
  59. <el-header>
  60. <div class="header-left">
  61. <el-button v-if="isMobile" type="text" class="hamburger-btn" @click="toggleSidebar">
  62. <i :class="sidebarVisible ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i>
  63. </el-button>
  64. </div>
  65. <div class="header-right">
  66. <el-badge :value="unreadMessageCount" :hidden="unreadMessageCount === 0" class="msg-badge">
  67. <el-button type="text" class="msg-btn" @click="handleMessageClick" icon="el-icon-bell"></el-button>
  68. </el-badge>
  69. <el-button v-if="hasPerm('service:*')" type="text" class="invite-code-btn" @click="showInviteCode" icon="el-icon-share">
  70. 邀请码
  71. </el-button>
  72. <el-dropdown trigger="click" @command="handleProfileCommand">
  73. <span class="el-dropdown-link username">
  74. {{ displayUserLabel }}<i class="el-icon-arrow-down el-icon--right"></i>
  75. </span>
  76. <el-dropdown-menu slot="dropdown">
  77. <el-dropdown-item command="profile" icon="el-icon-user">个人信息</el-dropdown-item>
  78. <el-dropdown-item command="password" icon="el-icon-key">修改密码</el-dropdown-item>
  79. <el-dropdown-item command="logout" icon="el-icon-switch-button" divided>退出登录</el-dropdown-item>
  80. </el-dropdown-menu>
  81. </el-dropdown>
  82. </div>
  83. <!-- 邀请码 dialog -->
  84. <el-dialog title="我的邀请码" :visible.sync="inviteCodeVisible" width="500px" :close-on-click-modal="false">
  85. <div v-loading="inviteCodeLoading">
  86. <div v-if="inviteCodeData" class="invite-code-content">
  87. <div class="invite-code-section">
  88. <div class="invite-code-label">团队邀请码</div>
  89. <div class="invite-code-value">
  90. <span class="code-text">{{ inviteCodeData.code || '无' }}</span>
  91. <el-button size="mini" type="primary" @click="copyCode(inviteCodeData.code)" plain>复制</el-button>
  92. </div>
  93. <div class="invite-code-desc">
  94. 家庭用户通过此码加入您的团队
  95. </div>
  96. </div>
  97. </div>
  98. <div v-else-if="!inviteCodeLoading" class="no-invite-code">
  99. <i class="el-icon-warning-outline"></i>
  100. <p>暂无邀请码,请先生成</p>
  101. <el-button type="primary" @click="generateInviteCode">生成邀请码</el-button>
  102. </div>
  103. </div>
  104. </el-dialog>
  105. </el-header>
  106. <!-- 个人信息 dialog -->
  107. <el-dialog title="个人信息" :visible.sync="profileDialogVisible" width="400px">
  108. <el-form :model="profileForm" label-width="80px">
  109. <el-form-item label="用户名">
  110. <el-input v-model="profileForm.username" disabled></el-input>
  111. </el-form-item>
  112. <el-form-item label="真实姓名">
  113. <el-input v-model="profileForm.realName" disabled></el-input>
  114. </el-form-item>
  115. <el-form-item label="昵称">
  116. <el-input v-model="profileForm.nickname"></el-input>
  117. </el-form-item>
  118. <el-form-item label="手机号">
  119. <el-input v-model="profileForm.phone"></el-input>
  120. </el-form-item>
  121. <el-form-item label="邮箱">
  122. <el-input v-model="profileForm.email"></el-input>
  123. </el-form-item>
  124. </el-form>
  125. <span slot="footer">
  126. <el-button @click="profileDialogVisible = false">取消</el-button>
  127. <el-button type="primary" @click="confirmUpdateInfo" :loading="submitting">保存</el-button>
  128. </span>
  129. </el-dialog>
  130. <!-- 修改密码 dialog -->
  131. <el-dialog title="修改密码" :visible.sync="passwordDialogVisible" width="400px">
  132. <el-form :model="passwordForm" :rules="passwordRules" ref="passwordForm" label-width="100px">
  133. <el-form-item label="原密码" prop="oldPassword">
  134. <el-input v-model="passwordForm.oldPassword" type="password" show-password></el-input>
  135. </el-form-item>
  136. <el-form-item label="新密码" prop="newPassword">
  137. <el-input v-model="passwordForm.newPassword" type="password" show-password></el-input>
  138. </el-form-item>
  139. <el-form-item label="确认密码" prop="confirmPassword">
  140. <el-input v-model="passwordForm.confirmPassword" type="password" show-password></el-input>
  141. </el-form-item>
  142. </el-form>
  143. <span slot="footer">
  144. <el-button @click="passwordDialogVisible = false">取消</el-button>
  145. <el-button type="primary" @click="confirmChangePassword" :loading="submitting">确定</el-button>
  146. </span>
  147. </el-dialog>
  148. <el-main>
  149. <div class="main-wrapper">
  150. <router-view />
  151. </div>
  152. </el-main>
  153. </el-container>
  154. </el-container>
  155. </template>
  156. <script>
  157. import { getAdminInfo, changePassword } from '@/api/auth'
  158. import { updateAdminInfo } from '@/api/admin'
  159. import { getMyInviteCode } from '@/api/guide'
  160. import { getUnreadMessageCount } from '@/api/teacherMessage'
  161. import { getEffectivePermissions, hasPermission, getRoleLabel } from '@/utils/permissions'
  162. import { getUserMenus } from '@/api/menu'
  163. export default {
  164. data() {
  165. return {
  166. menuItems: [
  167. // ===== 1. 首页 (ALL) =====
  168. { path: '/dashboard', label: '首页', icon: 'el-icon-s-home', perm: 'dashboard' },
  169. // ===== 2. 家庭运营 (family:*) =====
  170. { title: '家庭运营', icon: 'el-icon-s-custom', perm: 'family:*',
  171. children: [
  172. { path: '/families', label: '家庭列表', icon: 'el-icon-s-custom', perm: 'family:list,family:read,family:bound' },
  173. { path: '/children', label: '孩子管理', icon: 'el-icon-user-solid', perm: 'family:children,family:read,family:bound' },
  174. { path: '/points', label: '积分管理', icon: 'el-icon-s-finance', perm: 'family:points' },
  175. { path: '/points-log', label: '积分记录', icon: 'el-icon-document', perm: 'family:points,family:bound' },
  176. { path: '/wishes', label: '心愿管理', icon: 'el-icon-star-off', perm: 'family:wishes' },
  177. { path: '/rewards', label: '奖励管理', icon: 'el-icon-s-goods', perm: 'reward:list' },
  178. ]},
  179. // ===== 3. 方案中心 (plan:*) =====
  180. { title: '方案中心', icon: 'el-icon-notebook-2', perm: 'plan:*',
  181. children: [
  182. { path: '/health-plan-manage', label: '健康方案管理', icon: 'el-icon-first-aid-kit', perm: 'plan:health' },
  183. { path: '/assessment-plan-manage', label: '测评方案管理', icon: 'el-icon-edit', perm: 'plan:assessment' },
  184. ]},
  185. // ===== 4. 任务中心 (task:*) =====
  186. { title: '任务中心', icon: 'el-icon-s-order', perm: 'task:*,task:read',
  187. children: [
  188. { path: '/tasks', label: '任务列表', icon: 'el-icon-s-order', perm: 'task:list' },
  189. { path: '/task-templates', label: '任务模板', icon: 'el-icon-document', perm: 'task:templates' },
  190. { path: '/growth-task', label: '成长任务管理', icon: 'el-icon-s-management', perm: 'task:growth' },
  191. ]},
  192. // ===== 5. 审核中心(归集:服务角色申请/活动审核/退款/提现) =====
  193. { title: '审核中心', icon: 'el-icon-s-check', perm: 'audit',
  194. children: [
  195. { path: '/review-center', label: '审核中心总览', icon: 'el-icon-s-check', perm: 'audit' },
  196. { path: '/activity-review', label: '活动审核', icon: 'el-icon-document-checked', perm: 'audit:activity' },
  197. { path: '/pending-refund', label: '待退款管理', icon: 'el-icon-warning', perm: 'audit:refund' },
  198. { path: '/family-earnings-withdraw', label: '收益提现审核', icon: 'el-icon-document-checked', perm: 'audit:withdraw' },
  199. ]},
  200. // ===== 5. 商城营销 (commerce:*) =====
  201. { title: '商城营销', icon: 'el-icon-s-goods', perm: 'commerce:*',
  202. children: [
  203. { path: '/product-manage', label: '商品管理', icon: 'el-icon-s-goods', perm: 'commerce:products,commerce:self' },
  204. { path: '/inventory', label: '库存管理', icon: 'el-icon-document', perm: 'inventory:self' },
  205. { path: '/order-manage', label: '订单管理', icon: 'el-icon-s-order', perm: 'commerce:orders,order:self' },
  206. { path: '/ecom-supplier', label: '供应商管理', icon: 'el-icon-s-shop', perm: 'commerce:supplier' },
  207. { path: '/product-profit-rate', label: '产品利润率', icon: 'el-icon-data-line', perm: 'finance:profit-rate' },
  208. { path: '/coupon', label: '优惠券管理', icon: 'el-icon-ticket', perm: 'commerce:coupon' },
  209. { path: '/coupon-grant-log', label: '发券记录', icon: 'el-icon-document', perm: 'commerce:coupon' },
  210. { path: '/discount-rules', label: '限时折扣管理', icon: 'el-icon-timer', perm: 'commerce:discount' },
  211. { path: '/promotion', label: '推广管理', icon: 'el-icon-s-marketing', perm: 'commerce:promotion' },
  212. { path: '/home-banner-manage', label: '首页广告栏', icon: 'el-icon-picture', perm: 'marketing:promotion' },
  213. { path: '/family-earnings', label: '家庭收益', icon: 'el-icon-s-money', perm: 'finance:family-earnings' },
  214. ]},
  215. // ===== 6. 知识中心 (articles:*) =====
  216. { title: '知识中心', icon: 'el-icon-document', perm: 'articles:*,knowledge:read',
  217. children: [
  218. { path: '/article-categories', label: '知识分类', icon: 'el-icon-folder', perm: 'articles:categories' },
  219. { path: '/article-manage', label: '知识管理', icon: 'el-icon-document', perm: 'articles:manage' },
  220. { path: '/comment-review', label: '评论审核', icon: 'el-icon-chat-dot-round', perm: 'articles:manage' },
  221. { path: '/knowledge-tags', label: '知识标签', icon: 'el-icon-price-tag', perm: 'articles:categories' },
  222. { path: '/knowledge-base', label: '知识库', icon: 'el-icon-reading', perm: 'knowledge:base' },
  223. { path: '/knowledge-base/unified', label: '统一知识库', icon: 'el-icon-notebook-2', perm: 'knowledge:base' },
  224. { path: '/health-knowledge', label: '健康知识库', icon: 'el-icon-first-aid-kit', perm: 'knowledge:base' },
  225. { path: '/vector-knowledge', label: '向量知识库', icon: 'el-icon-data-line', perm: 'knowledge:base' },
  226. ]},
  227. // ===== 6.5 活动管理(activity:*,活动审核已移入审核中心) =====
  228. { title: '活动管理', icon: 'el-icon-date', perm: 'activity:*', children: [
  229. { path: '/activities', label: '活动列表', icon: 'el-icon-date', perm: 'activity:list,activity:self' },
  230. { path: '/activity-registration-review', label: '活动报名审核', icon: 'el-icon-document-checked', perm: 'activity:registration' },
  231. { path: '/poster-template-manage', label: '海报模板管理', icon: 'el-icon-picture', perm: 'activity:poster_template' },
  232. ]},
  233. // ===== 7. 健康饮食 (health:*,报告管理/代传报告挂载,顺序对齐方案最终菜单树) =====
  234. { title: '健康饮食', icon: 'el-icon-first-aid-kit', perm: 'health:*',
  235. children: [
  236. { path: '/report-management', label: '报告管理', icon: 'el-icon-document', perm: 'health:reports' },
  237. { path: '/report-proxy-upload', label: '代传报告', icon: 'el-icon-upload', perm: 'health:reports' },
  238. { path: '/report-parse-status', label: '解析进度', icon: 'el-icon-data-line', perm: 'health:reports' },
  239. { path: '/health-indicators', label: '健康指标', icon: 'el-icon-data-line', perm: 'health:indicators' },
  240. { path: '/health-checkins', label: '健康打卡', icon: 'el-icon-s-order', perm: 'health:checkins' },
  241. { path: '/emotion-alert', label: '情绪告警', icon: 'el-icon-warning', perm: 'health:checkins' },
  242. { path: '/nutrition-mappings', label: '营养素映射', icon: 'el-icon-connection', perm: 'health:mappings' },
  243. { path: '/foods', label: '食材管理', icon: 'el-icon-apple', perm: 'diet:foods' },
  244. { path: '/recipes', label: '食谱管理', icon: 'el-icon-dish', perm: 'diet:recipes' },
  245. { path: '/seasonal-foods', label: '应季食材', icon: 'el-icon-apple', perm: 'diet:foods' },
  246. { path: '/nutrition-products', label: '营养产品', icon: 'el-icon-first-aid-kit', perm: 'health:products' },
  247. { path: '/energy-sandbox', label: '五维能量', icon: 'el-icon-data-line', perm: 'health:energy' },
  248. ]},
  249. // ===== 8. 报告解析系统 (config:report-parser,LangGraph 管理归入) =====
  250. { title: '报告解析系统', icon: 'el-icon-cpu', perm: 'config:report-parser',
  251. children: [
  252. { path: '/report-types', label: '报告类型管理', icon: 'el-icon-collection', perm: 'config:report-parser' },
  253. { path: '/report-parser-import', label: '解析器导入', icon: 'el-icon-upload2', perm: 'config:report-parser' },
  254. { path: '/report-unknown-clusters', label: '未知报告审核', icon: 'el-icon-question', perm: 'config:report-parser' },
  255. { path: '/report-auto-learn', label: '报告自学习', icon: 'el-icon-magic-stick', perm: 'config:report-parser' },
  256. { path: '/report-collector-trainer', label: '报告采集训练', icon: 'el-icon-film', perm: 'config:report-parser' },
  257. { path: '/report-template', label: '报告模板管理', icon: 'el-icon-setting', perm: 'config:report-parser' },
  258. { path: '/langgraph-admin', label: 'LangGraph 管理', icon: 'el-icon-cpu', perm: 'config:report-parser' },
  259. ]},
  260. { title: '家庭服务', icon: 'el-icon-s-custom', perm: 'service:*',
  261. children: [
  262. { path: '/my-families', label: '我的家庭', icon: 'el-icon-s-custom', perm: 'service:family' },
  263. { path: '/teacher-team', label: '我的团队', icon: 'el-icon-s-custom', perm: 'service:team' },
  264. ]},
  265. { title: '业务管理', icon: 'el-icon-s-marketing', perm: 'biz:*',
  266. children: [
  267. { path: '/teacher-packages', label: '任务模板管理', icon: 'el-icon-s-goods', perm: 'biz:packages' },
  268. { path: '/teacher-orders', label: '订单佣金', icon: 'el-icon-s-order', perm: 'biz:orders' },
  269. ]},
  270. // ===== 测评咨询(测评管理/订单/待分配规划师已从系统配置移入) =====
  271. { title: '测评咨询', icon: 'el-icon-edit', perm: 'assessment:*,assessment:read',
  272. children: [
  273. { path: '/assessment-admin', label: '测评管理', icon: 'el-icon-edit', perm: 'assessment:manage' },
  274. { path: '/assessment-orders', label: '测评订单', icon: 'el-icon-s-order', perm: 'assessment:orders' },
  275. { path: '/assessment-assign', label: '待分配规划师', icon: 'el-icon-user', perm: 'assessment:assign' },
  276. { path: '/teacher-assessment', label: 'DAN测评', icon: 'el-icon-edit', perm: 'assessment:dan' },
  277. { path: '/teacher-consult', label: '家长咨询', icon: 'el-icon-chat-dot-round', perm: 'assessment:consult' },
  278. { path: '/growth-records', label: '成长记录', icon: 'el-icon-document', perm: 'growth:records' },
  279. { path: '/growth-plans', label: '成长计划', icon: 'el-icon-document', perm: 'growth:plans' },
  280. ]},
  281. // ===== 9. 系统配置 (system:*,权限拆分 system:base/config:member/config:dimension/config:health) =====
  282. { title: '系统配置', icon: 'el-icon-s-tools', perm: 'system:*',
  283. children: [
  284. // --- 基础管理 ---
  285. { title: '基础管理', icon: 'el-icon-s-tools', perm: 'system:base',
  286. children: [
  287. { path: '/sys-config', label: '系统配置', icon: 'el-icon-s-tools', perm: 'system:base' },
  288. { path: '/guide-config', label: '引导配置', icon: 'el-icon-setting', perm: 'system:base' },
  289. { path: '/users', label: '用户管理', icon: 'el-icon-user', perm: 'system:users' },
  290. { path: '/menu-manage', label: '菜单管理', icon: 'el-icon-menu', perm: 'system:menu' },
  291. { path: '/operation-logs', label: '操作日志', icon: 'el-icon-s-order', perm: 'system:logs' },
  292. { path: '/membership-center', label: '会员中心', icon: 'el-icon-s-custom', perm: 'config:member' },
  293. { path: '/badge-manage', label: '勋章管理', icon: 'el-icon-medal', perm: 'config:member' },
  294. { path: '/virtual-goods-config', label: '虚拟支付道具', icon: 'el-icon-goods', perm: 'config:member' },
  295. { path: '/gates', label: '关卡配置', icon: 'el-icon-key', perm: 'system:base' },
  296. { path: '/system-prompt', label: '系统提示词', icon: 'el-icon-chat-line-square', perm: 'system:base' },
  297. { path: '/file-manage', label: '文件管理', icon: 'el-icon-files', perm: 'system:base' },
  298. ]},
  299. // --- 配置中心 ---
  300. { title: '配置中心', icon: 'el-icon-setting', perm: 'config:dimension',
  301. children: [
  302. { path: '/dimension-config', label: '维度配置', icon: 'el-icon-data-line', perm: 'config:dimension' },
  303. ]},
  304. // --- 供应商体系 ---
  305. { title: '供应商体系', icon: 'el-icon-s-management', perm: 'system:supply',
  306. children: [
  307. { path: '/supply-system', label: '供应商体系', icon: 'el-icon-s-management', perm: 'system:supply' },
  308. ]},
  309. // --- 供应商管理 ---
  310. { title: '供应商管理', icon: 'el-icon-s-shop', perm: 'supply:manage',
  311. children: [
  312. { path: '/supply-manage', label: '供应商管理', icon: 'el-icon-s-shop', perm: 'supply:manage' },
  313. { path: '/supplier-products', label: '商品管理', icon: 'el-icon-s-goods', perm: 'supply:manage' },
  314. ]},
  315. // --- 健康配置(能量规则/行为/周期性服务已从健康饮食移入;术语统一:五维能量配置) ---
  316. { title: '健康配置', icon: 'el-icon-first-aid-kit', perm: 'config:health',
  317. children: [
  318. { path: '/health-norm-config', label: '健康常模', icon: 'el-icon-data-line', perm: 'config:health' },
  319. { path: '/health-data-source', label: '健康数据源', icon: 'el-icon-data-line', perm: 'config:health' },
  320. { path: '/health-energy-config', label: '五维能量配置', icon: 'el-icon-data-line', perm: 'config:health' },
  321. { path: '/energy-rule', label: '能量规则管理', icon: 'el-icon-setting', perm: 'config:health' },
  322. { path: '/energy-behavior-config', label: '能量行为配置', icon: 'el-icon-edit-outline', perm: 'config:health' },
  323. { path: '/periodic-service-config', label: '周期性服务配置', icon: 'el-icon-refresh', perm: 'config:health' },
  324. { path: '/indicator-correlations', label: '指标关联配置', icon: 'el-icon-connection', perm: 'config:health' },
  325. { path: '/indicator-mappings', label: '指标映射管理', icon: 'el-icon-sort', perm: 'config:health' },
  326. ]},
  327. // --- 人生维度 ---
  328. { title: '人生维度', icon: 'el-icon-s-custom', perm: 'config:dimension',
  329. children: [
  330. { path: '/zodiac-configs', label: '星座配置', icon: 'el-icon-s-management', perm: 'config:dimension' },
  331. { path: '/bazi-configs', label: '八字配置', icon: 'el-icon-s-management', perm: 'config:dimension' },
  332. { path: '/blood-type-configs', label: '血型配置', icon: 'el-icon-s-management', perm: 'config:dimension' },
  333. { path: '/innate-portrait-config', label: '先天画像权重配置', icon: 'el-icon-s-management', perm: 'config:dimension' },
  334. { path: '/numsoul-detail-config', label: '数字能量配置', icon: 'el-icon-s-management', perm: 'config:dimension' },
  335. ]},
  336. // --- 虚拟团队 ---
  337. { title: '虚拟团队', icon: 'el-icon-s-custom', perm: 'system:base',
  338. children: [
  339. { path: '/virtual-teams', label: '虚拟团队', icon: 'el-icon-s-custom', perm: 'system:base' },
  340. ]},
  341. ]},
  342. ],
  343. menuLoadFailed: false,
  344. profileDialogVisible: false,
  345. passwordDialogVisible: false,
  346. submitting: false,
  347. profileForm: {
  348. nickname: '',
  349. phone: '',
  350. email: '',
  351. username: '',
  352. realName: ''
  353. },
  354. passwordForm: {
  355. oldPassword: '',
  356. newPassword: '',
  357. confirmPassword: ''
  358. },
  359. inviteCodeVisible: false,
  360. inviteCodeLoading: false,
  361. inviteCodeData: null,
  362. unreadMessageCount: 0,
  363. isMobile: window.innerWidth <= 768,
  364. sidebarVisible: window.innerWidth > 768,
  365. passwordRules: {
  366. oldPassword: [
  367. { required: true, message: '请输入原密码', trigger: 'blur' }
  368. ],
  369. newPassword: [
  370. { required: true, message: '请输入新密码', trigger: 'blur' },
  371. { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }
  372. ],
  373. confirmPassword: [
  374. { required: true, message: '请确认新密码', trigger: 'blur' },
  375. {
  376. validator: (rule, value, callback) => {
  377. if (value !== this.passwordForm.newPassword) {
  378. callback(new Error('两次输入密码不一致'))
  379. } else {
  380. callback()
  381. }
  382. },
  383. trigger: 'blur'
  384. }
  385. ]
  386. }
  387. }
  388. },
  389. computed: {
  390. activeMenu() {
  391. return this.$route.path
  392. },
  393. // 菜单去重(B-7:按 title/path 去重,修复侧边栏菜单重复渲染 bug)
  394. effectiveMenuItems() {
  395. return this.dedupeMenuItems(this.menuItems)
  396. },
  397. currentRole() {
  398. return localStorage.getItem('role') || 'admin'
  399. },
  400. vendorType() {
  401. return localStorage.getItem('vendorType') || ''
  402. },
  403. effectivePerms() {
  404. // 菜单按当前登录身份隔离(登录时选择的身份),多角色账号不再默认并集展示
  405. return getEffectivePermissions([this.currentRole])
  406. },
  407. displayRoles() {
  408. const rolesStr = localStorage.getItem('roles')
  409. const roles = rolesStr ? JSON.parse(rolesStr) : [this.currentRole]
  410. return roles.map(function(r) { return getRoleLabel(r) }).join(' / ')
  411. },
  412. displayUserLabel() {
  413. const adminName = localStorage.getItem('adminName')
  414. if (adminName) {
  415. return adminName + ' (' + this.displayRoles + ')'
  416. }
  417. return this.displayRoles
  418. }
  419. },
  420. watch: {
  421. '$route'() {
  422. if (this.isMobile) {
  423. this.sidebarVisible = false
  424. }
  425. }
  426. },
  427. mounted() {
  428. // 清除可能的 beforeunload 处理,防止页面刷新弹出"离开网站?"提示
  429. window.onbeforeunload = null
  430. // 响应式监听
  431. this.handleResize = this.handleResize.bind(this)
  432. window.addEventListener('resize', this.handleResize)
  433. // 有消息权限(老师/营养师角色)才加载未读数,管理员不调用
  434. if (hasPermission(this.effectivePerms, 'messages') && this.currentRole !== 'admin') {
  435. this.fetchUnreadCount()
  436. }
  437. // 从后端加载菜单(/api/admin/menu/tree),失败则使用硬编码菜单
  438. this.fetchMenu()
  439. },
  440. beforeDestroy() {
  441. window.removeEventListener('resize', this.handleResize)
  442. },
  443. methods: {
  444. /**
  445. * 菜单去重:同层级内按 (title || path) + path 组合键去重,递归处理 children
  446. * 防止后端动态菜单与硬编码/全量菜单数据重叠时侧边栏重复渲染
  447. */
  448. dedupeMenuItems(items) {
  449. if (!items || items.length === 0) return items
  450. const seen = {}
  451. const result = []
  452. for (let i = 0; i < items.length; i++) {
  453. const it = items[i]
  454. const key = (it.title || '') + '|' + (it.path || '') + '|' + (it.label || '')
  455. if (seen[key]) continue
  456. seen[key] = true
  457. if (it.children && it.children.length > 0) {
  458. const copy = Object.assign({}, it)
  459. copy.children = this.dedupeMenuItems(it.children)
  460. result.push(copy)
  461. } else {
  462. result.push(it)
  463. }
  464. }
  465. return result
  466. },
  467. hasPerm(required) {
  468. return hasPermission(this.effectivePerms, required)
  469. },
  470. getMenuIndex(item) {
  471. return item.path === '/dashboard' && this.currentRole === 'teacher'
  472. ? '/teacher-dashboard'
  473. : item.path
  474. },
  475. handleMenuSelect(index) {
  476. if (index && index.startsWith('/')) {
  477. this.$router.push(index)
  478. }
  479. if (this.isMobile) {
  480. this.sidebarVisible = false
  481. }
  482. },
  483. toggleSidebar() {
  484. this.sidebarVisible = !this.sidebarVisible
  485. },
  486. handleResize() {
  487. const mobile = window.innerWidth <= 768
  488. if (mobile !== this.isMobile) {
  489. this.isMobile = mobile
  490. if (!mobile) {
  491. this.sidebarVisible = true
  492. } else {
  493. this.sidebarVisible = false
  494. }
  495. }
  496. },
  497. async fetchMenu() {
  498. try {
  499. var res = await getUserMenus()
  500. if (res.code === 200 && res.data && res.data.length > 0) {
  501. this.menuItems = this.buildMenuItems(res.data)
  502. this.menuLoadFailed = false
  503. } else {
  504. this.menuLoadFailed = true
  505. }
  506. } catch (e) {
  507. this.menuLoadFailed = true
  508. console.error('菜单加载失败', e)
  509. }
  510. },
  511. buildMenuItems(nodes) {
  512. var result = []
  513. for (var i = 0; i < nodes.length; i++) {
  514. var n = nodes[i]
  515. var item = {}
  516. if (n.path) {
  517. item.path = n.path
  518. item.label = n.label || n.title || ''
  519. item.icon = n.icon || ''
  520. item.perm = n.perm || ''
  521. } else {
  522. item.title = n.title || ''
  523. item.label = n.label || ''
  524. item.icon = n.icon || ''
  525. item.perm = n.perm || ''
  526. }
  527. if (n.children && n.children.length > 0) {
  528. item.children = this.buildMenuItems(n.children)
  529. }
  530. result.push(item)
  531. }
  532. return result
  533. },
  534. handleProfileCommand(command) {
  535. if (command === 'profile') {
  536. this.loadAdminInfo()
  537. this.profileDialogVisible = true
  538. } else if (command === 'password') {
  539. this.passwordForm = { oldPassword: '', newPassword: '', confirmPassword: '' }
  540. this.passwordDialogVisible = true
  541. } else if (command === 'logout') {
  542. this.handleLogout()
  543. }
  544. },
  545. async loadAdminInfo() {
  546. try {
  547. const res = await getAdminInfo()
  548. this.profileForm = {
  549. nickname: res.data.nickname || '',
  550. phone: res.data.phone || '',
  551. email: res.data.email || '',
  552. username: res.data.username || '',
  553. realName: res.data.realName || ''
  554. }
  555. } catch (e) {
  556. this.$message.error('加载个人信息失败')
  557. }
  558. },
  559. async confirmUpdateInfo() {
  560. this.submitting = true
  561. try {
  562. await updateAdminInfo({
  563. nickname: this.profileForm.nickname,
  564. phone: this.profileForm.phone,
  565. email: this.profileForm.email
  566. })
  567. if (this.profileForm.nickname) {
  568. localStorage.setItem('adminName', this.profileForm.nickname)
  569. }
  570. this.$message.success('保存成功')
  571. this.profileDialogVisible = false
  572. } catch (e) {
  573. this.$message.error(e.message || '保存失败')
  574. } finally {
  575. this.submitting = false
  576. }
  577. },
  578. async confirmChangePassword() {
  579. this.$refs.passwordForm.validate(async (valid) => {
  580. if (!valid) return
  581. this.submitting = true
  582. try {
  583. await changePassword({
  584. oldPassword: this.passwordForm.oldPassword,
  585. newPassword: this.passwordForm.newPassword
  586. })
  587. this.$message.success('密码修改成功')
  588. this.passwordDialogVisible = false
  589. } catch (e) {
  590. this.$message.error(e.message || '密码修改失败')
  591. } finally {
  592. this.submitting = false
  593. }
  594. })
  595. },
  596. async showInviteCode() {
  597. this.inviteCodeVisible = true
  598. this.inviteCodeLoading = true
  599. this.inviteCodeData = null
  600. try {
  601. const res = await getMyInviteCode()
  602. if (res.data) {
  603. this.inviteCodeData = res.data
  604. }
  605. } catch (e) {
  606. this.$message.error('获取邀请码失败')
  607. } finally {
  608. this.inviteCodeLoading = false
  609. }
  610. },
  611. async generateInviteCode() {
  612. this.inviteCodeLoading = true
  613. try {
  614. const res = await getMyInviteCode()
  615. if (res.data) {
  616. this.inviteCodeData = res.data
  617. this.$message.success('邀请码已生成')
  618. }
  619. } catch (e) {
  620. this.$message.error('生成邀请码失败')
  621. } finally {
  622. this.inviteCodeLoading = false
  623. }
  624. },
  625. copyCode(code) {
  626. if (!code) return
  627. const input = document.createElement('input')
  628. input.value = code
  629. document.body.appendChild(input)
  630. input.select()
  631. document.execCommand('copy')
  632. document.body.removeChild(input)
  633. this.$message.success('已复制邀请码')
  634. },
  635. async fetchUnreadCount() {
  636. try {
  637. const res = await getUnreadMessageCount()
  638. if (res.data !== undefined) {
  639. this.unreadMessageCount = res.data || 0
  640. }
  641. } catch (e) {
  642. // silent: not critical
  643. }
  644. },
  645. handleMessageClick() {
  646. this.$router.push('/teacher-messages')
  647. },
  648. handleLogout() {
  649. // 不使用 modal 遮罩(全局 .v-modal { display:none } 会与 $confirm 的遮罩冲突)
  650. this.$confirm('确定要退出登录吗?', '提示', {
  651. confirmButtonText: '确定',
  652. cancelButtonText: '取消',
  653. type: 'warning',
  654. modal: false,
  655. customClass: 'cfc-logout-confirm'
  656. }).then(() => {
  657. localStorage.removeItem('token')
  658. localStorage.removeItem('role')
  659. localStorage.removeItem('roles')
  660. localStorage.removeItem('adminId')
  661. localStorage.removeItem('adminName')
  662. this.$router.push('/login')
  663. })
  664. }
  665. }
  666. }
  667. </script>
  668. <style>
  669. /* 全局防御:防止 Element UI 弹窗或组件残留 DOM 产生遮罩覆盖 */
  670. .v-modal {
  671. display: none !important;
  672. }
  673. .layout-container {
  674. height: 100vh;
  675. }
  676. .el-aside {
  677. background-color: #001529;
  678. overflow: visible;
  679. display: flex;
  680. flex-direction: column;
  681. }
  682. .logo {
  683. height: 60px;
  684. line-height: 60px;
  685. text-align: center;
  686. color: #fff;
  687. font-size: 20px;
  688. font-weight: bold;
  689. background-color: #001529;
  690. flex-shrink: 0;
  691. }
  692. /* 侧边栏滚动条样式 */
  693. .sidebar-scrollbar-wrap {
  694. height: calc(100vh - 60px) !important;
  695. overflow-x: hidden !important;
  696. overflow-y: auto !important;
  697. }
  698. .sidebar-scrollbar-wrap .el-scrollbar__view {
  699. height: 100%;
  700. }
  701. .sidebar-scrollbar-wrap::-webkit-scrollbar {
  702. width: 6px;
  703. }
  704. .sidebar-scrollbar-wrap::-webkit-scrollbar-track {
  705. background: #001529;
  706. }
  707. .sidebar-scrollbar-wrap::-webkit-scrollbar-thumb {
  708. background: #4a5568;
  709. border-radius: 3px;
  710. }
  711. .sidebar-scrollbar-wrap::-webkit-scrollbar-thumb:hover {
  712. background: #5a6578;
  713. }
  714. .el-header {
  715. background-color: #fff;
  716. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  717. display: flex;
  718. justify-content: space-between;
  719. align-items: center;
  720. padding: 0 20px;
  721. }
  722. .header-right {
  723. display: flex;
  724. align-items: center;
  725. gap: 12px;
  726. }
  727. .username {
  728. color: #606266;
  729. }
  730. .invite-code-btn {
  731. color: #1677FF;
  732. font-size: 13px;
  733. }
  734. .invite-code-btn:hover {
  735. color: #4F46E5;
  736. }
  737. .msg-badge {
  738. margin-right: 4px;
  739. }
  740. .msg-badge .el-badge__content.is-fixed {
  741. top: 10px;
  742. right: 6px;
  743. }
  744. .msg-btn {
  745. font-size: 18px;
  746. color: #606266;
  747. padding: 4px;
  748. }
  749. .msg-btn:hover {
  750. color: #1677FF;
  751. }
  752. .invite-code-content {
  753. padding: 8px 0;
  754. }
  755. .invite-code-section {
  756. background: #F8FAFC;
  757. border: 1px solid #E2E8F0;
  758. border-radius: 8px;
  759. padding: 20px;
  760. text-align: center;
  761. }
  762. .invite-code-label {
  763. font-size: 14px;
  764. color: #64748B;
  765. margin-bottom: 12px;
  766. }
  767. .invite-code-value {
  768. display: flex;
  769. align-items: center;
  770. justify-content: center;
  771. gap: 12px;
  772. margin-bottom: 8px;
  773. }
  774. .code-text {
  775. font-size: 28px;
  776. font-weight: 700;
  777. letter-spacing: 6px;
  778. color: #1E293B;
  779. font-family: monospace;
  780. }
  781. .no-invite-code {
  782. text-align: center;
  783. padding: 24px;
  784. color: #94A3B8;
  785. }
  786. .no-invite-code i {
  787. font-size: 48px;
  788. margin-bottom: 12px;
  789. }
  790. .no-invite-code p {
  791. margin-bottom: 16px;
  792. }
  793. .el-main {
  794. background-color: #f0f2f5;
  795. padding: 24px;
  796. position: relative;
  797. z-index: 1;
  798. display: flex;
  799. flex-direction: column;
  800. min-height: 0;
  801. overflow-y: auto;
  802. }
  803. .main-wrapper {
  804. flex: 1;
  805. display: flex;
  806. flex-direction: column;
  807. min-height: 0;
  808. }
  809. /* ========== 全局 .admin-page 样式 ========== */
  810. /* 所有后台维护页面根元素使用此 class,使页面内容充满可视区 */
  811. .admin-page {
  812. flex: 1;
  813. display: flex;
  814. flex-direction: column;
  815. min-height: 0;
  816. }
  817. /* 当 admin-page 的直接子元素是 el-card 时让卡片自动填充 */
  818. .admin-page > .el-card {
  819. flex: 1;
  820. display: flex;
  821. flex-direction: column;
  822. min-height: 0;
  823. }
  824. .admin-page > .el-card .el-card__body {
  825. flex: 1;
  826. display: flex;
  827. flex-direction: column;
  828. min-height: 0;
  829. padding: 20px;
  830. }
  831. /* 当 admin-page > div > el-card(如 ArticleManage 的嵌套 div) */
  832. .admin-page > div:only-child {
  833. flex: 1;
  834. display: flex;
  835. flex-direction: column;
  836. min-height: 0;
  837. }
  838. .admin-page > div:only-child > .el-card {
  839. flex: 1;
  840. display: flex;
  841. flex-direction: column;
  842. min-height: 0;
  843. }
  844. .admin-page > div:only-child > .el-card .el-card__body {
  845. flex: 1;
  846. display: flex;
  847. flex-direction: column;
  848. min-height: 0;
  849. padding: 20px;
  850. }
  851. /* ========== 响应式:侧边栏折叠 ========== */
  852. @media (max-width: 768px) {
  853. .sidebar-overlay {
  854. position: fixed;
  855. top: 0;
  856. left: 0;
  857. right: 0;
  858. bottom: 0;
  859. background: rgba(0, 0, 0, 0.4);
  860. z-index: 1001;
  861. }
  862. .sidebar-mobile {
  863. position: fixed !important;
  864. top: 0;
  865. left: 0;
  866. height: 100vh !important;
  867. z-index: 1002;
  868. transition: transform 0.25s ease;
  869. transform: translateX(-100%);
  870. }
  871. .sidebar-mobile.sidebar-open {
  872. transform: translateX(0);
  873. }
  874. .sidebar-mobile.sidebar-closed {
  875. transform: translateX(-100%);
  876. }
  877. .header-left {
  878. display: flex;
  879. align-items: center;
  880. }
  881. .hamburger-btn {
  882. font-size: 20px;
  883. color: #606266;
  884. padding: 8px;
  885. }
  886. .hamburger-btn:hover {
  887. color: #1677FF;
  888. }
  889. .el-header {
  890. padding: 0 10px !important;
  891. }
  892. .el-main {
  893. padding: 12px !important;
  894. }
  895. .admin-page > .el-card .el-card__body {
  896. padding: 12px !important;
  897. }
  898. .admin-page > div:only-child > .el-card .el-card__body {
  899. padding: 12px !important;
  900. }
  901. .username {
  902. font-size: 13px;
  903. }
  904. /* el-table 小屏字号 */
  905. .el-table {
  906. font-size: 12px;
  907. }
  908. .el-table .cell {
  909. padding-left: 4px !important;
  910. padding-right: 4px !important;
  911. }
  912. /* 表格横向滚动优化 */
  913. .el-table {
  914. min-width: 600px !important;
  915. table-layout: auto !important;
  916. }
  917. .el-table__body-wrapper {
  918. overflow-x: auto !important;
  919. -webkit-overflow-scrolling: touch;
  920. }
  921. /* 搜索表单:form-item 换行 */
  922. .el-form-item--inline {
  923. display: block !important;
  924. margin-bottom: 12px !important;
  925. }
  926. .el-form-item--inline .el-form-item__content {
  927. display: flex !important;
  928. width: 100% !important;
  929. margin-left: 0 !important;
  930. }
  931. .el-form-item--inline .el-form-item__label {
  932. display: block !important;
  933. text-align: left !important;
  934. margin-bottom: 4px !important;
  935. }
  936. /* 搜索表单中 el-input/el-select 宽度 100% */
  937. .el-form-item--inline .el-input,
  938. .el-form-item--inline .el-select,
  939. .el-form-item--inline .el-date-editor {
  940. width: 100% !important;
  941. }
  942. /* 文章编辑等复杂表单 */
  943. .el-form--inline .el-form-item {
  944. display: block !important;
  945. }
  946. .el-form--inline .el-form-item__content {
  947. display: block !important;
  948. width: 100% !important;
  949. margin-left: 0 !important;
  950. }
  951. .el-form--inline .el-form-item__label {
  952. text-align: left !important;
  953. display: block !important;
  954. }
  955. /* 通用:卡片内容紧凑 */
  956. .stat-card {
  957. margin-bottom: 12px !important;
  958. }
  959. }
  960. /* 桌面端隐藏 header-left(无汉堡按钮) */
  961. @media (min-width: 769px) {
  962. .header-left {
  963. display: none;
  964. }
  965. }
  966. .menu-load-failed {
  967. padding: 24px 16px;
  968. text-align: center;
  969. color: #94a3b8;
  970. }
  971. .menu-load-failed .el-icon-warning-outline {
  972. font-size: 28px;
  973. color: #f59e0b;
  974. }
  975. .menu-load-failed-title {
  976. margin: 8px 0 0;
  977. font-size: 13px;
  978. font-weight: 600;
  979. color: #64748b;
  980. }
  981. .menu-load-failed-sub {
  982. margin: 4px 0 0;
  983. font-size: 12px;
  984. color: #94a3b8;
  985. }
  986. </style>