张延森 il y a 3 ans
Parent
révision
cd36675006

BIN
src/assets/barcodeimg.png Voir le fichier


BIN
src/assets/userBck.png Voir le fichier


+ 19
- 10
src/components/barcode/index.jsx Voir le fichier

@@ -5,17 +5,26 @@ import CodeText from './CodeText'
5 5
 import { code128 } from './drawCode'
6 6
 import './style.less'
7 7
 
8
+const widthRatio = 0.7;
9
+const barHeight = 80;
10
+
8 11
 export default (props) => {
9 12
 
10
-  const { width, height, code } = props
13
+  const { code } = props
11 14
 
12 15
   const canvasRef = useRef()
13 16
   const ctxRef = useRef()
14 17
 
15
-  console.log('---------------->', Taro.getSystemInfoSync().pixelRatio)
18
+  const sysInfo = useMemo(() => {
19
+    const { safeArea, pixelRatio } = Taro.getSystemInfoSync()
16 20
 
17
-  const dpr = useMemo(() => Taro.getSystemInfoSync().pixelRatio, [])
18
-  const size = useMemo(() => ({ width: width * dpr, height: height * dpr }), [width, height, dpr])
21
+    return {
22
+      width: safeArea.width,
23
+      height: safeArea.height,
24
+      dpr: pixelRatio,
25
+    }
26
+  }, [])
27
+  const size = useMemo(() => ({ width: sysInfo.width * sysInfo.dpr * widthRatio, height: barHeight * sysInfo.dpr }), [sysInfo])
19 28
 
20 29
   const style = useMemo(() => ({ width: `${size.width}rpx`, height: `${size.height}rpx` }), [size])
21 30
 
@@ -25,24 +34,24 @@ export default (props) => {
25 34
       query.select('#barCodeCanvas').fields({ node: true }).exec((res) => {
26 35
         const canvas = res[0].node
27 36
         const ctx = canvas.getContext('2d')
28
-        canvas.width = size.width
29
-        canvas.height = size.height
30
-        ctx.scale(dpr, dpr)
37
+        canvas.width = sysInfo.width
38
+        canvas.height = sysInfo.height
39
+        // ctx.scale(sysInfo.dpr, sysInfo.dpr)
31 40
 
32 41
         canvasRef.current = canvas;
33 42
         ctxRef.current = ctx;
34 43
 
35 44
         if (code) {
36
-          code128(ctx, code, size.width, size.height);
45
+          code128(ctx, code, sysInfo.width, sysInfo.height);
37 46
         }
38 47
       })
39 48
     })
40
-  }, [code, size, dpr])
49
+  }, [code, sysInfo])
41 50
 
42 51
   return (
43 52
     <View className='barcode-box' style={style}>
44 53
       <Canvas style={style} type='2d' id='barCodeCanvas'></Canvas>
45
-      <CodeText code={code}/>
54
+      <CodeText code={code} />
46 55
     </View>
47 56
   )
48 57
 }

+ 0
- 5
src/pages/index/index.jsx Voir le fichier

@@ -5,14 +5,9 @@ import { Icon } from "@antmjs/vantui";
5 5
 import Taro from '@tarojs/taro';
6 6
 import BarCode from '@/components/barcode'
7 7
 import CountDown from '@/components/CountDown'
8
-// import userBck from '../../assets/userBck.png'
9
-import barcodeimg from '../../assets/barcodeimg.png'
10
-
11 8
 
12 9
 import './style.less'
13 10
 
14
-
15
-
16 11
 export default (props) => {
17 12
   const userId = '320888800110023011';
18 13
   

+ 7
- 10
src/pages/index/style.less Voir le fichier

@@ -35,7 +35,6 @@
35 35
   &-cententQR {
36 36
     box-sizing: border-box;
37 37
     width: 95%;
38
-    height: 65vh;
39 38
     // box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
40 39
     border-radius: 15px;
41 40
     background-color: white;
@@ -43,23 +42,21 @@
43 42
     position: relative;
44 43
     top: -15vh;
45 44
     padding: 2em;
45
+    border: 1px solid rgba(0,0,0, 0.1);
46 46
 
47 47
     &-Times {
48 48
       padding-top: 3vh;
49 49
       text-align: center;
50
-      font-weight: 800;
51
-      font-size: 60px;
50
+      font-weight: bold;
51
+      font-size: 1.8em;
52 52
     }
53 53
     &-Barcode {
54
-      width: 80%;
55
-      height: 18vh;
54
+      height: 45vh;
56 55
       margin: 0 auto;
57 56
       position: relative;
58
-      top: 30%;
59
-      > Image {
60
-        width: 100%;
61
-        height: 100%;
62
-      }
57
+      display: flex;
58
+      justify-content: center;
59
+      align-items: center;
63 60
     }
64 61
   }
65 62
 }