index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <span v-if="themeBar">
  3. <vab-icon title="主题配置" :icon="['fas', 'palette']" @click="handleOpenThemeBar" />
  4. <!-- <div class="theme-bar-setting">
  5. <div @click="handleOpenThemeBar">
  6. <vab-icon :icon="['fas', 'palette']" />
  7. <p>主题配置</p>
  8. </div>
  9. <div @click="handleGetCode">
  10. <vab-icon :icon="['fas', 'laptop-code']"></vab-icon>
  11. <p>拷贝源码</p>
  12. </div>
  13. </div> -->
  14. <el-drawer title="主题配置" :visible.sync="drawerVisible" direction="rtl" append-to-body size="300px">
  15. <el-scrollbar style="height: 80vh; overflow: hidden">
  16. <div class="el-drawer__body">
  17. <el-form ref="form" :model="theme" label-position="top">
  18. <el-form-item label="主题">
  19. <el-radio-group v-model="theme.name">
  20. <el-radio-button label="default">默认</el-radio-button>
  21. <el-radio-button label="green">绿荫草场</el-radio-button>
  22. <el-radio-button label="glory">荣耀典藏</el-radio-button>
  23. </el-radio-group>
  24. </el-form-item>
  25. <el-form-item label="布局">
  26. <el-radio-group v-model="theme.layout">
  27. <el-radio-button label="vertical">纵向布局</el-radio-button>
  28. <el-radio-button label="horizontal">横向布局</el-radio-button>
  29. </el-radio-group>
  30. </el-form-item>
  31. <el-form-item label="头部">
  32. <el-radio-group v-model="theme.header">
  33. <el-radio-button label="fixed">固定头部</el-radio-button>
  34. <el-radio-button label="noFixed">不固定头部</el-radio-button>
  35. </el-radio-group>
  36. </el-form-item>
  37. <el-form-item label="多标签">
  38. <el-radio-group v-model="theme.tabsBar">
  39. <el-radio-button label="true">开启</el-radio-button>
  40. <el-radio-button label="false">不开启</el-radio-button>
  41. </el-radio-group>
  42. </el-form-item>
  43. </el-form>
  44. </div>
  45. </el-scrollbar>
  46. <div class="el-drawer__footer">
  47. <el-button type="primary" @click="handleSaveTheme">保存</el-button>
  48. <el-button type="" @click="drawerVisible = false">取消</el-button>
  49. </div>
  50. </el-drawer>
  51. </span>
  52. </template>
  53. <script>
  54. import { mapActions, mapGetters } from 'vuex'
  55. import { layout as defaultLayout } from '@/config'
  56. export default {
  57. name: 'VabThemeBar',
  58. data() {
  59. return {
  60. drawerVisible: false,
  61. theme: {
  62. name: 'default',
  63. layout: '',
  64. header: 'fixed',
  65. tabsBar: '',
  66. },
  67. }
  68. },
  69. computed: {
  70. ...mapGetters({
  71. layout: 'settings/layout',
  72. header: 'settings/header',
  73. tabsBar: 'settings/tabsBar',
  74. themeBar: 'settings/themeBar',
  75. }),
  76. },
  77. created() {
  78. this.$baseEventBus.$on('theme', () => {
  79. this.handleOpenThemeBar()
  80. })
  81. const theme = localStorage.getItem('vue-admin-beautiful-theme')
  82. if (null !== theme) {
  83. this.theme = JSON.parse(theme)
  84. this.handleSetTheme()
  85. } else {
  86. this.theme.layout = this.layout
  87. this.theme.header = this.header
  88. this.theme.tabsBar = this.tabsBar
  89. }
  90. },
  91. methods: {
  92. ...mapActions({
  93. changeLayout: 'settings/changeLayout',
  94. changeHeader: 'settings/changeHeader',
  95. changeTabsBar: 'settings/changeTabsBar',
  96. }),
  97. handleIsMobile() {
  98. return document.body.getBoundingClientRect().width - 1 < 992
  99. },
  100. handleOpenThemeBar() {
  101. this.drawerVisible = true
  102. },
  103. handleSetTheme() {
  104. let { name, layout, header, tabsBar } = this.theme
  105. localStorage.setItem(
  106. 'vue-admin-beautiful-theme',
  107. `{
  108. "name":"${name}",
  109. "layout":"${layout}",
  110. "header":"${header}",
  111. "tabsBar":"${tabsBar}"
  112. }`
  113. )
  114. if (!this.handleIsMobile()) this.changeLayout(layout)
  115. this.changeHeader(header)
  116. this.changeTabsBar(tabsBar)
  117. document.getElementsByTagName(
  118. 'body'
  119. )[0].className = `vue-admin-beautiful-theme-${name}`
  120. this.drawerVisible = false
  121. },
  122. handleSaveTheme() {
  123. this.handleSetTheme()
  124. },
  125. handleSetDfaultTheme() {
  126. let { name } = this.theme
  127. document
  128. .getElementsByTagName('body')[0]
  129. .classList.remove(`vue-admin-beautiful-theme-${name}`)
  130. localStorage.removeItem('vue-admin-beautiful-theme')
  131. this.$refs['form'].resetFields()
  132. Object.assign(this.$data, this.$options.data())
  133. this.changeHeader(defaultLayout)
  134. this.theme.name = 'default'
  135. this.theme.layout = this.layout
  136. this.theme.header = this.header
  137. this.theme.tabsBar = this.tabsBar
  138. this.drawerVisible = false
  139. location.reload()
  140. },
  141. handleGetCode() {
  142. // const url =
  143. // 'https://github.com/chuzhixin/vue-admin-beautiful/tree/master/src/views'
  144. let path = this.$route.path + '/index.vue'
  145. if (path === '/vab/menu1/menu1-1/menu1-1-1/index.vue') {
  146. path = '/vab/nested/menu1/menu1-1/menu1-1-1/index.vue'
  147. }
  148. if (path === '/vab/icon/awesomeIcon/index.vue') {
  149. path = '/vab/icon/index.vue'
  150. }
  151. if (path === '/vab/icon/remixIcon/index.vue') {
  152. path = '/vab/icon/remixIcon.vue'
  153. }
  154. if (path === '/vab/icon/colorfulIcon/index.vue') {
  155. path = '/vab/icon/colorfulIcon.vue'
  156. }
  157. if (path === '/vab/table/comprehensiveTable/index.vue') {
  158. path = '/vab/table/index.vue'
  159. }
  160. if (path === '/vab/table/inlineEditTable/index.vue') {
  161. path = '/vab/table/inlineEditTable.vue'
  162. }
  163. window.open(url + path)
  164. },
  165. },
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. @mixin right-bar {
  170. position: fixed;
  171. right: 0;
  172. z-index: $base-z-index;
  173. width: 60px;
  174. min-height: 60px;
  175. text-align: center;
  176. cursor: pointer;
  177. background: $base-color-blue;
  178. border-radius: $base-border-radius;
  179. >div {
  180. padding-top: 10px;
  181. border-bottom: 0 !important;
  182. &:hover {
  183. opacity: 0.9;
  184. }
  185. &+div {
  186. border-top: 1px solid $base-color-white;
  187. }
  188. p {
  189. padding: 0;
  190. margin: 0;
  191. font-size: $base-font-size-small;
  192. line-height: 30px;
  193. color: $base-color-white;
  194. }
  195. }
  196. }
  197. .theme-bar-setting {
  198. @include right-bar;
  199. top: calc((100vh - 110px) / 2);
  200. ::v-deep {
  201. svg:not(:root).svg-inline--fa {
  202. display: block;
  203. margin-right: auto;
  204. margin-left: auto;
  205. color: $base-color-white;
  206. }
  207. .svg-icon {
  208. display: block;
  209. margin-right: auto;
  210. margin-left: auto;
  211. font-size: 20px;
  212. color: $base-color-white;
  213. fill: $base-color-white;
  214. }
  215. }
  216. }
  217. .el-drawer__body {
  218. padding: 20px;
  219. }
  220. .el-drawer__footer {
  221. border-top: 1px solid #dedede;
  222. position: fixed;
  223. bottom: 0;
  224. width: 100%;
  225. padding: 10px 0 0 20px;
  226. height: 50px;
  227. }
  228. </style>
  229. <style lang="scss">
  230. .el-drawer__wrapper {
  231. outline: none !important;
  232. * {
  233. outline: none !important;
  234. }
  235. }
  236. .vab-color-picker {
  237. .el-color-dropdown__link-btn {
  238. display: none;
  239. }
  240. }
  241. </style>