Browse Source

Merge branch 'dev' of http://git.ycjcjy.com/shigongli/miniapp-v2 into dev

吃个甘蔗嚼一年 3 years ago
parent
commit
d6fb4de4af

+ 1
- 1
src/components/CompoentsOrder/complete/index.jsx View File

1
 import React, { useState, useEffect } from "react";
1
 import React, { useState, useEffect } from "react";
2
 import Taro, { useDidShow } from "@tarojs/taro";
2
 import Taro, { useDidShow } from "@tarojs/taro";
3
-import { getOrderSub, getQrcode } from "@/services/payOrder";
3
+import { getOrderSub } from "@/services/payOrder";
4
 import formatTime from "@/utils/formatTime";
4
 import formatTime from "@/utils/formatTime";
5
 import image from "@/assets/icons/ProCard/8kb.jpg";
5
 import image from "@/assets/icons/ProCard/8kb.jpg";
6
 import food from "@/assets/icons/ProCard/food.png";
6
 import food from "@/assets/icons/ProCard/food.png";

+ 8
- 0
src/services/miniapp.js View File

1
+import request from '@/utils/request'
2
+
3
+/**
4
+* 获取小程序码
5
+* @param {*} id
6
+* @returns 
7
+*/
8
+export const getQrcode = (id) => request(`/qrcode/${id}`)

+ 0
- 7
src/services/payOrder.js View File

32
 */
32
 */
33
 export const refund = (id, data) => request(`/order/${id}/refund`, { method: 'delete', data })
33
 export const refund = (id, data) => request(`/order/${id}/refund`, { method: 'delete', data })
34
 
34
 
35
-/**
36
-* 获取子订单列表
37
-* @param {*} id
38
-* @returns 
39
-*/
40
-export const getQrcode = (id) => request(`/qrcode/${id}`)
41
-
42
 /**
35
 /**
43
 * 获取待支付/待核销/退款数量
36
 * 获取待支付/待核销/退款数量
44
 * @param {*} id
37
 * @param {*} id

+ 31
- 10
src/utils/hooks/useRouter.js View File

1
 import Taro, { useRouter } from '@tarojs/taro'
1
 import Taro, { useRouter } from '@tarojs/taro'
2
 import { parseQueryString } from '@/utils'
2
 import { parseQueryString } from '@/utils'
3
 import { useModel } from '@/store'
3
 import { useModel } from '@/store'
4
+import { useEffect, useRef, useState } from 'react'
5
+import { getQrcode } from '@/services/miniapp'
4
 
6
 
5
 export default () => {
7
 export default () => {
6
   const router = useRouter()
8
   const router = useRouter()
9
+  const routerRef = useRef()
7
   const { qrCode } = useModel('person')
10
   const { qrCode } = useModel('person')
8
 
11
 
9
-  // 扫码进入的
10
-  if (router?.params?.scene) {
11
-    if (qrCode) {
12
-      const qrParams = parseQueryString(qrCode) || {}
13
-      router.params = {
14
-        ...router.params || {},
15
-        ...qrParams,
16
-        parseQRFinished: true, 
12
+  const [toggleRefresh, setToggleRefresh] = useState()
13
+  
14
+  routerRef.current = router
15
+  const scene = router?.params?.scene
16
+
17
+  useEffect(() => {
18
+    // 扫码进入
19
+    if (scene) {
20
+      if (qrCode) {
21
+        const qrParams = parseQueryString(qrCode) || {}
22
+        routerRef.current.params = {
23
+          ...routerRef.current.params || {},
24
+          ...qrParams,
25
+          parseQRFinished: true, 
26
+        }
27
+        setToggleRefresh(Math.random().toString())
28
+      } else {
29
+        getQrcode(scene).then((res) => {
30
+          const qrParams = parseQueryString(res.scene) || {}
31
+          routerRef.current.params = {
32
+            ...routerRef.current.params || {},
33
+            ...qrParams,
34
+            parseQRFinished: true, 
35
+          }
36
+          setToggleRefresh(Math.random().toString())
37
+        })
17
       }
38
       }
18
     }
39
     }
19
-  }
40
+  }, [qrCode, scene])
20
 
41
 
21
-  return router
42
+  return routerRef.current
22
 }
43
 }