Navbar.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div>
  3. <el-menu class="navbar"
  4. mode="horizontal">
  5. <hamburger :toggle-click="toggleSideBar"
  6. :is-active="sidebar.opened"
  7. class="hamburger-container" />
  8. <breadcrumb />
  9. <el-dropdown class="avatar-container"
  10. trigger="click">
  11. <div class="avatar-wrapper">
  12. <i class="icon iconfont iconyonghu user" />
  13. <span class="user-name">{{ operator }}</span>
  14. <i class="el-icon-caret-bottom" />
  15. </div>
  16. <el-dropdown-menu slot="dropdown"
  17. class="user-dropdown">
  18. <el-dropdown-item divided>
  19. <span style="display:block;"
  20. @click="logout">注销登录</span>
  21. </el-dropdown-item>
  22. </el-dropdown-menu>
  23. </el-dropdown>
  24. </el-menu>
  25. </div>
  26. </template>
  27. <script>
  28. import { mapGetters } from 'vuex'
  29. import Breadcrumb from '@/components/Breadcrumb'
  30. import Hamburger from '@/components/Hamburger'
  31. import { getItem, delItem, getStorageItem } from '@/utils/storage'
  32. import { aesEncrypt } from '@/utils/aes'
  33. import { reqUpdatePassword } from '@/api/login'
  34. export default {
  35. data () {
  36. // 确认密码
  37. var validatePass3 = (rule, value, callback) => {
  38. if (value === '') {
  39. callback(new Error('请再次输入密码'))
  40. } else if (value !== this.form.password) {
  41. callback(new Error('两次输入密码不一致!'))
  42. } else {
  43. callback()
  44. }
  45. }
  46. // const validatePass = (rule, value, callback) => {
  47. // if (!/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{6,}$/.test(value)) {
  48. // callback(new Error('请按要求输入密码'))
  49. // } else {
  50. // callback()
  51. // }
  52. // };
  53. const validateOldPass = (rule, value, callback) => {
  54. if (value.length < 6 || value.length > 30) {
  55. callback(new Error('请输入原密码'))
  56. } else {
  57. callback()
  58. }
  59. }
  60. return {
  61. wordVisible: false, //修改密码弹框
  62. form: {
  63. oldPassword: '',
  64. password: '',
  65. confirmPassword: '',
  66. },
  67. rules: {
  68. oldPassword: [
  69. { required: true, validator: validateOldPass, trigger: 'blur' },
  70. ],
  71. password: [
  72. { required: true, message: '请选择新密码', trigger: 'blur' },
  73. ],
  74. confirmPassword: [
  75. { required: true, validator: validatePass3, trigger: 'blur' },
  76. ],
  77. },
  78. }
  79. },
  80. components: {
  81. Breadcrumb,
  82. Hamburger,
  83. },
  84. computed: {
  85. ...mapGetters(['sidebar']),
  86. },
  87. created () { },
  88. methods: {
  89. toggleSideBar () {
  90. this.$store.dispatch('ToggleSideBar')
  91. },
  92. logout () {
  93. this.$confirm('确定要退出吗', '温馨提示', {
  94. confirmButtonText: '确定',
  95. cancelButtonText: '取消',
  96. type: 'warning',
  97. }).then(() => {
  98. delItem('token')
  99. sessionStorage.clear()
  100. localStorage.clear()
  101. this.$router.push('/login')
  102. })
  103. },
  104. // 修改密码
  105. updatePassword () {
  106. this.wordVisible = true
  107. this.$nextTick(() => {
  108. this.$refs.form && this.$refs.form.resetFields()
  109. })
  110. },
  111. // 发送请求 确认修改
  112. confrimUpdate () {
  113. this.$refs.form.validate((valid) => {
  114. if (valid) {
  115. const { oldPassword, password, confirmPassword } = this.form
  116. let data = {
  117. oldPassword: aesEncrypt(oldPassword),
  118. password: aesEncrypt(password),
  119. confirmPassword: aesEncrypt(confirmPassword),
  120. }
  121. reqUpdatePassword(data).then((res) => {
  122. if (res.repCode == '0000') {
  123. this.wordVisible = false
  124. this.$message.success('修改密码成功,请重新登录')
  125. sessionStorage.clear()
  126. localStorage.clear()
  127. delItem('token')
  128. this.$router.push('/login')
  129. }
  130. })
  131. } else {
  132. return false
  133. }
  134. })
  135. },
  136. helpCenter () {
  137. let helpCategory = JSON.parse(localStorage.getItem('helpCategory'))
  138. this.$router.push({
  139. path: '/helpCenList/list',
  140. query: {
  141. id: 0,
  142. val: helpCategory[0].value,
  143. title: helpCategory[0].label,
  144. },
  145. })
  146. },
  147. },
  148. }
  149. </script>
  150. <style rel="stylesheet/scss" lang="scss" scoped>
  151. .navbar {
  152. height: 50px;
  153. line-height: 50px;
  154. border-radius: 0px !important;
  155. background: #fff !important;
  156. .hamburger-container {
  157. line-height: 57px;
  158. height: 49px;
  159. float: left;
  160. padding: 0 10px;
  161. background: #fff;
  162. }
  163. .screenfull {
  164. position: absolute;
  165. right: 90px;
  166. top: 16px;
  167. color: red;
  168. }
  169. .avatar-container {
  170. height: 50px;
  171. display: inline-block;
  172. position: absolute;
  173. right: 35px;
  174. .avatar-wrapper {
  175. line-height: 50px;
  176. cursor: pointer;
  177. margin-top: 5px;
  178. position: relative;
  179. .user-avatar {
  180. width: 40px;
  181. height: 40px;
  182. border-radius: 10px;
  183. vertical-align: text-bottom;
  184. }
  185. .user-name {
  186. color: #333;
  187. }
  188. .el-icon-caret-bottom {
  189. color: #333;
  190. position: absolute;
  191. right: -20px;
  192. top: 21px;
  193. font-size: 12px;
  194. }
  195. .user {
  196. color: #333;
  197. font-size: 16px;
  198. }
  199. }
  200. }
  201. }
  202. .password-box {
  203. .password-tips {
  204. position: absolute;
  205. right: 0px;
  206. top: 100%;
  207. line-height: 1;
  208. font-size: 13px;
  209. padding-top: 4px;
  210. }
  211. }
  212. .el-popper {
  213. padding: 0;
  214. }
  215. .el-dropdown-menu__item--divided {
  216. margin-top: 0;
  217. }
  218. </style>