张延森 3 yıl önce
ebeveyn
işleme
cd36675006

BIN
src/assets/barcodeimg.png Dosyayı Görüntüle


BIN
src/assets/userBck.png Dosyayı Görüntüle


+ 19
- 10
src/components/barcode/index.jsx Dosyayı Görüntüle

5
 import { code128 } from './drawCode'
5
 import { code128 } from './drawCode'
6
 import './style.less'
6
 import './style.less'
7
 
7
 
8
+const widthRatio = 0.7;
9
+const barHeight = 80;
10
+
8
 export default (props) => {
11
 export default (props) => {
9
 
12
 
10
-  const { width, height, code } = props
13
+  const { code } = props
11
 
14
 
12
   const canvasRef = useRef()
15
   const canvasRef = useRef()
13
   const ctxRef = useRef()
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
   const style = useMemo(() => ({ width: `${size.width}rpx`, height: `${size.height}rpx` }), [size])
29
   const style = useMemo(() => ({ width: `${size.width}rpx`, height: `${size.height}rpx` }), [size])
21
 
30
 
25
       query.select('#barCodeCanvas').fields({ node: true }).exec((res) => {
34
       query.select('#barCodeCanvas').fields({ node: true }).exec((res) => {
26
         const canvas = res[0].node
35
         const canvas = res[0].node
27
         const ctx = canvas.getContext('2d')
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
         canvasRef.current = canvas;
41
         canvasRef.current = canvas;
33
         ctxRef.current = ctx;
42
         ctxRef.current = ctx;
34
 
43
 
35
         if (code) {
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
   return (
51
   return (
43
     <View className='barcode-box' style={style}>
52
     <View className='barcode-box' style={style}>
44
       <Canvas style={style} type='2d' id='barCodeCanvas'></Canvas>
53
       <Canvas style={style} type='2d' id='barCodeCanvas'></Canvas>
45
-      <CodeText code={code}/>
54
+      <CodeText code={code} />
46
     </View>
55
     </View>
47
   )
56
   )
48
 }
57
 }

+ 0
- 5
src/pages/index/index.jsx Dosyayı Görüntüle

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

+ 7
- 10
src/pages/index/style.less Dosyayı Görüntüle

35
   &-cententQR {
35
   &-cententQR {
36
     box-sizing: border-box;
36
     box-sizing: border-box;
37
     width: 95%;
37
     width: 95%;
38
-    height: 65vh;
39
     // box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
38
     // box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
40
     border-radius: 15px;
39
     border-radius: 15px;
41
     background-color: white;
40
     background-color: white;
43
     position: relative;
42
     position: relative;
44
     top: -15vh;
43
     top: -15vh;
45
     padding: 2em;
44
     padding: 2em;
45
+    border: 1px solid rgba(0,0,0, 0.1);
46
 
46
 
47
     &-Times {
47
     &-Times {
48
       padding-top: 3vh;
48
       padding-top: 3vh;
49
       text-align: center;
49
       text-align: center;
50
-      font-weight: 800;
51
-      font-size: 60px;
50
+      font-weight: bold;
51
+      font-size: 1.8em;
52
     }
52
     }
53
     &-Barcode {
53
     &-Barcode {
54
-      width: 80%;
55
-      height: 18vh;
54
+      height: 45vh;
56
       margin: 0 auto;
55
       margin: 0 auto;
57
       position: relative;
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
 }