张延森 3 years ago
parent
commit
7b34be9370

+ 7
- 3
src/components/CountDown.jsx View File

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

+ 23
- 17
src/components/barcode/index.jsx View File

6
 import './style.less'
6
 import './style.less'
7
 
7
 
8
 export default (props) => {
8
 export default (props) => {
9
-
10
   const { code, ratio, height } = props
9
   const { code, ratio, height } = props
11
 
10
 
11
+  const id = useMemo(() => Math.random().toString(36).substring(2, 10), [])
12
   const canvasRef = useRef()
12
   const canvasRef = useRef()
13
   const ctxRef = useRef()
13
   const ctxRef = useRef()
14
 
14
 
15
-  const sysInfo = useMemo(() => {
15
+  const { size, style } = useMemo(() => {
16
     const { safeArea, pixelRatio } = Taro.getSystemInfoSync()
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
   useEffect(() => {
34
   useEffect(() => {
29
     Taro.nextTick(() => {
35
     Taro.nextTick(() => {
30
       const query = Taro.createSelectorQuery()
36
       const query = Taro.createSelectorQuery()
31
-      query.select('#barCodeCanvas').fields({ node: true }).exec((res) => {
37
+      query.select(`#${id}`).fields({ node: true }).exec((res) => {
32
         const canvas = res[0].node
38
         const canvas = res[0].node
33
         const ctx = canvas.getContext('2d')
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
         canvasRef.current = canvas;
44
         canvasRef.current = canvas;
39
         ctxRef.current = ctx;
45
         ctxRef.current = ctx;
40
 
46
 
41
         if (code) {
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
   return (
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
       <CodeText code={code} />
57
       <CodeText code={code} />
52
     </View>
58
     </View>
53
   )
59
   )

+ 2
- 2
src/components/barcode/style.less View File

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

+ 9
- 3
src/pages/index/index.jsx View File

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

+ 15
- 3
src/pages/index/style.less View File

34
 
34
 
35
   &-cententQR {
35
   &-cententQR {
36
     box-sizing: border-box;
36
     box-sizing: border-box;
37
-    width: 95%;
37
+    width: 90%;
38
     // 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);
39
     border-radius: 15px;
39
     border-radius: 15px;
40
     background-color: white;
40
     background-color: white;
41
     margin: 0 auto;
41
     margin: 0 auto;
42
     position: relative;
42
     position: relative;
43
-    top: -15vh;
43
+    margin-top: -15vh;
44
     padding: 2em;
44
     padding: 2em;
45
     border: 1px solid rgba(0,0,0, 0.1);
45
     border: 1px solid rgba(0,0,0, 0.1);
46
 
46
 
51
       font-size: 1.8em;
51
       font-size: 1.8em;
52
     }
52
     }
53
     &-Barcode {
53
     &-Barcode {
54
-      height: 45vh;
54
+      height: 20vh;
55
       margin: 0 auto;
55
       margin: 0 auto;
56
       position: relative;
56
       position: relative;
57
       display: flex;
57
       display: flex;
58
       justify-content: center;
58
       justify-content: center;
59
       align-items: center;
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
 }