瀏覽代碼

feat(api): 修改api模块加载模式

曾志翔 3 年之前
父節點
當前提交
4fede9494f
共有 7 個文件被更改,包括 20 次插入47 次删除
  1. 0 7
      api/activity/invite-user.js
  2. 2 5
      api/message/phone.js
  3. 7 11
      api/public/agreement.js
  4. 2 9
      api/user/client.js
  5. 5 11
      api/wx/index.js
  6. 2 2
      pages/index.vue
  7. 2 2
      plugins/jweixin.js

+ 0 - 7
api/activity/invite-user.js

@@ -1,10 +1,3 @@
-// export default function ({ $axios }) {
-//   return {
-//     getStarCoinOverview: () =>
-//       $axios.$get('/activity/v1/inviteUser/orderRelation/starCoinOverview'),
-//   };
-// }
-
 export const getStarCoinOverview = ({ $axios }, params) =>
   $axios.$get('/activity/v1/inviteUser/orderRelation/starCoinOverview', {
     params,

+ 2 - 5
api/message/phone.js

@@ -1,5 +1,2 @@
-export default function ({ $axios }) {
-  return {
-    sendSmsCode: (data) => $axios.$post('/message/v5/phone/send', data),
-  };
-}
+export const sendSmsCode = ({ $axios }, data) =>
+  $axios.$post('/message/v5/phone/send', data);

+ 7 - 11
api/public/agreement.js

@@ -1,11 +1,7 @@
-export default function ({ $axios }) {
-  return {
-    getContentByType: (agreementCoding, type = 1) =>
-      $axios.$get('/public/v5/agreementApi/content/getContentByType', {
-        params: {
-          agreementCoding,
-          type,
-        },
-      }),
-  };
-}
+export const getContentByType = ({ $axios }, agreementCoding, type = 1) =>
+  $axios.$get('/public/v5/agreementApi/content/getContentByType', {
+    params: {
+      agreementCoding,
+      type,
+    },
+  });

+ 2 - 9
api/user/client.js

@@ -1,9 +1,2 @@
-export default function ({ $axios }) {
-  return {
-    registerForInvite: (data) =>
-      $axios.$post(
-        '/user/v5/client/register/forLachineH5',
-        data,
-      ),
-  };
-}
+export const registerForInvite = ({ $axios }, data) =>
+  $axios.$post('/user/v5/client/register/forLachineH5', data);

+ 5 - 11
api/wx/index.js

@@ -1,12 +1,6 @@
-export default function ({ $axios }) {
-  return {
-    // 获取微信js签名
-    getConfig(url) {
-      return $axios.$get('/wx/getConfig', {
-        params: {
-          url,
-        },
-      });
+export const getConfig = ({ $axios }, url) =>
+  $axios.$get('/wx/getConfig', {
+    params: {
+      url,
     },
-  };
-}
+  });

+ 2 - 2
pages/index.vue

@@ -24,7 +24,7 @@
 </template>
 
 <script>
-import agreement from '~/api/public/agreement.js';
+import { getContentByType } from '~/api/public/agreement.js';
 export default {
   name: 'IndexPage',
   auth: false,
@@ -44,7 +44,7 @@ export default {
   mounted() {},
   methods: {
     async getContentByType() {
-      const data = await agreement(this).getContentByType('XYPZYHXY2004', 1);
+      const data = await getContentByType(this, 'XYPZYHXY2004', 1);
       console.log(
         '🚀 ~ file: index.vue ~ line 24 ~ getContentByType ~ data',
         data,

+ 2 - 2
plugins/jweixin.js

@@ -1,7 +1,7 @@
 import wx from 'jweixin-module';
 
 // import Vue from 'vue';
-import wxApi from '~/api/wx/index.js';
+import { getConfig } from '~/api/wx/index.js';
 
 export default function (c, i) {
   // Vue.config.optionMergeStrategies.wxReady = function (toVal, fromVal) {
@@ -32,7 +32,7 @@ export default function (c, i) {
       //   //   },
       //   // });
       // }
-      const res = await wxApi(c).getConfig(location.href);
+      const res = await getConfig(c, location.href);
       await new Promise((resolve, reject) => {
         wx.config({
           debug: true, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。