editMe.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <div class="edit-me">
  3. <back-bar title="编辑资料"></back-bar>
  4. <div class="edit-list">
  5. <div class="item avatar-item">
  6. <span class="title">头像</span>
  7. <div class="cont">
  8. <img class="user-avatar" @click="$editUserAvatar(userInfo.cover_photo)" v-if="userInfo.cover_photo" :src="userInfo.cover_photo" alt="">
  9. <div v-else class="user-avatar"
  10. @click="$editUserAvatar"
  11. :class="'avatar_bg' + userInfo.user_id % 9"
  12. :data-name="userInfo.nick_name.slice(0,2).toUpperCase()"
  13. ></div>
  14. <i class="el-icon-arrow-right"></i>
  15. </div>
  16. </div>
  17. <div class="item" @click="editName">
  18. <span class="title">昵称</span>
  19. <span class="cont">
  20. {{userInfo.nick_name}} <i class="el-icon-arrow-right"></i>
  21. </span>
  22. </div>
  23. <div class="item" @click="editUserId">
  24. <span class="title">ID</span>
  25. <span class="cont">
  26. {{userInfo.user_name}}<i class="el-icon-arrow-right"></i>
  27. </span>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import { mapState } from 'vuex'
  34. import backBar from '@/components/backBar'
  35. import API from '@/api'
  36. import { Upload, MessageBox } from 'element-ui'
  37. import Vue from 'vue'
  38. Vue.component(Upload.name, Upload)
  39. export default {
  40. name: 'editMe',
  41. components: {
  42. backBar
  43. },
  44. data () {
  45. return {
  46. }
  47. },
  48. computed: {
  49. ...mapState({
  50. userInfo: state => {
  51. return state.userInfo
  52. }
  53. })
  54. },
  55. methods: {
  56. editName () {
  57. MessageBox.prompt('', '修改昵称', {
  58. confirmButtonText: '确定',
  59. cancelButtonText: '取消',
  60. inputValue: this.userInfo.nick_name
  61. }).then(({ value }) => {
  62. if (value.length) {
  63. API.user.changeNickName({
  64. nick_name: value
  65. }).then(({ data }) => {
  66. this.$store.commit('setUserNickName', value)
  67. this.$store.commit('updateMemberNickName', {
  68. userId: this.$store.state.userId,
  69. nickName: value
  70. })
  71. this.$showTips('修改成功')
  72. })
  73. }
  74. }).catch(() => {
  75. })
  76. },
  77. editUserId () {
  78. MessageBox.prompt('', '修改ID', {
  79. confirmButtonText: '确定',
  80. cancelButtonText: '取消',
  81. inputValue: this.userInfo.user_name,
  82. inputPattern: /^[a-zA-Z_0-9-]{5,36}$/i,
  83. inputErrorMessage: '只能是5-36位数字字母下划线'
  84. }).then(({ value }) => {
  85. if (value.length) {
  86. API.user.changeUserName({
  87. user_name: value
  88. }).then(({ data }) => {
  89. this.$store.commit('setUserUserName', value)
  90. this.$store.commit('updateMemberNickName', {
  91. userId: this.$store.state.userId,
  92. userName: value
  93. })
  94. this.$showTips('修改成功')
  95. })
  96. }
  97. }).catch(() => {
  98. })
  99. }
  100. },
  101. created () {
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .edit-list{
  107. background-color: #ffffff;
  108. .item{
  109. &.avatar-item{
  110. height: px2rem(166);
  111. line-height: px2rem(166);
  112. }
  113. padding: 0 px2rem(20);
  114. height: px2rem(106);
  115. line-height: px2rem(106);
  116. position: relative;
  117. &::after{
  118. content: '';
  119. position: absolute;
  120. height: 1px;
  121. background-color: #d8d8d8;
  122. right: 0;
  123. bottom: 0;
  124. left: px2rem(20);
  125. }
  126. &:last-child{
  127. &::after{
  128. display: none;
  129. }
  130. }
  131. }
  132. .title{
  133. font-size: px2rem(28);
  134. color: #000;
  135. }
  136. .cont{
  137. float: right;
  138. color: #999999;
  139. font-size: px2rem(28);
  140. i{
  141. display: inline-block;
  142. margin-left: px2rem(10);
  143. }
  144. .user-avatar{
  145. width: px2rem(120);
  146. height: px2rem(120);
  147. }
  148. }
  149. }
  150. </style>