index.vue 8.8 KB

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