SettingDrawer.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div class="setting-drawer">
  3. <a-drawer
  4. width="300"
  5. placement="right"
  6. :closable="false"
  7. @close="onClose"
  8. :visible="visible"
  9. :style="{}"
  10. >
  11. <div class="setting-drawer-index-content">
  12. <div :style="{ marginBottom: '24px' }">
  13. <h3 class="setting-drawer-index-title">整体风格设置</h3>
  14. <div class="setting-drawer-index-blockChecbox">
  15. <div class="setting-drawer-index-item" @click="changeMenuTheme('dark')">
  16. <img src="https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg" alt="dark">
  17. <div class="setting-drawer-index-selectIcon" v-if="theme === 'dark'">
  18. <a-icon type="check"/>
  19. </div>
  20. </div>
  21. <div class="setting-drawer-index-item" @click="changeMenuTheme('light')">
  22. <img src="https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg" alt="light">
  23. <div class="setting-drawer-index-selectIcon" v-if="theme !== 'dark'">
  24. <a-icon type="check"/>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <div :style="{ marginBottom: '24px' }">
  30. <h3 class="setting-drawer-index-title">主题色</h3>
  31. <div>
  32. <a-tooltip class="setting-drawer-theme-color-colorBlock" v-for="(item, index) in colorList" :key="index">
  33. <template slot='title'>
  34. {{ item.key }}
  35. </template>
  36. <a-tag :color="item.color" @click="changeColor(item)">
  37. <a-icon type="check" v-if="item.color === colorObj.color"></a-icon>
  38. </a-tag>
  39. </a-tooltip>
  40. </div>
  41. </div>
  42. </div>
  43. <div class="setting-drawer-index-handle" @click="toggle">
  44. <a-icon type="setting" v-if="!visible"/>
  45. <a-icon type="close" v-else/>
  46. </div>
  47. </a-drawer>
  48. </div>
  49. </template>
  50. <script>
  51. import DetailList from '@/components/tools/DetailList'
  52. import config from '@/defaultConfig'
  53. import { updateTheme } from '@/components/tools/setting'
  54. import { mapState } from 'vuex'
  55. const colorList = [
  56. {
  57. key: 'dust',
  58. color: '#F5222D',
  59. },
  60. {
  61. key: 'volcano',
  62. color: '#FA541C',
  63. },
  64. {
  65. key: 'sunset',
  66. color: '#FAAD14',
  67. },
  68. {
  69. key: 'cyan',
  70. color: '#13C2C2',
  71. },
  72. {
  73. key: 'green',
  74. color: '#52C41A',
  75. },
  76. {
  77. key: 'daybreak',
  78. color: '#1890FF',
  79. },
  80. {
  81. key: 'geekblue',
  82. color: '#2F54EB',
  83. },
  84. {
  85. key: 'purple',
  86. color: '#722ED1',
  87. },
  88. ];
  89. export default {
  90. components: {
  91. DetailList
  92. },
  93. data() {
  94. return {
  95. visible: true,
  96. colorList,
  97. }
  98. },
  99. computed: {
  100. ...mapState({
  101. theme: state => state.app.theme,
  102. colorObj: state => state.app.color,
  103. })
  104. },
  105. mounted () {
  106. const vm = this
  107. setTimeout(() => {
  108. vm.visible = false
  109. }, 1)
  110. // 当主题色不是默认色时,才进行主题编译
  111. if (this.colorObj.color !== config.color.color) {
  112. updateTheme(this.colorObj.color)
  113. }
  114. },
  115. methods: {
  116. showDrawer() {
  117. this.visible = true
  118. },
  119. onClose() {
  120. this.visible = false
  121. },
  122. toggle() {
  123. this.visible = !this.visible
  124. },
  125. changeMenuTheme(theme) {
  126. this.$store.dispatch('ToggleTheme', theme)
  127. },
  128. changeColor(color) {
  129. if (this.colorObj.color !== color.color) {
  130. this.$store.dispatch('ToggleColor', color)
  131. updateTheme(color.color)
  132. }
  133. }
  134. },
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .setting-drawer-index-content {
  139. .setting-drawer-index-title {
  140. font-size: 14px;
  141. color: rgba(0, 0, 0, .85);
  142. line-height: 22px;
  143. margin-bottom: 12px;
  144. }
  145. .setting-drawer-index-blockChecbox {
  146. display: flex;
  147. .setting-drawer-index-item {
  148. margin-right: 16px;
  149. position: relative;
  150. border-radius: 4px;
  151. cursor: pointer;
  152. img {
  153. width: 48px;
  154. }
  155. .setting-drawer-index-selectIcon {
  156. position: absolute;
  157. top: 0;
  158. right: 0;
  159. width: 100%;
  160. padding-top: 15px;
  161. padding-left: 24px;
  162. height: 100%;
  163. color: #1890ff;
  164. font-size: 14px;
  165. font-weight: 700;
  166. }
  167. }
  168. }
  169. .setting-drawer-theme-color-colorBlock {
  170. width: 20px;
  171. height: 20px;
  172. border-radius: 2px;
  173. float: left;
  174. cursor: pointer;
  175. margin-right: 8px;
  176. padding-left: 0px;
  177. padding-right: 0px;
  178. text-align: center;
  179. color: #fff;
  180. font-weight: 700;
  181. i {
  182. font-size: 14px;
  183. }
  184. }
  185. }
  186. .setting-drawer-index-handle {
  187. position: absolute;
  188. top: 240px;
  189. background: #1890ff;
  190. width: 48px;
  191. height: 48px;
  192. right: 300px;
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. cursor: pointer;
  197. pointer-events: auto;
  198. z-index: 1001;
  199. text-align: center;
  200. font-size: 16px;
  201. border-radius: 4px 0 0 4px;
  202. i {
  203. color: rgb(255, 255, 255);
  204. font-size: 20px;
  205. }
  206. }
  207. </style>