UserManage.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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=".jpg,.png,.bmp,.jpeg" 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. var file = event.target.files[0];
  154. if (file) {
  155. //判断文件格式
  156. var index= file.name.lastIndexOf(".");//获取最后一个.的位置
  157. var ext = file.name.substr(index+1);//获取后缀
  158. var pattern = /^(jpg|jpeg|png|bmp)$/;
  159. if(!pattern.test(ext)){
  160. Message.error("该图片格式不支持")
  161. return false;
  162. }else{
  163. //判断文件大小
  164. if(file.size > 2*1024*1024){
  165. Message.error("图片不能大于2M")
  166. } else {
  167. this.$axios.post('avatar/picUpload',formData).then((res)=> {
  168. if(res.code === 200) {
  169. this.getUserInfo()
  170. }
  171. })
  172. }
  173. }
  174. }
  175. }
  176. },
  177. props:["dialogVisiable"],
  178. mounted() {
  179. this.username = this.$store.state.userInfo.name
  180. },
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .accountmanage-tittle {
  185. color: rgb(255, 79, 79);
  186. text-align: center;
  187. margin: 0;
  188. p {
  189. font-size: 20px;
  190. line-height: 64px;
  191. }
  192. }
  193. .accountmanage-content {
  194. .changeheader {
  195. text-align: center;
  196. margin: 0 24px;
  197. span img {
  198. width: 64px;
  199. border-radius: 35px;
  200. }
  201. .userManageAvatarUrl{
  202. object-fit: cover;
  203. width: 64px;
  204. height: 64px;
  205. display: inline-block;
  206. border: none;
  207. border-radius: 35px;
  208. }
  209. .headers {
  210. width: 64px;
  211. height: 64px;
  212. // margin: 0 24px;
  213. padding-bottom: 24px;
  214. display:flex;
  215. justify-content:center;
  216. align-items:center;
  217. border-radius: 35px;
  218. background: #979797cc;
  219. img {
  220. width: 20px;
  221. margin-top: 22px;
  222. border-radius: 35px;
  223. }
  224. }
  225. }
  226. .row-name {
  227. border-top: 1px solid rgb(240, 240, 240);
  228. margin: 0 24px;
  229. height: 64px;
  230. line-height: 64px;
  231. position: relative;
  232. margin-top: 25px;
  233. span {
  234. color: rgb(153, 153, 153);
  235. font-size: 14px;
  236. float: left;
  237. width: 10%;
  238. }
  239. input {
  240. width: 88%;
  241. float: right;
  242. height: 50px;
  243. line-height: 30px;
  244. text-align: right;
  245. border: 0px;
  246. margin-top: 12px;
  247. border: none;
  248. outline: medium;
  249. &:focus {
  250. text-align: right;
  251. border: 1px;
  252. }
  253. }
  254. p {
  255. position: absolute;
  256. right: 0px;
  257. bottom: 0px;
  258. height: 20px;
  259. width: 100%;
  260. color: rgb(255, 79, 79);
  261. font-size: 14px;
  262. line-height: 20px;
  263. text-align: right;
  264. display: none;
  265. }
  266. }
  267. .changepwd {
  268. color: rgba(0, 0, 0, 0.4);
  269. height: 64px;
  270. font-size: 14px;
  271. cursor:pointer;
  272. margin: 0 24px;
  273. line-height: 64px;
  274. border-top: 1px solid rgb(240, 240, 240);
  275. background: url(http://cn-file.17pdf.com/website/account/ic_cebian_normal.png) right 50% no-repeat;
  276. }
  277. }
  278. // .changepwd-content {
  279. // margin: 20px 0px;
  280. // }
  281. .login_content {
  282. text-align: center;
  283. font-size: 14px;
  284. .error-mess {
  285. position: relative;
  286. font-size: 14px;
  287. // display: none;
  288. span{
  289. display: inline-block;
  290. background: #808080;
  291. color: rgb(255, 255, 255);
  292. padding: 5px 15px;
  293. border-radius: 4px;
  294. }
  295. }
  296. .error-mess-signup {
  297. position: initial;
  298. clear: both;
  299. margin-top: 15px;
  300. }
  301. .login_input_password {
  302. height: 60px;
  303. width: 360px;
  304. border-width: 0 0 1px 0;
  305. border-color: rgb(238, 238, 238);
  306. padding-left: 42px;
  307. padding-top: 16px;
  308. line-height: 44px;
  309. outline:none;
  310. background: url(http://cn-file.17pdf.com/website/account/ic_login_inputpassword.png) no-repeat 0px 28px;
  311. &.new {
  312. background: url(http://cn-file.17pdf.com/website/account/ic_lock_new.png) no-repeat 0px 28px;
  313. }
  314. &.confirm {
  315. background: url(http://cn-file.17pdf.com/website/account/ic_lock_sure.png) no-repeat 0px 28px;
  316. }
  317. }
  318. .login_input_password:-webkit-autofill {
  319. box-shadow: 0 0 0px 1000px white inset;
  320. }
  321. .logging {
  322. width: 360px;
  323. height: 48px;
  324. font-size: 16px;
  325. color: rgb(255, 255, 255);
  326. border: none;
  327. background-color: rgb(255, 79, 79);
  328. margin-bottom: 40px;
  329. border-radius: 4px;
  330. outline:none;
  331. }
  332. }
  333. </style>