index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. <script setup lang="ts">
  2. import {
  3. ref,
  4. unref,
  5. watch,
  6. reactive,
  7. computed,
  8. nextTick,
  9. onUnmounted,
  10. onBeforeMount
  11. } from "vue";
  12. import { useI18n } from "vue-i18n";
  13. import { emitter } from "@/utils/mitt";
  14. import LayPanel from "../lay-panel/index.vue";
  15. import { useNav } from "@/layout/hooks/useNav";
  16. import { useAppStoreHook } from "@/store/modules/app";
  17. import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
  18. import Segmented, { type OptionsType } from "@/components/ReSegmented";
  19. import { useDataThemeChange } from "@/layout/hooks/useDataThemeChange";
  20. import { useDark, useGlobal, debounce, isNumber } from "@pureadmin/utils";
  21. import Check from "~icons/ep/check";
  22. import LeftArrow from "~icons/ri/arrow-left-s-line?width=20&height=20";
  23. import RightArrow from "~icons/ri/arrow-right-s-line?width=20&height=20";
  24. import DayIcon from "@/assets/svg/day.svg?component";
  25. import DarkIcon from "@/assets/svg/dark.svg?component";
  26. import SystemIcon from "@/assets/svg/system.svg?component";
  27. const { t } = useI18n();
  28. const { device } = useNav();
  29. const { isDark } = useDark();
  30. const { $storage } = useGlobal<GlobalPropertiesApi>();
  31. const mixRef = ref();
  32. const verticalRef = ref();
  33. const horizontalRef = ref();
  34. const {
  35. dataTheme,
  36. overallStyle,
  37. layoutTheme,
  38. themeColors,
  39. toggleClass,
  40. dataThemeChange,
  41. setLayoutThemeColor
  42. } = useDataThemeChange();
  43. /* body添加layout属性,作用于src/style/sidebar.scss */
  44. if (unref(layoutTheme)) {
  45. const layout = unref(layoutTheme).layout;
  46. const theme = unref(layoutTheme).theme;
  47. document.documentElement.setAttribute("data-theme", theme);
  48. setLayoutModel(layout);
  49. }
  50. /** 默认灵动模式 */
  51. const markValue = ref($storage.configure?.showModel ?? "smart");
  52. const logoVal = ref($storage.configure?.showLogo ?? true);
  53. const settings = reactive({
  54. greyVal: $storage.configure.grey,
  55. weakVal: $storage.configure.weak,
  56. tabsVal: $storage.configure.hideTabs,
  57. showLogo: $storage.configure.showLogo,
  58. showModel: $storage.configure.showModel,
  59. hideFooter: $storage.configure.hideFooter,
  60. multiTagsCache: $storage.configure.multiTagsCache,
  61. stretch: $storage.configure.stretch
  62. });
  63. const getThemeColorStyle = computed(() => {
  64. return color => {
  65. return { background: color };
  66. };
  67. });
  68. /** 当网页整体为暗色风格时不显示亮白色主题配色切换选项 */
  69. const showThemeColors = computed(() => {
  70. return themeColor => {
  71. return themeColor === "light" && isDark.value ? false : true;
  72. };
  73. });
  74. function storageConfigureChange<T>(key: string, val: T): void {
  75. const storageConfigure = $storage.configure;
  76. storageConfigure[key] = val;
  77. $storage.configure = storageConfigure;
  78. }
  79. /** 灰色模式设置 */
  80. const greyChange = (value): void => {
  81. const htmlEl = document.querySelector("html");
  82. toggleClass(settings.greyVal, "html-grey", htmlEl);
  83. storageConfigureChange("grey", value);
  84. };
  85. /** 色弱模式设置 */
  86. const weekChange = (value): void => {
  87. const htmlEl = document.querySelector("html");
  88. toggleClass(settings.weakVal, "html-weakness", htmlEl);
  89. storageConfigureChange("weak", value);
  90. };
  91. /** 隐藏标签页设置 */
  92. const tagsChange = () => {
  93. const showVal = settings.tabsVal;
  94. storageConfigureChange("hideTabs", showVal);
  95. emitter.emit("tagViewsChange", showVal as unknown as string);
  96. };
  97. /** 隐藏页脚设置 */
  98. const hideFooterChange = () => {
  99. const hideFooter = settings.hideFooter;
  100. storageConfigureChange("hideFooter", hideFooter);
  101. };
  102. /** 标签页持久化设置 */
  103. const multiTagsCacheChange = () => {
  104. const multiTagsCache = settings.multiTagsCache;
  105. storageConfigureChange("multiTagsCache", multiTagsCache);
  106. useMultiTagsStoreHook().multiTagsCacheChange(multiTagsCache);
  107. };
  108. function onChange({ option }) {
  109. const { value } = option;
  110. markValue.value = value;
  111. storageConfigureChange("showModel", value);
  112. emitter.emit("tagViewsShowModel", value);
  113. }
  114. /** 侧边栏Logo */
  115. function logoChange() {
  116. unref(logoVal)
  117. ? storageConfigureChange("showLogo", true)
  118. : storageConfigureChange("showLogo", false);
  119. emitter.emit("logoChange", unref(logoVal));
  120. }
  121. function setFalse(Doms): any {
  122. Doms.forEach(v => {
  123. toggleClass(false, "is-select", unref(v));
  124. });
  125. }
  126. /** 页宽 */
  127. const stretchTypeOptions = computed<Array<OptionsType>>(() => {
  128. return [
  129. {
  130. label: t("panel.pureStretchFixed"),
  131. tip: t("panel.pureStretchFixedTip"),
  132. value: "fixed"
  133. },
  134. {
  135. label: t("panel.pureStretchCustom"),
  136. tip: t("panel.pureStretchCustomTip"),
  137. value: "custom"
  138. }
  139. ];
  140. });
  141. const setStretch = value => {
  142. settings.stretch = value;
  143. storageConfigureChange("stretch", value);
  144. };
  145. const stretchTypeChange = ({ option }) => {
  146. const { value } = option;
  147. value === "custom" ? setStretch(1440) : setStretch(false);
  148. };
  149. /** 主题色 激活选择项 */
  150. const getThemeColor = computed(() => {
  151. return current => {
  152. if (
  153. current === layoutTheme.value.theme &&
  154. layoutTheme.value.theme !== "light"
  155. ) {
  156. return "#fff";
  157. } else if (
  158. current === layoutTheme.value.theme &&
  159. layoutTheme.value.theme === "light"
  160. ) {
  161. return "#1d2b45";
  162. } else {
  163. return "transparent";
  164. }
  165. };
  166. });
  167. const pClass = computed(() => {
  168. return "panel-title";
  169. });
  170. const themeOptions = computed<Array<OptionsType>>(() => {
  171. return [
  172. {
  173. label: t("panel.pureOverallStyleLight"),
  174. icon: DayIcon,
  175. theme: "light",
  176. tip: t("panel.pureOverallStyleLightTip"),
  177. iconAttrs: { fill: isDark.value ? "#fff" : "#000" }
  178. },
  179. {
  180. label: t("panel.pureOverallStyleDark"),
  181. icon: DarkIcon,
  182. theme: "dark",
  183. tip: t("panel.pureOverallStyleDarkTip"),
  184. iconAttrs: { fill: isDark.value ? "#fff" : "#000" }
  185. },
  186. {
  187. label: t("panel.pureOverallStyleSystem"),
  188. icon: SystemIcon,
  189. theme: "system",
  190. tip: t("panel.pureOverallStyleSystemTip"),
  191. iconAttrs: { fill: isDark.value ? "#fff" : "#000" }
  192. }
  193. ];
  194. });
  195. const markOptions = computed<Array<OptionsType>>(() => {
  196. return [
  197. {
  198. label: t("panel.pureTagsStyleSmart"),
  199. tip: t("panel.pureTagsStyleSmartTip"),
  200. value: "smart"
  201. },
  202. {
  203. label: t("panel.pureTagsStyleCard"),
  204. tip: t("panel.pureTagsStyleCardTip"),
  205. value: "card"
  206. },
  207. {
  208. label: t("panel.pureTagsStyleChrome"),
  209. tip: t("panel.pureTagsStyleChromeTip"),
  210. value: "chrome"
  211. }
  212. ];
  213. });
  214. /** 设置导航模式 */
  215. function setLayoutModel(layout: string) {
  216. layoutTheme.value.layout = layout;
  217. window.document.body.setAttribute("layout", layout);
  218. $storage.layout = {
  219. layout,
  220. theme: layoutTheme.value.theme,
  221. darkMode: $storage.layout?.darkMode,
  222. sidebarStatus: $storage.layout?.sidebarStatus,
  223. epThemeColor: $storage.layout?.epThemeColor,
  224. themeColor: $storage.layout?.themeColor,
  225. overallStyle: $storage.layout?.overallStyle
  226. };
  227. useAppStoreHook().setLayout(layout);
  228. }
  229. watch($storage, ({ layout }) => {
  230. switch (layout["layout"]) {
  231. case "vertical":
  232. toggleClass(true, "is-select", unref(verticalRef));
  233. debounce(setFalse([horizontalRef]), 50);
  234. debounce(setFalse([mixRef]), 50);
  235. break;
  236. case "horizontal":
  237. toggleClass(true, "is-select", unref(horizontalRef));
  238. debounce(setFalse([verticalRef]), 50);
  239. debounce(setFalse([mixRef]), 50);
  240. break;
  241. case "mix":
  242. toggleClass(true, "is-select", unref(mixRef));
  243. debounce(setFalse([verticalRef]), 50);
  244. debounce(setFalse([horizontalRef]), 50);
  245. break;
  246. }
  247. });
  248. const mediaQueryList = window.matchMedia("(prefers-color-scheme: dark)");
  249. /** 根据操作系统主题设置平台整体风格 */
  250. function updateTheme() {
  251. if (overallStyle.value !== "system") return;
  252. if (mediaQueryList.matches) {
  253. dataTheme.value = true;
  254. } else {
  255. dataTheme.value = false;
  256. }
  257. dataThemeChange(overallStyle.value);
  258. }
  259. function removeMatchMedia() {
  260. mediaQueryList.removeEventListener("change", updateTheme);
  261. }
  262. /** 监听操作系统主题改变 */
  263. function watchSystemThemeChange() {
  264. updateTheme();
  265. removeMatchMedia();
  266. mediaQueryList.addEventListener("change", updateTheme);
  267. }
  268. onBeforeMount(() => {
  269. /* 初始化系统配置 */
  270. nextTick(() => {
  271. watchSystemThemeChange();
  272. settings.greyVal &&
  273. document.querySelector("html")?.classList.add("html-grey");
  274. settings.weakVal &&
  275. document.querySelector("html")?.classList.add("html-weakness");
  276. settings.tabsVal && tagsChange();
  277. settings.hideFooter && hideFooterChange();
  278. });
  279. });
  280. onUnmounted(() => removeMatchMedia);
  281. </script>
  282. <template>
  283. <LayPanel>
  284. <div class="panel-container">
  285. <p :class="pClass">{{ t("panel.pureOverallStyle") }}</p>
  286. <Segmented
  287. resize
  288. class="select-none"
  289. :modelValue="overallStyle === 'system' ? 2 : dataTheme ? 1 : 0"
  290. :options="themeOptions"
  291. @change="
  292. theme => {
  293. theme.index === 1 && theme.index !== 2
  294. ? (dataTheme = true)
  295. : (dataTheme = false);
  296. overallStyle = theme.option.theme;
  297. dataThemeChange(theme.option.theme);
  298. theme.index === 2 && watchSystemThemeChange();
  299. }
  300. "
  301. />
  302. <p class="panel-title mt-5">{{ t("panel.pureThemeColor") }}</p>
  303. <ul class="theme-color">
  304. <li
  305. v-for="(item, index) in themeColors"
  306. v-show="showThemeColors(item.themeColor)"
  307. :key="index"
  308. :style="getThemeColorStyle(item.color)"
  309. @click="setLayoutThemeColor(item.themeColor)"
  310. >
  311. <el-icon class="check-icon" :color="getThemeColor(item.themeColor)">
  312. <IconifyIconOffline :icon="Check" />
  313. </el-icon>
  314. </li>
  315. </ul>
  316. <p class="panel-title mt-5">{{ t("panel.pureLayoutModel") }}</p>
  317. <ul class="pure-theme">
  318. <li
  319. ref="verticalRef"
  320. v-tippy="{
  321. content: t('panel.pureVerticalTip'),
  322. zIndex: 41000
  323. }"
  324. :class="layoutTheme.layout === 'vertical' ? 'is-select' : ''"
  325. @click="setLayoutModel('vertical')"
  326. >
  327. <div />
  328. <div />
  329. </li>
  330. <li
  331. v-if="device !== 'mobile'"
  332. ref="horizontalRef"
  333. v-tippy="{
  334. content: t('panel.pureHorizontalTip'),
  335. zIndex: 41000
  336. }"
  337. :class="layoutTheme.layout === 'horizontal' ? 'is-select' : ''"
  338. @click="setLayoutModel('horizontal')"
  339. >
  340. <div />
  341. <div />
  342. </li>
  343. <li
  344. v-if="device !== 'mobile'"
  345. ref="mixRef"
  346. v-tippy="{
  347. content: t('panel.pureMixTip'),
  348. zIndex: 41000
  349. }"
  350. :class="layoutTheme.layout === 'mix' ? 'is-select' : ''"
  351. @click="setLayoutModel('mix')"
  352. >
  353. <div />
  354. <div />
  355. </li>
  356. </ul>
  357. <span v-if="useAppStoreHook().getViewportWidth > 1280">
  358. <p class="panel-title mt-5">{{ t("panel.pureStretch") }}</p>
  359. <Segmented
  360. resize
  361. class="segmented mb-2 select-none"
  362. :modelValue="isNumber(settings.stretch) ? 1 : 0"
  363. :options="stretchTypeOptions"
  364. @change="stretchTypeChange"
  365. />
  366. <el-input-number
  367. v-if="isNumber(settings.stretch)"
  368. v-model="settings.stretch as number"
  369. :min="1280"
  370. :max="1600"
  371. controls-position="right"
  372. @change="value => setStretch(value)"
  373. />
  374. <button
  375. v-else
  376. v-ripple="{ class: 'text-gray-300' }"
  377. class="stretch-btn"
  378. @click="setStretch(!settings.stretch)"
  379. >
  380. <div
  381. class="stretch-btn-content"
  382. :class="[
  383. settings.stretch ? 'stretch-expanded' : 'stretch-collapsed'
  384. ]"
  385. >
  386. <IconifyIconOffline
  387. :icon="settings.stretch ? RightArrow : LeftArrow"
  388. />
  389. <div class="stretch-line" />
  390. <IconifyIconOffline
  391. :icon="settings.stretch ? LeftArrow : RightArrow"
  392. />
  393. </div>
  394. </button>
  395. </span>
  396. <p class="panel-title mt-4">{{ t("panel.pureTagsStyle") }}</p>
  397. <Segmented
  398. resize
  399. class="select-none"
  400. :modelValue="markValue === 'smart' ? 0 : markValue === 'card' ? 1 : 2"
  401. :options="markOptions"
  402. @change="onChange"
  403. />
  404. <p class="panel-title mt-5 interface-title">
  405. {{ t("panel.pureInterfaceDisplay") }}
  406. </p>
  407. <ul class="setting">
  408. <li>
  409. <span class="setting-text">{{ t("panel.pureGreyModel") }}</span>
  410. <el-switch
  411. v-model="settings.greyVal"
  412. inline-prompt
  413. :active-text="t('buttons.pureOpenText')"
  414. :inactive-text="t('buttons.pureCloseText')"
  415. @change="greyChange"
  416. />
  417. </li>
  418. <li>
  419. <span class="setting-text">{{ t("panel.pureWeakModel") }}</span>
  420. <el-switch
  421. v-model="settings.weakVal"
  422. inline-prompt
  423. :active-text="t('buttons.pureOpenText')"
  424. :inactive-text="t('buttons.pureCloseText')"
  425. @change="weekChange"
  426. />
  427. </li>
  428. <li>
  429. <span class="setting-text">{{ t("panel.pureHiddenTags") }}</span>
  430. <el-switch
  431. v-model="settings.tabsVal"
  432. inline-prompt
  433. :active-text="t('buttons.pureOpenText')"
  434. :inactive-text="t('buttons.pureCloseText')"
  435. @change="tagsChange"
  436. />
  437. </li>
  438. <li>
  439. <span class="setting-text">{{ t("panel.pureHiddenFooter") }}</span>
  440. <el-switch
  441. v-model="settings.hideFooter"
  442. inline-prompt
  443. :active-text="t('buttons.pureOpenText')"
  444. :inactive-text="t('buttons.pureCloseText')"
  445. @change="hideFooterChange"
  446. />
  447. </li>
  448. <li>
  449. <span class="setting-text">Logo</span>
  450. <el-switch
  451. v-model="logoVal"
  452. inline-prompt
  453. :active-value="true"
  454. :inactive-value="false"
  455. :active-text="t('buttons.pureOpenText')"
  456. :inactive-text="t('buttons.pureCloseText')"
  457. @change="logoChange"
  458. />
  459. </li>
  460. <li>
  461. <span class="setting-text">
  462. {{ t("panel.pureMultiTagsCache") }}
  463. </span>
  464. <el-switch
  465. v-model="settings.multiTagsCache"
  466. inline-prompt
  467. :active-text="t('buttons.pureOpenText')"
  468. :inactive-text="t('buttons.pureCloseText')"
  469. @change="multiTagsCacheChange"
  470. />
  471. </li>
  472. </ul>
  473. </div>
  474. </LayPanel>
  475. </template>
  476. <style lang="scss" scoped>
  477. :deep(.el-divider__text) {
  478. font-size: 16px;
  479. font-weight: 700;
  480. }
  481. :deep(.el-switch__core) {
  482. --el-switch-off-color: var(--pure-switch-off-color);
  483. min-width: 36px;
  484. height: 18px;
  485. }
  486. :deep(.el-switch__core .el-switch__action) {
  487. height: 14px;
  488. }
  489. .panel-container {
  490. padding: 1.25rem; /* p-5 */
  491. }
  492. .panel-title {
  493. margin-bottom: 12px !important; /* mb-[12px]! */
  494. font-weight: 500; /* font-medium */
  495. font-size: 0.875rem; /* text-sm */
  496. }
  497. .dark .panel-title,
  498. .dark .setting-text {
  499. color: white; /* dark:text-white */
  500. }
  501. .mt-5 {
  502. margin-top: 1.25rem !important; /* mt-5! */
  503. }
  504. .mt-4 {
  505. margin-top: 1rem !important; /* mt-4! */
  506. }
  507. .mb-2 {
  508. margin-bottom: 0.5rem !important; /* mb-2 */
  509. }
  510. .theme-color {
  511. height: 20px;
  512. list-style: none;
  513. padding: 0;
  514. margin: 0;
  515. li {
  516. float: left;
  517. height: 20px;
  518. margin-right: 8px;
  519. cursor: pointer;
  520. border-radius: 4px;
  521. &:nth-child(1) {
  522. border: 1px solid #ddd;
  523. }
  524. }
  525. }
  526. .check-icon {
  527. margin: 0.1em 0.1em 0 0;
  528. font-size: 17px; /* size=17 */
  529. }
  530. .pure-theme {
  531. display: flex;
  532. gap: 12px;
  533. list-style: none;
  534. padding: 0;
  535. margin: 0;
  536. li {
  537. position: relative;
  538. width: 46px;
  539. height: 36px;
  540. overflow: hidden;
  541. cursor: pointer;
  542. background: #f0f2f5;
  543. border-radius: 4px;
  544. box-shadow: 0 1px 2.5px 0 rgb(0 0 0 / 18%);
  545. &:nth-child(1) {
  546. div {
  547. &:nth-child(1) {
  548. width: 30%;
  549. height: 100%;
  550. background: #1b2a47;
  551. }
  552. &:nth-child(2) {
  553. position: absolute;
  554. top: 0;
  555. right: 0;
  556. width: 70%;
  557. height: 30%;
  558. background: #fff;
  559. box-shadow: 0 0 1px #888;
  560. }
  561. }
  562. }
  563. &:nth-child(2) {
  564. div {
  565. &:nth-child(1) {
  566. width: 100%;
  567. height: 30%;
  568. background: #1b2a47;
  569. box-shadow: 0 0 1px #888;
  570. }
  571. }
  572. }
  573. &:nth-child(3) {
  574. div {
  575. &:nth-child(1) {
  576. width: 100%;
  577. height: 30%;
  578. background: #1b2a47;
  579. box-shadow: 0 0 1px #888;
  580. }
  581. &:nth-child(2) {
  582. position: absolute;
  583. bottom: 0;
  584. left: 0;
  585. width: 30%;
  586. height: 70%;
  587. background: #fff;
  588. box-shadow: 0 0 1px #888;
  589. }
  590. }
  591. }
  592. }
  593. }
  594. .is-select {
  595. border: 2px solid var(--el-color-primary);
  596. }
  597. .setting {
  598. list-style: none;
  599. padding: 0;
  600. margin: 0;
  601. li {
  602. display: flex;
  603. align-items: center;
  604. justify-content: space-between;
  605. padding: 3px 0;
  606. font-size: 14px;
  607. }
  608. }
  609. .select-none {
  610. user-select: none;
  611. }
  612. .stretch-btn {
  613. background: transparent;
  614. display: flex;
  615. align-items: center;
  616. justify-content: center;
  617. width: 100%;
  618. height: 5rem; /* h-20 */
  619. border-radius: 0.375rem; /* rounded-md */
  620. border: 1px solid var(--pure-border-color);
  621. padding: 0;
  622. cursor: pointer;
  623. }
  624. .stretch-btn-content {
  625. display: flex;
  626. align-items: center;
  627. justify-content: space-between;
  628. width: 100%;
  629. transition: all 0.3s;
  630. color: var(--el-color-primary);
  631. padding: 0 1rem;
  632. }
  633. .stretch-expanded {
  634. width: 24%;
  635. }
  636. .stretch-collapsed {
  637. width: 50%;
  638. }
  639. .stretch-line {
  640. flex-grow: 1;
  641. border: 0;
  642. border-bottom: 1px dashed;
  643. border-color: var(--el-color-primary);
  644. margin: 0 0.5rem;
  645. }
  646. .interface-title {
  647. font-weight: 500;
  648. font-size: 0.875rem;
  649. }
  650. </style>