UserManage.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <div>
  3. <div v-if="!changePsd">
  4. <div class="accountmanage-tittle">
  5. <p>账号管理</p>
  6. </div>
  7. <div class="accountmanage-content">
  8. <div class="changeheader flex justify-center relative" >
  9. <span >
  10. <img @mouseover="showEdit = true" @mouseout = "showEdit = false" class="cursor-pointer userManageAvatarUrl" :src="userInfo.avatarUrl">
  11. </span>
  12. <div class="absolute headers" v-show="showEdit">
  13. <span class="absolute z-1"><img src="~/assets/images/common/edit.png"></span>
  14. <input type="file" accept="image/*" class="cursor-pointer left z-10 w-64px h-64px rounded-35px bg-[#000] opacity-0" title="请选择合适图片"
  15. @change="addFile($event)" @mouseover="showEdit = true" @mouseout = "showEdit = false">
  16. </div>
  17. </div>
  18. <div class="row-name">
  19. <span>昵称</span>
  20. <input v-model="username" @blur="handlerChangeUserName">
  21. <!-- <p class="err-prompt">用户名已经存在</p> -->
  22. </div>
  23. <div class="changepwd" @click="changepwdModal()">
  24. 修改密码
  25. </div>
  26. </div>
  27. </div>
  28. <div v-else>
  29. <div class="accountmanage-tittle">
  30. <p>修改密码</p>
  31. </div>
  32. <div class="login_content changepwd-content">
  33. <input v-model="form.password" class="login_input_password" type="password" placeholder="原始密码" @input="changeErr" @keydown.enter="vailidate">
  34. <br/>
  35. <input v-model="form.newPassword" class="login_input_password new" type="password" placeholder="新密码(6-16个字符,区分大小写)" @keydown="keydown($event)" @input="changeErr" @keydown.enter="vailidate">
  36. <br/>
  37. <input v-model="form.newPasswordConfirm" class="login_input_password confirm" type="password" placeholder="确认新密码" @keydown="keydown($event)" @input="changeErr" @keydown.enter="vailidate">
  38. <br/>
  39. <div v-show="isRight">
  40. <div class="error-mess error-mess-signup mb-5px" >
  41. <span id="error-message error-tip ">{{errMsg}}</span>
  42. </div>
  43. </div>
  44. <button class="logging" @click="vailidate">确认</button>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import { Message } from 'element-ui';
  51. import { mapState } from 'vuex'
  52. export default {
  53. data() {
  54. return {
  55. changePsd: false,
  56. username: "",
  57. form: {
  58. password:'',
  59. newPassword: '',
  60. newPasswordConfirm:''
  61. },
  62. errMsg:'',
  63. isRight: false,
  64. showEdit: false
  65. }
  66. },
  67. watch:{
  68. dialogVisiable(){
  69. this.isRight = false
  70. this.errMsg = ''
  71. }
  72. },
  73. computed:{
  74. ...mapState(["userInfo"])
  75. },
  76. methods: {
  77. // 点击注册前置校验
  78. vailidate() {
  79. const reg = new RegExp(/\s/)
  80. if(this.form.newPassword !== this.form.newPasswordConfirm) {
  81. this.isRight=true
  82. this.errMsg = '密码不一致'
  83. }else if(this.form.newPassword.length < 6) {
  84. this.isRight=true
  85. this.errMsg = '密码位数不能少于6位'
  86. }else if(this.form.newPassword.length> 16){
  87. this.isRight=true
  88. this.errMsg = '密码位数不能大于16位'
  89. }else if(reg.test(this.form.newPassword)){
  90. this.isRight=true
  91. this.errMsg = '新密码中不能存在空格'
  92. }else {
  93. this.errMsg = ''
  94. this.handlerResetPsw()
  95. }
  96. },
  97. handlerResetPsw() {
  98. this.$axios.post('members/modifyPassword', this.form).then((res)=> {
  99. if(res.code === 200) {
  100. // console.log(this.form)
  101. this.$emit('close')
  102. this.isRight = false
  103. this.errMsg = ''
  104. }else{
  105. this.isRight = true
  106. this.errMsg = res.data.msg
  107. }
  108. })
  109. },
  110. changepwdModal() {
  111. this.changePsd = true
  112. },
  113. handlerChangeUserName() {
  114. this.$axios.get(`/members/modifyNickname?name=${this.username}`).then((res)=> {
  115. if(res.code === 200) {
  116. this.getUserInfo()
  117. }else{
  118. Message.error(res.data.msg)
  119. this.getUserInfo()
  120. this.username = this.$store.state.userInfo.name
  121. }
  122. })
  123. },
  124. getUserInfo() {
  125. this.$axios.get('members/getMemberInfo').then((res)=> {
  126. if(res.code === 200) {
  127. this.$store.commit('setUser',res.result.memberInfo)
  128. }
  129. })
  130. },
  131. resetInterfaceStatus() {
  132. this.changePsd = false
  133. this.form.password = ''
  134. this.form.newPassword = ''
  135. this.form.newPasswordConfirm = ''
  136. },
  137. //不允许输入空格
  138. keydown(event){
  139. if(event.keyCode == 32){
  140. event.returnValue = false
  141. this.errMsg = '请勿输入空格'
  142. this.isRight = true
  143. }
  144. },
  145. changeErr(){
  146. this.errMsg = ''
  147. this.isRight = false
  148. },
  149. //上传图片
  150. addFile(event){
  151. const formData = new FormData()
  152. formData.append("file",event.target.files[0])
  153. this.$axios.post('avatar/picUpload',formData).then((res)=> {
  154. if(res.code === 200) {
  155. this.getUserInfo()
  156. }
  157. })
  158. }
  159. },
  160. props:["dialogVisiable"],
  161. mounted() {
  162. this.username = this.$store.state.userInfo.name
  163. },
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .accountmanage-tittle {
  168. color: rgb(255, 79, 79);
  169. text-align: center;
  170. margin: 0;
  171. p {
  172. font-size: 20px;
  173. line-height: 64px;
  174. }
  175. }
  176. .accountmanage-content {
  177. .changeheader {
  178. text-align: center;
  179. margin: 0 24px;
  180. span img {
  181. width: 64px;
  182. border-radius: 35px;
  183. }
  184. .userManageAvatarUrl{
  185. object-fit: cover;
  186. width: 64px;
  187. height: 64px;
  188. display: inline-block;
  189. border: none;
  190. border-radius: 35px;
  191. }
  192. .headers {
  193. width: 64px;
  194. height: 64px;
  195. // margin: 0 24px;
  196. padding-bottom: 24px;
  197. display:flex;
  198. justify-content:center;
  199. align-items:center;
  200. border-radius: 35px;
  201. background: #979797cc;
  202. img {
  203. width: 20px;
  204. margin-top: 22px;
  205. border-radius: 35px;
  206. }
  207. }
  208. }
  209. .row-name {
  210. border-top: 1px solid rgb(240, 240, 240);
  211. margin: 0 24px;
  212. height: 64px;
  213. line-height: 64px;
  214. position: relative;
  215. margin-top: 25px;
  216. span {
  217. color: rgb(153, 153, 153);
  218. font-size: 14px;
  219. float: left;
  220. width: 10%;
  221. }
  222. input {
  223. width: 88%;
  224. float: right;
  225. height: 50px;
  226. line-height: 30px;
  227. text-align: right;
  228. border: 0px;
  229. margin-top: 12px;
  230. border: none;
  231. outline: medium;
  232. &:focus {
  233. text-align: right;
  234. border: 1px;
  235. }
  236. }
  237. p {
  238. position: absolute;
  239. right: 0px;
  240. bottom: 0px;
  241. height: 20px;
  242. width: 100%;
  243. color: rgb(255, 79, 79);
  244. font-size: 14px;
  245. line-height: 20px;
  246. text-align: right;
  247. display: none;
  248. }
  249. }
  250. .changepwd {
  251. color: rgba(0, 0, 0, 0.4);
  252. height: 64px;
  253. font-size: 14px;
  254. cursor:pointer;
  255. margin: 0 24px;
  256. line-height: 64px;
  257. border-top: 1px solid rgb(240, 240, 240);
  258. background: url(http://cn-file.17pdf.com/website/account/ic_cebian_normal.png) right 50% no-repeat;
  259. }
  260. }
  261. // .changepwd-content {
  262. // margin: 20px 0px;
  263. // }
  264. .login_content {
  265. text-align: center;
  266. font-size: 14px;
  267. .error-mess {
  268. position: relative;
  269. font-size: 14px;
  270. // display: none;
  271. span{
  272. display: inline-block;
  273. background: #808080;
  274. color: rgb(255, 255, 255);
  275. padding: 5px 15px;
  276. border-radius: 4px;
  277. }
  278. }
  279. .error-mess-signup {
  280. position: initial;
  281. clear: both;
  282. margin-top: 15px;
  283. }
  284. .login_input_password {
  285. height: 60px;
  286. width: 360px;
  287. border-width: 0 0 1px 0;
  288. border-color: rgb(238, 238, 238);
  289. padding-left: 42px;
  290. padding-top: 16px;
  291. line-height: 44px;
  292. outline:none;
  293. background: url(http://cn-file.17pdf.com/website/account/ic_login_inputpassword.png) no-repeat 0px 28px;
  294. &.new {
  295. background: url(http://cn-file.17pdf.com/website/account/ic_lock_new.png) no-repeat 0px 28px;
  296. }
  297. &.confirm {
  298. background: url(http://cn-file.17pdf.com/website/account/ic_lock_sure.png) no-repeat 0px 28px;
  299. }
  300. }
  301. .login_input_password:-webkit-autofill {
  302. box-shadow: 0 0 0px 1000px white inset;
  303. }
  304. .logging {
  305. width: 360px;
  306. height: 48px;
  307. font-size: 16px;
  308. color: rgb(255, 255, 255);
  309. border: none;
  310. background-color: rgb(255, 79, 79);
  311. margin-bottom: 40px;
  312. border-radius: 4px;
  313. outline:none;
  314. }
  315. }
  316. </style>