|
@@ -188,24 +188,54 @@ export const actions = {
|
|
|
resetGameLogin ({ dispatch, commit, state }, params) {
|
|
|
localStorage.removeItem('user_id')
|
|
|
localStorage.removeItem('token')
|
|
|
- dispatch('doGameLogin')
|
|
|
+ dispatch('doContractLogin')
|
|
|
},
|
|
|
/**
|
|
|
- * 内嵌版本调起合约登录
|
|
|
+ * 合约登录, 生成业务登录态token
|
|
|
* @param {Array} params
|
|
|
*/
|
|
|
- async doParentLogin ({ dispatch, commit, state }, params) {
|
|
|
+ async doContractLogin ({ commit, state }, params) {
|
|
|
try {
|
|
|
+ // 合约登录
|
|
|
+ let { data } = await API.user.getRandom2({ account: state.account.name })
|
|
|
+ let random = data.data.random
|
|
|
+ let accessToken = data.data.accessToken
|
|
|
let identity = { authorization: [`${state.account.name}@${state.account.authority}`] }
|
|
|
- let trx = await window.postMessager.send({
|
|
|
- action: 'meechat:eosAction',
|
|
|
- data: {
|
|
|
- contract: 'meechatadmin',
|
|
|
- action: 'login',
|
|
|
- param: params.concat(identity)
|
|
|
- }
|
|
|
- })
|
|
|
- return Promise.resolve(trx.transaction_id)
|
|
|
+
|
|
|
+ let trx = null
|
|
|
+ if (self !== top) {
|
|
|
+ trx = await window.postMessager.send({
|
|
|
+ action: 'meechat:eosAction',
|
|
|
+ data: {
|
|
|
+ contract: 'meechatadmin',
|
|
|
+ action: 'login',
|
|
|
+ param: [state.account.name, random, identity]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ let contract = await window.EOS.contract('meechatadmin')
|
|
|
+ trx = await contract.login(state.account.name, random, identity)
|
|
|
+ }
|
|
|
+
|
|
|
+ let param = {
|
|
|
+ account: state.account.name,
|
|
|
+ access_token: accessToken,
|
|
|
+ trx_id: trx.transaction_id
|
|
|
+ }
|
|
|
+
|
|
|
+ let res = await API.user.eosLogin2(param)
|
|
|
+ if (res.data.result === 1) {
|
|
|
+ let userId = res.data.data.user_id
|
|
|
+ let token = res.data.data.token
|
|
|
+
|
|
|
+ localStorage.setItem('user_id', userId)
|
|
|
+ localStorage.setItem('token', token)
|
|
|
+
|
|
|
+ commit('setUserId', userId)
|
|
|
+ commit('setToken', token)
|
|
|
+
|
|
|
+ return Promise.resolve(res.data)
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
return Promise.reject(error)
|
|
|
}
|