topbar.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div class="topbarall flex column">
  3. <div class="flex align-center topbar">
  4. <div class="title">
  5. <i :class="[pageicon, 'iconfont']"></i>
  6. {{pageTitle}}
  7. </div>
  8. <el-dropdown class="ml20">
  9. <span class="el-dropdown-link flex align-center">
  10. {{userName}}
  11. <i class="el-icon-arrow-down el-icon--right"></i>
  12. </span>
  13. <el-dropdown-menu slot="dropdown">
  14. <!-- <el-dropdown-item @click.native="resetPassword">修改密码</el-dropdown-item> -->
  15. <el-dropdown-item @click.native="loginOut">退出</el-dropdown-item>
  16. </el-dropdown-menu>
  17. </el-dropdown>
  18. <!-- 修改密码 -->
  19. <dialog-tel
  20. dialogTitle="修改密码"
  21. :visible.sync="dialogVisible"
  22. @closeDialog="handleClose"
  23. @saveDialog="submit"
  24. dialogWidth="500px"
  25. >
  26. <el-form :model="form" ref="form" label-width="100px">
  27. <el-form-item label="原密码" prop="oldPassword" :rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
  28. <el-input v-model="form.oldPassword" type="password"></el-input>
  29. </el-form-item>
  30. <el-form-item label="新密码" prop="password" :rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
  31. <el-input v-model="form.password" type="password"></el-input>
  32. </el-form-item>
  33. <el-form-item label="请重复密码" prop="copyPassword" :rules="{ required: true, message: '必填项不能为空', trigger: 'blur' }">
  34. <el-input v-model="form.copyPassword" type="password"></el-input>
  35. </el-form-item>
  36. </el-form>
  37. </dialog-tel>
  38. </div>
  39. <div class="line"></div>
  40. </div>
  41. </template>
  42. <script>
  43. import store from '@/store/index'
  44. import dialogTel from '@/components/dialog.vue';
  45. import {
  46. logout
  47. } from "@/api/login";
  48. export default {
  49. name: "index",
  50. computed:{
  51. pageTitle() {
  52. if(store.getters?.getMenuInfo?.meta?.title){
  53. return store.getters.getMenuInfo.meta.title
  54. }else{
  55. return '商品管理'
  56. }
  57. },
  58. pageicon() {
  59. if(store.getters?.getMenuInfo?.meta?.icon){
  60. return store.getters.getMenuInfo.meta.icon
  61. }else{
  62. return "icon-shangpinguanli"
  63. }
  64. },
  65. userName(){
  66. if(store.getters?.getUserInfo?.name){
  67. return store.getters.getUserInfo.name
  68. }else{
  69. return "admin"
  70. }
  71. }
  72. },
  73. components: {
  74. dialogTel
  75. },
  76. data() {
  77. return {
  78. dialogVisible: false,
  79. loginUser: null,
  80. form:{
  81. oldPassword: '',
  82. password: ''
  83. },
  84. };
  85. },
  86. created() {
  87. if(localStorage.getItem("loginUser")){
  88. this.loginUser = JSON.parse(localStorage.getItem("loginUser"));
  89. }
  90. },
  91. methods: {
  92. // 退出
  93. loginOut(){
  94. logout().then(()=>{
  95. this.$router.push('/');
  96. store.commit('CLEAR')
  97. })
  98. },
  99. // 修改密码
  100. resetPassword(){
  101. this.dialogVisible = true;
  102. this.form = {
  103. oldPassword: '',
  104. password: ''
  105. }
  106. },
  107. checkPassWord(pass){
  108. var ls = 0;
  109. if(pass.match(/([a-z])+/)){
  110. ls++;
  111. }
  112. if(pass.match(/([0-9])+/)){
  113. ls++;
  114. }
  115. if(pass.match(/([A-Z])+/)){
  116. ls++;
  117. }
  118. if(pass.match(/[^a-zA-Z0-9]+/)){
  119. ls++;
  120. }
  121. return ls;
  122. },
  123. validate(){
  124. if(!this.form.oldPassword){
  125. this.$message.closeAll();
  126. this.$message.warning('原密码不能为空!');
  127. return;
  128. }
  129. if(!this.form.password){
  130. this.$message.closeAll();
  131. this.$message.warning('新密码不能为空!');
  132. return;
  133. }
  134. if(this.checkPassWord(this.form.password) < 3){
  135. this.$message.closeAll();
  136. this.$message.warning('新密码需包含大小写、数字,请重新设置!');
  137. return;
  138. }
  139. if(this.form.password.length > 20 || this.form.password.length < 6){
  140. this.$message.closeAll();
  141. this.$message.warning('新密码长度为6-20位,请重新设置!');
  142. return;
  143. }
  144. if(this.form.password === this.form.oldPassword){
  145. this.$message.closeAll();
  146. this.$message.warning('新密码不可以与原密码相同!');
  147. return;
  148. }
  149. if(this.form.password != this.form.copyPassword){
  150. this.$message.closeAll();
  151. this.$message.warning('新密码与重复密码不一致!');
  152. return;
  153. }
  154. return true;
  155. },
  156. // 取消设置密码
  157. handleClose(){
  158. this.dialogVisible = false;
  159. },
  160. // 确定设置密码
  161. submit(){
  162. this.$refs.form.validate((valid) => {
  163. if (valid) {
  164. if(this.validate()){
  165. let params = {
  166. oldPassword: this.form.oldPassword,
  167. password: this.form.password,
  168. }
  169. // resetPwd(params).then(response => {
  170. // if(response.code == 200){
  171. // this.$router.push('/');
  172. // this.$message.closeAll();
  173. // this.$message.success('修改成功');
  174. // this.dialogVisible = false;
  175. // localStorage.removeItem('loginUser');
  176. // localStorage.removeItem('token');
  177. // localStorage.removeItem('status');
  178. // }
  179. // });
  180. }
  181. }
  182. });
  183. }
  184. }
  185. };
  186. </script>
  187. <style lang="less" scoped>
  188. .topbarall{
  189. background:white;
  190. }
  191. .line{
  192. background:#DEDEDE;
  193. height: 1px;
  194. width: 100%;
  195. margin-top: 20px;
  196. }
  197. .topbar{
  198. background: #fff;
  199. font-size:14px;
  200. color: #333;
  201. justify-content: space-between;
  202. align-items: center;
  203. padding: 20px 15px 0px 0;
  204. .title{
  205. color: #ababab;
  206. }
  207. .iconfont{
  208. margin-right: 5px;
  209. font-size: 22px;
  210. margin-left: 20px;
  211. }
  212. &>*{
  213. cursor:pointer;
  214. }
  215. a{
  216. color: #333;
  217. text-decoration: none;
  218. }
  219. }
  220. </style>