Browse Source

feat(KIP-6765): 适配子目录路径的接口

John-Hong 2 years ago
parent
commit
e9f81b3a7f
3 changed files with 69 additions and 207 deletions
  1. 7 145
      src/App.vue
  2. 59 59
      src/utils/api-crm-member.js
  3. 3 3
      src/utils/request-kip.js

+ 7 - 145
src/App.vue

@@ -86,6 +86,7 @@ export default {
   },
   methods: {
     async init() {
+      uni.setStorageSync('env', window.env);
       // 如果是微信小程序。初始化wss
       if (getIsMin()) {
         // this.Toastloading = Toast.loading({
@@ -219,18 +220,18 @@ export default {
       console.log('当前页面的url地址  ', href);
       if (/dev-|8080/.test(href)) {
         window.env = 'qa';
-        window.profileApi = 'profileApi';
+        window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
         window.api = 'qaApi';
         return;
       }
       if (/qa-/.test(href)) {
         window.env = 'qa';
         window.api = 'qaApi';
-        window.profileApi = 'profileApi';
+        window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
         return;
       }
       window.env = 'prod';
-      window.profileApi = 'profileApiProd';
+      window.profileApi = 'https://apim.kerryplus.com/c/api';
       window.api = 'api';
     },
     send() {
@@ -304,6 +305,9 @@ export default {
           // 用户选择不登录
           if (this.isLogin !== '3') {
             this.isInit = false;
+            setTimeout(() => {
+              this.isInit = true;
+            }, 700);
             // 判断用户是否需要登录
             this.checkIsLogin(() => {
               this.isInit = true;
@@ -327,148 +331,6 @@ export default {
           }
         }
       });
-      // 获取openid
-      // openid 在本地存在的话,走登录验证
-      // openid 不存在的话
-      // window.location.pathname
-      // this.$router.replace({
-      //   path: 'openWx',
-      //   query: query,
-      // });
-      // 初始化微信jsdk
-      // 初始化appid,根据 lbsId、groupId、mallId
-
-      /*console.log(109, { groupId, mallId });
-      const kipAccessToken = uni.getStorageSync('kipAccessToken');
-      // 设置 member、groupId 和 mallId
-      this.$store.commit(
-        'SET_GROUP_ID',
-        groupId || uni.getStorageSync('groupId')
-      );
-      this.$store.commit('SET_MALL_ID', mallId || uni.getStorageSync('mallId'));
-      // 如果用户没有登录的话,我们需要让用户完成授权拿到 openid
-      /!* const openid = uni.getStorageSync('openid');
-       // console.log(949494, openid);
-       // 设置openid
-       if (openid && openid !== 'undefined') {
-       this.$store.commit('SET_OPENID', openid);
-       } *!/
-      // 如果用户没有openid
-      const openid = uni.getStorageSync('openid');
-      // 如果 存在,清空缓存,然后先去openid
-      // console.log(949494, openid);
-      // 设置openid
-      if (openid && openid !== 'undefined') {
-        this.$store.commit('SET_OPENID', openid);
-      }
-      if (!openid) {
-        // 当进入其他页面时,需要先打开路由展示
-        this.isInit = true;
-        // 前往授权页面
-        this.$router.replace({
-          path: '/openWx',
-          query: query,
-        });
-        return;
-      }
-      /!* 如果用户选择不登录 *!/
-      const passLogin = uni.getStorageSync('passLogin');
-      if (passLogin && /true/.test(passLogin)) {
-        return;
-      }
-      if (!openid) {
-        // 当进入其他页面时,需要先打开路由展示
-        this.isInit = true;
-        // 前往授权页面
-        this.$router.replace({
-          path: 'openWx',
-          query: query,
-        });
-        return;
-      }
-      if (!kipAccessToken) {
-        // 如果用户不选择登录,则不走登录逻辑
-        this.isInit = true;
-        this.$router.replace({
-          path: '/login',
-          query: query,
-        });
-        return;
-      }
-      // 如果用已经登录
-      // 验证 kipAccessToken 是否过期,过期则刷新
-      const _this = this;
-      kipCheckToken(kipAccessToken)
-        .then((resp) => {
-          // console.log(120, resp);
-          if (resp && resp.statusCode == '401') {
-            log.info(
-              `access_token已过期,使用refresh_token刷新access_token,如果refresh_token过期则删除所有数据`
-            );
-            // token过期之后使用refresh_token刷新access_token,如果refresh_token过期则删除所有数据
-            const kipRefreshToken = KipCacheTool.getKipRefreshToken();
-            kipGetNewAccessTokenByRefreshToken(kipRefreshToken)
-              .then((result) => {
-                // const result = resp.data;
-                if (
-                  result &&
-                  result.code === '000000' &&
-                  result.data.access_token
-                ) {
-                  KipCacheTool.setKipToken(result.data.access_token);
-                  log.info(
-                    `refreshToken获取成功,这是新的token:`,
-                    result.data.access_token
-                  );
-                } else {
-                  if (
-                    result &&
-                    result.code !== KIP_API_CODE.REFRESH_TOKEN_EXPIRED
-                  ) {
-                    uni.showToast({
-                      title: result.message,
-                      duration: 2000,
-                      icon: 'none',
-                    });
-                  }
-                  console.warn('===>清除所有缓存1');
-                  log.info(`清除所有缓存1`);
-                  _this.cleanAll();
-                  this.$router.replace({
-                    path: '/login',
-                    query: query,
-                  });
-                }
-              })
-              .catch((err) => {
-                console.warn('===>清除所有缓存2');
-                log.info(`清除所有缓存2`);
-                _this.cleanAll();
-                this.$router.replace({
-                  path: '/login',
-                  query: query,
-                });
-              });
-          }
-        })
-        .catch((err) => {
-          console.error(err);
-          console.warn('===>清除所有缓存3');
-          log.info(`refresh_token获取失败,清除所有缓存3`, err);
-          _this.cleanAll();
-          this.$router.replace({
-            path: '/login',
-            query: query,
-          });
-        });
-      // 初始化微信
-      console.log('初始化');
-      // initWxJsSdkConfig(['chooseWXPay', 'scanQRCode', 'checkJsApi'],['wx-open-launch-weapp']);
-      // initWxJsSdkConfig(['chooseWXPay']);
-      this.$router.push({
-        path: '/home',
-        query: query,
-      });*/
     },
   },
 };

+ 59 - 59
src/utils/api-crm-member.js

@@ -1,107 +1,107 @@
-import request from '@/utils/request-crm.js'
-import CacheTool from '@/utils/cache-tool.js'
+import request from '@/utils/request-crm.js';
+import CacheTool from '@/utils/cache-tool.js';
 
-const BASE_URL  = () => {
+const BASE_URL = () => {
   const curEnvConst = CacheTool.getCurEnvConst();
-  return curEnvConst.BASE_URL
-}
+  return curEnvConst.BASE_URL;
+};
 const DEFAULT_CONFIG = {
   refreshTokenUrl: `/oauth/v1/oauth/renewToken?refreshToken=`,
-}
+};
 // 根据groupId, kipUserId查询crm会员
-export function crmGetMemberByKipProfileId (baseUrl, params) {
-	const url = `${baseUrl}api/1.0/member/getKipMemberInfo`;
-	return request.post(url, params);
+export function crmGetMemberByKipProfileId(baseUrl, params) {
+  const url = `${baseUrl}api/1.0/member/getKipMemberInfo`;
+  return request.post(url, params);
 }
 
 // 根据brandId,kipUserId 创建会员
 export function crmCreateNewMemberByBrand(baseUrl, params) {
-	const url = `${baseUrl}api/1.0/login/saveMember`;
-	return request.post(url, params);
+  const url = `${baseUrl}api/1.0/login/saveMember`;
+  return request.post(url, params);
 }
 
 export function crmGetMiniCodeParam(baseUrl, params) {
-	const url = `${baseUrl}api/1.0/login/getMiniCodeParam`;
-	return request.post(url, params);
+  const url = `${baseUrl}api/1.0/login/getMiniCodeParam`;
+  return request.post(url, params);
 }
 
 export function crmUpdateMemberCompleted(baseUrl, params) {
-	const { kipUserId, groupId, mallid } = params || {};
-	if (!kipUserId || !groupId || !mallid) {
-		console.error(`===>[参数缺失] kipUserId || groupId || mallid 不能为空`)
-		return;
-	}
-	const url = `${baseUrl}api/1.0/member/isCompleted`;
-	return request.put(url, params);
+  const { kipUserId, groupId, mallid } = params || {};
+  if (!kipUserId || !groupId || !mallid) {
+    console.error(`===>[参数缺失] kipUserId || groupId || mallid 不能为空`);
+    return;
+  }
+  const url = `${baseUrl}api/1.0/member/isCompleted`;
+  return request.put(url, params);
 }
 
 export function memberCertification(baseUrl, params) {
-	const url = `${baseUrl}api/1.0/member/memberCertification`;
-	return request.post(url, params);
+  const url = `${baseUrl}api/1.0/member/memberCertification`;
+  return request.post(url, params);
 }
 
 // 退出接口
 export function crmLogout(baseUrl, params) {
-	const { openid } = params || {};
-	if (!openid) {
-		console.error(`===>[参数缺失] kipUserId & groupId 不能为空`)
-		return;
-	}
-	const url = `${baseUrl}api/1.0/login/logout`;
-	return request.post(url, params);
+  const { openid } = params || {};
+  if (!openid) {
+    console.error(`===>[参数缺失] kipUserId & groupId 不能为空`);
+    return;
+  }
+  const url = `${baseUrl}api/1.0/login/logout`;
+  return request.post(url, params);
 }
 
 export function crmLogOff(baseUrl, params) {
-	const { mobile } = params || {};
-	if (!mobile) {
-		console.error(`===>[参数缺失] mobile 不能为空`)
-		return;
-	}
-	const url = `${baseUrl}api/1.0/login/logOff`;
-	return request.post(url, params);
+  const { mobile } = params || {};
+  if (!mobile) {
+    console.error(`===>[参数缺失] mobile 不能为空`);
+    return;
+  }
+  const url = `${baseUrl}api/1.0/login/logOff`;
+  return request.post(url, params);
 }
 
 export function crmGetOpenId(baseUrl, params) {
-	const { code, mallid } = params || {};
-	if (!code) {
-		console.error(`===>[参数缺失] code 不能为空`)
-		return;
-	}
-	if (!mallid) {
-		console.error(`===>[参数缺失] mallid 不能为空`)
-		return;
-	}
-	const url = `${baseUrl}api/1.0/login/onLogin`
-	return request.post(url, params);
+  const { code, mallid } = params || {};
+  if (!code) {
+    console.error(`===>[参数缺失] code 不能为空`);
+    return;
+  }
+  if (!mallid) {
+    console.error(`===>[参数缺失] mallid 不能为空`);
+    return;
+  }
+  const url = `${baseUrl}api/1.0/login/onLogin`;
+  return request.post(url, params);
 }
 export function crmUpdateMobilePhone(params) {
-	const url = `${BASE_URL()}api/1.0/member/mobilePhone`
-	return request.put(url, params);
+  const url = `${BASE_URL()}api/1.0/member/mobilePhone`;
+  return request.put(url, params);
 }
 
 // 获取腾讯key
-export function getTencentKey (params) {
-	const url = `${BASE_URL()}api/1.0/tencent/list`;
-	return request.get(url, params);
+export function getTencentKey(params) {
+  const url = `${BASE_URL()}api/1.0/tencent/list`;
+  return request.get(url, params);
 }
 
 /**
  * 只返回crm特有的信息,基础信息不返回
  * @param {*} params
  */
-export function crmQueryMemberInfo (params) {
+export function crmQueryMemberInfo(params) {
   const url = `${BASE_URL()}api/1.0/member/queryMemberInfo`;
   return request.get(url, params);
 }
 
 // 获取会员详细信息用于会员注册后完善信息操作,在obj.extend属性中,外层是基础会员信息
-export function kipGetUserDetail (params) {
+export function kipGetUserDetail(params) {
   // https://apim.kerryplus.com/c/api/profile/v1/customer/crm/current
-  const url = + `/${window.profileApi}/profile/v1/customer/crm/current`;
-  return request.get(url, params, {...DEFAULT_CONFIG});
+  const url = `${window.profileApi}/profile/v1/customer/crm/current`;
+  return request.get(url, params, { ...DEFAULT_CONFIG });
 }
 
-export function crmSaveMemberSource (params) {
-	const url = `${BASE_URL}api/1.0/login/updateRegister`;
-	return request.post(url, params);
+export function crmSaveMemberSource(params) {
+  const url = `${BASE_URL}api/1.0/login/updateRegister`;
+  return request.post(url, params);
 }

+ 3 - 3
src/utils/request-kip.js

@@ -52,12 +52,12 @@ function getToken() {
 }
 
 function getUrl(path) {
-  // console.log(555555555, path);
+  console.log(555555555, path);
   // 如果是dev、qa、prod环境
   if (window.ininjectConfig) {
     if (path.indexOf(`/${window.profileApi}`) > -1) {
       // return `${window.ininjectConfig.profileApi}${path}`
-      return `/${window.profileApi}${path}`;
+      return `${window.profileApi}${path}`;
     }
     if (/weixinApi/g.test(path)) {
       return path;
@@ -133,7 +133,7 @@ export default {
     };
     return new Promise((resolve, reject) => {
       const url = getUrl(
-        /\/sns|http/g.test(path) ? path : `/${window.profileApi}${path}`
+        /\/sns|http/g.test(path) ? path : `${window.profileApi}${path}`
       );
       // console.log(130, url);
       const { header } = handleConfig(config);