import { mapState, mapActions } from 'vuex' import API from '@/api' import User from '@/store/db/User.js' import { getMeechatType } from '@/util/util' export const otherInfoMixins = { data () { return { accountList: null, userInfo: null, meechatType: getMeechatType()// meechat版本 } }, computed: { ...mapState({ members: state => state.group.members, groupId: state => state.group.groupId, sessionList: state => state.chat.sessionList, meId: state => state.userId, meInfo: state => state.userInfo }), linkToOther () { let youId = this.userInfo.user_id let sessionId = Number(youId) < Number(this.meId) ? `${youId}-${this.meId}` : `${this.meId}-${youId}` return `${location.origin}/#/pm/${sessionId}` } }, methods: { ...mapActions(['getUserInfo']), sendMsg () { this.visible = false let youId = this.userInfo.user_id let sessionId = Number(youId) < Number(this.meId) ? `${youId}-${this.meId}` : `${this.meId}-${youId}` let repeatFlag = this.sessionList.some(e => { return e.session_id == sessionId }) if (!repeatFlag) { let obj = { cover_photo: this.userInfo.cover_photo, is_group: '0', name: this.userInfo.nick_name, // read_hash:null session_id: sessionId } this.$store.commit('addSessionItem', obj) } // 创建members,应对还没聊天记录的情况 let myId = this.meInfo.user_id let members = {} members[myId] = { cover_photo: this.meInfo.cover_photo, nick_name: this.meInfo.nick_name } members[this.userInfo.user_id] = { cover_photo: this.userInfo.cover_photo, nick_name: this.userInfo.nick_name } this.$store.commit('updateGroup', { key: 'members', data: members }) this.$store.commit('updateGroup', { key: 'privateName', data: this.userInfo.nick_name }) this.$router.push({ path: `/pm/${sessionId}` }) } }, async created () { if (!this.meInfo) { await this.getUserInfo() } API.user.getOtherInfo({ target_id: this.userId, group_id: this.groupId || null }).then(({ data }) => { this.accountList = data.data.binds this.userInfo = data.data this.visible = true if (data.data.user_id) { // 更新他人的信息 let objUser = new User() let newData = { cover_photo: data.data.cover_photo, nick_name: data.data.nick_name, user_name: data.data.user_name } objUser.updateObject(newData, { user_id: data.data.user_id }) } }) } }