index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <script setup lang="ts">
  2. import {
  3. ref,
  4. unref,
  5. watch,
  6. reactive,
  7. computed,
  8. nextTick,
  9. useCssModule
  10. } from "vue";
  11. import { getConfig } from "/@/config";
  12. import { useRouter } from "vue-router";
  13. import panel from "../panel/index.vue";
  14. import { emitter } from "/@/utils/mitt";
  15. import { resetRouter } from "/@/router";
  16. import { templateRef } from "@vueuse/core";
  17. import { routerArrays } from "/@/layout/types";
  18. import { useNav } from "/@/layout/hooks/useNav";
  19. import { useAppStoreHook } from "/@/store/modules/app";
  20. import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
  21. import { useDataThemeChange } from "/@/layout/hooks/useDataThemeChange";
  22. import {
  23. useDark,
  24. debounce,
  25. useGlobal,
  26. storageLocal,
  27. storageSession
  28. } from "@pureadmin/utils";
  29. import { toggleTheme } from "@pureadmin/theme/dist/browser-utils";
  30. import dayIcon from "/@/assets/svg/day.svg?component";
  31. import darkIcon from "/@/assets/svg/dark.svg?component";
  32. const router = useRouter();
  33. const { device } = useNav();
  34. const { isDark } = useDark();
  35. const { isSelect } = useCssModule();
  36. const { $storage } = useGlobal<GlobalPropertiesApi>();
  37. const mixRef = templateRef<HTMLElement | null>("mixRef", null);
  38. const verticalRef = templateRef<HTMLElement | null>("verticalRef", null);
  39. const horizontalRef = templateRef<HTMLElement | null>("horizontalRef", null);
  40. const {
  41. body,
  42. dataTheme,
  43. layoutTheme,
  44. themeColors,
  45. dataThemeChange,
  46. setEpThemeColor,
  47. setLayoutThemeColor
  48. } = useDataThemeChange();
  49. /* body添加layout属性,作用于src/style/sidebar.scss */
  50. if (unref(layoutTheme)) {
  51. let layout = unref(layoutTheme).layout;
  52. let theme = unref(layoutTheme).theme;
  53. toggleTheme({
  54. scopeName: `layout-theme-${theme}`
  55. });
  56. setLayoutModel(layout);
  57. }
  58. /** 默认灵动模式 */
  59. const markValue = ref($storage.configure?.showModel ?? "smart");
  60. const logoVal = ref($storage.configure?.showLogo ?? true);
  61. const settings = reactive({
  62. greyVal: $storage.configure.grey,
  63. weakVal: $storage.configure.weak,
  64. tabsVal: $storage.configure.hideTabs,
  65. showLogo: $storage.configure.showLogo,
  66. showModel: $storage.configure.showModel,
  67. multiTagsCache: $storage.configure.multiTagsCache
  68. });
  69. const getThemeColorStyle = computed(() => {
  70. return color => {
  71. return { background: color };
  72. };
  73. });
  74. /** 当网页为暗黑模式时不显示亮白色切换选项 */
  75. const showThemeColors = computed(() => {
  76. return themeColor => {
  77. return themeColor === "light" && isDark.value ? false : true;
  78. };
  79. });
  80. function storageConfigureChange<T>(key: string, val: T): void {
  81. const storageConfigure = $storage.configure;
  82. storageConfigure[key] = val;
  83. $storage.configure = storageConfigure;
  84. }
  85. function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
  86. const targetEl = target || document.body;
  87. let { className } = targetEl;
  88. className = className.replace(clsName, "").trim();
  89. targetEl.className = flag ? `${className} ${clsName} ` : className;
  90. }
  91. /** 灰色模式设置 */
  92. const greyChange = (value): void => {
  93. toggleClass(settings.greyVal, "html-grey", document.querySelector("html"));
  94. storageConfigureChange("grey", value);
  95. };
  96. /** 色弱模式设置 */
  97. const weekChange = (value): void => {
  98. toggleClass(
  99. settings.weakVal,
  100. "html-weakness",
  101. document.querySelector("html")
  102. );
  103. storageConfigureChange("weak", value);
  104. };
  105. const tagsChange = () => {
  106. let showVal = settings.tabsVal;
  107. storageConfigureChange("hideTabs", showVal);
  108. emitter.emit("tagViewsChange", showVal as unknown as string);
  109. };
  110. const multiTagsCacheChange = () => {
  111. let multiTagsCache = settings.multiTagsCache;
  112. storageConfigureChange("multiTagsCache", multiTagsCache);
  113. useMultiTagsStoreHook().multiTagsCacheChange(multiTagsCache);
  114. };
  115. /** 清空缓存并返回登录页 */
  116. function onReset() {
  117. router.push("/login");
  118. const { Grey, Weak, MultiTagsCache, EpThemeColor, Layout } = getConfig();
  119. useAppStoreHook().setLayout(Layout);
  120. setEpThemeColor(EpThemeColor);
  121. useMultiTagsStoreHook().multiTagsCacheChange(MultiTagsCache);
  122. toggleClass(Grey, "html-grey", document.querySelector("html"));
  123. toggleClass(Weak, "html-weakness", document.querySelector("html"));
  124. useMultiTagsStoreHook().handleTags("equal", [...routerArrays]);
  125. storageLocal.clear();
  126. storageSession.clear();
  127. resetRouter();
  128. }
  129. function onChange(label) {
  130. storageConfigureChange("showModel", label);
  131. emitter.emit("tagViewsShowModel", label);
  132. }
  133. /** 侧边栏Logo */
  134. function logoChange() {
  135. unref(logoVal)
  136. ? storageConfigureChange("showLogo", true)
  137. : storageConfigureChange("showLogo", false);
  138. emitter.emit("logoChange", unref(logoVal));
  139. }
  140. function setFalse(Doms): any {
  141. Doms.forEach(v => {
  142. toggleClass(false, isSelect, unref(v));
  143. });
  144. }
  145. watch($storage, ({ layout }) => {
  146. /* 设置wangeditorV5主题色 */
  147. body.style.setProperty("--w-e-toolbar-active-color", layout["epThemeColor"]);
  148. switch (layout["layout"]) {
  149. case "vertical":
  150. toggleClass(true, isSelect, unref(verticalRef));
  151. debounce(setFalse([horizontalRef]), 50);
  152. debounce(setFalse([mixRef]), 50);
  153. break;
  154. case "horizontal":
  155. toggleClass(true, isSelect, unref(horizontalRef));
  156. debounce(setFalse([verticalRef]), 50);
  157. debounce(setFalse([mixRef]), 50);
  158. break;
  159. case "mix":
  160. toggleClass(true, isSelect, unref(mixRef));
  161. debounce(setFalse([verticalRef]), 50);
  162. debounce(setFalse([horizontalRef]), 50);
  163. break;
  164. }
  165. });
  166. /** 主题色 激活选择项 */
  167. const getThemeColor = computed(() => {
  168. return current => {
  169. if (
  170. current === layoutTheme.value.theme &&
  171. layoutTheme.value.theme !== "light"
  172. ) {
  173. return "#fff";
  174. } else if (
  175. current === layoutTheme.value.theme &&
  176. layoutTheme.value.theme === "light"
  177. ) {
  178. return "#1d2b45";
  179. } else {
  180. return "transparent";
  181. }
  182. };
  183. });
  184. /** 设置导航模式 */
  185. function setLayoutModel(layout: string) {
  186. layoutTheme.value.layout = layout;
  187. window.document.body.setAttribute("layout", layout);
  188. $storage.layout = {
  189. layout,
  190. theme: layoutTheme.value.theme,
  191. darkMode: $storage.layout?.darkMode,
  192. sidebarStatus: $storage.layout?.sidebarStatus,
  193. epThemeColor: $storage.layout?.epThemeColor
  194. };
  195. useAppStoreHook().setLayout(layout);
  196. }
  197. /* 初始化项目配置 */
  198. nextTick(() => {
  199. settings.greyVal &&
  200. document.querySelector("html")?.setAttribute("class", "html-grey");
  201. settings.weakVal &&
  202. document.querySelector("html")?.setAttribute("class", "html-weakness");
  203. settings.tabsVal && tagsChange();
  204. dataThemeChange();
  205. });
  206. </script>
  207. <template>
  208. <panel>
  209. <el-divider>主题</el-divider>
  210. <el-switch
  211. v-model="dataTheme"
  212. inline-prompt
  213. class="pure-datatheme"
  214. :active-icon="dayIcon"
  215. :inactive-icon="darkIcon"
  216. @change="dataThemeChange"
  217. />
  218. <el-divider>导航栏模式</el-divider>
  219. <ul class="pure-theme">
  220. <el-tooltip class="item" content="左侧模式" placement="bottom">
  221. <li
  222. :class="layoutTheme.layout === 'vertical' ? $style.isSelect : ''"
  223. ref="verticalRef"
  224. @click="setLayoutModel('vertical')"
  225. >
  226. <div />
  227. <div />
  228. </li>
  229. </el-tooltip>
  230. <el-tooltip
  231. v-if="device !== 'mobile'"
  232. class="item"
  233. content="顶部模式"
  234. placement="bottom"
  235. >
  236. <li
  237. :class="layoutTheme.layout === 'horizontal' ? $style.isSelect : ''"
  238. ref="horizontalRef"
  239. @click="setLayoutModel('horizontal')"
  240. >
  241. <div />
  242. <div />
  243. </li>
  244. </el-tooltip>
  245. <el-tooltip
  246. v-if="device !== 'mobile'"
  247. class="item"
  248. content="混合模式"
  249. placement="bottom"
  250. >
  251. <li
  252. :class="layoutTheme.layout === 'mix' ? $style.isSelect : ''"
  253. ref="mixRef"
  254. @click="setLayoutModel('mix')"
  255. >
  256. <div />
  257. <div />
  258. </li>
  259. </el-tooltip>
  260. </ul>
  261. <el-divider>主题色</el-divider>
  262. <ul class="theme-color">
  263. <li
  264. v-for="(item, index) in themeColors"
  265. :key="index"
  266. v-show="showThemeColors(item.themeColor)"
  267. :style="getThemeColorStyle(item.color)"
  268. @click="setLayoutThemeColor(item.themeColor)"
  269. >
  270. <el-icon
  271. style="margin: 0.1em 0.1em 0 0"
  272. :size="17"
  273. :color="getThemeColor(item.themeColor)"
  274. >
  275. <IconifyIconOffline icon="check" />
  276. </el-icon>
  277. </li>
  278. </ul>
  279. <el-divider>界面显示</el-divider>
  280. <ul class="setting">
  281. <li>
  282. <span>灰色模式</span>
  283. <el-switch
  284. v-model="settings.greyVal"
  285. inline-prompt
  286. inactive-color="#a6a6a6"
  287. active-text="开"
  288. inactive-text="关"
  289. @change="greyChange"
  290. />
  291. </li>
  292. <li>
  293. <span>色弱模式</span>
  294. <el-switch
  295. v-model="settings.weakVal"
  296. inline-prompt
  297. inactive-color="#a6a6a6"
  298. active-text="开"
  299. inactive-text="关"
  300. @change="weekChange"
  301. />
  302. </li>
  303. <li>
  304. <span>隐藏标签页</span>
  305. <el-switch
  306. v-model="settings.tabsVal"
  307. inline-prompt
  308. inactive-color="#a6a6a6"
  309. active-text="开"
  310. inactive-text="关"
  311. @change="tagsChange"
  312. />
  313. </li>
  314. <li>
  315. <span>侧边栏Logo</span>
  316. <el-switch
  317. v-model="logoVal"
  318. inline-prompt
  319. :active-value="true"
  320. :inactive-value="false"
  321. inactive-color="#a6a6a6"
  322. active-text="开"
  323. inactive-text="关"
  324. @change="logoChange"
  325. />
  326. </li>
  327. <li>
  328. <span>标签页持久化</span>
  329. <el-switch
  330. v-model="settings.multiTagsCache"
  331. inline-prompt
  332. inactive-color="#a6a6a6"
  333. active-text="开"
  334. inactive-text="关"
  335. @change="multiTagsCacheChange"
  336. />
  337. </li>
  338. <li>
  339. <span>标签风格</span>
  340. <el-radio-group v-model="markValue" size="small" @change="onChange">
  341. <el-radio label="card">卡片</el-radio>
  342. <el-radio label="smart">灵动</el-radio>
  343. </el-radio-group>
  344. </li>
  345. </ul>
  346. <el-divider />
  347. <el-button
  348. type="danger"
  349. style="width: 90%; margin: 24px 15px"
  350. @click="onReset"
  351. >
  352. <IconifyIconOffline
  353. icon="fa-sign-out"
  354. width="15"
  355. height="15"
  356. style="margin-right: 4px"
  357. />
  358. 清空缓存并返回登录页
  359. </el-button>
  360. </panel>
  361. </template>
  362. <style scoped module>
  363. .isSelect {
  364. border: 2px solid var(--el-color-primary);
  365. }
  366. </style>
  367. <style lang="scss" scoped>
  368. .setting {
  369. width: 100%;
  370. li {
  371. display: flex;
  372. justify-content: space-between;
  373. align-items: center;
  374. margin: 25px;
  375. }
  376. }
  377. :deep(.el-divider__text) {
  378. font-size: 16px;
  379. font-weight: 700;
  380. }
  381. .pure-datatheme {
  382. width: 100%;
  383. height: 50px;
  384. text-align: center;
  385. display: block;
  386. padding-top: 25px;
  387. }
  388. .pure-theme {
  389. margin-top: 25px;
  390. width: 100%;
  391. height: 50px;
  392. display: flex;
  393. flex-wrap: wrap;
  394. justify-content: space-around;
  395. li {
  396. width: 18%;
  397. height: 45px;
  398. background: #f0f2f5;
  399. position: relative;
  400. overflow: hidden;
  401. cursor: pointer;
  402. border-radius: 4px;
  403. box-shadow: 0 1px 2.5px 0 rgb(0 0 0 / 18%);
  404. &:nth-child(1) {
  405. div {
  406. &:nth-child(1) {
  407. width: 30%;
  408. height: 100%;
  409. background: #1b2a47;
  410. }
  411. &:nth-child(2) {
  412. width: 70%;
  413. height: 30%;
  414. top: 0;
  415. right: 0;
  416. background: #fff;
  417. box-shadow: 0 0 1px #888;
  418. position: absolute;
  419. }
  420. }
  421. }
  422. &:nth-child(2) {
  423. div {
  424. &:nth-child(1) {
  425. width: 100%;
  426. height: 30%;
  427. background: #1b2a47;
  428. box-shadow: 0 0 1px #888;
  429. }
  430. }
  431. }
  432. &:nth-child(3) {
  433. div {
  434. &:nth-child(1) {
  435. width: 100%;
  436. height: 30%;
  437. background: #1b2a47;
  438. box-shadow: 0 0 1px #888;
  439. }
  440. &:nth-child(2) {
  441. width: 30%;
  442. height: 70%;
  443. bottom: 0;
  444. left: 0;
  445. background: #fff;
  446. box-shadow: 0 0 1px #888;
  447. position: absolute;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. .theme-color {
  454. width: 100%;
  455. height: 40px;
  456. margin-top: 20px;
  457. display: flex;
  458. justify-content: center;
  459. li {
  460. float: left;
  461. width: 20px;
  462. height: 20px;
  463. margin-top: 8px;
  464. margin-right: 8px;
  465. font-weight: 700;
  466. text-align: center;
  467. border-radius: 2px;
  468. cursor: pointer;
  469. &:nth-child(2) {
  470. border: 1px solid #ddd;
  471. }
  472. }
  473. }
  474. </style>