Showing
11 changed files
with
46 additions
and
18 deletions
@@ -14,6 +14,20 @@ export default { | @@ -14,6 +14,20 @@ export default { | ||
14 | name: 'App', | 14 | name: 'App', |
15 | computed: { | 15 | computed: { |
16 | ...mapState(['yoho']) | 16 | ...mapState(['yoho']) |
17 | + }, | ||
18 | + mounted() { | ||
19 | + if (this.yoho.context.needLogin) { | ||
20 | + this.$yoho.ready(() => { | ||
21 | + this.$sdk.goLogin(); | ||
22 | + }); | ||
23 | + } | ||
24 | + }, | ||
25 | + watch: { | ||
26 | + 'yoho.context.needLogin': function(newVal) { | ||
27 | + if (newVal) { | ||
28 | + this.$sdk.goLogin(); | ||
29 | + } | ||
30 | + }, | ||
17 | } | 31 | } |
18 | }; | 32 | }; |
19 | </script> | 33 | </script> |
@@ -14,25 +14,31 @@ const errHandle = (error) => { | @@ -14,25 +14,31 @@ const errHandle = (error) => { | ||
14 | message: '服务器开小差了~' | 14 | message: '服务器开小差了~' |
15 | }); | 15 | }); |
16 | }; | 16 | }; |
17 | -const request = (options) => { | ||
18 | - return axios(options).then(res => res.data, errHandle); | 17 | +const request = (options, store) => { |
18 | + return axios(options).then((res) => { | ||
19 | + if (res.data.code === 401) { | ||
20 | + store && store.commit('needLogin', {needLogin: true}); | ||
21 | + return Promise.reject(res.data); | ||
22 | + } | ||
23 | + return res.data; | ||
24 | + }, errHandle); | ||
19 | }; | 25 | }; |
20 | 26 | ||
21 | -export const createApi = () => { | 27 | +export const createApi = (context, store) => { |
22 | return { | 28 | return { |
23 | get(url, params, options) { | 29 | get(url, params, options) { |
24 | return request(Object.assign({ | 30 | return request(Object.assign({ |
25 | url, | 31 | url, |
26 | params, | 32 | params, |
27 | method: 'get', | 33 | method: 'get', |
28 | - }), options); | 34 | + }), options, store); |
29 | }, | 35 | }, |
30 | post(url, data, options) { | 36 | post(url, data, options) { |
31 | return request(Object.assign({ | 37 | return request(Object.assign({ |
32 | url, | 38 | url, |
33 | data, | 39 | data, |
34 | method: 'post', | 40 | method: 'post', |
35 | - }, options)); | 41 | + }, options), store); |
36 | } | 42 | } |
37 | }; | 43 | }; |
38 | }; | 44 | }; |
@@ -8,6 +8,7 @@ import {Style, Toast, Dialog, DatePicker} from 'cube-ui'; //eslint-disable-line | @@ -8,6 +8,7 @@ import {Style, Toast, Dialog, DatePicker} from 'cube-ui'; //eslint-disable-line | ||
8 | import {get} from 'lodash'; | 8 | import {get} from 'lodash'; |
9 | import Lazy from 'vue-lazyload'; | 9 | import Lazy from 'vue-lazyload'; |
10 | import yoho from 'common/yoho'; | 10 | import yoho from 'common/yoho'; |
11 | +import sdk from 'yoho-activity-sdk'; | ||
11 | import 'statics/scss/common.scss'; | 12 | import 'statics/scss/common.scss'; |
12 | import 'statics/font/iconfont.css'; | 13 | import 'statics/font/iconfont.css'; |
13 | import 'statics/font/ufofont.css'; | 14 | import 'statics/font/ufofont.css'; |
@@ -25,6 +26,7 @@ if (window.__INITIAL_STATE__) { | @@ -25,6 +26,7 @@ if (window.__INITIAL_STATE__) { | ||
25 | window._router = get(store, 'state.yoho.context.route'); | 26 | window._router = get(store, 'state.yoho.context.route'); |
26 | 27 | ||
27 | Vue.prop('yoho', yoho); | 28 | Vue.prop('yoho', yoho); |
29 | +Vue.prop('sdk', sdk); | ||
28 | Vue.use(Toast); | 30 | Vue.use(Toast); |
29 | Vue.use(DatePicker); | 31 | Vue.use(DatePicker); |
30 | Vue.use(Dialog); | 32 | Vue.use(Dialog); |
@@ -40,6 +40,10 @@ export default context => { | @@ -40,6 +40,10 @@ export default context => { | ||
40 | return resolve(app); | 40 | return resolve(app); |
41 | }).catch(e => { | 41 | }).catch(e => { |
42 | reportError(e); | 42 | reportError(e); |
43 | + if (e.code === 401) { | ||
44 | + store.commit('needLogin', {needLogin: true}); | ||
45 | + } | ||
46 | + context.state = store.state; | ||
43 | return resolve(app); | 47 | return resolve(app); |
44 | }); | 48 | }); |
45 | }); | 49 | }); |
@@ -131,7 +131,7 @@ export default { | @@ -131,7 +131,7 @@ export default { | ||
131 | methods: { | 131 | methods: { |
132 | async onSubmit() { | 132 | async onSubmit() { |
133 | if (!this.$yoho.isLogin()) { | 133 | if (!this.$yoho.isLogin()) { |
134 | - this.$yoho.goLogin(); | 134 | + this.$sdk.goLogin(); |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | 137 |
@@ -18,7 +18,7 @@ export function createStore(context) { | @@ -18,7 +18,7 @@ export function createStore(context) { | ||
18 | strict: process.env.NODE_ENV !== 'production' | 18 | strict: process.env.NODE_ENV !== 'production' |
19 | }); | 19 | }); |
20 | 20 | ||
21 | - const api = createApi(context); | 21 | + const api = createApi(context, store); |
22 | 22 | ||
23 | store.$api = api; | 23 | store.$api = api; |
24 | store.$context = context; | 24 | store.$context = context; |
@@ -39,16 +39,7 @@ export default { | @@ -39,16 +39,7 @@ export default { | ||
39 | }, | 39 | }, |
40 | 40 | ||
41 | async licenseStatus({ commit }) { | 41 | async licenseStatus({ commit }) { |
42 | - let result = {}; | ||
43 | - | ||
44 | - try { | ||
45 | - result = await this.$api.get('/api/ufo/license/status'); | ||
46 | - } catch (e) { | ||
47 | - if (e.code === 401) { | ||
48 | - commit(Types.FETCH_UFO_NEED_LOGIN, true); | ||
49 | - return; | ||
50 | - } | ||
51 | - } | 42 | + let result = await this.$api.get('/api/ufo/license/status'); |
52 | 43 | ||
53 | if (result.code === 200) { | 44 | if (result.code === 200) { |
54 | commit(Types.FETCH_UFO_STATUS_SUCCESS, { status: result.data, message: result.message }); | 45 | commit(Types.FETCH_UFO_STATUS_SUCCESS, { status: result.data, message: result.message }); |
@@ -15,7 +15,8 @@ export default function() { | @@ -15,7 +15,8 @@ export default function() { | ||
15 | fs: true, | 15 | fs: true, |
16 | }, | 16 | }, |
17 | route: '', | 17 | route: '', |
18 | - path: '' | 18 | + path: '', |
19 | + needLogin: false | ||
19 | }, | 20 | }, |
20 | historys: [], | 21 | historys: [], |
21 | visible: true, | 22 | visible: true, |
@@ -51,6 +52,9 @@ export default function() { | @@ -51,6 +52,9 @@ export default function() { | ||
51 | }); | 52 | }); |
52 | state.direction = 'forword'; | 53 | state.direction = 'forword'; |
53 | } | 54 | } |
55 | + }, | ||
56 | + [Types.NEED_LOGIN](state, {needLogin}) { | ||
57 | + state.context.needLogin = needLogin; | ||
54 | } | 58 | } |
55 | }, | 59 | }, |
56 | actions: { | 60 | actions: { |
@@ -4,3 +4,4 @@ export const ROUTE_CHANGE = 'ROUTE_CHANGE'; | @@ -4,3 +4,4 @@ export const ROUTE_CHANGE = 'ROUTE_CHANGE'; | ||
4 | export const PAGE_INIT_VISIBLE = 'PAGE_INIT_VISIBLE'; | 4 | export const PAGE_INIT_VISIBLE = 'PAGE_INIT_VISIBLE'; |
5 | export const YOHO_PAGE_VISIBLE = 'YOHO_PAGE_VISIBLE'; | 5 | export const YOHO_PAGE_VISIBLE = 'YOHO_PAGE_VISIBLE'; |
6 | export const REPORT_YAS = 'REPORT_YAS'; | 6 | export const REPORT_YAS = 'REPORT_YAS'; |
7 | +export const NEED_LOGIN = 'needLogin'; |
@@ -62,6 +62,7 @@ | @@ -62,6 +62,7 @@ | ||
62 | "vue-virtual-scroll-list": "^1.2.8", | 62 | "vue-virtual-scroll-list": "^1.2.8", |
63 | "vuex": "^3.0.1", | 63 | "vuex": "^3.0.1", |
64 | "winston": "^3.1.0", | 64 | "winston": "^3.1.0", |
65 | + "yoho-activity-sdk": "^1.1.3", | ||
65 | "yoho-cookie": "^1.2.0", | 66 | "yoho-cookie": "^1.2.0", |
66 | "yoho-express-session": "^2.0.0", | 67 | "yoho-express-session": "^2.0.0", |
67 | "yoho-md5": "^2.1.0", | 68 | "yoho-md5": "^2.1.0", |
@@ -9357,6 +9357,11 @@ yargs@^7.0.0: | @@ -9357,6 +9357,11 @@ yargs@^7.0.0: | ||
9357 | y18n "^3.2.1" | 9357 | y18n "^3.2.1" |
9358 | yargs-parser "^5.0.0" | 9358 | yargs-parser "^5.0.0" |
9359 | 9359 | ||
9360 | +yoho-activity-sdk@^1.1.3: | ||
9361 | + version "1.1.3" | ||
9362 | + resolved "http://npm.yohops.com/yoho-activity-sdk/-/yoho-activity-sdk-1.1.3.tgz#14a8a952e1fd68cc7c167f1e6336d67262d55ba6" | ||
9363 | + integrity sha512-XbE6K/Ioid0Uguyf+2zdmFPgVALB9Ozsei1JLpp7MZhZNlVALQ0sER/L5sOQdZqIrtBmTiplur7u2pgaXl374g== | ||
9364 | + | ||
9360 | yoho-cookie@^1.2.0: | 9365 | yoho-cookie@^1.2.0: |
9361 | version "1.2.0" | 9366 | version "1.2.0" |
9362 | resolved "http://npm.yohops.com/yoho-cookie/-/yoho-cookie-1.2.0.tgz#e8600ff0fcf316e8a9f88d32cd263396dc7e5f22" | 9367 | resolved "http://npm.yohops.com/yoho-cookie/-/yoho-cookie-1.2.0.tgz#e8600ff0fcf316e8a9f88d32cd263396dc7e5f22" |
-
Please register or login to post a comment