Authored by htoooth

fix needlogin

@@ -25,7 +25,7 @@ const request = async({url, method, reqParams = {}, context}) => { @@ -25,7 +25,7 @@ const request = async({url, method, reqParams = {}, context}) => {
25 }, 25 },
26 sessionKey: user.sessionKey, 26 sessionKey: user.sessionKey,
27 appSessionType: user.appSessionType 27 appSessionType: user.appSessionType
28 - } : 1, 28 + } : null,
29 method: apiInfo.api, 29 method: apiInfo.api,
30 }); 30 });
31 } 31 }
@@ -143,7 +143,7 @@ export default { @@ -143,7 +143,7 @@ export default {
143 143
144 this.toast && this.toast.hide(); 144 this.toast && this.toast.hide();
145 145
146 - if (result.code === 200) { 146 + if (result && result.code === 200) {
147 this.$store.commit('license/form/FETCH_UFO_STATUS_SUCCESS', 0); 147 this.$store.commit('license/form/FETCH_UFO_STATUS_SUCCESS', 0);
148 } else { 148 } else {
149 this.$createToast({ 149 this.$createToast({
@@ -186,11 +186,19 @@ export default { @@ -186,11 +186,19 @@ export default {
186 this.model.certFaceImage.length === 1 && 186 this.model.certFaceImage.length === 1 &&
187 this.model.certReverseImage.length === 1 && 187 this.model.certReverseImage.length === 1 &&
188 (this.model.time.noLimit ? this.model.time.start_time : this.model.time.start_time && this.model.time.expire_time); 188 (this.model.time.noLimit ? this.model.time.start_time : this.model.time.start_time && this.model.time.expire_time);
189 - } 189 + },
  190 + ...mapState(['needLogin'])
190 }, 191 },
191 mounted() { 192 mounted() {
192 this.fetchToken(); 193 this.fetchToken();
193 }, 194 },
  195 + watch: {
  196 + needLogin(newVal) {
  197 + if (newVal) {
  198 + this.$yoho.goLogin({});
  199 + }
  200 + }
  201 + },
194 components: { 202 components: {
195 LayoutApp, 203 LayoutApp,
196 FixedBottom, 204 FixedBottom,
@@ -30,16 +30,23 @@ export default { @@ -30,16 +30,23 @@ export default {
30 }, 30 },
31 31
32 async saveLicense({ commit }, data) { 32 async saveLicense({ commit }, data) {
33 - const result = await this.$api.post(  
34 - '/api/ufo/license/save',  
35 - _handleData(data)  
36 - ); 33 + let result = {};
  34 +
  35 + try {
  36 + result = await this.$api.post(
  37 + '/api/ufo/license/save',
  38 + _handleData(data)
  39 + );
  40 + } catch (e) {
  41 + commit(Types.FETCH_UFO_NEED_LOGIN, true);
  42 + return result;
  43 + }
37 44
38 return result; 45 return result;
39 }, 46 },
40 47
41 async licenseStatus({ commit }) { 48 async licenseStatus({ commit }) {
42 - let result = null; 49 + let result = {};
43 50
44 try { 51 try {
45 result = await this.$api.get('/api/ufo/license/status'); 52 result = await this.$api.get('/api/ufo/license/status');
@@ -58,7 +65,13 @@ export default { @@ -58,7 +65,13 @@ export default {
58 }, 65 },
59 66
60 async getStoreStatus({ commit }) { 67 async getStoreStatus({ commit }) {
61 - const result = await this.$api.get('/api/ufo/store/status'); 68 + let result = {};
  69 +
  70 + try {
  71 + result = await this.$api.get('/api/ufo/store/status');
  72 + } catch (e) {
  73 + return result;
  74 + }
62 75
63 return result; 76 return result;
64 } 77 }
@@ -7,25 +7,29 @@ const qiniu = require('qiniu'); @@ -7,25 +7,29 @@ const qiniu = require('qiniu');
7 const qiniuConfig = global.yoho.config.qiniu; 7 const qiniuConfig = global.yoho.config.qiniu;
8 const qiniuYohoCdnConfig = global.yoho.config.qiniuYohoCdn; 8 const qiniuYohoCdnConfig = global.yoho.config.qiniuYohoCdn;
9 9
10 -function getToken(req, res) {  
11 - let conf = qiniuConfig;  
12 - let type = req.query.type || ''; 10 +function getToken(req, res, next) {
  11 + try {
  12 + let conf = qiniuConfig;
  13 + let type = req.query.type || '';
13 14
14 - if (type.toLowerCase() === 'yohocdn') {  
15 - conf = qiniuYohoCdnConfig;  
16 - } 15 + if (type.toLowerCase() === 'yohocdn') {
  16 + conf = qiniuYohoCdnConfig;
  17 + }
17 18
18 - let mac = new qiniu.auth.digest.Mac(conf.ACCESS_KEY, conf.SECRET_KEY);  
19 - let options = {  
20 - scope: conf.BUCKET_NAME  
21 - };  
22 - let putPolicy = new qiniu.rs.PutPolicy(options);  
23 - let uploadToken = putPolicy.uploadToken(mac); 19 + let mac = new qiniu.auth.digest.Mac(conf.ACCESS_KEY, conf.SECRET_KEY);
  20 + let options = {
  21 + scope: conf.BUCKET_NAME
  22 + };
  23 + let putPolicy = new qiniu.rs.PutPolicy(options);
  24 + let uploadToken = putPolicy.uploadToken(mac);
24 25
25 - res.json({  
26 - code: 200,  
27 - uptoken: uploadToken  
28 - }); 26 + res.json({
  27 + code: 200,
  28 + uptoken: uploadToken
  29 + });
  30 + } catch (e) {
  31 + return next(e);
  32 + }
29 } 33 }
30 34
31 module.exports = { 35 module.exports = {
@@ -25,7 +25,7 @@ module.exports = async(req, res, next) => { @@ -25,7 +25,7 @@ module.exports = async(req, res, next) => {
25 }, 25 },
26 sessionKey: req.user.sessionKey, 26 sessionKey: req.user.sessionKey,
27 appSessionType: req.user.appSessionType 27 appSessionType: req.user.appSessionType
28 - } : 0, 28 + } : null,
29 method: apiInfo.api 29 method: apiInfo.api
30 }; 30 };
31 } 31 }