index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. <span class="open-tips" v-if="item.type == 'eth' || item.type == 'tron'">{{$t('userinfo.openingSoon')}}</span>
  38. <div class="fr" v-if="item.account">
  39. <span>{{item.is_visible === 0?$t('userinfo.private'):$t('userinfo.public')}}</span>
  40. <el-switch
  41. v-model="item.is_visible"
  42. :active-value="0"
  43. :inactive-value="1"
  44. @change="hanldeChange(item, $event)"
  45. active-color="#2298f0"
  46. inactive-color="#cbcbcb">
  47. </el-switch>
  48. <div class="btn-unbind" @click.stop="unbindAccount(item.type)">{{$t('userinfo.unbind')}}</div>
  49. </div>
  50. </div>
  51. <p v-if="item.account" class="key">{{item.account}}</p>
  52. <el-button @click="bindAccount(item.type)" :disabled="item.type == 'eth' || item.type == 'tron'" v-else>{{$t('userinfo.bind')}}</el-button>
  53. </div>
  54. </div>
  55. <!-- <button class="send-msg-btn">发消息</button> -->
  56. </div>
  57. </div>
  58. </div>
  59. </transition>
  60. </template>
  61. <script>
  62. import { Button, Message, Switch } from 'element-ui'
  63. import Vue from 'vue'
  64. import { mapState } from 'vuex'
  65. import { bindAccountMixins } from '@/mixins/user'
  66. import { mobileInputBlur } from '@/util/util'
  67. import API from '@/api'
  68. Vue.component(Button.name, Button)
  69. Vue.component(Message.name, Message)
  70. Vue.component(Switch.name, Switch)
  71. export default {
  72. name: 'infoPopup',
  73. mixins: [bindAccountMixins],
  74. data () {
  75. return {
  76. isMe: true,
  77. newNickName: '', // 新用户名
  78. isEditName: false, // 编辑用户名
  79. newUserName: '', // 新@名
  80. isEditIntroduce: false // 编辑简介
  81. }
  82. },
  83. computed: {
  84. ...mapState({
  85. scatter: state => state.scatter,
  86. userInfo: state => state.userInfo
  87. }),
  88. avatarUrl () {
  89. if (/^http/.test(this.userInfo.cover_photo)) return `${this.userInfo.cover_photo}?imageview/0/w/180`
  90. else return this.userInfo.cover_photo
  91. }
  92. },
  93. methods: {
  94. // 账号显示与隐藏
  95. hanldeChange (item, val) {
  96. let type = item.type
  97. API.user.setVisible({
  98. type,
  99. is_visible: val
  100. }).then(({ data }) => {
  101. })
  102. },
  103. bindAccount (type) {
  104. switch (type) {
  105. case 'eos':
  106. this.bindEos('eos')
  107. break
  108. case 'tg':
  109. this.bindTg()
  110. break
  111. case 'meetone':
  112. this.bindEos('meetone')
  113. break
  114. }
  115. },
  116. // 编辑用户名昵称
  117. handleEditName () {
  118. mobileInputBlur()
  119. if (this.newNickName === this.userInfo.nick_name) {
  120. this.isEditName = false
  121. return
  122. }
  123. if (this.newNickName.length > 16) {
  124. this.$showTips(this.$t('userinfo.nickTooLong'))
  125. return
  126. }
  127. this.isEditName = false
  128. if (this.newNickName.length) {
  129. API.user.changeNickName({
  130. nick_name: this.newNickName
  131. }).then(({ data }) => {
  132. this.$store.commit('setUserNickName', this.newNickName)
  133. this.$store.commit('updateMemberInfo', {
  134. userId: this.$store.state.userId,
  135. nickName: this.newNickName
  136. })
  137. this.$showTips(this.$t('public.updateSucc'))
  138. })
  139. }
  140. },
  141. // 编辑用户名
  142. handleEditIntroduce () {
  143. mobileInputBlur()
  144. if (this.newUserName === this.userInfo.user_name) {
  145. this.isEditIntroduce = false
  146. return
  147. }
  148. if (!/^[a-zA-Z_0-9]{5,20}$/i.test(this.newUserName)) {
  149. this.$showTips(this.$t('userinfo.wrongPattern'))
  150. return
  151. }
  152. this.isEditIntroduce = false
  153. if (this.newUserName.length) {
  154. API.user.changeUserName({
  155. user_name: this.newUserName
  156. }).then(({ data }) => {
  157. this.$store.commit('setUserUserName', this.newUserName)
  158. this.$store.commit('updateMemberInfo', {
  159. userId: this.$store.state.userId,
  160. userName: this.newUserName
  161. })
  162. this.$showTips(this.$t('public.updateSucc'))
  163. })
  164. }
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. @import "./style.scss";
  171. </style>