SettingDrawer.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div class="setting-drawer">
  3. <a-drawer
  4. width="300"
  5. placement="right"
  6. @close="onClose"
  7. :closable="false"
  8. :visible="visible"
  9. style="z-index: 999"
  10. >
  11. <div class="setting-drawer-index-content">
  12. <setting-item title="整体风格设置">
  13. <div class="setting-drawer-index-blockChecbox">
  14. <a-tooltip>
  15. <template slot="title">
  16. 暗色菜单风格
  17. </template>
  18. <div class="setting-drawer-index-blockChecbox-item" @click="handleChange('theme', 'dark')">
  19. <img src="https://gw.alipayobjects.com/zos/rmsportal/LCkqqYNmvBEbokSDscrm.svg" alt="dark">
  20. <div class="setting-drawer-index-selectIcon" v-if="navTheme === 'dark'">
  21. <a-icon type="check"/>
  22. </div>
  23. </div>
  24. </a-tooltip>
  25. <a-tooltip>
  26. <template slot="title">
  27. 亮色菜单风格
  28. </template>
  29. <div class="setting-drawer-index-blockChecbox-item" @click="handleChange('theme', 'light')">
  30. <img src="https://gw.alipayobjects.com/zos/rmsportal/jpRkZQMyYRryryPNtyIC.svg" alt="light">
  31. <div class="setting-drawer-index-selectIcon" v-if="navTheme !== 'dark'">
  32. <a-icon type="check"/>
  33. </div>
  34. </div>
  35. </a-tooltip>
  36. </div>
  37. </setting-item>
  38. <setting-item title="主题色" divider>
  39. <div style="height: 20px">
  40. <a-tooltip class="setting-drawer-theme-color-colorBlock" v-for="(item, index) in colorList" :key="index">
  41. <template slot="title">
  42. {{ item.key }}
  43. </template>
  44. <a-tag :color="item.color" @click="handleChange('primaryColor', item.color)">
  45. <a-icon type="check" v-if="item.color === primaryColor"></a-icon>
  46. </a-tag>
  47. </a-tooltip>
  48. </div>
  49. </setting-item>
  50. <setting-item title="导航模式" divider>
  51. <div class="setting-drawer-index-blockChecbox">
  52. <a-tooltip>
  53. <template slot="title">
  54. 侧边栏导航
  55. </template>
  56. <div class="setting-drawer-index-blockChecbox-item" @click="handleChange('layout', 'sidemenu')">
  57. <img src="https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg" alt="sidemenu">
  58. <div class="setting-drawer-index-selectIcon" v-if="layout === 'sidemenu'">
  59. <a-icon type="check"/>
  60. </div>
  61. </div>
  62. </a-tooltip>
  63. <a-tooltip>
  64. <template slot="title">
  65. 顶部栏导航
  66. </template>
  67. <div class="setting-drawer-index-blockChecbox-item" @click="handleChange('layout', 'topmenu')">
  68. <img src="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" alt="topmenu">
  69. <div class="setting-drawer-index-selectIcon" v-if="layout === 'topmenu'">
  70. <a-icon type="check"/>
  71. </div>
  72. </div>
  73. </a-tooltip>
  74. </div>
  75. <div>
  76. <a-list :split="false">
  77. <a-list-item>
  78. <span>内容区域宽度</span>
  79. <a-tooltip slot="actions">
  80. <template slot="title">
  81. 该设定仅 [顶部栏导航] 时有效
  82. </template>
  83. <a-select size="small" style="width: 80px;" v-model="contentWidth" @change="(value) => handleChange('contentWidth', value)">
  84. <a-select-option value="Fixed" v-if="layout === 'topmenu'">固定</a-select-option>
  85. <a-select-option value="Fluid">流式</a-select-option>
  86. </a-select>
  87. </a-tooltip>
  88. </a-list-item>
  89. <a-list-item>
  90. <span>固定 Header</span>
  91. <a-switch slot="actions" size="small" :checked="fixedHeader" @change="(checked) => handleChange('fixedHeader', checked)" />
  92. </a-list-item>
  93. <a-list-item >
  94. <span :style="{ opacity: layout === 'topmenu' ? 0.5 : 1 }">固定侧边菜单</span>
  95. <a-switch slot="actions" size="small" :disabled="(layout === 'topmenu')" :checked="fixedSidebar" @change="(checked) => handleChange('fixSiderbar', checked)" />
  96. </a-list-item>
  97. <a-list-item>
  98. <span>隐藏 Footer</span>
  99. <a-switch slot="actions" size="small" :defaultChecked="hideFooter" @change="(checked) => handleChange('hideFooter', checked)" />
  100. </a-list-item>
  101. <a-list-item>
  102. <span>多页签模式</span>
  103. <a-switch slot="actions" size="small" :defaultChecked="multiTab" @change="(checked) => handleChange('multiTab', checked)" />
  104. </a-list-item>
  105. </a-list>
  106. </div>
  107. </setting-item>
  108. <setting-item title="表格通用样式" divider>
  109. <div>
  110. <a-list :split="false">
  111. <a-list-item>
  112. <span>表格大小</span>
  113. <a-radio-group slot="actions" :default-value="tableSize" size="small" button-style="solid" @change="(e) => handleChange('tableSize', e.target.value)">
  114. <a-radio-button value="default">
  115. 默认
  116. </a-radio-button>
  117. <a-radio-button value="middle">
  118. 中等
  119. </a-radio-button>
  120. <a-radio-button value="small">
  121. 紧凑
  122. </a-radio-button>
  123. </a-radio-group>
  124. </a-list-item>
  125. <a-list-item>
  126. <span>显示边框</span>
  127. <a-switch slot="actions" size="small" :checked="tableBordered" @change="(checked) => handleChange('tableBordered', checked)" />
  128. </a-list-item>
  129. </a-list>
  130. </div>
  131. </setting-item>
  132. <setting-item title="其他设置" divider>
  133. <div>
  134. <a-list :split="false">
  135. <a-list-item>
  136. <span>色弱模式</span>
  137. <a-switch slot="actions" size="small" :checked="colorWeak" @change="(checked) => handleChange('colorWeak', checked)" />
  138. </a-list-item>
  139. </a-list>
  140. </div>
  141. </setting-item>
  142. <a-button
  143. @click="doCopy"
  144. icon="copy"
  145. block
  146. >拷贝设置</a-button>
  147. </div>
  148. <div class="setting-drawer-index-handle" @click="toggle" slot="handle">
  149. <a-icon type="setting" v-if="!visible"/>
  150. <a-icon type="close" v-else/>
  151. </div>
  152. </a-drawer>
  153. </div>
  154. </template>
  155. <script>
  156. import SettingItem from './SettingItem'
  157. import { updateTheme, updateColorWeak, colorList } from './settingConfig'
  158. import { baseMixin } from '@/store/app-mixin'
  159. import { tableMixin } from '@/store/table-mixin'
  160. export default {
  161. components: {
  162. SettingItem
  163. },
  164. mixins: [baseMixin, tableMixin],
  165. data () {
  166. return {
  167. visible: false,
  168. colorList
  169. }
  170. },
  171. watch: {
  172. },
  173. mounted () {
  174. },
  175. methods: {
  176. handleChange (type, value) {
  177. if (type === 'primaryColor') {
  178. // 更新主色调
  179. updateTheme(value)
  180. }
  181. if (type === 'colorWeak') {
  182. updateColorWeak(value)
  183. }
  184. this.$emit('change', { type, value })
  185. },
  186. showDrawer () {
  187. this.visible = true
  188. },
  189. onClose () {
  190. this.visible = false
  191. },
  192. toggle () {
  193. this.visible = !this.visible
  194. },
  195. doCopy () {
  196. // get current settings from mixin or this.$store.state.app, pay attention to the property name
  197. const text = `export default {
  198. navTheme: '${this.navTheme}', // theme for nav menu
  199. primaryColor: '${this.primaryColor}', // primary color of ant design
  200. layout: '${this.layout}', // nav menu position: sidemenu or topmenu
  201. contentWidth: '${this.contentWidth}', // layout of content: Fluid or Fixed, only works when layout is topmenu
  202. fixedHeader: ${this.fixedHeader}, // sticky header
  203. fixSiderbar: ${this.fixedSidebar}, // sticky siderbar
  204. colorWeak: ${this.colorWeak},
  205. multiTab: ${this.multiTab},
  206. tableSize: '${this.tableSize}',
  207. tableBordered: ${this.tableBordered},
  208. hideFooter: ${this.hideFooter},
  209. title: '两江消防车联网系统',
  210. production: process.env.NODE_ENV === 'production' && process.env.VUE_APP_PREVIEW !== 'true'
  211. }`
  212. this.$copyText(text).then(message => {
  213. console.log('copy', message)
  214. this.$message.success('复制完毕')
  215. }).catch(err => {
  216. console.log('copy.err', err)
  217. this.$message.error('复制失败')
  218. })
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="less" scoped>
  224. .setting-drawer-index-content {
  225. position: relative;
  226. min-height: 100%;
  227. .setting-drawer-index-blockChecbox {
  228. display: flex;
  229. .setting-drawer-index-blockChecbox-item {
  230. margin-right: 16px;
  231. position: relative;
  232. border-radius: 4px;
  233. cursor: pointer;
  234. img {
  235. width: 48px;
  236. }
  237. .setting-drawer-index-selectIcon {
  238. position: absolute;
  239. top: 0;
  240. right: 0;
  241. width: 100%;
  242. padding-top: 15px;
  243. padding-left: 24px;
  244. height: 100%;
  245. color: #1890ff;
  246. font-size: 14px;
  247. font-weight: 700;
  248. }
  249. }
  250. }
  251. .setting-drawer-theme-color-colorBlock {
  252. width: 20px;
  253. height: 20px;
  254. border-radius: 2px;
  255. float: left;
  256. cursor: pointer;
  257. margin-right: 8px;
  258. padding-left: 0px;
  259. padding-right: 0px;
  260. text-align: center;
  261. color: #fff;
  262. font-weight: 700;
  263. i {
  264. font-size: 14px;
  265. }
  266. }
  267. }
  268. .setting-drawer-index-handle {
  269. position: absolute;
  270. top: 240px;
  271. background: #1890ff;
  272. width: 48px;
  273. height: 48px;
  274. right: 300px;
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. cursor: pointer;
  279. pointer-events: auto;
  280. z-index: 1001;
  281. text-align: center;
  282. font-size: 16px;
  283. border-radius: 4px 0 0 4px;
  284. i {
  285. color: rgb(255, 255, 255);
  286. font-size: 20px;
  287. }
  288. }
  289. </style>