index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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="nav-wrap">
  10. <el-tooltip content="左侧菜单" placement="bottom">
  11. <div class="item left" @click="handleNavType(1)" :style="{'--theme': theme}" :class="{ activeItem: navType == 1 }">
  12. <b></b><b></b>
  13. </div>
  14. </el-tooltip>
  15. <el-tooltip content="混合菜单" placement="bottom">
  16. <div class="item mix" @click="handleNavType(2)" :style="{'--theme': theme}" :class="{ activeItem: navType == 2 }">
  17. <b></b><b></b>
  18. </div>
  19. </el-tooltip>
  20. <el-tooltip content="顶部菜单" placement="bottom">
  21. <div class="item top" @click="handleNavType(3)" :style="{'--theme': theme}" :class="{ activeItem: navType == 3 }">
  22. <b></b><b></b>
  23. </div>
  24. </el-tooltip>
  25. </div>
  26. <div class="setting-drawer-title">
  27. <h3 class="drawer-title">主题风格设置</h3>
  28. </div>
  29. <div class="setting-drawer-block-checbox">
  30. <div class="setting-drawer-block-checbox-item" @click="handleTheme('theme-dark')">
  31. <img src="@/assets/images/dark.svg" alt="dark">
  32. <div v-if="sideTheme === 'theme-dark'" class="setting-drawer-block-checbox-selectIcon" style="display: block;">
  33. <i aria-label="图标: check" class="anticon anticon-check">
  34. <svg viewBox="64 64 896 896" data-icon="check" width="1em" height="1em" :fill="theme" aria-hidden="true" focusable="false" class="">
  35. <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"/>
  36. </svg>
  37. </i>
  38. </div>
  39. </div>
  40. <div class="setting-drawer-block-checbox-item" @click="handleTheme('theme-light')">
  41. <img src="@/assets/images/light.svg" alt="light">
  42. <div v-if="sideTheme === 'theme-light'" class="setting-drawer-block-checbox-selectIcon" style="display: block;">
  43. <i aria-label="图标: check" class="anticon anticon-check">
  44. <svg viewBox="64 64 896 896" data-icon="check" width="1em" height="1em" :fill="theme" aria-hidden="true" focusable="false" class="">
  45. <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"/>
  46. </svg>
  47. </i>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="drawer-item">
  52. <span>主题颜色</span>
  53. <theme-picker style="float: right;height: 26px;margin: -3px 8px 0 0;" @change="themeChange" />
  54. </div>
  55. </div>
  56. <el-divider/>
  57. <h3 class="drawer-title">系统布局配置</h3>
  58. <div class="drawer-item">
  59. <span>开启 Tags-Views</span>
  60. <el-switch v-model="tagsView" class="drawer-switch" />
  61. </div>
  62. <div class="drawer-item">
  63. <span>持久化标签页</span>
  64. <el-switch v-model="tagsViewPersist" :disabled="!tagsView" class="drawer-switch" />
  65. </div>
  66. <div class="drawer-item">
  67. <span>显示页签图标</span>
  68. <el-switch v-model="tagsIcon" :disabled="!tagsView" class="drawer-switch" />
  69. </div>
  70. <div class="drawer-item">
  71. <span>固定 Header</span>
  72. <el-switch v-model="fixedHeader" class="drawer-switch" />
  73. </div>
  74. <div class="drawer-item">
  75. <span>显示 Logo</span>
  76. <el-switch v-model="sidebarLogo" class="drawer-switch" />
  77. </div>
  78. <div class="drawer-item">
  79. <span>动态标题</span>
  80. <el-switch v-model="dynamicTitle" class="drawer-switch" />
  81. </div>
  82. <div class="drawer-item">
  83. <span>底部版权</span>
  84. <el-switch v-model="footerVisible" class="drawer-switch" />
  85. </div>
  86. <el-divider/>
  87. <el-button size="small" type="primary" plain icon="el-icon-document-add" @click="saveSetting">保存配置</el-button>
  88. <el-button size="small" plain icon="el-icon-refresh" @click="resetSetting">重置配置</el-button>
  89. </div>
  90. </div>
  91. </el-drawer>
  92. </template>
  93. <script>
  94. import ThemePicker from '@/components/ThemePicker'
  95. export default {
  96. components: { ThemePicker },
  97. expose: ['openSetting'],
  98. data() {
  99. return {
  100. theme: this.$store.state.settings.theme,
  101. sideTheme: this.$store.state.settings.sideTheme,
  102. navType: this.$store.state.settings.navType,
  103. showSettings: false
  104. }
  105. },
  106. computed: {
  107. fixedHeader: {
  108. get() {
  109. return this.$store.state.settings.fixedHeader
  110. },
  111. set(val) {
  112. this.$store.dispatch('settings/changeSetting', {
  113. key: 'fixedHeader',
  114. value: val
  115. })
  116. }
  117. },
  118. tagsViewPersist: {
  119. get() {
  120. return this.$store.state.settings.tagsViewPersist
  121. },
  122. set(val) {
  123. this.$store.dispatch('settings/changeSetting', {
  124. key: 'tagsViewPersist',
  125. value: val
  126. })
  127. }
  128. },
  129. tagsView: {
  130. get() {
  131. return this.$store.state.settings.tagsView
  132. },
  133. set(val) {
  134. this.$store.dispatch('settings/changeSetting', {
  135. key: 'tagsView',
  136. value: val
  137. })
  138. }
  139. },
  140. tagsIcon: {
  141. get() {
  142. return this.$store.state.settings.tagsIcon
  143. },
  144. set(val) {
  145. this.$store.dispatch('settings/changeSetting', {
  146. key: 'tagsIcon',
  147. value: val
  148. })
  149. }
  150. },
  151. sidebarLogo: {
  152. get() {
  153. return this.$store.state.settings.sidebarLogo
  154. },
  155. set(val) {
  156. this.$store.dispatch('settings/changeSetting', {
  157. key: 'sidebarLogo',
  158. value: val
  159. })
  160. }
  161. },
  162. dynamicTitle: {
  163. get() {
  164. return this.$store.state.settings.dynamicTitle
  165. },
  166. set(val) {
  167. this.$store.dispatch('settings/changeSetting', {
  168. key: 'dynamicTitle',
  169. value: val
  170. })
  171. this.$store.dispatch('settings/setTitle', this.$store.state.settings.title)
  172. }
  173. },
  174. footerVisible: {
  175. get() {
  176. return this.$store.state.settings.footerVisible
  177. },
  178. set(val) {
  179. this.$store.dispatch('settings/changeSetting', {
  180. key: 'footerVisible',
  181. value: val
  182. })
  183. }
  184. }
  185. },
  186. watch: {
  187. navType: {
  188. handler(val) {
  189. if (val == 1) {
  190. this.$store.dispatch("app/toggleSideBarHide", false)
  191. }
  192. if (val == 2) {
  193. }
  194. if (val == 3) {
  195. this.$store.dispatch("app/toggleSideBarHide", true)
  196. }
  197. if ([1, 3].includes(val)) {
  198. this.$store.commit("SET_SIDEBAR_ROUTERS",this.$store.state.permission.defaultRoutes)
  199. }
  200. },
  201. immediate: true,
  202. deep: true
  203. }
  204. },
  205. methods: {
  206. themeChange(val) {
  207. this.$store.dispatch('settings/changeSetting', {
  208. key: 'theme',
  209. value: val
  210. })
  211. this.theme = val
  212. },
  213. handleTheme(val) {
  214. this.$store.dispatch('settings/changeSetting', {
  215. key: 'sideTheme',
  216. value: val
  217. })
  218. this.sideTheme = val
  219. },
  220. handleNavType(val) {
  221. this.$store.dispatch('settings/changeSetting', {
  222. key: 'navType',
  223. value: val
  224. })
  225. this.navType = val
  226. },
  227. openSetting() {
  228. this.showSettings = true
  229. },
  230. closeSetting(){
  231. this.showSettings = false
  232. },
  233. saveSetting() {
  234. this.$modal.loading("正在保存到本地,请稍候...")
  235. if (!this.tagsViewPersist) {
  236. this.$cache.local.remove('tags-view-visited')
  237. }
  238. this.$cache.local.set(
  239. "layout-setting",
  240. `{
  241. "navType":${this.navType},
  242. "tagsView":${this.tagsView},
  243. "tagsIcon":${this.tagsIcon},
  244. "tagsViewPersist":${this.tagsViewPersist},
  245. "fixedHeader":${this.fixedHeader},
  246. "sidebarLogo":${this.sidebarLogo},
  247. "dynamicTitle":${this.dynamicTitle},
  248. "footerVisible":${this.footerVisible},
  249. "sideTheme":"${this.sideTheme}",
  250. "theme":"${this.theme}"
  251. }`
  252. )
  253. setTimeout(this.$modal.closeLoading(), 1000)
  254. },
  255. resetSetting() {
  256. this.$modal.loading("正在清除设置缓存并刷新,请稍候...")
  257. this.$cache.local.remove('tags-view-visited')
  258. this.$cache.local.remove("layout-setting")
  259. setTimeout("window.location.reload()", 1000)
  260. }
  261. }
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. .setting-drawer-content {
  266. .setting-drawer-title {
  267. margin-bottom: 12px;
  268. color: rgba(0, 0, 0, .85);
  269. font-size: 14px;
  270. line-height: 22px;
  271. font-weight: bold;
  272. }
  273. .setting-drawer-block-checbox {
  274. display: flex;
  275. justify-content: flex-start;
  276. align-items: center;
  277. margin-top: 10px;
  278. margin-bottom: 20px;
  279. .setting-drawer-block-checbox-item {
  280. position: relative;
  281. margin-right: 16px;
  282. border-radius: 2px;
  283. cursor: pointer;
  284. img {
  285. width: 48px;
  286. height: 48px;
  287. }
  288. .setting-drawer-block-checbox-selectIcon {
  289. position: absolute;
  290. top: 0;
  291. right: 0;
  292. width: 100%;
  293. height: 100%;
  294. padding-top: 15px;
  295. padding-left: 24px;
  296. color: #1890ff;
  297. font-weight: 700;
  298. font-size: 14px;
  299. }
  300. }
  301. }
  302. }
  303. .drawer-container {
  304. padding: 20px;
  305. font-size: 14px;
  306. line-height: 1.5;
  307. word-wrap: break-word;
  308. .drawer-title {
  309. margin-bottom: 12px;
  310. color: rgba(0, 0, 0, .85);
  311. font-size: 14px;
  312. line-height: 22px;
  313. }
  314. .drawer-item {
  315. color: rgba(0, 0, 0, .65);
  316. font-size: 14px;
  317. padding: 12px 0;
  318. }
  319. .drawer-switch {
  320. float: right
  321. }
  322. }
  323. // 导航模式
  324. .nav-wrap {
  325. display: flex;
  326. justify-content: flex-start;
  327. align-items: center;
  328. margin-top: 10px;
  329. margin-bottom: 20px;
  330. .activeItem {
  331. border: 2px solid #{'var(--theme)'} !important;
  332. }
  333. .item {
  334. position: relative;
  335. margin-right: 16px;
  336. cursor: pointer;
  337. width: 56px;
  338. height: 48px;
  339. border-radius: 4px;
  340. background: #f0f2f5;
  341. border: 2px solid transparent;
  342. }
  343. .left {
  344. b:first-child {
  345. display: block;
  346. height: 30%;
  347. background: #fff;
  348. }
  349. b:last-child {
  350. width: 30%;
  351. background: #1b2a47;
  352. position: absolute;
  353. height: 100%;
  354. top: 0;
  355. border-radius: 4px 0 0 4px;
  356. }
  357. }
  358. .mix {
  359. b:first-child {
  360. border-radius: 4px 4px 0 0;
  361. display: block;
  362. height: 30%;
  363. background: #1b2a47;
  364. }
  365. b:last-child {
  366. width: 30%;
  367. background: #1b2a47;
  368. position: absolute;
  369. height: 70%;
  370. border-radius: 0 0 0 4px;
  371. }
  372. }
  373. .top {
  374. b:first-child {
  375. display: block;
  376. height: 30%;
  377. background: #1b2a47;
  378. border-radius: 4px 4px 0 0;
  379. }
  380. }
  381. }
  382. </style>