index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <transition name="msgbox-fade">
  3. <div class="pub-wrapper" v-if="visible">
  4. <div class="pub-mask" @click="visible = false"></div>
  5. <div class="pub-modal avater-modal" v-loading="isLoading">
  6. <div class="modal-hd">
  7. <i class="el-icon-close" @click="visible = false"></i>
  8. </div>
  9. <div class="modal-bd" v-if="userInfo">
  10. <div class="user-top">
  11. <div class="user-avatar" @click="$editUserAvatar(userInfo.cover_photo)">
  12. <img v-if="avatarUrl" :src="avatarUrl" alt="">
  13. <div v-else class="user-avatar"
  14. :class="'avatar_bg' + userInfo.user_id % 9"
  15. :data-name="userInfo.nick_name.slice(0,2).toUpperCase()"
  16. ></div>
  17. <p>{{$t('userinfo.changePhoto')}}</p>
  18. </div>
  19. <div class="r-info">
  20. <span class="name" v-if="!isEditName" @click="isEditName = true;newNickName = userInfo.nick_name">{{userInfo.nick_name}} <i class="el-icon-edit"></i></span>
  21. <input class="edit-name-input" type="text" v-else
  22. v-model="newNickName"
  23. v-focus
  24. @blur="handleEditName">
  25. <div class="introduce" v-if="!isEditIntroduce" @click="isEditIntroduce = true;newUserName = userInfo.user_name">@{{userInfo.user_name}} <i class="el-icon-edit"></i></div>
  26. <input class="edit-name-input" type="text" v-else
  27. v-model="newUserName"
  28. v-focus
  29. @blur="handleEditIntroduce">
  30. </div>
  31. </div>
  32. <div class="account-wrap">
  33. <div class="title">{{$t('userinfo.bindAccounts')}}</div>
  34. <div class="account-item" v-for="(item, key) in userInfo.binds" :key="key">
  35. <div class="type">
  36. <strong>{{item.type.toUpperCase()}}</strong>
  37. <div class="fr" v-if="item.account">
  38. <span>{{item.is_visible === 0?$t('userinfo.private'):$t('userinfo.public')}}</span>
  39. <el-switch
  40. v-model="item.is_visible"
  41. :active-value="0"
  42. :inactive-value="1"
  43. @change="hanldeChange(item, $event)"
  44. active-color="#2298f0"
  45. inactive-color="#cbcbcb">
  46. </el-switch>
  47. <div class="btn-unbind" @click.stop="unbindAccount(item.type)">{{$t('userinfo.unbind')}}</div>
  48. </div>
  49. </div>
  50. <p v-if="item.account" class="key">{{item.account}}</p>
  51. <el-button @click="bindAccount(item.type)" v-else>{{$t('userinfo.bind')}}</el-button>
  52. </div>
  53. </div>
  54. <!-- <button class="send-msg-btn">发消息</button> -->
  55. </div>
  56. </div>
  57. </div>
  58. </transition>
  59. </template>
  60. <script>
  61. import { Button, Message, Switch } from 'element-ui'
  62. import Vue from 'vue'
  63. import { mapState } from 'vuex'
  64. import { bindAccountMixins } from '@/mixins/user'
  65. import { mobileInputBlur } from '@/util/util'
  66. import API from '@/api'
  67. Vue.component(Button.name, Button)
  68. Vue.component(Message.name, Message)
  69. Vue.component(Switch.name, Switch)
  70. export default {
  71. name: 'infoPopup',
  72. mixins: [bindAccountMixins],
  73. data () {
  74. return {
  75. isMe: true,
  76. newNickName: '', // 新用户名
  77. isEditName: false, // 编辑用户名
  78. newUserName: '', // 新@名
  79. isEditIntroduce: false // 编辑简介
  80. }
  81. },
  82. computed: {
  83. ...mapState({
  84. scatter: state => state.scatter,
  85. userInfo: state => state.userInfo
  86. }),
  87. avatarUrl () {
  88. if (/^http/.test(this.userInfo.cover_photo)) return `${this.userInfo.cover_photo}?imageview/0/w/180`
  89. else return this.userInfo.cover_photo
  90. }
  91. },
  92. methods: {
  93. // 账号显示与隐藏
  94. hanldeChange (item, val) {
  95. let type = item.type
  96. API.user.setVisible({
  97. type,
  98. is_visible: val
  99. }).then(({ data }) => {
  100. })
  101. },
  102. // 编辑用户名昵称
  103. handleEditName () {
  104. mobileInputBlur()
  105. if (this.newNickName === this.userInfo.nick_name) {
  106. this.isEditName = false
  107. return
  108. }
  109. if (this.newNickName.length > 16) {
  110. this.$showTips(this.$t('userinfo.nickTooLong'))
  111. return
  112. }
  113. this.isEditName = false
  114. if (this.newNickName.length) {
  115. API.user.changeNickName({
  116. nick_name: this.newNickName
  117. }).then(({ data }) => {
  118. this.$store.commit('setUserNickName', this.newNickName)
  119. this.$store.commit('updateMemberInfo', {
  120. userId: this.$store.state.userId,
  121. nickName: this.newNickName
  122. })
  123. this.$showTips(this.$t('public.updateSucc'))
  124. })
  125. }
  126. },
  127. // 编辑用户名
  128. handleEditIntroduce () {
  129. mobileInputBlur()
  130. if (this.newUserName === this.userInfo.user_name) {
  131. this.isEditIntroduce = false
  132. return
  133. }
  134. if (!/^[a-zA-Z_0-9]{5,20}$/i.test(this.newUserName)) {
  135. this.$showTips(this.$t('userinfo.wrongPattern'))
  136. return
  137. }
  138. this.isEditIntroduce = false
  139. if (this.newUserName.length) {
  140. API.user.changeUserName({
  141. user_name: this.newUserName
  142. }).then(({ data }) => {
  143. this.$store.commit('setUserUserName', this.newUserName)
  144. this.$store.commit('updateMemberInfo', {
  145. userId: this.$store.state.userId,
  146. userName: this.newUserName
  147. })
  148. this.$showTips(this.$t('public.updateSucc'))
  149. })
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. @import "./style.scss";
  157. </style>