Layout.vue 37 KB

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