123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- import { mapState, mapMutations, mapActions } from 'vuex'
- import API from '@/api'
- import User from '@/store/db/User.js'
- import { setUserOpt, confirmPopup, openBlankWindow, getMeechatType, showError } from '@/util/util'
- import ScatterJS from 'scatterjs-core'
- import EthHelper from '@/util/ethHelper'
- import TronHelper from '@/util/tronHelper'
- 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)
- }
- 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 })
- }
- })
- }
- }
- // 绑定相关
- export const bindAccountMixins = {
- data () {
- return {
- isLoading: false
- }
- },
- computed: {
- ...mapState({
- scatter: state => state.scatter
- })
- },
- methods: {
- ...mapMutations([
- 'changeUserBinds'
- ]),
- ...mapActions([
- 'setScatter',
- 'doScatterBind',
- 'getUserInfo'
- ]),
- bindAccount (type) {
- switch (type) {
- case 'eos':
- this.bindEos('eos')
- break
- case 'tg':
- this.bindTg()
- break
- case 'eth':
- this.bindEth()
- break
- case 'tron':
- this.bindTron()
- break
- case 'meetone':
- this.bindEos('meetone')
- break
- }
- },
- // eos/meetone绑定
- async bindEos (eosType) {
- setUserOpt('eosType', eosType)
- this.isLoading = true
- if (this.scatter) {
- this.doScatterBind().then((res) => {
- this.isLoading = false
- this.changeUserBinds({
- type: eosType,
- account: res.account
- })
- }).catch((e) => {
- showError(e)
- this.isLoading = false
- })
- } else {
- // 连接scatter
- await ScatterJS.scatter.connect('MEE_CHAT').then(async connected => {
- if (connected) {
- // 设置scatter
- this.setScatter(ScatterJS.scatter)
- // 清空全局scatter引用
- window.ScatterJS = null
- this.doScatterBind().then((res) => {
- this.isLoading = false
- this.changeUserBinds({
- type: eosType,
- account: res.account
- })
- }).catch((e) => {
- showError(e)
- this.isLoading = false
- })
- }
- })
- }
- },
- // telegram绑定
- async bindTg () {
- this.winHandler = openBlankWindow('')
- let { data } = await API.user.tgCSRF({
- type: 'bind'
- })
- this.winHandler.location.href = data.data.url
- var loop = setInterval(() => {
- if (this.winHandler != null && this.winHandler.closed) {
- clearInterval(loop)
- this.winHandler = null
- }
- }, 800)
- this.bindCheck(data.data.csrf_token)
- },
- // eth绑定
- async bindEth () {
- this.isLoading = true
- try {
- let { account, sign } = await EthHelper.initEth()
- await API.user.ethBind({
- account: account,
- sign: sign
- })
- await this.changeUserBinds({
- type: 'eth',
- account: account
- })
- } catch (e) {
- this.isLoading = false
- }
- this.isLoading = false
- },
- // tron绑定
- async bindTron () {
- this.isLoading = true
- try {
- let { account, sign } = await TronHelper.initTron()
- await API.user.tronBind({
- account: account,
- sign: sign
- })
- await this.changeUserBinds({
- type: 'tron',
- account: account
- })
- } catch (e) {
- }
- this.isLoading = false
- },
- async bindCheck (uuID, times) {
- this.isLoading = true
- if (times === 0) {
- // 第一次调用
- clearTimeout(this.timeoutHandler)
- } else if (times >= 60) {
- return false
- }
- let res = {}
- try {
- // 校验telegram
- res = await API.user.tgBind2({ csrf_token: uuID })
- } catch (ex) {
- this.isLoading = false
- }
- if (res.data && res.data.data && res.data.data.status > 0) {
- this.isLoading = false
- if (this.winHandler != null) {
- this.winHandler.close()
- this.winHandler = null
- }
- this.getSyncInfo && this.getSyncInfo(this.params)// 关联页
- this.getUserInfo()
- } else if (!res.data) {
- if (this.winHandler != null) {
- this.winHandler.close()
- this.winHandler = null
- }
- } else if ((this.winHandler != null) || (res.data && res.data.status == 0)) {
- // 定时检查是否登录成功
- this.timeoutHandler = setTimeout(() => {
- this.bindCheck(uuID, ++times)
- }, 1000)
- }
- },
- unbindAccount (type) {
- confirmPopup(`${this.$t('userinfo.unbindMsg')} ${type.toLocaleUpperCase()} ?`).then(() => {
- API.user.unBind({
- type
- }).then(() => {
- if (type == 'eos') this.scatter && this.scatter.logout && this.scatter.logout()
- this.$showTips(this.$t('userinfo.unbindSuccess'))
- this.changeUserBinds({
- type: type,
- account: ''
- })
- })
- })
- }
- }
- }
|