张延森 před 3 roky
rodič
revize
7b34be9370

+ 7
- 3
src/components/CountDown.jsx Zobrazit soubor

@@ -1,15 +1,19 @@
1
-import React, { useEffect, useMemo, useState } from 'react'
1
+import React, { useEffect, useState } from 'react'
2 2
 import { View } from '@tarojs/components'
3 3
 import dayjs from 'dayjs'
4 4
 
5
+function getTime () {
6
+  return dayjs().format('HH:mm:ss')
7
+}
8
+
5 9
 export default (props) => {
6 10
   const { className, style } = props
7 11
 
8
-  const [dt, setDt] = useState(dayjs().format('YYYY-MM-DD HH:mm:ss'))
12
+  const [dt, setDt] = useState(getTime())
9 13
 
10 14
   useEffect(() => {
11 15
     const t = setInterval(() => {
12
-      setDt(dayjs().format('YYYY-MM-DD HH:mm:ss'))
16
+      setDt(getTime())
13 17
     }, 1000);
14 18
 
15 19
     return () => clearInterval(t)

+ 23
- 17
src/components/barcode/index.jsx Zobrazit soubor

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

+ 2
- 2
src/components/barcode/style.less Zobrazit soubor

@@ -4,8 +4,8 @@
4 4
     justify-content: space-between;
5 5
     align-items: center;
6 6
     font-size: 32px;
7
-    font-weight: bold;
8
-    line-height: 3em;
7
+    // font-weight: bold;
8
+    line-height: 2em;
9 9
     text-align: center;
10 10
 
11 11
     & > view {

+ 9
- 3
src/pages/index/index.jsx Zobrazit soubor

@@ -1,5 +1,5 @@
1 1
 import { View, Text, Image } from '@tarojs/components'
2
-import { useEffect, useRef, useState } from 'react'
2
+import { useEffect, useMemo, useRef, useState } from 'react'
3 3
 import dayjs from 'dayjs'
4 4
 import { Button, Icon } from "@antmjs/vantui";
5 5
 import Taro from '@tarojs/taro';
@@ -16,9 +16,10 @@ export default (props) => {
16 16
     Taro.redirectTo({
17 17
       url: '/pages/setUserInfo/index'
18 18
     })
19
-
20 19
   }
21 20
 
21
+  const today = useMemo(() => dayjs().format('YYYY-MM-DD'))
22
+
22 23
   return (
23 24
     <View className='index-UserQRcode'>
24 25
       {/* <Text>Hello world!</Text> */}
@@ -31,10 +32,15 @@ export default (props) => {
31 32
         <View className='index-UserQRcode-headerInfo-UserID'>身份证:{userId.replace(/^(\d{6})\d+(\d{4})$/, "$1******$2")}</View>
32 33
       </View>
33 34
       <View className='index-UserQRcode-cententQR'>
34
-        <CountDown className='index-UserQRcode-cententQR-Times' />
35 35
         <View className='index-UserQRcode-cententQR-Barcode'>
36 36
           <BarCode ratio={0.7} height={80} code='322050442037' />
37 37
         </View>
38
+        <View className='index-UserQRcode-cententQR-Barcode'>
39
+          <BarCode ratio={0.7} height={80} code='32032219901021050X' />
40
+        </View>
41
+      </View>
42
+      <View className='index-UserQRcode-footer'>
43
+      {today}
38 44
       </View>
39 45
     </View>
40 46
   )

+ 15
- 3
src/pages/index/style.less Zobrazit soubor

@@ -34,13 +34,13 @@
34 34
 
35 35
   &-cententQR {
36 36
     box-sizing: border-box;
37
-    width: 95%;
37
+    width: 90%;
38 38
     // box-shadow: 0px 8px 38px 0px rgba(0, 0, 0, 0.12);
39 39
     border-radius: 15px;
40 40
     background-color: white;
41 41
     margin: 0 auto;
42 42
     position: relative;
43
-    top: -15vh;
43
+    margin-top: -15vh;
44 44
     padding: 2em;
45 45
     border: 1px solid rgba(0,0,0, 0.1);
46 46
 
@@ -51,12 +51,24 @@
51 51
       font-size: 1.8em;
52 52
     }
53 53
     &-Barcode {
54
-      height: 45vh;
54
+      height: 20vh;
55 55
       margin: 0 auto;
56 56
       position: relative;
57 57
       display: flex;
58 58
       justify-content: center;
59 59
       align-items: center;
60
+
61
+      & + & {
62
+        margin-top: 5vh;
63
+      }
60 64
     }
61 65
   }
66
+
67
+  &-footer {
68
+    height: calc(100% - 80vh);
69
+    display: flex;
70
+    justify-content: center;
71
+    align-items: center;
72
+    color: #888;
73
+  }
62 74
 }