GlobalLayout.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <template>
  2. <a-layout class="layout" :class="[device]">
  3. <template v-if="isSideMenu()">
  4. <a-drawer
  5. v-if="isMobile()"
  6. :wrapClassName="'drawer-sider ' + navTheme"
  7. :closable="false"
  8. :visible="collapsed"
  9. placement="left"
  10. @close="() => this.collapsed = false"
  11. >
  12. <side-menu
  13. :menus="menus"
  14. :theme="navTheme"
  15. :collapsed="false"
  16. :collapsible="true"
  17. mode="inline"
  18. @menuSelect="menuSelect"></side-menu>
  19. </a-drawer>
  20. <side-menu
  21. v-else
  22. mode="inline"
  23. :menus="menus"
  24. :theme="navTheme"
  25. :collapsed="collapsed"
  26. :collapsible="true"></side-menu>
  27. </template>
  28. <!-- 下次优化这些代码 -->
  29. <template v-else>
  30. <a-drawer
  31. v-if="isMobile()"
  32. :wrapClassName="'drawer-sider ' + navTheme"
  33. placement="left"
  34. @close="() => this.collapsed = false"
  35. :closable="false"
  36. :visible="collapsed"
  37. >
  38. <side-menu
  39. :menus="menus"
  40. :theme="navTheme"
  41. :collapsed="false"
  42. :collapsible="true"
  43. mode="inline"
  44. @menuSelect="menuSelect"></side-menu>
  45. </a-drawer>
  46. </template>
  47. <a-layout :class="[layoutMode, `content-width-${contentWidth}`]" :style="{ paddingLeft: contentPaddingLeft, minHeight: '100vh' }">
  48. <!-- layout header -->
  49. <global-header
  50. :mode="layoutMode"
  51. :menus="menus"
  52. :theme="navTheme"
  53. :collapsed="collapsed"
  54. :device="device"
  55. @toggle="toggle"
  56. />
  57. <!-- layout content -->
  58. <a-layout-content :style="{ margin: '24px 24px 0', height: '100%', paddingTop: fixedHeader ? '64px' : '0' }">
  59. <slot></slot>
  60. </a-layout-content>
  61. <!-- layout footer -->
  62. <a-layout-footer style="padding: 0">
  63. <global-footer />
  64. </a-layout-footer>
  65. <setting-drawer></setting-drawer>
  66. </a-layout>
  67. </a-layout>
  68. </template>
  69. <script>
  70. import SideMenu from '@/components/menu/SideMenu'
  71. import GlobalHeader from '@/components/page/GlobalHeader'
  72. import GlobalFooter from '@/components/page/GlobalFooter'
  73. import SettingDrawer from '@/components/setting/SettingDrawer'
  74. import { triggerWindowResizeEvent } from '@/utils/util'
  75. import { mapState, mapActions } from 'vuex'
  76. import { mixin, mixinDevice } from '@/utils/mixin.js'
  77. export default {
  78. name: 'GlobalLayout',
  79. components: {
  80. SideMenu,
  81. GlobalHeader,
  82. GlobalFooter,
  83. SettingDrawer
  84. },
  85. mixins: [mixin, mixinDevice],
  86. data () {
  87. return {
  88. collapsed: false,
  89. menus: []
  90. }
  91. },
  92. computed: {
  93. ...mapState({
  94. // 主路由
  95. mainMenu: state => state.permission.addRouters
  96. }),
  97. contentPaddingLeft () {
  98. if (!this.fixSidebar || this.isMobile()) {
  99. return '0'
  100. }
  101. if (this.sidebarOpened) {
  102. return '256px'
  103. }
  104. return '80px'
  105. }
  106. },
  107. watch: {
  108. sidebarOpened (val) {
  109. console.log('sidebarOpened', val)
  110. this.collapsed = !val
  111. }
  112. },
  113. created () {
  114. this.menus = this.mainMenu.find((item) => item.path === '/').children
  115. this.collapsed = !this.sidebarOpened
  116. },
  117. methods: {
  118. ...mapActions(['setSidebar']),
  119. toggle () {
  120. this.collapsed = !this.collapsed
  121. this.setSidebar(!this.collapsed)
  122. triggerWindowResizeEvent()
  123. },
  124. paddingCalc () {
  125. let left = ''
  126. if (this.sidebarOpened) {
  127. left = this.isDesktop() ? '256px' : '80px'
  128. } else {
  129. left = this.isMobile() && '0' || (this.fixSidebar && '80px' || '0')
  130. }
  131. console.log('left', left)
  132. return left
  133. },
  134. menuSelect () {
  135. if (!this.isDesktop()) {
  136. this.collapsed = false
  137. }
  138. }
  139. }
  140. }
  141. </script>
  142. <style lang="less">
  143. body {
  144. // 打开滚动条固定显示
  145. overflow-y: scroll;
  146. &.colorWeak {
  147. filter: invert(80%);
  148. }
  149. }
  150. .layout.ant-layout {
  151. overflow-x: hidden;
  152. &.mobile,&.tablet {
  153. .ant-layout-content {
  154. .content {
  155. margin: 24px 0 0;
  156. }
  157. }
  158. /**
  159. * ant-table-wrapper
  160. * 覆盖的表格手机模式样式,如果想修改在手机上表格最低宽度,可以在这里改动
  161. */
  162. .ant-table-wrapper {
  163. .ant-table-content {
  164. overflow-y: auto;
  165. }
  166. .ant-table-body {
  167. min-width: 800px;
  168. }
  169. }
  170. .topmenu {
  171. /* 必须为 topmenu 才能启用流式布局 */
  172. &.content-width-Fluid {
  173. .header-index-wide {
  174. margin-left: 0;
  175. }
  176. }
  177. }
  178. }
  179. &.mobile {
  180. .sidemenu {
  181. .ant-header-fixedHeader {
  182. &.ant-header-side-opened, &.ant-header-side-closed {
  183. width: 100%
  184. }
  185. }
  186. }
  187. }
  188. &.ant-layout-has-sider {
  189. flex-direction: row;
  190. }
  191. .trigger {
  192. font-size: 20px;
  193. line-height: 64px;
  194. padding: 0 24px;
  195. cursor: pointer;
  196. transition: color .3s;
  197. &:hover {
  198. background: rgba(0, 0, 0, 0.025);
  199. }
  200. }
  201. .topmenu {
  202. .ant-header-fixedHeader {
  203. position: fixed;
  204. top: 0;
  205. right: 0;
  206. z-index: 9;
  207. width: 100%;
  208. transition: width .2s;
  209. &.ant-header-side-opened {
  210. width: 100%;
  211. }
  212. &.ant-header-side-closed {
  213. width: 100%;
  214. }
  215. }
  216. /* 必须为 topmenu 才能启用流式布局 */
  217. &.content-width-Fluid {
  218. .header-index-wide {
  219. max-width: unset;
  220. margin-left: 24px;
  221. }
  222. .page-header-index-wide {
  223. max-width: unset;
  224. }
  225. }
  226. }
  227. .sidemenu {
  228. .ant-header-fixedHeader {
  229. position: fixed;
  230. top: 0;
  231. right: 0;
  232. z-index: 9;
  233. width: 100%;
  234. transition: width .2s;
  235. &.ant-header-side-opened {
  236. width: calc(100% - 256px)
  237. }
  238. &.ant-header-side-closed {
  239. width: calc(100% - 80px)
  240. }
  241. }
  242. }
  243. .header {
  244. height: 64px;
  245. padding: 0 12px 0 0;
  246. background: #fff;
  247. box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  248. position: relative;
  249. }
  250. .header, .top-nav-header-index {
  251. .user-wrapper {
  252. float: right;
  253. height: 100%;
  254. .action {
  255. cursor: pointer;
  256. padding: 0 12px;
  257. display: inline-block;
  258. transition: all .3s;
  259. height: 100%;
  260. &:hover {
  261. background: rgba(0, 0, 0, 0.025);
  262. }
  263. .avatar {
  264. margin: 20px 8px 20px 0;
  265. color: #1890ff;
  266. background: hsla(0, 0%, 100%, .85);
  267. vertical-align: middle;
  268. }
  269. .icon {
  270. font-size: 16px;
  271. padding: 4px;
  272. }
  273. }
  274. }
  275. &.dark {
  276. .user-wrapper {
  277. .action {
  278. color: rgba(255, 255, 255, 0.85);
  279. &:hover {
  280. background: rgba(255, 255, 255, 0.16);
  281. }
  282. }
  283. }
  284. }
  285. }
  286. &.mobile,&.tablet {
  287. .top-nav-header-index {
  288. .header-index-wide {
  289. .header-index-left {
  290. .trigger {
  291. color: rgba(255, 255, 255, 0.85);
  292. padding: 0 12px;
  293. }
  294. .logo.top-nav-header {
  295. text-align: center;
  296. width: 56px;
  297. line-height: 58px;
  298. }
  299. }
  300. }
  301. &.light {
  302. .header-index-wide {
  303. .header-index-left {
  304. .trigger {
  305. color: rgba(0, 0, 0, 0.65);
  306. }
  307. }
  308. }
  309. //
  310. }
  311. }
  312. }
  313. &.tablet {
  314. // overflow: hidden; text-overflow:ellipsis; white-space: nowrap;
  315. .top-nav-header-index {
  316. .header-index-wide {
  317. .header-index-left {
  318. .logo > a {
  319. overflow: hidden;
  320. text-overflow:ellipsis;
  321. white-space: nowrap;
  322. }
  323. }
  324. }
  325. }
  326. }
  327. .top-nav-header-index {
  328. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  329. position: relative;
  330. transition: background .3s,width .2s;
  331. .header-index-wide {
  332. max-width: 1200px;
  333. margin: auto;
  334. padding-left: 0;
  335. display: flex;
  336. height: 64px;
  337. .ant-menu.ant-menu-horizontal {
  338. border: none;
  339. height: 64px;
  340. line-height: 64px;
  341. }
  342. .header-index-left {
  343. flex: 1 1;
  344. display: flex;
  345. .logo.top-nav-header {
  346. width: 165px;
  347. height: 64px;
  348. position: relative;
  349. line-height: 64px;
  350. transition: all .3s;
  351. overflow: hidden;
  352. img {
  353. display: inline-block;
  354. vertical-align: middle;
  355. height: 32px;
  356. }
  357. h1 {
  358. color: #fff;
  359. display: inline-block;
  360. vertical-align: top;
  361. font-size: 16px;
  362. margin: 0 0 0 12px;
  363. font-weight: 400;
  364. }
  365. }
  366. }
  367. .header-index-right {
  368. float: right;
  369. height: 64px;
  370. overflow: hidden;
  371. }
  372. }
  373. &.light {
  374. background-color: #fff;
  375. .header-index-wide {
  376. .header-index-left {
  377. .logo {
  378. h1 {
  379. color: #002140;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386. // 内容区
  387. .layout-content {
  388. margin: 24px 24px 0px;
  389. height: 100%;
  390. height: 64px;
  391. padding: 0 12px 0 0;
  392. }
  393. }
  394. .topmenu {
  395. .page-header-index-wide {
  396. max-width: 1200px;
  397. margin: 0 auto;
  398. }
  399. }
  400. // drawer-sider 自定义
  401. .ant-drawer.drawer-sider {
  402. .sider {
  403. box-shadow: none;
  404. }
  405. &.dark {
  406. .ant-drawer-content {
  407. background-color: rgb(0, 21, 41);
  408. }
  409. }
  410. &.light {
  411. box-shadow: none;
  412. .ant-drawer-content {
  413. background-color: #fff;
  414. }
  415. }
  416. .ant-drawer-body {
  417. padding: 0
  418. }
  419. }
  420. // 菜单样式
  421. .sider {
  422. box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
  423. position: relative;
  424. z-index: 10;
  425. .ant-layout-sider-children:hover {
  426. overflow-y: auto;
  427. }
  428. &.ant-fixed-sidemenu {
  429. position: fixed;
  430. height: 100%;
  431. }
  432. .logo {
  433. height: 64px;
  434. position: relative;
  435. line-height: 64px;
  436. padding-left: 24px;
  437. -webkit-transition: all .3s;
  438. transition: all .3s;
  439. background: #002140;
  440. overflow: hidden;
  441. img, h1 {
  442. display: inline-block;
  443. vertical-align: middle;
  444. }
  445. img {
  446. height: 32px;
  447. }
  448. h1 {
  449. color: #fff;
  450. font-size: 20px;
  451. margin: 0 0 0 12px;
  452. font-family: "Chinese Quote", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  453. font-weight: 600;
  454. }
  455. }
  456. &.light {
  457. background-color: #fff;
  458. box-shadow: 2px 0px 8px 0px rgba(29, 35, 41, 0.05);
  459. .logo {
  460. background: #fff;
  461. box-shadow: 1px 1px 0px 0px #e8e8e8;
  462. h1 {
  463. color: unset;
  464. }
  465. }
  466. .ant-menu-light {
  467. border-right-color: transparent;
  468. }
  469. }
  470. }
  471. // 外置的样式控制
  472. .user-dropdown-menu {
  473. span {
  474. user-select: none;
  475. }
  476. }
  477. .user-dropdown-menu-wrapper.ant-dropdown-menu {
  478. padding: 4px 0;
  479. .ant-dropdown-menu-item {
  480. width: 160px;
  481. }
  482. .ant-dropdown-menu-item > .anticon:first-child,
  483. .ant-dropdown-menu-item > a > .anticon:first-child,
  484. .ant-dropdown-menu-submenu-title > .anticon:first-child
  485. .ant-dropdown-menu-submenu-title > a > .anticon:first-child {
  486. min-width: 12px;
  487. margin-right: 8px;
  488. }
  489. }
  490. // 数据列表 样式
  491. .table-alert {
  492. margin-bottom: 16px;
  493. }
  494. .table-page-search-wrapper {
  495. .ant-form-inline {
  496. .ant-form-item {
  497. display: flex;
  498. margin-bottom: 24px;
  499. margin-right: 0;
  500. .ant-form-item-control-wrapper {
  501. flex: 1 1;
  502. display: inline-block;
  503. vertical-align: middle;
  504. }
  505. >.ant-form-item-label {
  506. line-height: 32px;
  507. padding-right: 8px;
  508. width: auto;
  509. }
  510. .ant-form-item-control {
  511. height: 32px;
  512. line-height: 32px;
  513. }
  514. }
  515. }
  516. .table-page-search-submitButtons {
  517. display: block;
  518. margin-bottom: 24px;
  519. white-space: nowrap;
  520. }
  521. }
  522. .content {
  523. .table-operator {
  524. margin-bottom: 18px;
  525. button {
  526. margin-right: 8px;
  527. }
  528. }
  529. }
  530. </style>