user.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { mapState, mapActions } from 'vuex'
  2. import API from '@/api'
  3. import User from '@/store/db/User.js'
  4. import { getMeechatType } from '@/util/util'
  5. export const otherInfoMixins = {
  6. data () {
  7. return {
  8. accountList: null,
  9. userInfo: null,
  10. meechatType: getMeechatType()// meechat版本
  11. }
  12. },
  13. computed: {
  14. ...mapState({
  15. members: state => state.group.members,
  16. groupId: state => state.group.groupId,
  17. sessionList: state => state.chat.sessionList,
  18. meId: state => state.userId,
  19. meInfo: state => state.userInfo
  20. }),
  21. linkToOther () {
  22. let youId = this.userInfo.user_id
  23. let sessionId = Number(youId) < Number(this.meId) ? `${youId}-${this.meId}` : `${this.meId}-${youId}`
  24. return `${location.origin}/#/pm/${sessionId}`
  25. }
  26. },
  27. methods: {
  28. ...mapActions(['getUserInfo']),
  29. sendMsg () {
  30. this.visible = false
  31. let youId = this.userInfo.user_id
  32. let sessionId = Number(youId) < Number(this.meId)
  33. ? `${youId}-${this.meId}`
  34. : `${this.meId}-${youId}`
  35. let repeatFlag = this.sessionList.some(e => {
  36. return e.session_id == sessionId
  37. })
  38. if (!repeatFlag) {
  39. let obj = {
  40. cover_photo: this.userInfo.cover_photo,
  41. is_group: '0',
  42. name: this.userInfo.nick_name,
  43. // read_hash:null
  44. session_id: sessionId
  45. }
  46. this.$store.commit('addSessionItem', obj)
  47. }
  48. // 创建members,应对还没聊天记录的情况
  49. let myId = this.meInfo.user_id
  50. let members = {}
  51. members[myId] = {
  52. cover_photo: this.meInfo.cover_photo,
  53. nick_name: this.meInfo.nick_name
  54. }
  55. members[this.userInfo.user_id] = {
  56. cover_photo: this.userInfo.cover_photo,
  57. nick_name: this.userInfo.nick_name
  58. }
  59. this.$store.commit('updateGroup', {
  60. key: 'members',
  61. data: members
  62. })
  63. this.$store.commit('updateGroup', {
  64. key: 'privateName',
  65. data: this.userInfo.nick_name
  66. })
  67. this.$router.push({ path: `/pm/${sessionId}` })
  68. }
  69. },
  70. async created () {
  71. if (!this.meInfo) {
  72. await this.getUserInfo()
  73. }
  74. API.user.getOtherInfo({
  75. target_id: this.userId,
  76. group_id: this.groupId || null
  77. }).then(({ data }) => {
  78. this.accountList = data.data.binds
  79. this.userInfo = data.data
  80. this.visible = true
  81. if (data.data.user_id) {
  82. // 更新他人的信息
  83. let objUser = new User()
  84. let newData = {
  85. cover_photo: data.data.cover_photo,
  86. nick_name: data.data.nick_name,
  87. user_name: data.data.user_name
  88. }
  89. objUser.updateObject(newData, { user_id: data.data.user_id })
  90. }
  91. })
  92. }
  93. }