index.vue 9.6 KB

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