index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <el-drawer v-model="showSettings" :withHeader="false" direction="rtl" size="300px">
  3. <div class="setting-drawer-title">
  4. <h3 class="drawer-title">主题风格设置</h3>
  5. </div>
  6. <div class="setting-drawer-block-checbox">
  7. <div class="setting-drawer-block-checbox-item" @click="handleTheme('theme-dark')">
  8. <img src="@/assets/images/dark.svg" alt="dark" />
  9. <div v-if="sideTheme === 'theme-dark'" class="setting-drawer-block-checbox-selectIcon" style="display: block;">
  10. <i aria-label="图标: check" class="anticon anticon-check">
  11. <svg viewBox="64 64 896 896" data-icon="check" width="1em" height="1em" :fill="theme" aria-hidden="true" focusable="false" class>
  12. <path d="M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z" />
  13. </svg>
  14. </i>
  15. </div>
  16. </div>
  17. <div class="setting-drawer-block-checbox-item" @click="handleTheme('theme-light')">
  18. <img src="@/assets/images/light.svg" alt="light" />
  19. <div v-if="sideTheme === 'theme-light'" class="setting-drawer-block-checbox-selectIcon" style="display: block;">
  20. <i aria-label="图标: check" class="anticon anticon-check">
  21. <svg viewBox="64 64 896 896" data-icon="check" width="1em" height="1em" :fill="theme" aria-hidden="true" focusable="false" class>
  22. <path d="M912 190h-69.9c-9.8 0-19.1 4.5-25.1 12.2L404.7 724.5 207 474a32 32 0 0 0-25.1-12.2H112c-6.7 0-10.4 7.7-6.3 12.9l273.9 347c12.8 16.2 37.4 16.2 50.3 0l488.4-618.9c4.1-5.1.4-12.8-6.3-12.8z" />
  23. </svg>
  24. </i>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="drawer-item">
  29. <span>主题颜色</span>
  30. <span class="comp-style">
  31. <el-color-picker v-model="theme" :predefine="predefineColors" @change="themeChange"/>
  32. </span>
  33. </div>
  34. <el-divider />
  35. <h3 class="drawer-title">系统布局配置</h3>
  36. <div class="drawer-item">
  37. <span>开启 TopNav</span>
  38. <span class="comp-style">
  39. <el-switch v-model="settingsStore.topNav" @change="topNavChange" class="drawer-switch" />
  40. </span>
  41. </div>
  42. <div class="drawer-item">
  43. <span>开启 Tags-Views</span>
  44. <span class="comp-style">
  45. <el-switch v-model="settingsStore.tagsView" class="drawer-switch" />
  46. </span>
  47. </div>
  48. <div class="drawer-item">
  49. <span>固定 Header</span>
  50. <span class="comp-style">
  51. <el-switch v-model="settingsStore.fixedHeader" class="drawer-switch" />
  52. </span>
  53. </div>
  54. <div class="drawer-item">
  55. <span>显示 Logo</span>
  56. <span class="comp-style">
  57. <el-switch v-model="settingsStore.sidebarLogo" class="drawer-switch" />
  58. </span>
  59. </div>
  60. <div class="drawer-item">
  61. <span>动态标题</span>
  62. <span class="comp-style">
  63. <el-switch v-model="settingsStore.dynamicTitle" class="drawer-switch" />
  64. </span>
  65. </div>
  66. <el-divider />
  67. <el-button type="primary" plain icon="DocumentAdd" @click="saveSetting">保存配置</el-button>
  68. <el-button plain icon="Refresh" @click="resetSetting">重置配置</el-button>
  69. </el-drawer>
  70. </template>
  71. <script setup>
  72. import variables from '@/assets/styles/variables.module.scss'
  73. import axios from 'axios'
  74. import { ElLoading, ElMessage } from 'element-plus'
  75. import { useDynamicTitle } from '@/utils/dynamicTitle'
  76. import useAppStore from '@/store/modules/app'
  77. import useSettingsStore from '@/store/modules/settings'
  78. import usePermissionStore from '@/store/modules/permission'
  79. import { handleThemeStyle } from '@/utils/theme'
  80. const { proxy } = getCurrentInstance();
  81. const appStore = useAppStore()
  82. const settingsStore = useSettingsStore()
  83. const permissionStore = usePermissionStore()
  84. const showSettings = ref(false);
  85. const theme = ref(settingsStore.theme);
  86. const sideTheme = ref(settingsStore.sideTheme);
  87. const storeSettings = computed(() => settingsStore);
  88. const predefineColors = ref(["#409EFF", "#ff4500", "#ff8c00", "#ffd700", "#90ee90", "#00ced1", "#1e90ff", "#c71585"]);
  89. /** 是否需要topnav */
  90. function topNavChange(val) {
  91. if (!val) {
  92. appStore.toggleSideBarHide(false);
  93. permissionStore.setSidebarRouters(permissionStore.defaultRoutes);
  94. }
  95. }
  96. function themeChange(val) {
  97. settingsStore.theme = val;
  98. handleThemeStyle(val);
  99. }
  100. function handleTheme(val) {
  101. settingsStore.sideTheme = val;
  102. sideTheme.value = val;
  103. }
  104. function saveSetting() {
  105. proxy.$modal.loading("正在保存到本地,请稍候...");
  106. let layoutSetting = {
  107. "topNav": storeSettings.value.topNav,
  108. "tagsView": storeSettings.value.tagsView,
  109. "fixedHeader": storeSettings.value.fixedHeader,
  110. "sidebarLogo": storeSettings.value.sidebarLogo,
  111. "dynamicTitle": storeSettings.value.dynamicTitle,
  112. "sideTheme": storeSettings.value.sideTheme,
  113. "theme": storeSettings.value.theme
  114. };
  115. localStorage.setItem("layout-setting", JSON.stringify(layoutSetting));
  116. setTimeout(proxy.$modal.closeLoading(), 1000)
  117. }
  118. function resetSetting() {
  119. proxy.$modal.loading("正在清除设置缓存并刷新,请稍候...");
  120. localStorage.removeItem("layout-setting")
  121. setTimeout("window.location.reload()", 1000)
  122. }
  123. function openSetting() {
  124. showSettings.value = true;
  125. }
  126. defineExpose({
  127. openSetting,
  128. })
  129. </script>
  130. <style lang='scss' scoped>
  131. .setting-drawer-title {
  132. margin-bottom: 12px;
  133. color: rgba(0, 0, 0, 0.85);
  134. line-height: 22px;
  135. font-weight: bold;
  136. .drawer-title {
  137. font-size: 14px;
  138. }
  139. }
  140. .setting-drawer-block-checbox {
  141. display: flex;
  142. justify-content: flex-start;
  143. align-items: center;
  144. margin-top: 10px;
  145. margin-bottom: 20px;
  146. .setting-drawer-block-checbox-item {
  147. position: relative;
  148. margin-right: 16px;
  149. border-radius: 2px;
  150. cursor: pointer;
  151. img {
  152. width: 48px;
  153. height: 48px;
  154. }
  155. .custom-img {
  156. width: 48px;
  157. height: 38px;
  158. border-radius: 5px;
  159. box-shadow: 1px 1px 2px #898484;
  160. }
  161. .setting-drawer-block-checbox-selectIcon {
  162. position: absolute;
  163. top: 0;
  164. right: 0;
  165. width: 100%;
  166. height: 100%;
  167. padding-top: 15px;
  168. padding-left: 24px;
  169. color: #1890ff;
  170. font-weight: 700;
  171. font-size: 14px;
  172. }
  173. }
  174. }
  175. .drawer-item {
  176. color: rgba(0, 0, 0, 0.65);
  177. padding: 12px 0;
  178. font-size: 14px;
  179. .comp-style {
  180. float: right;
  181. margin: -3px 8px 0px 0px;
  182. }
  183. }
  184. </style>