index.vue 8.7 KB

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