index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <el-container class="layout-cont">
  3. <el-container :class="[isSider?'openside':'hideside',isMobile ? 'mobile': '']">
  4. <el-row :class="[isShadowBg?'shadowBg':'']" @click.native="changeShadow()"></el-row>
  5. <el-aside class="main-cont main-left">
  6. <div class="tilte">
  7. <img alt class="logoimg" src="~@/assets/nav_logo.png" />
  8. <h2 class="tit-text" v-if="isSider">Gin-Vue-Admin</h2>
  9. </div>
  10. <Aside class="aside" />
  11. </el-aside>
  12. <!-- 分块滑动功能 -->
  13. <el-main class="main-cont main-right">
  14. <transition :duration="{ enter: 800, leave: 100 }" mode="out-in" name="el-fade-in-linear">
  15. <div
  16. :style="{width: `calc(100% - ${isMobile?'0px':isCollapse?'54px':'220px'})`}"
  17. class="topfix"
  18. >
  19. <el-header class="header-cont">
  20. <div @click="totalCollapse" class="menu-total">
  21. <i class="el-icon-s-unfold" v-if="isCollapse"></i>
  22. <i class="el-icon-s-fold" v-else></i>
  23. </div>
  24. <el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
  25. <el-breadcrumb-item
  26. :key="item.path"
  27. v-for="item in matched.slice(1,matched.length)"
  28. >{{item.meta.title}}</el-breadcrumb-item>
  29. </el-breadcrumb>
  30. <div class="fl-right right-box">
  31. <Search />
  32. <Screenfull class="screenfull"></Screenfull>
  33. <el-dropdown>
  34. <span class="header-avatar">
  35. 欢迎您,<CustomPic/>
  36. <span style="margin-left: 5px">{{userInfo.nickName}}</span>
  37. <i class="el-icon-arrow-down"></i>
  38. </span>
  39. <el-dropdown-menu class="dropdown-group" slot="dropdown">
  40. <el-dropdown-item>
  41. <span>
  42. 更多信息
  43. <el-badge is-dot />
  44. </span>
  45. </el-dropdown-item>
  46. <el-dropdown-item @click.native="showPassword=true" icon="el-icon-s-custom">修改密码</el-dropdown-item>
  47. <el-dropdown-item @click.native="toPerson" icon="el-icon-s-custom">个人信息</el-dropdown-item>
  48. <el-dropdown-item @click.native="LoginOut" icon="el-icon-table-lamp">登 出</el-dropdown-item>
  49. </el-dropdown-menu>
  50. </el-dropdown>
  51. </div>
  52. </el-header>
  53. <!-- 当前面包屑用路由自动生成可根据需求修改 -->
  54. <!--
  55. :to="{ path: item.path }" 暂时注释不用-->
  56. <HistoryComponent />
  57. </div>
  58. </transition>
  59. <transition mode="out-in" name="el-fade-in-linear">
  60. <keep-alive>
  61. <router-view class="admin-box" v-if="$route.meta.keepAlive"></router-view>
  62. </keep-alive>
  63. </transition>
  64. <transition mode="out-in" name="el-fade-in-linear">
  65. <router-view class="admin-box" v-if="!$route.meta.keepAlive"></router-view>
  66. </transition>
  67. <BottomInfo />
  68. </el-main>
  69. </el-container>
  70. <el-dialog :visible.sync="showPassword" @close="clearPassword" title="修改密码" width="360px">
  71. <el-form :model="pwdModify" :rules="rules" label-width="80px" ref="modifyPwdForm">
  72. <el-form-item :minlength="6" label="原密码" prop="password">
  73. <el-input show-password v-model="pwdModify.password"></el-input>
  74. </el-form-item>
  75. <el-form-item :minlength="6" label="新密码" prop="newPassword">
  76. <el-input show-password v-model="pwdModify.newPassword"></el-input>
  77. </el-form-item>
  78. <el-form-item :minlength="6" label="确认密码" prop="confirmPassword">
  79. <el-input show-password v-model="pwdModify.confirmPassword"></el-input>
  80. </el-form-item>
  81. </el-form>
  82. <div class="dialog-footer" slot="footer">
  83. <el-button @click="showPassword=false">取 消</el-button>
  84. <el-button @click="savePassword" type="primary">确 定</el-button>
  85. </div>
  86. </el-dialog>
  87. </el-container>
  88. </template>
  89. <script>
  90. import Aside from '@/view/layout/aside'
  91. import HistoryComponent from '@/view/layout/aside/historyComponent/history'
  92. import Screenfull from '@/view/layout/screenfull'
  93. import Search from '@/view/layout/search/search'
  94. import BottomInfo from '@/view/layout/bottomInfo/bottomInfo'
  95. import { mapGetters, mapActions } from 'vuex'
  96. import { changePassword } from '@/api/user'
  97. import CustomPic from '@/components/customPic'
  98. export default {
  99. name: 'Layout',
  100. data() {
  101. return {
  102. show: false,
  103. isCollapse: false,
  104. isSider: true,
  105. isMobile: false,
  106. isShadowBg: false,
  107. showPassword: false,
  108. pwdModify: {},
  109. rules: {
  110. password: [
  111. { required: true, message: '请输入密码', trigger: 'blur' },
  112. { min: 6, message: '最少6个字符', trigger: 'blur' }
  113. ],
  114. newPassword: [
  115. { required: true, message: '请输入新密码', trigger: 'blur' },
  116. { min: 6, message: '最少6个字符', trigger: 'blur' }
  117. ],
  118. confirmPassword: [
  119. { required: true, message: '请输入确认密码', trigger: 'blur' },
  120. { min: 6, message: '最少6个字符', trigger: 'blur' },
  121. {
  122. validator: (rule, value, callback) => {
  123. if (value !== this.pwdModify.newPassword) {
  124. callback(new Error('两次密码不一致'))
  125. } else {
  126. callback()
  127. }
  128. },
  129. trigger: 'blur'
  130. }
  131. ]
  132. },
  133. value: ''
  134. }
  135. },
  136. components: {
  137. Aside,
  138. HistoryComponent,
  139. Screenfull,
  140. Search,
  141. BottomInfo,
  142. CustomPic
  143. },
  144. methods: {
  145. ...mapActions('user', ['LoginOut']),
  146. totalCollapse() {
  147. this.isCollapse = !this.isCollapse
  148. this.isSider = !this.isCollapse
  149. this.isShadowBg = !this.isCollapse
  150. this.$bus.emit('collapse', this.isCollapse)
  151. },
  152. toPerson() {
  153. this.$router.push({ name: 'person' })
  154. },
  155. changeShadow() {
  156. this.isShadowBg = !this.isShadowBg
  157. this.isSider = !!this.isCollapse
  158. this.totalCollapse()
  159. },
  160. savePassword() {
  161. this.$refs.modifyPwdForm.validate(valid => {
  162. if (valid) {
  163. changePassword({
  164. username: this.userInfo.userName,
  165. password: this.pwdModify.password,
  166. newPassword: this.pwdModify.newPassword
  167. }).then(() => {
  168. this.$message.success('修改密码成功!')
  169. this.showPassword = false
  170. })
  171. } else {
  172. return false
  173. }
  174. })
  175. },
  176. clearPassword() {
  177. this.pwdModify = {
  178. password: '',
  179. newPassword: '',
  180. confirmPassword: ''
  181. }
  182. this.$refs.modifyPwdForm.clearValidate()
  183. }
  184. },
  185. computed: {
  186. ...mapGetters('user', ['userInfo']),
  187. title() {
  188. return this.$route.meta.title || '当前页面'
  189. },
  190. matched() {
  191. return this.$route.matched
  192. }
  193. },
  194. mounted() {
  195. let screenWidth = document.body.clientWidth
  196. if (screenWidth < 1000) {
  197. this.isMobile = true
  198. this.isSider = false
  199. this.isCollapse = true
  200. } else if (screenWidth >= 1000 && screenWidth < 1200) {
  201. this.isMobile = false
  202. this.isSider = false
  203. this.isCollapse = true
  204. } else {
  205. this.isMobile = false
  206. this.isSider = true
  207. this.isCollapse = false
  208. }
  209. this.$bus.emit('collapse', this.isCollapse)
  210. this.$bus.emit('mobile', this.isMobile)
  211. window.onresize = () => {
  212. return (() => {
  213. let screenWidth = document.body.clientWidth
  214. if (screenWidth < 1000) {
  215. this.isMobile = true
  216. this.isSider = false
  217. this.isCollapse = true
  218. } else if (screenWidth >= 1000 && screenWidth < 1200) {
  219. this.isMobile = false
  220. this.isSider = false
  221. this.isCollapse = true
  222. } else {
  223. this.isMobile = false
  224. this.isSider = true
  225. this.isCollapse = false
  226. }
  227. this.$bus.emit('collapse', this.isCollapse)
  228. this.$bus.emit('mobile', this.isMobile)
  229. })()
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss">
  235. $headerHigh: 52px;
  236. $mainHight: 100vh;
  237. .dropdown-group {
  238. min-width: 100px;
  239. }
  240. .topfix {
  241. position: fixed;
  242. top: 0;
  243. box-sizing: border-box;
  244. z-index: 999;
  245. }
  246. .admin-box {
  247. min-height: calc(100vh - 240px);
  248. background-color: rgb(255, 255, 255);
  249. margin-top: 100px;
  250. }
  251. .el-scrollbar__wrap {
  252. padding-bottom: 17px;
  253. }
  254. .layout-cont {
  255. .right-box {
  256. text-align: center;
  257. vertical-align: middle;
  258. img {
  259. vertical-align: middle;
  260. border: 1px solid #ccc;
  261. border-radius: 6px;
  262. }
  263. }
  264. .header-cont {
  265. height: $headerHigh !important;
  266. background: #fff;
  267. box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  268. line-height: $headerHigh;
  269. }
  270. .main-cont {
  271. .breadcrumb {
  272. line-height: 48px;
  273. display: inline-block;
  274. padding: 0 24px;
  275. // padding: 6px;
  276. // border-bottom: 1px solid #eee;
  277. }
  278. &.el-main {
  279. overflow: auto;
  280. background: #fff;
  281. // padding: 0px 10px;
  282. // background: #fff;
  283. }
  284. height: $mainHight !important;
  285. overflow: visible;
  286. position: relative;
  287. .menu-total {
  288. // z-index: 5;
  289. // position: absolute;
  290. // top: 10px;
  291. // right: -35px;
  292. margin-left: -10px;
  293. float: left;
  294. margin-top: 10px;
  295. width: 30px;
  296. height: 30px;
  297. line-height: 30px;
  298. font-size: 30px;
  299. // border: 0 solid #ffffff;
  300. // border-radius: 50%;
  301. // background: #fff;
  302. }
  303. .aside {
  304. overflow: auto;
  305. // background: #fff;
  306. &::-webkit-scrollbar {
  307. display: none;
  308. }
  309. }
  310. .el-menu-vertical {
  311. height: calc(100vh - 64px) !important;
  312. visibility: auto;
  313. &:not(.el-menu--collapse) {
  314. width: 220px;
  315. }
  316. }
  317. .el-menu--collapse {
  318. width: 54px;
  319. li {
  320. .el-tooltip,
  321. .el-submenu__title {
  322. padding: 0px 15px !important;
  323. }
  324. }
  325. }
  326. &::-webkit-scrollbar {
  327. display: none;
  328. }
  329. &.main-left {
  330. width: auto !important;
  331. }
  332. &.main-right {
  333. .admin-title {
  334. float: left;
  335. font-size: 16px;
  336. vertical-align: middle;
  337. margin-left: 20px;
  338. img {
  339. vertical-align: middle;
  340. }
  341. &.collapse {
  342. width: 53px;
  343. }
  344. }
  345. }
  346. }
  347. }
  348. .tilte {
  349. background: #001529;
  350. min-height: 64px;
  351. line-height: 64px;
  352. background: #002140;
  353. text-align: center;
  354. .logoimg {
  355. width: 30px;
  356. height: 30px;
  357. vertical-align: middle;
  358. background: #fff;
  359. border-radius: 50%;
  360. padding: 3px;
  361. }
  362. .tit-text {
  363. display: inline-block;
  364. color: #fff;
  365. font-weight: 600;
  366. font-size: 20px;
  367. vertical-align: middle;
  368. }
  369. }
  370. .screenfull {
  371. display: inline-block;
  372. }
  373. .header-avatar{
  374. display: flex;
  375. justify-content: center;
  376. align-items: center;
  377. }
  378. </style>