indexNav.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <el-affix :offset="0">
  3. <Disclosure as="nav" class="bg-gray-800" v-slot="{ open }">
  4. <div class="mx-auto max-w-7xl px-2 sm:px-6 lg:px-8">
  5. <div class="relative flex h-16 items-center justify-between">
  6. <div class="absolute inset-y-0 left-0 flex items-center sm:hidden">
  7. <!-- Mobile menu button-->
  8. <DisclosureButton
  9. class="relative inline-flex items-center justify-center rounded-md p-2 text-gray-400 hover:bg-gray-700 hover:text-white focus:outline-none focus:ring-2 focus:ring-inset focus:ring-white"
  10. >
  11. <span class="absolute -inset-0.5" />
  12. <span class="sr-only">Open main menu</span>
  13. <Bars3Icon
  14. v-if="!open"
  15. class="block h-6 w-6"
  16. aria-hidden="true"
  17. />
  18. <XMarkIcon v-else class="block h-6 w-6" aria-hidden="true" />
  19. </DisclosureButton>
  20. </div>
  21. <div
  22. class="flex flex-1 items-center justify-center sm:items-stretch sm:justify-start"
  23. >
  24. <div class="flex flex-shrink-0 items-center">
  25. <img
  26. class="h-8 w-auto"
  27. src="../assets/images/苹果.png"
  28. alt="Your Company"
  29. />
  30. </div>
  31. <div class="hidden sm:ml-6 sm:block">
  32. <div class="flex space-x-4">
  33. <router-link
  34. to="/home"
  35. v-for="item in navigation"
  36. :key="item.name"
  37. :class="[
  38. item.current
  39. ? 'bg-gray-900 text-white'
  40. : 'text-gray-300 hover:bg-gray-700 hover:text-white',
  41. 'rounded-md px-3 py-2 text-sm font-medium',
  42. ]"
  43. :aria-current="item.current ? 'page' : undefined"
  44. >{{ item.name }}</router-link
  45. >
  46. </div>
  47. </div>
  48. </div>
  49. <div
  50. class="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0"
  51. >
  52. <button
  53. type="button"
  54. class="relative rounded-full bg-gray-800 p-1 text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-gray-800"
  55. >
  56. <span class="absolute -inset-1.5" />
  57. <span class="sr-only">View notifications</span>
  58. <BellIcon class="h-6 w-6" aria-hidden="true" />
  59. </button>
  60. <!-- Profile dropdown -->
  61. <Menu as="div" class="relative ml-3">
  62. <div class="relative ml-3">
  63. <div>
  64. <button
  65. @click="showMenu = !showMenu"
  66. class="relative flex rounded-full bg-gray-800 text-sm focus:outline-none"
  67. >
  68. <span class="absolute -inset-1.5" />
  69. <span class="sr-only">Open user menu</span>
  70. <img
  71. class="h-8 w-8 rounded-full"
  72. src="../assets/images/商务职业男.png"
  73. alt="User Avatar"
  74. />
  75. </button>
  76. <transition name="fade-scale" appear>
  77. <div
  78. v-if="showMenu"
  79. class="absolute right-0 z-10 mt-2 w-80 origin-top-right rounded-md bg-white py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"
  80. >
  81. <!-- 在这里添加头像 -->
  82. <img
  83. class="h-12 w-12 rounded-full mx-auto mb-2"
  84. src="../assets/images/商务职业男.png"
  85. alt="User Avatar"
  86. />
  87. <!-- 用户名和修改按钮 -->
  88. <div
  89. class="dropdown-menu-item flex items-center justify-between px-4 py-2"
  90. >
  91. <div class="flex-1 text-center ml-2">
  92. {{ username }}
  93. </div>
  94. <!-- 名字居中显示 -->
  95. <button class="flex items-center justify-center ml-1">
  96. <!-- 减少左边距 -->
  97. <img
  98. src="../assets/images/修改.png"
  99. alt="Edit"
  100. class="h-6 w-6 mr-2"
  101. />
  102. </button>
  103. </div>
  104. <!-- 添加的两个按钮 -->
  105. <div class="dropdown-menu-item px-4 py-2">
  106. <button
  107. class="flex items-center justify-between w-full dropdown-button"
  108. >
  109. <!-- 左侧文本和图标 -->
  110. <div class="flex items-center">
  111. <span>电话号码:{{ phone }}</span>
  112. </div>
  113. </button>
  114. </div>
  115. <!-- 退出登录按钮 -->
  116. <div class="dropdown-menu-item px-1 py-1 text-left">
  117. <button class="btn-logout" @click="LogOut">
  118. <span
  119. class="iconify"
  120. data-icon="mdi:logout"
  121. data-inline="false"
  122. >退出登录</span
  123. >
  124. </button>
  125. </div>
  126. </div>
  127. </transition>
  128. </div>
  129. </div>
  130. </Menu>
  131. </div>
  132. </div>
  133. </div>
  134. <DisclosurePanel class="sm:hidden">
  135. <div class="space-y-1 px-2 pb-3 pt-2">
  136. <DisclosureButton
  137. v-for="item in navigation"
  138. :key="item.name"
  139. as="a"
  140. :href="item.href"
  141. :class="[
  142. item.current
  143. ? 'bg-gray-900 text-white'
  144. : 'text-gray-300 hover:bg-gray-700 hover:text-white',
  145. 'block rounded-md px-3 py-2 text-base font-medium',
  146. ]"
  147. :aria-current="item.current ? 'page' : undefined"
  148. >{{ item.name }}</DisclosureButton
  149. >
  150. </div>
  151. </DisclosurePanel>
  152. </Disclosure>
  153. </el-affix>
  154. </template>
  155. <script>
  156. export default {
  157. // ... 其他选项 ...
  158. data() {
  159. return {
  160. showMenu: false, // 假设这是控制下拉菜单显示与否的数据属性
  161. menuItems: [],
  162. // ... 其他数据属性 ...
  163. };
  164. },
  165. };
  166. </script>
  167. <script setup>
  168. import {
  169. Disclosure,
  170. DisclosureButton,
  171. DisclosurePanel,
  172. Menu,
  173. MenuButton,
  174. MenuItem,
  175. MenuItems,
  176. } from "@headlessui/vue";
  177. import { Bars3Icon, BellIcon, XMarkIcon } from "@heroicons/vue/24/outline";
  178. import { useUserInfoStore } from "@/stores/userInfo";
  179. import { useRouter } from "vue-router";
  180. import { ref, onMounted } from "vue";
  181. import pinia from "../stores/index";
  182. import { manLoginOut } from "../api/index";
  183. import { ElMessage } from 'element-plus';
  184. const userInfoStore = useUserInfoStore(pinia);
  185. const router = useRouter();
  186. // Initialization for ES Users
  187. const username = ref("");
  188. const phone = ref("");
  189. const LogOut = () => {
  190. username.value = "";
  191. manLoginOut().then(
  192. (response)=>{
  193. userInfoStore.initUserInfo();
  194. }
  195. )
  196. router.push({ path: "/home" });
  197. };
  198. const navigation = [
  199. { name: "首页", current: false },
  200. { name: "Calendar", current: true },
  201. ];
  202. onMounted(() => {
  203. userInfoStore.getInfo().then((response) => {
  204. username.value = userInfoStore.username;
  205. phone.value = userInfoStore.phone;
  206. });
  207. });
  208. </script>
  209. <style scoped>
  210. a {
  211. text-decoration: none;
  212. }
  213. .dropdown-menu {
  214. /* 其他样式 */
  215. }
  216. .dropdown-button {
  217. /* 您的按钮样式 */
  218. background-color: white; /* 默认背景色 */
  219. color: #403d3d; /* 默认文字颜色 */
  220. border: none;
  221. padding: 0.5em 1em; /* 根据需要调整 */
  222. transition: all 0.3s ease; /* 添加过渡效果 */
  223. cursor: pointer;
  224. /* 其他样式... */
  225. }
  226. /* 添加悬浮效果 */
  227. .dropdown-button:hover {
  228. background-color: #f5f1f1; /* 悬浮时的背景色 */
  229. color: black; /* 悬浮时的文字颜色 */
  230. /* 如果有其他样式也想改变,可以在这里添加 */
  231. }
  232. .ml-1 {
  233. /* 修改图标 */
  234. /* 或者你想要的任何值 */
  235. margin-right: 70px;
  236. }
  237. .ml-2 {
  238. /* 用户名 */
  239. margin-left: 100px;
  240. font-size: 18px;
  241. }
  242. .mt-2 {
  243. /* 下拉菜单 */
  244. height: 330px;
  245. }
  246. .mb-2 {
  247. /* 头像 */
  248. width: 80px;
  249. height: 80px;
  250. }
  251. .btn-logout {
  252. padding: 0.5rem 1rem;
  253. background-color: #f44336;
  254. color: #fff;
  255. border-radius: 4px;
  256. border: none;
  257. cursor: pointer;
  258. transition: background-color 0.3s ease;
  259. text-decoration: none;
  260. margin-top: 10px;
  261. margin-left: 110px;
  262. }
  263. .btn-logout:hover {
  264. background-color: #e53935;
  265. /* 悬停时的颜色 */
  266. }
  267. </style>