Commit b9125e40 by MichaelJier

feature

1. 内部登录方法 plugins/userAction login({token: ''})
parent 62488a6d
......@@ -16,4 +16,13 @@
后期可修改成 feature/alioss
4. 最新 nuxtjs 发现存在部分服务端与客户端 dom 不匹配的 bug
初步解决方案 <client-only> #content</client-only>
```html
<!-- 初步解决方案 -->
<client-only> #content</client-only>
```
5. 内部登录方法
```js
import login from '@/plugins/userAction/login'
login({token: ''})
```
......@@ -19,7 +19,6 @@
</template>
<script>
import { getWatchLoginInfo } from '@/plugins/API/apiAll';
import { watchTime } from '@/plugins/API/apiWS';
import { mapGetters, mapMutations, mapActions } from 'vuex';
import encrypt from '@/components/encrypt/index';
import white from '@/components/white/index';
......@@ -27,7 +26,7 @@ import welcome from '@/components/welcome/index';
import viewPc from './pc';
import viewMobile from './mobile';
import viewVertical from './vertical';
import websocketHeartbeat from '@/plugins/websocketHeartbeat';
export default {
name: 'view-box',
components: {
......@@ -76,24 +75,7 @@ export default {
await this.get_userInfo({ refererId: this.$route.query.refererId });
this.set_nowDate();
if (!process.env.private) {
const websocketHeartbeat = require('@/plugins/timer').default;
const userInfo = {
"userId": this.userInfo.id || 0,
// "token": this.token,
"id": this.channelInfo.id,
"type":"live",
"uin": this.channelInfo.uin,
"liveNowStatus": this.channelInfo.liveNowStatus
}
this.timer = websocketHeartbeat({
url: watchTime,
pingTimeout: 5000,
pongTimeout: 5000,
manualStart: false,
repeatLimit: 10,
userInfo,
webworker: false
}).useIt('uuid').useIt('ua')
this.timer = websocketHeartbeat()
this.set_uuid(this.timer.uuid)
// bus注册ws暂停和开始事件
this.$Bus.$on('ws-start', () => {
......
export const getQueryVariable = (variable) =>{
const query = window.location.search.substring(1);
const vars = query.split("&");
for (let i = 0;i < vars.length;i++) {
const pair = vars[i].split("=");
if (pair[0] === variable){return pair[1];}
}
return (false);
}
\ No newline at end of file
......@@ -72,3 +72,4 @@ if (process.client) {
}
});
}
// export default Vue
/**
* 登录
* @param {object} {token}
* return Pomise
*/
import { getWatchLoginInfo } from '../API/apiAll';
import store from '@/store/index'
// import Layer from '@/plugins/Layer/index'; //登陆成功
import Cookie from 'js-cookie'
import { getQueryVariable } from '../Utils/index'
export const login = async ({token} = {token: ''}) => {
Cookie.set('token', token, { expires: 10 });
const { id, uin, liveNowStatus } = store().getters['channelInfo']
const res = await getWatchLoginInfo({
id, uin
});
if (res.code === 200 && res.errorCode === 0) {
const info = res.data.watchUserInfo;
store().commit('set_userInfo', info)
const referer = {refererId: getQueryVariable('refererId')}
// 邀请统计
if (referer.refererId && info.id) {
store().dispatch('invitation', referer)
}
// 数据统计相关
store().dispatch('PostInfo')
// 用户行为
const Inkmarks = require('@gdyfe/ink-marks');
Inkmarks.setUser({
id: Number(info.id) || 0,
username: info.userNick || '游客'
});
const websocketHeartbeat = require('../websocketHeartbeat').default;
websocketHeartbeat().useIt('userInfo', {
"userId": info.id || 0,
// "token": this.token,
"id": id,
"type":"live",
"uin": uin,
"liveNowStatus": liveNowStatus
})
}
return this
}
\ No newline at end of file
import store from '@/store/index'
import { watchTime } from './API/apiWS';
export default () => {
const userInfo = store().getters['userInfo']
const channelInfo = store().getters['channelInfo']
const websocketHeartbeat = require('./timer').default;
const info = {
"userId": userInfo.id || 0,
// "token": this.token,
"id": channelInfo.id,
"type":"live",
"uin": channelInfo.uin,
"liveNowStatus": channelInfo.liveNowStatus
}
return websocketHeartbeat({
url: watchTime,
pingTimeout: 5000,
pongTimeout: 5000,
manualStart: false,
repeatLimit: 10,
userInfo: info,
webworker: false
}).useIt('uuid').useIt('ua')
}
\ No newline at end of file
import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import actions from './actions'
import mutations from './mutations'
import getters from './getters'
Vue.use(Vuex)
let store
const initStore = () => {
return store || (store = new Vuex.Store({
// 存放公用数据
state,
// 异步操作要通过actions,否则通过cimmit直接操作mutations
actions,
// 同步放数据
mutations,
getters,
modules: {
// store 模块....
}
}))
}
export default initStore
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment