index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <transition name="msgbox-fade">
  3. <div class="pub-wrapper" v-if="visible">
  4. <div class="pub-mask"></div>
  5. <div class="pub-modal avater-modal">
  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>
  49. </div>
  50. <p v-if="item.account" class="key">{{item.account}}</p>
  51. <el-button @click="bindAccount(item.type)" :disabled="item.type == 'eth' || item.type == 'tron'" 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 API from '@/api'
  65. Vue.component(Button.name, Button)
  66. Vue.component(Message.name, Message)
  67. Vue.component(Switch.name, Switch)
  68. export default {
  69. name: 'infoPopup',
  70. data () {
  71. return {
  72. isMe: true,
  73. newNickName: '', // 新用户名
  74. isEditName: false, // 编辑用户名
  75. newUserName: '', // 新@名
  76. isEditIntroduce: false // 编辑简介
  77. }
  78. },
  79. computed: {
  80. ...mapState({
  81. userInfo: state => {
  82. return state.userInfo
  83. }
  84. })
  85. },
  86. methods: {
  87. // 账号显示与隐藏
  88. hanldeChange (item, val) {
  89. let type = item.type
  90. API.user.setVisible({
  91. type,
  92. is_visible: val
  93. }).then(({ data }) => {
  94. })
  95. },
  96. bindAccount (type) {
  97. },
  98. // 编辑用户名昵称
  99. handleEditName () {
  100. if (this.newNickName === this.userInfo.nick_name) {
  101. this.isEditName = false
  102. return
  103. }
  104. if (this.newNickName.length > 16) {
  105. this.$showTips(this.$t('userinfo.nickTooLong'))
  106. return
  107. }
  108. this.isEditName = false
  109. if (this.newNickName.length) {
  110. API.user.changeNickName({
  111. nick_name: this.newNickName
  112. }).then(({ data }) => {
  113. this.$store.commit('setUserNickName', this.newNickName)
  114. this.$store.commit('updateMemberNickName', {
  115. userId: this.$store.state.userId,
  116. nickName: this.newNickName
  117. })
  118. this.$showTips(this.$t('public.updateSucc'))
  119. })
  120. }
  121. },
  122. // 编辑用户名
  123. handleEditIntroduce () {
  124. if (this.newUserName === this.userInfo.user_name) {
  125. this.isEditIntroduce = false
  126. return
  127. }
  128. if (!/^[a-zA-Z_0-9]{5,20}$/i.test(this.newUserName)) {
  129. this.$showTips(this.$t('userinfo.wrongPattern'))
  130. return
  131. }
  132. this.isEditIntroduce = false
  133. if (this.newUserName.length) {
  134. API.user.changeUserName({
  135. user_name: this.newUserName
  136. }).then(({ data }) => {
  137. this.$store.commit('setUserUserName', this.newUserName)
  138. this.$store.commit('updateMemberNickName', {
  139. userId: this.$store.state.userId,
  140. userName: this.newUserName
  141. })
  142. this.$showTips(this.$t('public.updateSucc'))
  143. })
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss">
  150. @import "./style.scss";
  151. </style>