cf1c71eb7334f2a216c71589583a131e7786d853.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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="height: 100%;overflow: auto;"
  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. <a-tooltip>
  16. <template slot="title">
  17. 暗色菜单风格
  18. </template>
  19. <div class="setting-drawer-index-item" @click="handleMenuTheme('dark')">
  20. <img src="https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg" alt="dark">
  21. <div class="setting-drawer-index-selectIcon" v-if="navTheme === 'dark'">
  22. <a-icon type="check"/>
  23. </div>
  24. </div>
  25. </a-tooltip>
  26. <a-tooltip>
  27. <template slot="title">
  28. 亮色菜单风格
  29. </template>
  30. <div class="setting-drawer-index-item" @click="handleMenuTheme('light')">
  31. <img src="https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg" alt="light">
  32. <div class="setting-drawer-index-selectIcon" v-if="navTheme !== 'dark'">
  33. <a-icon type="check"/>
  34. </div>
  35. </div>
  36. </a-tooltip>
  37. </div>
  38. </div>
  39. <div :style="{ marginBottom: '24px' }">
  40. <h3 class="setting-drawer-index-title">主题色</h3>
  41. <div style="height: 20px">
  42. <a-tooltip class="setting-drawer-theme-color-colorBlock" v-for="(item, index) in colorList" :key="index">
  43. <template slot="title">
  44. {{ item.key }}
  45. </template>
  46. <a-tag :color="item.color" @click="changeColor(item.color)">
  47. <a-icon type="check" v-if="item.color === primaryColor"></a-icon>
  48. </a-tag>
  49. </a-tooltip>
  50. </div>
  51. </div>
  52. <a-divider />
  53. <div :style="{ marginBottom: '24px' }">
  54. <h3 class="setting-drawer-index-title">导航模式</h3>
  55. <div class="setting-drawer-index-blockChecbox">
  56. <a-tooltip>
  57. <template slot="title">
  58. 侧边栏导航
  59. </template>
  60. <div class="setting-drawer-index-item" @click="handleLayout('sidemenu')">
  61. <img src="https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg" alt="sidemenu">
  62. <div class="setting-drawer-index-selectIcon" v-if="layoutMode === 'sidemenu'">
  63. <a-icon type="check"/>
  64. </div>
  65. </div>
  66. </a-tooltip>
  67. <a-tooltip>
  68. <template slot="title">
  69. 顶部栏导航
  70. </template>
  71. <div class="setting-drawer-index-item" @click="handleLayout('topmenu')">
  72. <img src="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" alt="topmenu">
  73. <div class="setting-drawer-index-selectIcon" v-if="layoutMode !== 'sidemenu'">
  74. <a-icon type="check"/>
  75. </div>
  76. </div>
  77. </a-tooltip>
  78. </div>
  79. <div :style="{ marginTop: '24px' }">
  80. <a-list :split="false">
  81. <a-list-item>
  82. <a-tooltip slot="actions">
  83. <template slot="title">
  84. 该设定仅 [顶部栏导航] 时有效
  85. </template>
  86. <a-select size="small" style="width: 80px;" :defaultValue="contentWidth" @change="handleContentWidthChange">
  87. <a-select-option value="Fixed">固定</a-select-option>
  88. <a-select-option value="Fluid" v-if="layoutMode !== 'sidemenu'">流式</a-select-option>
  89. </a-select>
  90. </a-tooltip>
  91. <a-list-item-meta>
  92. <div slot="title">内容区域宽度</div>
  93. </a-list-item-meta>
  94. </a-list-item>
  95. <a-list-item>
  96. <a-switch slot="actions" size="small" :defaultChecked="fixedHeader" @change="handleFixedHeader" />
  97. <a-list-item-meta>
  98. <div slot="title">固定 Header</div>
  99. </a-list-item-meta>
  100. </a-list-item>
  101. <a-list-item>
  102. <a-switch slot="actions" size="small" :disabled="!fixedHeader" :defaultChecked="autoHideHeader" @change="handleFixedHeaderHidden" />
  103. <a-list-item-meta>
  104. <div slot="title" :style="{ textDecoration: !fixedHeader ? 'line-through' : 'unset' }">下滑时隐藏 Header</div>
  105. </a-list-item-meta>
  106. </a-list-item>
  107. <a-list-item>
  108. <a-switch slot="actions" size="small" :disabled="(layoutMode === 'topmenu')" :checked="dataFixSiderbar" @change="handleFixSiderbar" />
  109. <a-list-item-meta>
  110. <div slot="title" :style="{ textDecoration: layoutMode === 'topmenu' ? 'line-through' : 'unset' }">固定侧边菜单</div>
  111. </a-list-item-meta>
  112. </a-list-item>
  113. </a-list>
  114. </div>
  115. </div>
  116. <a-divider />
  117. <div :style="{ marginBottom: '24px' }">
  118. <h3 class="setting-drawer-index-title">其他设置</h3>
  119. <div>
  120. <a-list :split="false">
  121. <a-list-item>
  122. <a-switch slot="actions" size="small" :defaultChecked="colorWeak" @change="onColorWeak" />
  123. <a-list-item-meta>
  124. <div slot="title">色弱模式</div>
  125. </a-list-item-meta>
  126. </a-list-item>
  127. <a-list-item>
  128. <a-switch slot="actions" size="small" :defaultChecked="multipage" @change="onMultipageWeak" />
  129. <a-list-item-meta>
  130. <div slot="title">多页签模式</div>
  131. </a-list-item-meta>
  132. </a-list-item>
  133. </a-list>
  134. </div>
  135. </div>
  136. <a-divider />
  137. <div :style="{ marginBottom: '24px' }">
  138. <a-alert type="warning">
  139. <span slot="message">
  140. 配置栏只在开发环境用于预览,生产环境不会展现,请手动修改配置文件
  141. <a href="https://github.com/sendya/ant-design-pro-vue/blob/master/src/defaultSettings.js" target="_blank">src/defaultSettings.js</a>
  142. </span>
  143. </a-alert>
  144. </div>
  145. </div>
  146. <div class="setting-drawer-index-handle" @click="toggle" v-if="visible">
  147. <!-- <a-icon type="setting" v-if="!visible"/>-->
  148. <!-- <a-icon type="close" v-else/>-->
  149. <a-icon type="close" />
  150. </div>
  151. </a-drawer>
  152. </div>
  153. </template>
  154. <script>
  155. import DetailList from '@/components/tools/DetailList'
  156. import SettingItem from '@/components/setting/SettingItem'
  157. import config from '@/defaultSettings'
  158. import { updateTheme, updateColorWeak, colorList } from '@/components/tools/setting'
  159. import { mixin, mixinDevice } from '@/utils/mixin.js'
  160. import { triggerWindowResizeEvent } from '@/utils/util'
  161. export default {
  162. components: {
  163. DetailList,
  164. SettingItem
  165. },
  166. mixins: [mixin, mixinDevice],
  167. data() {
  168. return {
  169. visible: false,
  170. colorList,
  171. dataFixSiderbar: false
  172. }
  173. },
  174. mounted () {
  175. // 当主题色不是默认色时,才进行主题编译
  176. if (this.primaryColor !== config.primaryColor) {
  177. updateTheme(this.primaryColor)
  178. }
  179. if (this.colorWeak !== config.colorWeak) {
  180. updateColorWeak(this.colorWeak)
  181. }
  182. if (this.multipage !== config.multipage) {
  183. this.$store.dispatch('ToggleMultipage', this.multipage)
  184. }
  185. },
  186. methods: {
  187. showDrawer() {
  188. this.visible = true
  189. },
  190. onClose() {
  191. this.visible = false
  192. },
  193. toggle() {
  194. this.visible = !this.visible
  195. },
  196. onColorWeak (checked) {
  197. this.$store.dispatch('ToggleWeak', checked)
  198. updateColorWeak(checked)
  199. },
  200. onMultipageWeak (checked) {
  201. this.$store.dispatch('ToggleMultipage', checked)
  202. },
  203. handleMenuTheme (theme) {
  204. this.$store.dispatch('ToggleTheme', theme)
  205. },
  206. handleLayout (mode) {
  207. this.$store.dispatch('ToggleLayoutMode', mode)
  208. // 因为顶部菜单不能固定左侧菜单栏,所以强制关闭
  209. this.handleFixSiderbar(false)
  210. // 触发窗口resize事件
  211. triggerWindowResizeEvent()
  212. },
  213. handleContentWidthChange (type) {
  214. this.$store.dispatch('ToggleContentWidth', type)
  215. },
  216. changeColor (color) {
  217. if (this.primaryColor !== color) {
  218. this.$store.dispatch('ToggleColor', color)
  219. updateTheme(color)
  220. }
  221. },
  222. handleFixedHeader (fixed) {
  223. this.$store.dispatch('ToggleFixedHeader', fixed)
  224. },
  225. handleFixedHeaderHidden (autoHidden) {
  226. this.$store.dispatch('ToggleFixedHeaderHidden', autoHidden)
  227. },
  228. handleFixSiderbar (fixed) {
  229. if (this.layoutMode === 'topmenu') {
  230. fixed = false
  231. }
  232. this.dataFixSiderbar = fixed
  233. this.$store.dispatch('ToggleFixSiderbar', fixed)
  234. }
  235. },
  236. }
  237. </script>
  238. <style lang="less" scoped>
  239. .setting-drawer-index-content {
  240. .setting-drawer-index-blockChecbox {
  241. display: flex;
  242. .setting-drawer-index-item {
  243. margin-right: 16px;
  244. position: relative;
  245. border-radius: 4px;
  246. cursor: pointer;
  247. img {
  248. width: 48px;
  249. }
  250. .setting-drawer-index-selectIcon {
  251. position: absolute;
  252. top: 0;
  253. right: 0;
  254. width: 100%;
  255. padding-top: 15px;
  256. padding-left: 24px;
  257. height: 100%;
  258. color: #1890ff;
  259. font-size: 14px;
  260. font-weight: 700;
  261. }
  262. }
  263. }
  264. .setting-drawer-theme-color-colorBlock {
  265. width: 20px;
  266. height: 20px;
  267. border-radius: 2px;
  268. float: left;
  269. cursor: pointer;
  270. margin-right: 8px;
  271. padding-left: 0px;
  272. padding-right: 0px;
  273. text-align: center;
  274. color: #fff;
  275. font-weight: 700;
  276. i {
  277. font-size: 14px;
  278. }
  279. }
  280. }
  281. .setting-drawer-index-handle {
  282. position: absolute;
  283. top: 240px;
  284. background: #1890ff;
  285. width: 48px;
  286. height: 48px;
  287. right: 300px;
  288. display: flex;
  289. justify-content: center;
  290. align-items: center;
  291. cursor: pointer;
  292. pointer-events: auto;
  293. z-index: 1001;
  294. text-align: center;
  295. font-size: 16px;
  296. border-radius: 4px 0 0 4px;
  297. i {
  298. color: rgb(255, 255, 255);
  299. font-size: 20px;
  300. }
  301. }
  302. </style>