header.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <template>
  2. <header
  3. class="fixed w-full top-0 z-100 bg-white border-b border-[#f0f2f5] shadow-sm"
  4. >
  5. <div
  6. class="w-full mx-auto flex items-center justify-between px-10 pr-0 h-18"
  7. >
  8. <div class="flex items-center gap-2 cursor-pointer" @click="goHome">
  9. <img :src="logo" alt="logo" class="w-20 h-9" />
  10. <span class="text-[#02409b] text-[20px] font-bold border-l-2 pl-1"
  11. >DeepOil</span
  12. >
  13. </div>
  14. <nav class="hidden lg:flex flex-1 mx-4 ml-10 text-sm">
  15. <ul class="flex items-center gap-6 text-[#303133]">
  16. <li><a class="hover:text-[#409EFF] cursor-pointer">产品</a></li>
  17. <li><a class="hover:text-[#409EFF] cursor-pointer">解决方案</a></li>
  18. <li><a class="hover:text-[#409EFF] cursor-pointer">典型案例</a></li>
  19. <li><a class="hover:text-[#409EFF] cursor-pointer">平台服务</a></li>
  20. <li><a class="hover:text-[#409EFF] cursor-pointer">应用市场</a></li>
  21. <li><a class="hover:text-[#409EFF] cursor-pointer">开源社区</a></li>
  22. </ul>
  23. </nav>
  24. <div class="hidden lg:flex items-center gap-3 h-full">
  25. <!-- 消息中心 -->
  26. <el-dropdown trigger="click" placement="bottom-end">
  27. <div class="flex items-center gap-2 cursor-pointer pr-2">
  28. <Icon
  29. icon="mdi:bell"
  30. class="w-5 h-5 text-gray-600 hover:text-[#409EFF]"
  31. />
  32. <span class="text-sm text-gray-600">消息代办</span>
  33. </div>
  34. <template #dropdown>
  35. <el-dropdown-menu class="notification-dropdown">
  36. <div class="notification-tabs pl-2">
  37. <el-tabs v-model="activeTab" class="demo-tabs">
  38. <el-tab-pane label="消息中心" name="messages">
  39. <div class="tab-content">
  40. <!-- 消息中心内容 -->
  41. <div
  42. class="message-item"
  43. v-for="(item, index) in messages"
  44. :key="index"
  45. >
  46. <div class="message-icon">
  47. <Icon
  48. :icon="item.icon"
  49. class="w-5 h-5"
  50. :class="item.typeClass"
  51. />
  52. </div>
  53. <div class="message-text">
  54. <p class="message-title">{{ item.title }}</p>
  55. <p class="message-desc">{{ item.desc }}</p>
  56. <p class="message-time">{{ item.time }}</p>
  57. </div>
  58. </div>
  59. <div v-if="!messages.length" class="no-messages">
  60. 暂无新消息
  61. </div>
  62. </div>
  63. </el-tab-pane>
  64. <el-tab-pane label="待办任务" name="tasks">
  65. <div class="tab-content">
  66. <!-- 待办任务内容 -->
  67. <div
  68. class="task-item"
  69. v-for="(task, index) in tasks"
  70. :key="index"
  71. >
  72. <div class="task-info">
  73. <p class="task-title">{{ task.title }}</p>
  74. <p class="task-desc">{{ task.desc }}</p>
  75. <p class="task-time">截止时间: {{ task.dueTime }}</p>
  76. </div>
  77. <el-tag :type="task.priorityTag" size="small">{{
  78. task.priorityText
  79. }}</el-tag>
  80. </div>
  81. <div v-if="!tasks.length" class="no-tasks">
  82. 暂无待办任务
  83. </div>
  84. </div>
  85. </el-tab-pane>
  86. </el-tabs>
  87. </div>
  88. </el-dropdown-menu>
  89. </template>
  90. </el-dropdown>
  91. <template v-if="isLoggedIn">
  92. <el-dropdown @command="onUserCommand" trigger="click">
  93. <span class="flex items-center gap-2 cursor-pointer pr-2">
  94. <div class="avatar-wrapper">
  95. <img
  96. :src="userAvatar || person"
  97. alt="avatar"
  98. class="w-8 h-8 rounded-full avatar-image"
  99. />
  100. </div>
  101. <span class="text-sm text-[#303133]">{{ userName }}</span>
  102. </span>
  103. <template #dropdown>
  104. <el-dropdown-menu>
  105. <el-dropdown-item command="profile">
  106. <svg
  107. xmlns="http://www.w3.org/2000/svg"
  108. width="18"
  109. height="18"
  110. viewBox="0 0 16 16"
  111. >
  112. <g fill="none">
  113. <path
  114. fill="url(#SVG3BqCJdyi)"
  115. d="M11.5 8A1.5 1.5 0 0 1 13 9.5v.5c0 1.971-1.86 4-5 4s-5-2.029-5-4v-.5A1.5 1.5 0 0 1 4.5 8z"
  116. />
  117. <path
  118. fill="url(#SVGfKhxtenh)"
  119. d="M11.5 8A1.5 1.5 0 0 1 13 9.5v.5c0 1.971-1.86 4-5 4s-5-2.029-5-4v-.5A1.5 1.5 0 0 1 4.5 8z"
  120. />
  121. <path
  122. fill="url(#SVGJYCMTblH)"
  123. d="M8 1.5A2.75 2.75 0 1 1 8 7a2.75 2.75 0 0 1 0-5.5"
  124. />
  125. <defs>
  126. <linearGradient
  127. id="SVG3BqCJdyi"
  128. x1="5.378"
  129. x2="7.616"
  130. y1="8.798"
  131. y2="14.754"
  132. gradientUnits="userSpaceOnUse"
  133. >
  134. <stop offset=".125" stop-color="#9c6cfe" />
  135. <stop offset="1" stop-color="#7a41dc" />
  136. </linearGradient>
  137. <linearGradient
  138. id="SVGfKhxtenh"
  139. x1="8"
  140. x2="11.164"
  141. y1="7.286"
  142. y2="17.139"
  143. gradientUnits="userSpaceOnUse"
  144. >
  145. <stop stop-color="#885edb" stop-opacity="0" />
  146. <stop offset="1" stop-color="#e362f8" />
  147. </linearGradient>
  148. <linearGradient
  149. id="SVGJYCMTblH"
  150. x1="6.558"
  151. x2="9.361"
  152. y1="2.231"
  153. y2="6.707"
  154. gradientUnits="userSpaceOnUse"
  155. >
  156. <stop offset=".125" stop-color="#9c6cfe" />
  157. <stop offset="1" stop-color="#7a41dc" />
  158. </linearGradient>
  159. </defs>
  160. </g>
  161. </svg>
  162. <span class="pl-2">个人中心</span>
  163. </el-dropdown-item>
  164. <el-dropdown-item command="logout">
  165. <svg
  166. xmlns="http://www.w3.org/2000/svg"
  167. width="18"
  168. height="18"
  169. viewBox="0 0 24 24"
  170. >
  171. <g fill="none">
  172. <path
  173. fill="url(#SVG0pAmxd9w)"
  174. d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12S6.477 2 12 2"
  175. />
  176. <path
  177. fill="url(#SVGFnXqmeDt)"
  178. d="m15.53 8.47l-.084-.073a.75.75 0 0 0-.882-.007l-.094.08L12 10.939l-2.47-2.47l-.084-.072a.75.75 0 0 0-.882-.007l-.094.08l-.073.084a.75.75 0 0 0-.007.882l.08.094L10.939 12l-2.47 2.47l-.072.084a.75.75 0 0 0-.007.882l.08.094l.084.073a.75.75 0 0 0 .882.007l.094-.08L12 13.061l2.47 2.47l.084.072a.75.75 0 0 0 .882.007l.094-.08l.073-.084a.75.75 0 0 0 .007-.882l-.08-.094L13.061 12l2.47-2.47l.072-.084a.75.75 0 0 0 .007-.882z"
  179. />
  180. <defs>
  181. <linearGradient
  182. id="SVG0pAmxd9w"
  183. x1="5.125"
  184. x2="18.25"
  185. y1="3.25"
  186. y2="22.625"
  187. gradientUnits="userSpaceOnUse"
  188. >
  189. <stop stop-color="#f83f54" />
  190. <stop offset="1" stop-color="#ca2134" />
  191. </linearGradient>
  192. <linearGradient
  193. id="SVGFnXqmeDt"
  194. x1="8.685"
  195. x2="12.591"
  196. y1="12.332"
  197. y2="16.392"
  198. gradientUnits="userSpaceOnUse"
  199. >
  200. <stop stop-color="#fdfdfd" />
  201. <stop offset="1" stop-color="#fecbe6" />
  202. </linearGradient>
  203. </defs>
  204. </g>
  205. </svg>
  206. <span class="pl-2">退出登录</span>
  207. </el-dropdown-item>
  208. </el-dropdown-menu>
  209. </template>
  210. </el-dropdown>
  211. </template>
  212. <template v-else>
  213. <div
  214. class="bg-[#0050b3] hover:bg-[#0050b3]/90 text-white text-sm flex items-center justify-center cursor-pointer h-full px-10 py-4"
  215. @click="login"
  216. >
  217. 登录
  218. </div>
  219. </template>
  220. </div>
  221. <div class="lg:hidden">
  222. <el-button link @click="drawer = true">
  223. <i class="el-icon" />
  224. <Icon icon="fa:bars" class="icon" />
  225. </el-button>
  226. </div>
  227. </div>
  228. <el-drawer
  229. v-model="drawer"
  230. placement="right"
  231. size="80%"
  232. :with-header="false"
  233. >
  234. <div class="p-4 space-y-3">
  235. <ul class="flex flex-col gap-3 text-[#303133]">
  236. <li><a class="block py-2">产品</a></li>
  237. <li><a class="block py-2">解决方案</a></li>
  238. <li><a class="block py-2">典型案例</a></li>
  239. <li><a class="block py-2">平台服务</a></li>
  240. <li><a class="block py-2">应用市场</a></li>
  241. <li><a class="block py-2">开源社区</a></li>
  242. </ul>
  243. <div class="flex items-center gap-3 mt-3">
  244. <el-button type="primary" class="flex-1 bg-[#0050b3]!" @click="login"
  245. >登录</el-button
  246. >
  247. </div>
  248. </div>
  249. </el-drawer>
  250. </header>
  251. </template>
  252. <script setup lang="ts">
  253. import { Icon } from "@iconify/vue";
  254. import { ref, computed } from "vue";
  255. import { useRouter } from "vue-router";
  256. import logo from "@/assets/images/logo.png";
  257. import person from "@/assets/images/person.png";
  258. import { useUserStoreWithOut } from "@/stores/useUserStore";
  259. const userStore = useUserStoreWithOut();
  260. import {
  261. getAccessToken,
  262. getRefreshToken,
  263. removeToken,
  264. setToken,
  265. } from "@utils/auth";
  266. import { deleteUserCache } from "@hooks/useCache";
  267. // 新增消息中心状态
  268. const activeTab = ref("messages");
  269. const messages = ref([
  270. {
  271. title: "系统通知",
  272. desc: "您的账户已成功激活",
  273. time: "10分钟前",
  274. icon: "mdi:message-text-outline",
  275. typeClass: "text-blue-500",
  276. },
  277. {
  278. title: "安全提醒",
  279. desc: "检测到异地登录行为",
  280. time: "30分钟前",
  281. icon: "mdi:security",
  282. typeClass: "text-red-500",
  283. },
  284. {
  285. title: "更新提示",
  286. desc: "系统将于今晚进行维护升级",
  287. time: "1小时前",
  288. icon: "mdi:update",
  289. typeClass: "text-green-500",
  290. },
  291. ]);
  292. const tasks = ref([
  293. {
  294. title: "审批申请",
  295. desc: "部门采购申请等待您审批",
  296. dueTime: "今天 17:00",
  297. priorityText: "高",
  298. priorityTag: "danger",
  299. },
  300. {
  301. title: "项目汇报",
  302. desc: "月度项目进度报告待提交",
  303. dueTime: "明天",
  304. priorityText: "中",
  305. priorityTag: "warning",
  306. },
  307. {
  308. title: "会议安排",
  309. desc: "准备下周团队会议材料",
  310. dueTime: "后天",
  311. priorityText: "低",
  312. priorityTag: "info",
  313. },
  314. ]);
  315. const isLoggedIn = computed(
  316. () => !!userStore.isSetUser || !!userStore.user?.id,
  317. );
  318. const userAvatar = computed(() => userStore.user?.avatar || "");
  319. const userName = computed(() => userStore.user?.nickname || "");
  320. const router = useRouter();
  321. const drawer = ref(false);
  322. const goHome = () => {
  323. router.push({ path: "/" });
  324. };
  325. const login = () => {
  326. router.push({
  327. path: "/login",
  328. });
  329. };
  330. const onUserCommand = async (command: string) => {
  331. if (command === "logout") {
  332. // await userStore.loginOut();
  333. deleteUserCache(); // 删除用户缓存
  334. removeToken();
  335. window.location.reload();
  336. }
  337. };
  338. </script>
  339. <style scoped>
  340. .avatar-wrapper {
  341. position: relative;
  342. overflow: hidden;
  343. border-radius: 50%;
  344. }
  345. .avatar-wrapper::before {
  346. content: "";
  347. position: absolute;
  348. top: 0;
  349. left: -100%;
  350. width: 50%;
  351. height: 100%;
  352. background: linear-gradient(
  353. 90deg,
  354. rgba(255, 255, 255, 0) 0%,
  355. rgba(255, 255, 255, 0.8) 50%,
  356. rgba(255, 255, 255, 0) 100%
  357. );
  358. transform: skewX(-25deg);
  359. transition: none;
  360. z-index: 1;
  361. opacity: 0;
  362. }
  363. .avatar-wrapper:hover::before {
  364. animation: shine 0.5s ease-out;
  365. }
  366. @keyframes shine {
  367. 0% {
  368. left: -100%;
  369. opacity: 0;
  370. }
  371. 10% {
  372. opacity: 1;
  373. }
  374. 100% {
  375. left: 100%;
  376. opacity: 0;
  377. }
  378. }
  379. .notification-dropdown {
  380. width: 400px !important;
  381. max-height: 500px;
  382. overflow: hidden;
  383. }
  384. .notification-tabs .el-tabs__header {
  385. margin-bottom: 0;
  386. padding: 10px;
  387. background-color: #f8f9fa;
  388. }
  389. .tab-content {
  390. max-height: 400px;
  391. overflow-y: auto;
  392. padding: 10px;
  393. }
  394. .message-item {
  395. display: flex;
  396. align-items: flex-start;
  397. padding: 12px 8px;
  398. border-bottom: 1px solid #eee;
  399. }
  400. .message-item:last-child {
  401. border-bottom: none;
  402. }
  403. .message-icon {
  404. margin-right: 12px;
  405. display: flex;
  406. align-items: center;
  407. }
  408. .message-text {
  409. flex: 1;
  410. }
  411. .message-title {
  412. font-weight: 500;
  413. color: #303133;
  414. margin-bottom: 4px;
  415. }
  416. .message-desc {
  417. font-size: 13px;
  418. color: #909399;
  419. line-height: 1.4;
  420. margin-bottom: 4px;
  421. }
  422. .message-time {
  423. font-size: 12px;
  424. color: #c0c4cc;
  425. }
  426. .no-messages,
  427. .no-tasks {
  428. text-align: center;
  429. padding: 20px;
  430. color: #909399;
  431. font-style: italic;
  432. }
  433. .task-item {
  434. display: flex;
  435. align-items: center;
  436. justify-content: space-between;
  437. padding: 12px 8px;
  438. border-bottom: 1px solid #eee;
  439. }
  440. .task-item:last-child {
  441. border-bottom: none;
  442. }
  443. .task-info {
  444. flex: 1;
  445. }
  446. .task-title {
  447. font-weight: 500;
  448. color: #303133;
  449. margin-bottom: 4px;
  450. }
  451. .task-desc {
  452. font-size: 13px;
  453. color: #909399;
  454. line-height: 1.4;
  455. margin-bottom: 4px;
  456. }
  457. .task-time {
  458. font-size: 12px;
  459. color: #c0c4cc;
  460. }
  461. </style>