index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="userInfo.cover_photo" :src="userInfo.cover_photo" 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 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. },
  88. methods: {
  89. // 账号显示与隐藏
  90. hanldeChange (item, val) {
  91. let type = item.type
  92. API.user.setVisible({
  93. type,
  94. is_visible: val
  95. }).then(({ data }) => {
  96. })
  97. },
  98. bindAccount (type) {
  99. switch (type) {
  100. case 'eos':
  101. this.bindEos()
  102. break
  103. case 'tg':
  104. this.bindTg()
  105. break
  106. }
  107. },
  108. // 编辑用户名昵称
  109. handleEditName () {
  110. if (this.newNickName === this.userInfo.nick_name) {
  111. this.isEditName = false
  112. return
  113. }
  114. if (this.newNickName.length > 16) {
  115. this.$showTips(this.$t('userinfo.nickTooLong'))
  116. return
  117. }
  118. this.isEditName = false
  119. if (this.newNickName.length) {
  120. API.user.changeNickName({
  121. nick_name: this.newNickName
  122. }).then(({ data }) => {
  123. this.$store.commit('setUserNickName', this.newNickName)
  124. this.$store.commit('updateMemberNickName', {
  125. userId: this.$store.state.userId,
  126. nickName: this.newNickName
  127. })
  128. this.$showTips(this.$t('public.updateSucc'))
  129. })
  130. }
  131. },
  132. // 编辑用户名
  133. handleEditIntroduce () {
  134. if (this.newUserName === this.userInfo.user_name) {
  135. this.isEditIntroduce = false
  136. return
  137. }
  138. if (!/^[a-zA-Z_0-9]{5,20}$/i.test(this.newUserName)) {
  139. this.$showTips(this.$t('userinfo.wrongPattern'))
  140. return
  141. }
  142. this.isEditIntroduce = false
  143. if (this.newUserName.length) {
  144. API.user.changeUserName({
  145. user_name: this.newUserName
  146. }).then(({ data }) => {
  147. this.$store.commit('setUserUserName', this.newUserName)
  148. this.$store.commit('updateMemberNickName', {
  149. userId: this.$store.state.userId,
  150. userName: this.newUserName
  151. })
  152. this.$showTips(this.$t('public.updateSucc'))
  153. })
  154. }
  155. }
  156. }
  157. }
  158. </script>
  159. <style lang="scss" scoped>
  160. @import "./style.scss";
  161. </style>