Dashboard.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div class="dashboard-container">
  3. <el-container class="main-container">
  4. <el-aside width="240px" class="aside">
  5. <div class="logo-container">
  6. <img src="/logo.png" alt="Logo" class="logo-img" />
  7. <span class="logo-text">统一登录平台</span>
  8. </div>
  9. <el-menu
  10. router
  11. :default-active="$route.path"
  12. class="el-menu-vertical"
  13. >
  14. <el-menu-item index="/dashboard/launchpad">
  15. <el-icon><Menu /></el-icon>
  16. <span>快捷导航</span>
  17. </el-menu-item>
  18. <el-menu-item index="/dashboard/messages">
  19. <el-icon><ChatDotRound /></el-icon>
  20. <span>消息中心</span>
  21. </el-menu-item>
  22. <el-menu-item
  23. v-if="user && (user.role === 'SUPER_ADMIN' || user.role === 'DEVELOPER')"
  24. index="/dashboard/apps"
  25. >
  26. <el-icon><Grid /></el-icon>
  27. <span>应用管理</span>
  28. </el-menu-item>
  29. <el-menu-item
  30. v-if="user && (user.role === 'SUPER_ADMIN' || user.role === 'DEVELOPER')"
  31. index="/dashboard/client-distributions"
  32. >
  33. <el-icon><Upload /></el-icon>
  34. <span>客户端分发</span>
  35. </el-menu-item>
  36. <el-menu-item index="/dashboard/mappings">
  37. <el-icon><Connection /></el-icon>
  38. <span>平台账号管理</span>
  39. </el-menu-item>
  40. <el-menu-item v-if="user && user.role === 'SUPER_ADMIN'" index="/dashboard/users">
  41. <el-icon><User /></el-icon>
  42. <span>用户管理</span>
  43. </el-menu-item>
  44. <el-sub-menu index="ops" v-if="user && user.role === 'SUPER_ADMIN'">
  45. <template #title>
  46. <el-icon><Monitor /></el-icon>
  47. <span>运维服务</span>
  48. </template>
  49. <el-menu-item index="/dashboard/system-logs">
  50. <el-icon><Document /></el-icon>
  51. <span>后台日志</span>
  52. </el-menu-item>
  53. <el-menu-item index="/dashboard/system-status">
  54. <el-icon><Monitor /></el-icon>
  55. <span>服务器资源监控</span>
  56. </el-menu-item>
  57. <el-menu-item index="/dashboard/login-logs">
  58. <el-icon><List /></el-icon>
  59. <span>登录日志</span>
  60. </el-menu-item>
  61. <el-menu-item index="/dashboard/backup">
  62. <el-icon><Download /></el-icon>
  63. <span>数据备份</span>
  64. </el-menu-item>
  65. <el-menu-item index="/dashboard/restore">
  66. <el-icon><RefreshRight /></el-icon>
  67. <span>数据还原</span>
  68. </el-menu-item>
  69. <el-menu-item index="/dashboard/ssl-config">
  70. <el-icon><Lock /></el-icon>
  71. <span>证书配置</span>
  72. </el-menu-item>
  73. <el-menu-item index="/dashboard/login-config">
  74. <el-icon><Setting /></el-icon>
  75. <span>登录配置</span>
  76. </el-menu-item>
  77. <el-menu-item index="/dashboard/app-categories">
  78. <el-icon><Folder /></el-icon>
  79. <span>应用分类管理</span>
  80. </el-menu-item>
  81. </el-sub-menu>
  82. <el-menu-item
  83. v-if="user && (user.role === 'SUPER_ADMIN' || user.role === 'DEVELOPER')"
  84. index="/dashboard/help"
  85. >
  86. <el-icon><QuestionFilled /></el-icon>
  87. <span>使用帮助</span>
  88. </el-menu-item>
  89. </el-menu>
  90. </el-aside>
  91. <el-container class="content-container">
  92. <el-header>
  93. <div class="header-content">
  94. <div class="breadcrumb">
  95. <!-- Breadcrumb placeholder -->
  96. </div>
  97. <div class="user-actions">
  98. <el-dropdown trigger="click" @command="handleCommand">
  99. <span class="el-dropdown-link">
  100. <span v-if="user" class="username">{{ user.mobile }}</span>
  101. <el-icon class="el-icon--right"><arrow-down /></el-icon>
  102. </span>
  103. <template #dropdown>
  104. <el-dropdown-menu>
  105. <el-dropdown-item command="changePassword">修改密码</el-dropdown-item>
  106. <el-dropdown-item divided command="logout">退出登录</el-dropdown-item>
  107. </el-dropdown-menu>
  108. </template>
  109. </el-dropdown>
  110. </div>
  111. </div>
  112. </el-header>
  113. <el-main>
  114. <router-view></router-view>
  115. </el-main>
  116. </el-container>
  117. </el-container>
  118. <!-- Change Password Dialog -->
  119. <el-dialog v-model="changePwdVisible" title="修改密码" width="400px">
  120. <el-form :model="pwdForm" :rules="pwdRules" ref="pwdFormRef" label-width="100px">
  121. <el-form-item label="旧密码" prop="old_password">
  122. <el-input v-model="pwdForm.old_password" type="password" show-password />
  123. </el-form-item>
  124. <el-form-item label="新密码" prop="new_password">
  125. <el-input v-model="pwdForm.new_password" type="password" show-password />
  126. </el-form-item>
  127. <el-form-item label="确认新密码" prop="confirm_password">
  128. <el-input v-model="pwdForm.confirm_password" type="password" show-password />
  129. </el-form-item>
  130. </el-form>
  131. <template #footer>
  132. <el-button @click="changePwdVisible = false">取消</el-button>
  133. <el-button type="primary" @click="submitChangePwd" :loading="changingPwd">确定</el-button>
  134. </template>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script setup lang="ts">
  139. import { computed, onMounted, ref, reactive } from 'vue'
  140. import { useRouter } from 'vue-router'
  141. import { useAuthStore } from '../store/auth'
  142. import { Grid, List, QuestionFilled, User, ArrowDown, Connection, Monitor, Document, Download, RefreshRight, Lock, Setting, ChatDotRound, Folder, Menu, Upload } from '@element-plus/icons-vue'
  143. import { ElMessage, FormInstance, FormRules } from 'element-plus'
  144. import api from '../utils/request'
  145. const router = useRouter()
  146. const authStore = useAuthStore()
  147. const user = computed(() => authStore.user)
  148. // Logout & Menu Command
  149. const handleCommand = (command: string) => {
  150. if (command === 'logout') {
  151. handleLogout()
  152. } else if (command === 'changePassword') {
  153. openChangePwd()
  154. }
  155. }
  156. const handleLogout = () => {
  157. authStore.logout()
  158. router.push('/login')
  159. }
  160. // Change Password Logic
  161. const changePwdVisible = ref(false)
  162. const changingPwd = ref(false)
  163. const pwdFormRef = ref<FormInstance>()
  164. const pwdForm = reactive({
  165. old_password: '',
  166. new_password: '',
  167. confirm_password: ''
  168. })
  169. const validatePass2 = (rule: any, value: any, callback: any) => {
  170. if (value === '') {
  171. callback(new Error('请再次输入密码'))
  172. } else if (value !== pwdForm.new_password) {
  173. callback(new Error('两次输入密码不一致!'))
  174. } else {
  175. callback()
  176. }
  177. }
  178. const pwdRules = reactive<FormRules>({
  179. old_password: [{ required: true, message: '请输入旧密码', trigger: 'blur' }],
  180. new_password: [
  181. { required: true, message: '请输入新密码', trigger: 'blur' },
  182. { min: 6, message: '密码长度不能少于6位', trigger: 'blur' },
  183. { pattern: /^(?=.*[a-zA-Z])(?=.*\d).+$/, message: '密码必须包含字母和数字', trigger: 'blur' }
  184. ],
  185. confirm_password: [{ required: true, validator: validatePass2, trigger: 'blur' }]
  186. })
  187. const openChangePwd = () => {
  188. pwdForm.old_password = ''
  189. pwdForm.new_password = ''
  190. pwdForm.confirm_password = ''
  191. changePwdVisible.value = true
  192. }
  193. const submitChangePwd = async () => {
  194. if (!pwdFormRef.value) return
  195. await pwdFormRef.value.validate(async (valid) => {
  196. if (valid) {
  197. changingPwd.value = true
  198. try {
  199. await api.post('/simple/me/change-password', {
  200. old_password: pwdForm.old_password,
  201. new_password: pwdForm.new_password
  202. })
  203. ElMessage.success('密码修改成功')
  204. changePwdVisible.value = false
  205. } catch (e) {
  206. // handled
  207. } finally {
  208. changingPwd.value = false
  209. }
  210. }
  211. })
  212. }
  213. onMounted(() => {
  214. if (!user.value) {
  215. authStore.fetchUser()
  216. }
  217. })
  218. </script>
  219. <style scoped>
  220. .dashboard-container {
  221. height: 100%;
  222. width: 100%;
  223. }
  224. .main-container {
  225. height: 100%;
  226. }
  227. .content-container {
  228. height: 100%;
  229. overflow: hidden;
  230. }
  231. .aside {
  232. background-color: #304156;
  233. color: #fff;
  234. height: 100%;
  235. }
  236. .logo-container {
  237. height: 60px;
  238. display: flex;
  239. align-items: center;
  240. justify-content: center;
  241. background-color: #2b3649;
  242. padding: 0 10px;
  243. }
  244. .logo-img {
  245. height: 32px;
  246. margin-right: 10px;
  247. }
  248. .logo-text {
  249. font-weight: bold;
  250. font-size: 16px;
  251. white-space: nowrap;
  252. }
  253. .el-menu-vertical {
  254. border-right: none;
  255. background-color: #304156;
  256. }
  257. :deep(.el-menu-item) {
  258. color: #bfcbd9;
  259. }
  260. :deep(.el-menu-item.is-active) {
  261. color: #409eff;
  262. background-color: #263445;
  263. }
  264. :deep(.el-menu-item:hover) {
  265. background-color: #263445;
  266. }
  267. :deep(.el-sub-menu__title) {
  268. color: #bfcbd9 !important;
  269. }
  270. :deep(.el-sub-menu__title:hover) {
  271. background-color: #263445 !important;
  272. }
  273. /* Fix nested menu background color */
  274. :deep(.el-sub-menu .el-menu) {
  275. background-color: #1f2d3d !important;
  276. }
  277. :deep(.el-sub-menu .el-menu-item) {
  278. background-color: #1f2d3d !important;
  279. }
  280. :deep(.el-sub-menu .el-menu-item:hover) {
  281. background-color: #001528 !important;
  282. }
  283. .el-header {
  284. padding: 0;
  285. }
  286. .header-content {
  287. display: flex;
  288. justify-content: space-between;
  289. align-items: center;
  290. height: 60px;
  291. border-bottom: 1px solid #dcdfe6;
  292. padding: 0 20px;
  293. background-color: #fff;
  294. }
  295. .user-actions {
  296. display: flex;
  297. align-items: center;
  298. }
  299. .el-dropdown-link {
  300. cursor: pointer;
  301. display: flex;
  302. align-items: center;
  303. color: #333;
  304. }
  305. .username {
  306. margin-right: 5px;
  307. font-size: 14px;
  308. }
  309. .el-main {
  310. background-color: #f0f2f5;
  311. padding: 20px;
  312. height: calc(100% - 60px);
  313. overflow-y: auto;
  314. }
  315. </style>