index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="navbar">
  3. <div class="left-side">
  4. <a-space>
  5. <img alt="logo"
  6. src="//p3-armor.byteimg.com/tos-cn-i-49unhts6dw/dfdba5317c0c20ce20e64fac803d52bc.svg~tplv-49unhts6dw-image.image" />
  7. <a-typography-title :style="{ margin: 0, fontSize: '18px' }" :heading="5">
  8. 魔力链
  9. <a-tag v-if="false && currentPlatform == 'parse'" color="arcoblue"
  10. @click="clickChangePlatform">口令</a-tag>
  11. <a-tag v-if="false && currentPlatform == 'coupon'" color="red"
  12. @click="clickChangePlatform">优惠券</a-tag>
  13. </a-typography-title>
  14. <icon-menu-fold v-if="!topMenu && appStore.device === 'mobile'" style="font-size: 22px; cursor: pointer"
  15. @click="toggleDrawerMenu" />
  16. </a-space>
  17. </div>
  18. <a-modal v-model:visible="visibleChangePlatform" title="切换平台" @before-ok="changePlatform">
  19. <a-radio-group v-model="currentPlatform">
  20. <template v-for="item in platformList" :key="item">
  21. <a-radio :value="item.value">
  22. <template #radio="{ checked }">
  23. <a-space align="start" class="custom-radio-card"
  24. :class="{ 'custom-radio-card-checked': checked }">
  25. <div className="custom-radio-card-mask">
  26. <div className="custom-radio-card-mask-dot" />
  27. </div>
  28. <div>
  29. <div className="custom-radio-card-title">
  30. {{ item.name }}
  31. </div>
  32. <a-typography-text type="secondary"> {{ item.desc }}
  33. </a-typography-text>
  34. </div>
  35. </a-space>
  36. </template>
  37. </a-radio>
  38. </template>
  39. </a-radio-group>
  40. </a-modal>
  41. <div class="center-side">
  42. <Menu v-if="topMenu" />
  43. </div>
  44. <ul class="right-side">
  45. <li>
  46. <AccountWarning />
  47. </li>
  48. <li>
  49. <a-tooltip :content="$t('settings.search')">
  50. <a-button class="nav-btn" type="outline" :shape="'circle'">
  51. <template #icon>
  52. <icon-search />
  53. </template>
  54. </a-button>
  55. </a-tooltip>
  56. </li>
  57. <li>
  58. <a-tooltip :content="$t('settings.language')">
  59. <a-button class="nav-btn" type="outline" :shape="'circle'" @click="setDropDownVisible">
  60. <template #icon>
  61. <icon-language />
  62. </template>
  63. </a-button>
  64. </a-tooltip>
  65. <a-dropdown trigger="click" @select="changeLocale as any">
  66. <div ref="triggerBtn" class="trigger-btn"></div>
  67. <template #content>
  68. <a-doption v-for="item in locales" :key="item.value" :value="item.value">
  69. <template #icon>
  70. <icon-check v-show="item.value === currentLocale" />
  71. </template>
  72. {{ item.label }}
  73. </a-doption>
  74. </template>
  75. </a-dropdown>
  76. </li>
  77. <li>
  78. <a-tooltip :content="theme === 'light'
  79. ? $t('settings.navbar.theme.toDark')
  80. : $t('settings.navbar.theme.toLight')
  81. ">
  82. <a-button class="nav-btn" type="outline" :shape="'circle'" @click="handleToggleTheme">
  83. <template #icon>
  84. <icon-moon-fill v-if="theme === 'dark'" />
  85. <icon-sun-fill v-else />
  86. </template>
  87. </a-button>
  88. </a-tooltip>
  89. </li>
  90. <li>
  91. <a-tooltip :content="$t('settings.navbar.alerts')">
  92. <div class="message-box-trigger">
  93. <a-badge :count="9" dot>
  94. <a-button class="nav-btn" type="outline" :shape="'circle'" @click="setPopoverVisible">
  95. <icon-notification />
  96. </a-button>
  97. </a-badge>
  98. </div>
  99. </a-tooltip>
  100. <a-popover trigger="click" :arrow-style="{ display: 'none' }"
  101. :content-style="{ padding: 0, minWidth: '400px' }" content-class="message-popover">
  102. <div ref="refBtn" class="ref-btn"></div>
  103. <template #content>
  104. <message-box />
  105. </template>
  106. </a-popover>
  107. </li>
  108. <li>
  109. <a-tooltip :content="isFullscreen
  110. ? $t('settings.navbar.screen.toExit')
  111. : $t('settings.navbar.screen.toFull')
  112. ">
  113. <a-button class="nav-btn" type="outline" :shape="'circle'" @click="toggleFullScreen">
  114. <template #icon>
  115. <icon-fullscreen-exit v-if="isFullscreen" />
  116. <icon-fullscreen v-else />
  117. </template>
  118. </a-button>
  119. </a-tooltip>
  120. </li>
  121. <li>
  122. <a-tooltip :content="$t('settings.title')">
  123. <a-button class="nav-btn" type="outline" :shape="'circle'" @click="setVisible">
  124. <template #icon>
  125. <icon-settings />
  126. </template>
  127. </a-button>
  128. </a-tooltip>
  129. </li>
  130. <li>
  131. <a-dropdown trigger="click">
  132. <a-avatar :size="32" :style="{ marginRight: '8px', cursor: 'pointer' }">
  133. <img alt="avatar" :src="avatar" />
  134. </a-avatar>
  135. <template #content>
  136. <a-doption>
  137. <a-space @click="$router.push({ name: 'Info' })">
  138. <icon-user />
  139. <span>
  140. {{ $t('messageBox.userCenter') }}
  141. </span>
  142. </a-space>
  143. </a-doption>
  144. <a-doption>
  145. <a-space @click="$router.push({ name: 'Setting' })">
  146. <icon-settings />
  147. <span>
  148. {{ $t('messageBox.userSettings') }}
  149. </span>
  150. </a-space>
  151. </a-doption>
  152. <a-doption>
  153. <a-space @click="handleLogout">
  154. <icon-export />
  155. <span>
  156. {{ $t('messageBox.logout') }}
  157. </span>
  158. </a-space>
  159. </a-doption>
  160. </template>
  161. </a-dropdown>
  162. </li>
  163. </ul>
  164. </div>
  165. </template>
  166. <script lang="ts" setup>
  167. import { computed, ref, inject, onMounted } from 'vue';
  168. import { useDark, useToggle, useFullscreen, } from '@vueuse/core';
  169. import { useAppStore, useUserStore } from '@/store';
  170. import { LOCALE_OPTIONS } from '@/locale';
  171. import useLocale from '@/hooks/locale';
  172. import useUser from '@/hooks/user';
  173. import AccountWarning from '@/components/account-warning/index.vue';
  174. import Menu from '@/components/menu/index.vue';
  175. import MessageBox from '../message-box/index.vue';
  176. const appStore = useAppStore();
  177. const userStore = useUserStore();
  178. const { logout } = useUser();
  179. const { changeLocale, currentLocale } = useLocale();
  180. const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
  181. const locales = [...LOCALE_OPTIONS];
  182. const avatar = computed(() => {
  183. return userStore.avatar;
  184. });
  185. const theme = computed(() => {
  186. return appStore.theme;
  187. });
  188. const topMenu = computed(() => appStore.topMenu && appStore.menu);
  189. const isDark = useDark({
  190. selector: 'body',
  191. attribute: 'arco-theme',
  192. valueDark: 'dark',
  193. valueLight: 'light',
  194. storageKey: 'arco-theme',
  195. onChanged(dark: boolean) {
  196. // overridden default behavior
  197. appStore.toggleTheme(dark);
  198. },
  199. });
  200. const toggleTheme = useToggle(isDark);
  201. const visibleChangePlatform = ref(false);
  202. const handleToggleTheme = () => {
  203. toggleTheme();
  204. };
  205. const setVisible = () => {
  206. appStore.updateSettings({ globalSettings: true });
  207. };
  208. const refBtn = ref();
  209. const triggerBtn = ref();
  210. const setPopoverVisible = () => {
  211. const event = new MouseEvent('click', {
  212. view: window,
  213. bubbles: true,
  214. cancelable: true,
  215. });
  216. refBtn.value.dispatchEvent(event);
  217. };
  218. const currentPlatform = ref('parse')
  219. currentPlatform.value = appStore.currentPlatform
  220. const platformList = computed(() => [
  221. {
  222. value: 'parse',
  223. name: "口令",
  224. desc: "口令平台",
  225. },
  226. {
  227. value: 'coupon',
  228. name: "优惠券",
  229. desc: "优惠券平台",
  230. },
  231. ]);
  232. const clickChangePlatform = (val: string) => {
  233. visibleChangePlatform.value = true;
  234. };
  235. const changePlatform = () => {
  236. console.log(currentPlatform.value);
  237. appStore.togglePlatform(currentPlatform.value);
  238. return true;
  239. };
  240. const handleLogout = () => {
  241. logout();
  242. };
  243. const setDropDownVisible = () => {
  244. const event = new MouseEvent('click', {
  245. view: window,
  246. bubbles: true,
  247. cancelable: true,
  248. });
  249. triggerBtn.value.dispatchEvent(event);
  250. };
  251. const toggleDrawerMenu = inject('toggleDrawerMenu') as () => void;
  252. </script>
  253. <style scoped lang="less">
  254. .navbar {
  255. display: flex;
  256. justify-content: space-between;
  257. height: 100%;
  258. background-color: var(--color-bg-2);
  259. border-bottom: 1px solid var(--color-border);
  260. }
  261. .left-side {
  262. display: flex;
  263. align-items: center;
  264. padding-left: 20px;
  265. }
  266. .center-side {
  267. flex: 1;
  268. }
  269. .right-side {
  270. display: flex;
  271. padding-right: 20px;
  272. list-style: none;
  273. :deep(.locale-select) {
  274. border-radius: 20px;
  275. }
  276. li {
  277. display: flex;
  278. align-items: center;
  279. padding: 0 10px;
  280. }
  281. a {
  282. color: var(--color-text-1);
  283. text-decoration: none;
  284. }
  285. .nav-btn {
  286. border-color: rgb(var(--gray-2));
  287. color: rgb(var(--gray-8));
  288. font-size: 16px;
  289. }
  290. .trigger-btn,
  291. .ref-btn {
  292. position: absolute;
  293. bottom: 14px;
  294. }
  295. .trigger-btn {
  296. margin-left: 14px;
  297. }
  298. }
  299. </style>
  300. <style lang="less">
  301. .message-popover {
  302. .arco-popover-content {
  303. margin-top: 0;
  304. }
  305. }
  306. </style>
  307. <style scoped>
  308. .custom-radio-card {
  309. padding: 10px 16px;
  310. border: 1px solid var(--color-border-2);
  311. border-radius: 4px;
  312. width: 200px;
  313. box-sizing: border-box;
  314. }
  315. .custom-radio-card-mask {
  316. height: 14px;
  317. width: 14px;
  318. display: inline-flex;
  319. align-items: center;
  320. justify-content: center;
  321. border-radius: 100%;
  322. border: 1px solid var(--color-border-2);
  323. box-sizing: border-box;
  324. }
  325. .custom-radio-card-mask-dot {
  326. width: 8px;
  327. height: 8px;
  328. border-radius: 100%;
  329. }
  330. .custom-radio-card-title {
  331. color: var(--color-text-1);
  332. font-size: 14px;
  333. font-weight: bold;
  334. margin-bottom: 8px;
  335. }
  336. .custom-radio-card:hover,
  337. .custom-radio-card-checked,
  338. .custom-radio-card:hover .custom-radio-card-mask,
  339. .custom-radio-card-checked .custom-radio-card-mask {
  340. border-color: rgb(var(--primary-6));
  341. }
  342. .custom-radio-card-checked {
  343. background-color: var(--color-primary-light-1);
  344. }
  345. .custom-radio-card:hover .custom-radio-card-title,
  346. .custom-radio-card-checked .custom-radio-card-title {
  347. color: rgb(var(--primary-6));
  348. }
  349. .custom-radio-card-checked .custom-radio-card-mask-dot {
  350. background-color: rgb(var(--primary-6));
  351. }
  352. </style>