index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="drawer-container">
  3. <div>
  4. <div class="setting-drawer-content">
  5. <div class="setting-drawer-title">
  6. <h3 class="drawer-title">主题风格设置</h3>
  7. </div>
  8. <div class="setting-drawer-block-checbox">
  9. <div class="setting-drawer-block-checbox-item" @click="handleTheme('theme-dark')">
  10. <img src="@/assets/images/dark.svg" alt="dark">
  11. <div v-if="sideTheme === 'theme-dark'" class="setting-drawer-block-checbox-selectIcon" style="display: block;">
  12. <i aria-label="图标: check" class="anticon anticon-check">
  13. <svg viewBox="64 64 896 896" data-icon="check" width="1em" height="1em" :fill="theme" aria-hidden="true"
  14. focusable="false" class="">
  15. <path
  16. 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"/>
  17. </svg>
  18. </i>
  19. </div>
  20. </div>
  21. <div class="setting-drawer-block-checbox-item" @click="handleTheme('theme-light')">
  22. <img src="@/assets/images/light.svg" alt="light">
  23. <div v-if="sideTheme === 'theme-light'" class="setting-drawer-block-checbox-selectIcon" style="display: block;">
  24. <i aria-label="图标: check" class="anticon anticon-check">
  25. <svg viewBox="64 64 896 896" data-icon="check" width="1em" height="1em" :fill="theme" aria-hidden="true"
  26. focusable="false" class="">
  27. <path
  28. 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"/>
  29. </svg>
  30. </i>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="drawer-item">
  35. <span>主题颜色</span>
  36. <theme-picker style="float: right;height: 26px;margin: -3px 8px 0 0;" @change="themeChange" />
  37. </div>
  38. </div>
  39. <el-divider/>
  40. <h3 class="drawer-title">系统布局配置</h3>
  41. <div class="drawer-item">
  42. <span>开启 TopNav</span>
  43. <el-switch v-model="topNav" class="drawer-switch" />
  44. </div>
  45. <div class="drawer-item">
  46. <span>开启 Tags-Views</span>
  47. <el-switch v-model="tagsView" class="drawer-switch" />
  48. </div>
  49. <div class="drawer-item">
  50. <span>固定 Header</span>
  51. <el-switch v-model="fixedHeader" class="drawer-switch" />
  52. </div>
  53. <div class="drawer-item">
  54. <span>显示 Logo</span>
  55. <el-switch v-model="sidebarLogo" class="drawer-switch" />
  56. </div>
  57. <div class="drawer-item">
  58. <span>动态标题</span>
  59. <el-switch v-model="dynamicTitle" class="drawer-switch" />
  60. </div>
  61. <el-divider/>
  62. <el-button size="small" type="primary" plain icon="el-icon-document-add" @click="saveSetting">保存配置</el-button>
  63. <el-button size="small" plain icon="el-icon-refresh" @click="resetSetting">重置配置</el-button>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import ThemePicker from '@/components/ThemePicker'
  69. export default {
  70. components: { ThemePicker },
  71. data() {
  72. return {
  73. theme: this.$store.state.settings.theme,
  74. sideTheme: this.$store.state.settings.sideTheme
  75. };
  76. },
  77. computed: {
  78. fixedHeader: {
  79. get() {
  80. return this.$store.state.settings.fixedHeader
  81. },
  82. set(val) {
  83. this.$store.dispatch('settings/changeSetting', {
  84. key: 'fixedHeader',
  85. value: val
  86. })
  87. }
  88. },
  89. topNav: {
  90. get() {
  91. return this.$store.state.settings.topNav
  92. },
  93. set(val) {
  94. this.$store.dispatch('settings/changeSetting', {
  95. key: 'topNav',
  96. value: val
  97. })
  98. if (!val) {
  99. this.$store.commit("SET_SIDEBAR_ROUTERS", this.$store.state.permission.defaultRoutes);
  100. }
  101. }
  102. },
  103. tagsView: {
  104. get() {
  105. return this.$store.state.settings.tagsView
  106. },
  107. set(val) {
  108. this.$store.dispatch('settings/changeSetting', {
  109. key: 'tagsView',
  110. value: val
  111. })
  112. }
  113. },
  114. sidebarLogo: {
  115. get() {
  116. return this.$store.state.settings.sidebarLogo
  117. },
  118. set(val) {
  119. this.$store.dispatch('settings/changeSetting', {
  120. key: 'sidebarLogo',
  121. value: val
  122. })
  123. }
  124. },
  125. dynamicTitle: {
  126. get() {
  127. return this.$store.state.settings.dynamicTitle
  128. },
  129. set(val) {
  130. this.$store.dispatch('settings/changeSetting', {
  131. key: 'dynamicTitle',
  132. value: val
  133. })
  134. }
  135. },
  136. },
  137. methods: {
  138. themeChange(val) {
  139. this.$store.dispatch('settings/changeSetting', {
  140. key: 'theme',
  141. value: val
  142. })
  143. this.theme = val;
  144. },
  145. handleTheme(val) {
  146. this.$store.dispatch('settings/changeSetting', {
  147. key: 'sideTheme',
  148. value: val
  149. })
  150. this.sideTheme = val;
  151. },
  152. saveSetting() {
  153. this.$modal.loading("正在保存到本地,请稍候...");
  154. this.$cache.local.set(
  155. "layout-setting",
  156. `{
  157. "topNav":${this.topNav},
  158. "tagsView":${this.tagsView},
  159. "fixedHeader":${this.fixedHeader},
  160. "sidebarLogo":${this.sidebarLogo},
  161. "dynamicTitle":${this.dynamicTitle},
  162. "sideTheme":"${this.sideTheme}",
  163. "theme":"${this.theme}"
  164. }`
  165. );
  166. setTimeout(this.$modal.closeLoading(), 1000)
  167. },
  168. resetSetting() {
  169. this.$modal.loading("正在清除设置缓存并刷新,请稍候...");
  170. this.$cache.local.remove("layout-setting")
  171. setTimeout("window.location.reload()", 1000)
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .setting-drawer-content {
  178. .setting-drawer-title {
  179. margin-bottom: 12px;
  180. color: rgba(0, 0, 0, .85);
  181. font-size: 14px;
  182. line-height: 22px;
  183. font-weight: bold;
  184. }
  185. .setting-drawer-block-checbox {
  186. display: flex;
  187. justify-content: flex-start;
  188. align-items: center;
  189. margin-top: 10px;
  190. margin-bottom: 20px;
  191. .setting-drawer-block-checbox-item {
  192. position: relative;
  193. margin-right: 16px;
  194. border-radius: 2px;
  195. cursor: pointer;
  196. img {
  197. width: 48px;
  198. height: 48px;
  199. }
  200. .setting-drawer-block-checbox-selectIcon {
  201. position: absolute;
  202. top: 0;
  203. right: 0;
  204. width: 100%;
  205. height: 100%;
  206. padding-top: 15px;
  207. padding-left: 24px;
  208. color: #1890ff;
  209. font-weight: 700;
  210. font-size: 14px;
  211. }
  212. }
  213. }
  214. }
  215. .drawer-container {
  216. padding: 24px;
  217. font-size: 14px;
  218. line-height: 1.5;
  219. word-wrap: break-word;
  220. .drawer-title {
  221. margin-bottom: 12px;
  222. color: rgba(0, 0, 0, .85);
  223. font-size: 14px;
  224. line-height: 22px;
  225. }
  226. .drawer-item {
  227. color: rgba(0, 0, 0, .65);
  228. font-size: 14px;
  229. padding: 12px 0;
  230. }
  231. .drawer-switch {
  232. float: right
  233. }
  234. }
  235. </style>