UserManage.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. this.$emit('close')
  101. this.isRight = false
  102. this.errMsg = ''
  103. }else{
  104. this.isRight = true
  105. this.errMsg = res.data.msg
  106. }
  107. })
  108. },
  109. changepwdModal() {
  110. this.changePsd = true
  111. },
  112. handlerChangeUserName() {
  113. this.$axios.get(`/members/modifyNickname?name=${this.username}`).then((res)=> {
  114. if(res.code === 200) {
  115. this.getUserInfo()
  116. }else{
  117. Message.error(res.data.msg)
  118. this.getUserInfo()
  119. this.username = this.$store.state.userInfo.name
  120. }
  121. })
  122. },
  123. getUserInfo() {
  124. this.$axios.get('members/getMemberInfo').then((res)=> {
  125. if(res.code === 200) {
  126. this.$store.commit('setUser',res.result.memberInfo)
  127. }
  128. })
  129. },
  130. resetInterfaceStatus() {
  131. this.changePsd = false
  132. this.form.password = ''
  133. this.form.newPassword = ''
  134. this.form.newPasswordConfirm = ''
  135. },
  136. //不允许输入空格
  137. keydown(event){
  138. if(event.keyCode == 32){
  139. event.returnValue = false
  140. this.errMsg = '请勿输入空格'
  141. this.isRight = true
  142. }
  143. },
  144. changeErr(){
  145. this.errMsg = ''
  146. this.isRight = false
  147. },
  148. //上传图片
  149. addFile(event){
  150. const formData = new FormData()
  151. formData.append("file",event.target.files[0])
  152. var file = event.target.files[0];
  153. if (file) {
  154. //判断文件格式
  155. var ext = file.type;
  156. var pattern = /(jpg|jpeg|png|bmp)$/;
  157. if(!pattern.test(ext)){
  158. Message.error("该图片格式不支持")
  159. return false;
  160. }else{
  161. //判断文件大小
  162. if(file.size > 2*1024*1024){
  163. Message.error("图片不能大于2M")
  164. } else {
  165. this.$axios.post('avatar/picUpload',formData).then((res)=> {
  166. if(res.code === 200) {
  167. this.getUserInfo()
  168. }
  169. })
  170. }
  171. }
  172. }
  173. }
  174. },
  175. props:["dialogVisiable"],
  176. mounted() {
  177. this.username = this.$store.state.userInfo.name
  178. },
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .accountmanage-tittle {
  183. color: rgb(255, 79, 79);
  184. text-align: center;
  185. margin: 0;
  186. p {
  187. font-size: 20px;
  188. line-height: 64px;
  189. }
  190. }
  191. .accountmanage-content {
  192. .changeheader {
  193. text-align: center;
  194. margin: 0 24px;
  195. span img {
  196. width: 64px;
  197. border-radius: 35px;
  198. }
  199. .userManageAvatarUrl{
  200. object-fit: cover;
  201. width: 64px;
  202. height: 64px;
  203. display: inline-block;
  204. border: none;
  205. border-radius: 35px;
  206. }
  207. .headers {
  208. width: 64px;
  209. height: 64px;
  210. // margin: 0 24px;
  211. padding-bottom: 24px;
  212. display:flex;
  213. justify-content:center;
  214. align-items:center;
  215. border-radius: 35px;
  216. background: #979797cc;
  217. img {
  218. width: 20px;
  219. margin-top: 22px;
  220. border-radius: 35px;
  221. }
  222. }
  223. }
  224. .row-name {
  225. border-top: 1px solid rgb(240, 240, 240);
  226. margin: 0 24px;
  227. height: 64px;
  228. line-height: 64px;
  229. position: relative;
  230. margin-top: 25px;
  231. span {
  232. color: rgb(153, 153, 153);
  233. font-size: 14px;
  234. float: left;
  235. width: 10%;
  236. }
  237. input {
  238. width: 88%;
  239. float: right;
  240. height: 50px;
  241. line-height: 30px;
  242. text-align: right;
  243. border: 0px;
  244. margin-top: 12px;
  245. border: none;
  246. outline: medium;
  247. &:focus {
  248. text-align: right;
  249. border: 1px;
  250. }
  251. }
  252. p {
  253. position: absolute;
  254. right: 0px;
  255. bottom: 0px;
  256. height: 20px;
  257. width: 100%;
  258. color: rgb(255, 79, 79);
  259. font-size: 14px;
  260. line-height: 20px;
  261. text-align: right;
  262. display: none;
  263. }
  264. }
  265. .changepwd {
  266. color: rgba(0, 0, 0, 0.4);
  267. height: 64px;
  268. font-size: 14px;
  269. cursor:pointer;
  270. margin: 0 24px;
  271. line-height: 64px;
  272. border-top: 1px solid rgb(240, 240, 240);
  273. background: url(http://cn-file.17pdf.com/website/account/ic_cebian_normal.png) right 50% no-repeat;
  274. }
  275. }
  276. // .changepwd-content {
  277. // margin: 20px 0px;
  278. // }
  279. .login_content {
  280. text-align: center;
  281. font-size: 14px;
  282. .error-mess {
  283. position: relative;
  284. font-size: 14px;
  285. // display: none;
  286. span{
  287. display: inline-block;
  288. background: #808080;
  289. color: rgb(255, 255, 255);
  290. padding: 5px 15px;
  291. border-radius: 4px;
  292. }
  293. }
  294. .error-mess-signup {
  295. position: initial;
  296. clear: both;
  297. margin-top: 15px;
  298. }
  299. .login_input_password {
  300. height: 60px;
  301. width: 360px;
  302. border-width: 0 0 1px 0;
  303. border-color: rgb(238, 238, 238);
  304. padding-left: 42px;
  305. padding-top: 16px;
  306. line-height: 44px;
  307. outline:none;
  308. background: url(http://cn-file.17pdf.com/website/account/ic_login_inputpassword.png) no-repeat 0px 28px;
  309. &.new {
  310. background: url(http://cn-file.17pdf.com/website/account/ic_lock_new.png) no-repeat 0px 28px;
  311. }
  312. &.confirm {
  313. background: url(http://cn-file.17pdf.com/website/account/ic_lock_sure.png) no-repeat 0px 28px;
  314. }
  315. }
  316. .login_input_password:-webkit-autofill {
  317. box-shadow: 0 0 0px 1000px white inset;
  318. }
  319. .logging {
  320. width: 360px;
  321. height: 48px;
  322. font-size: 16px;
  323. color: rgb(255, 255, 255);
  324. border: none;
  325. background-color: rgb(255, 79, 79);
  326. margin-bottom: 40px;
  327. border-radius: 4px;
  328. outline:none;
  329. }
  330. }
  331. </style>