UserManage.vue 8.9 KB

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