Your Name 3 年之前
父節點
當前提交
ac35a6234d

+ 1
- 0
src/app.config.js 查看文件

@@ -1,6 +1,7 @@
1 1
 export default {
2 2
   pages: [
3 3
     'pages/index/index',
4
+    'pages/History/index',
4 5
     'pages/setUserInfo/index',
5 6
     'pages/DepartmentSelection/index',
6 7
   ],

+ 27
- 38
src/components/barcode/index.jsx 查看文件

@@ -1,4 +1,4 @@
1
-import React, { useEffect, useMemo, useRef } from 'react'
1
+import React, { useCallback, useEffect, useMemo, useRef } from 'react'
2 2
 import Taro from '@tarojs/taro'
3 3
 import { View, Canvas } from '@tarojs/components'
4 4
 import CodeText from './CodeText'
@@ -6,52 +6,41 @@ import { code128 } from './drawCode'
6 6
 import './style.less'
7 7
 
8 8
 export default (props) => {
9
-  const { code, ratio, height, codeVisible = true } = props
9
+  const { code, height, codeVisible = true } = props
10 10
 
11 11
   // 使用 createSelectorQuery 有个注意点, id 或者 class 不能以数字开头
12 12
   const id = useMemo(() => `canvas-${Math.random().toString(36).substring(2, 10)}`, [])
13
-  const canvasRef = useRef()
14
-  const ctxRef = useRef()
13
+  // const canvasRef = useRef()
14
+  // const ctxRef = useRef()
15 15
 
16
-  const { size, style } = useMemo(() => {
17
-    const { safeArea, pixelRatio } = Taro.getSystemInfoSync()
18
-
19
-    const rpxSize = {
20
-      width: safeArea.width * ratio * pixelRatio,
21
-      height: height * pixelRatio,
22
-    }
23
-
24
-    const pxStyle = {
25
-      width: `${safeArea.width * ratio}px`,
16
+  const style = useMemo(() => {
17
+    return {
26 18
       height: `${height}px`,
27 19
       zIndex: 0,
28 20
     }
29
-
30
-    return {
31
-      size: rpxSize,
32
-      style: pxStyle,
33
-    }
34
-  }, [ratio, height])
21
+  }, [height])
22
+
23
+  const renderBarCode = useCallback(() => {
24
+    const query = Taro.createSelectorQuery()
25
+    query.select(`#${id}`).fields({ node: true, size: true }).exec((res) => {
26
+      if (!res[0]) return;
27
+      const { node: canvas, width: w, height: h } = res[0]
28
+      const ctx = canvas.getContext('2d')
29
+      canvas.width = w
30
+      canvas.height = h
31
+
32
+      // canvasRef.current = canvas;
33
+      // ctxRef.current = ctx;
34
+
35
+      if (code) {
36
+        code128(ctx, code, w, h);
37
+      }
38
+    })
39
+  }, [code, id])
35 40
 
36 41
   useEffect(() => {
37
-    Taro.nextTick(() => {
38
-      const query = Taro.createSelectorQuery()
39
-      query.select(`#${id}`).fields({ node: true }).exec((res) => {
40
-        const canvas = res[0].node
41
-        const ctx = canvas.getContext('2d')
42
-        canvas.width = size.width
43
-        canvas.height = size.height
44
-        // ctx.scale(1, 1)
45
-
46
-        canvasRef.current = canvas;
47
-        ctxRef.current = ctx;
48
-
49
-        if (code) {
50
-          code128(ctx, code, size.width, size.height);
51
-        }
52
-      })
53
-    })
54
-  }, [code, size, id])
42
+    Taro.nextTick(renderBarCode)
43
+  }, [renderBarCode])
55 44
 
56 45
   return (
57 46
     <View className='barcode-box'>

+ 6
- 1
src/components/barcode/style.less 查看文件

@@ -1,6 +1,11 @@
1 1
 .barcode-box {
2
+  width: 100%;
2 3
   position: relative;
3 4
 
5
+  canvas {
6
+    width: 100%;
7
+  }
8
+
4 9
   .barcode-txt {
5 10
     display: flex;
6 11
     justify-content: space-between;
@@ -22,7 +27,7 @@
22 27
     font-size: 1.8em;
23 28
     color: rgba(0, 0, 0, .5);
24 29
     line-height: 3em;
25
-    z-index: 1000;
30
+    z-index: 100;
26 31
     top: 0;
27 32
     left: 0;
28 33
     text-align: center;

+ 35
- 0
src/pages/History/Item.jsx 查看文件

@@ -0,0 +1,35 @@
1
+import { View } from '@tarojs/components'
2
+import { Tag } from '@antmjs/vantui'
3
+import BarCode from '@/components/barcode';
4
+import { useMemo } from 'react';
5
+
6
+export default (props) => {
7
+  const { barData, person } = props;
8
+
9
+  const { tagShow, tagType, tagText } = useMemo(() => {
10
+    if (barData.reqStat !== '6') return { tagShow: false };
11
+
12
+    return {
13
+      tagShow: true, 
14
+      tagType: 'success',
15
+      tagText: '阴性'
16
+     }
17
+  }, [barData])
18
+
19
+  return (
20
+    <View className='history-item'>
21
+      <View className='history-item-code'>
22
+        <BarCode ratio={0.5} height={60} code={barData.barcode} />
23
+      </View>
24
+      <View className='history-item-info'>
25
+        <View>{person?.personName}</View>
26
+        <View>{barData.sampledDt}</View>
27
+        <View>
28
+        {
29
+          tagShow && <Tag size='large' type={tagType}>{tagText}</Tag>
30
+        }
31
+        </View>
32
+      </View>
33
+    </View>
34
+  )
35
+}

+ 6
- 0
src/pages/History/index.config.js 查看文件

@@ -0,0 +1,6 @@
1
+export default {
2
+  navigationBarTitleText: '历史条码',
3
+  usingComponents: {
4
+  }
5
+
6
+}

+ 55
- 0
src/pages/History/index.jsx 查看文件

@@ -0,0 +1,55 @@
1
+import { useEffect, useState } from 'react';
2
+import dayjs from 'dayjs';
3
+import { View } from '@tarojs/components'
4
+import { PowerScrollView } from '@antmjs/vantui';
5
+import { useModel } from '@/store';
6
+import { getBarcode } from '@/services/user';
7
+import Item from './Item';
8
+
9
+import './style.less'
10
+
11
+export default (props) => {
12
+  const { person } = useModel('userData')
13
+  const [loading, setLoading] = useState(false)
14
+  const [list, setList] = useState([
15
+    { barcode: '32013201', sampledDt: '2022-05-15', reqStat: '0' },
16
+    { barcode: '32013202', sampledDt: '2022-05-15', reqStat: '6' },
17
+    { barcode: '32013203', sampledDt: '2022-05-15', reqStat: '6' },
18
+    { barcode: '32013204', sampledDt: '2022-05-15', reqStat: '6' },
19
+    { barcode: '32013205', sampledDt: '2022-05-15', reqStat: '6' },
20
+    { barcode: '32013206', sampledDt: '2022-05-15', reqStat: '6' },
21
+  ])
22
+
23
+  useEffect(() => {
24
+    if (person && person.personId) {
25
+      const today = dayjs()
26
+      const params = {
27
+        startDate: today.subtract(7, 'day').format('YYYY-MM-DD'),
28
+        endDate: today.format('YYYY-MM-DD'),
29
+        idNo: person.idNo,
30
+      }
31
+      setLoading(true)
32
+      getBarcode(person.personId, params).then((res) => {
33
+        setList(res || [])
34
+        setLoading(false)
35
+      }).catch(err => {
36
+        console.error(err)
37
+        setLoading(false)
38
+      })
39
+    }
40
+  }, [person])
41
+
42
+  return (
43
+    <PowerScrollView
44
+      className='barcode-history-list'
45
+      refresherEnabled={false}
46
+      total={list.length}
47
+    >
48
+      {
49
+        list.map((barData, inx) => (
50
+          <Item key={inx} person={person} barData={barData} />
51
+        ))
52
+      }
53
+    </PowerScrollView>
54
+  )
55
+}

+ 36
- 0
src/pages/History/style.less 查看文件

@@ -0,0 +1,36 @@
1
+
2
+.barcode-history-list {
3
+  height: 100vh;
4
+  background-color: #f7f8fa;
5
+
6
+  .history-item {
7
+    box-sizing: border-box;
8
+    padding: 0 5vw;
9
+    background: #fff;
10
+    border: 1px solid rgba(0, 0, 0, 0.1);
11
+    border-radius: 16rpx;
12
+    margin: 1em;
13
+  }
14
+
15
+  .history-item-code {
16
+    box-sizing: border-box;
17
+    padding-top: 1.4em;
18
+    width: 70vw;
19
+    margin: auto;
20
+  }
21
+
22
+  .history-item-info {
23
+    display: flex;
24
+    justify-content: space-between;
25
+    align-items: center;
26
+    border-top: 1px solid rgba(0, 0, 0, 0.08);
27
+    box-sizing: border-box;
28
+    padding-top: .5em;
29
+    padding-bottom: 1em;
30
+    margin-top: .5em;
31
+
32
+    & > view {
33
+      flex: none;
34
+    }
35
+  }
36
+}

+ 1
- 23
src/pages/index/components/Footer.jsx 查看文件

@@ -6,32 +6,10 @@ import dayjs from 'dayjs'
6 6
 import './style.less'
7 7
 
8 8
 export default (props) => {
9
-  const [height, setHeight] = useState(40)
10 9
   const today = useMemo(() => dayjs().format('YYYY-MM-DD'), [])
11 10
 
12
-  const footerStyle = useMemo(() => {
13
-    return {
14
-      height: `${height}px`
15
-    }
16
-  }, [height])
17
-
18
-  useEffect(() => {
19
-    Taro.nextTick(() => {
20
-      const query = Taro.createSelectorQuery();
21
-      query.select('.index-footer').boundingClientRect((rect) => {
22
-        const { top } = rect || {}
23
-        if (!top) return;
24
-  
25
-        const { safeArea } = Taro.getSystemInfoSync()
26
-  
27
-        // 4 是随便给的一个允许误差范围
28
-        setHeight(safeArea.height - Math.ceil(top) - 4);
29
-      }).exec()
30
-    })
31
-  }, [])
32
-
33 11
   return (
34
-    <View className='index-footer' style={footerStyle}>
12
+    <View className='index-footer'>
35 13
       <View>
36 14
         <View className='footer-time'>{today}</View>
37 15
         <View className='footer-copyright'>

+ 0
- 30
src/pages/index/components/History/index.jsx 查看文件

@@ -1,30 +0,0 @@
1
-import { useEffect, useState } from 'react';
2
-import { View } from '@tarojs/components'
3
-import { getBarCodeList } from '@/services/user';
4
-
5
-import './style.less'
6
-
7
-export default (props) => {
8
-  const { person } = props
9
-  const [loading, setLoading] = useState(false)
10
-  const [list, setList] = useState([])
11
-
12
-  useEffect(() => {
13
-    if (person && person.personId) {
14
-      setLoading(true)
15
-      getBarCodeList(person.personId, { start, end }).then((res) => {
16
-        setList(res || [])
17
-        setLoading(false)
18
-      }).catch(err => {
19
-        console.error(err)
20
-        setLoading(false)
21
-      })
22
-    }
23
-  }, [person])
24
-
25
-  return (
26
-    <View>
27
-      
28
-    </View>
29
-  )
30
-}

+ 0
- 0
src/pages/index/components/History/style.less 查看文件


+ 50
- 43
src/pages/index/components/style.less 查看文件

@@ -25,11 +25,15 @@
25 25
 
26 26
 .index-main-content {
27 27
   position: relative;
28
+  height: 100vh;
28 29
   z-index: 10;
29 30
   box-sizing: border-box;
30 31
   padding: 0 5vw;
32
+  display: flex;
33
+  flex-direction: column;
31 34
 
32 35
   .index-header {
36
+    flex: none;
33 37
     padding-top: 1em;
34 38
     color: #fff;
35 39
     font-size: 36rpx;
@@ -45,58 +49,61 @@
45 49
 
46 50
     .index-person-dept {
47 51
       font-size: 1.2em;
48
-    }
49
-  
52
+    }  
50 53
   }
51
-}
54
+  
55
+  .index-qrbox {
56
+    flex: none;
57
+    width: 100%;
58
+    background: #fff;
59
+    border-radius: 16rpx;
60
+    border: 1px solid rgba(0, 0, 0, 0.1);
61
+    padding: 4px;
62
+    box-sizing: border-box;
52 63
 
53
-.index-qrbox {
54
-  width: 100%;
55
-  background: #fff;
56
-  border-radius: 16rpx;
57
-  border: 1px solid rgba(0, 0, 0, 0.1);
58
-  padding: 4px;
59
-  box-sizing: border-box;
64
+    .index-qr-item {
65
+      margin-top: 6rpx;
66
+      border-top: 1px solid rgba(0, 0, 0, 0.05);
67
+      position: relative;
68
+      box-sizing: border-box;
69
+      padding: 2em;
70
+      display: flex;
71
+      align-items: center;
72
+      justify-content: center;
73
+      height: 36vh;
60 74
 
61
-  .index-qr-item {
62
-    margin-top: 6rpx;
63
-    border-top: 1px solid rgba(0, 0, 0, 0.05);
64
-    position: relative;
65
-    box-sizing: border-box;
66
-    padding: 2em;
75
+      .index-barcode-tag {
76
+        position: absolute;
77
+        top: 40rpx;
78
+        left:20rpx;
79
+      }
80
+    }
81
+  }
82
+  
83
+  .index-footer {
84
+    flex: auto;
67 85
     display: flex;
68
-    align-items: center;
69 86
     justify-content: center;
70
-    height: 36vh;
87
+    align-items: center;
71 88
 
72
-    .index-barcode-tag {
73
-      position: absolute;
74
-      top: 40rpx;
75
-      left:20rpx;
89
+    & > view {
90
+      width: 100%;
76 91
     }
77
-  }
78
-}
79 92
 
80
-.index-footer {
81
-  display: flex;
82
-  justify-content: center;
83
-  align-items: center;
93
+    .footer-time {
94
+      font-size: 34rpx;
95
+      color: rgba(0, 0, 0, 0.4);
96
+      text-align: center;
97
+      margin-bottom: 1em;
98
+    }
84 99
 
85
-  & > view {
86
-    width: 100%;
100
+    .footer-copyright {
101
+      font-size: 24rpx;
102
+      color: rgba(0, 0, 0, 0.2);
103
+      box-sizing: border-box;
104
+      padding: 0 16vw;
105
+    }
87 106
   }
107
+}
88 108
 
89
-  .footer-time {
90
-    font-size: 34rpx;
91
-    color: rgba(0, 0, 0, 0.4);
92
-    text-align: center;
93
-    margin-bottom: 1em;
94
-  }
95 109
 
96
-  .footer-copyright {
97
-    font-size: 24rpx;
98
-    color: rgba(0, 0, 0, 0.2);
99
-    box-sizing: border-box;
100
-    padding: 0 16vw;
101
-  }
102
-}

+ 35
- 8
src/pages/index/index.jsx 查看文件

@@ -1,6 +1,9 @@
1
-import { View, Text, Image } from '@tarojs/components'
2
-import { useEffect, useMemo, useRef, useState } from 'react'
3
-import { SwipeCell, Dialog, Tabs, Tab } from "@antmjs/vantui";
1
+import { View } from '@tarojs/components'
2
+import { useEffect, useState } from 'react'
3
+import dayjs from 'dayjs';
4
+import { Button, Dialog, Tabs, Tab } from "@antmjs/vantui";
5
+import { useModel } from '@/store';
6
+import { getBarcode } from '@/services/user';
4 7
 import Taro from '@tarojs/taro';
5 8
 import BarCode from '@/components/barcode'
6 9
 import Back from './components/Back';
@@ -9,25 +12,37 @@ import Header from './components/Header';
9 12
 import QRBox from './components/QRBox';
10 13
 import QRItem from './components/QRItem';
11 14
 import Footer from './components/Footer';
12
-import { useModel } from '@/store';
13
-import { getBarcode } from '@/services/user';
14 15
 
15 16
 import './style.less'
16 17
 
18
+const color = '#03737b'
19
+
17 20
 const tabTitleStyle = {
18 21
   fontSize: '36rpx'
19 22
 }
20 23
 
24
+const borderBtnStyle = {
25
+  border: `1px solid ${color}`,
26
+  backgroundColor: 'transparent',
27
+}
28
+
21 29
 export default (props) => {
22 30
   const { person, user } = useModel('userData')
23 31
   const [barData, setBarData] = useState({})
24 32
   const [idCardVisible, setIdCardVisible] = useState(false)
33
+
25 34
   const goUserInfo = () => {
26 35
     Taro.navigateTo({
27 36
       url: '/pages/setUserInfo/index'
28 37
     })
29 38
   }
30 39
 
40
+  const toHistory = () => {
41
+    Taro.navigateTo({
42
+      url: '/pages/History/index'
43
+    })
44
+  }
45
+
31 46
   const handleShowEditor = () => {
32 47
     setIdCardVisible(false)
33 48
     goUserInfo()
@@ -35,7 +50,11 @@ export default (props) => {
35 50
 
36 51
   useEffect(() => {
37 52
     if (person && person.personId) {
38
-      getBarcode(person.personId).then((res) => {
53
+      const params = {
54
+        createDate: dayjs().subtract(1, 'day').format('YYYY-MM-DD'),
55
+        idNo: person.idNo,
56
+      }
57
+      getBarcode(person.personId, params).then((res) => {
39 58
         if (typeof res === 'string') {
40 59
           const resp = JSON.parse(res) || {}
41 60
           setBarData(resp)
@@ -60,7 +79,7 @@ export default (props) => {
60 79
       <Main>
61 80
         <Header person={person} onEdit={goUserInfo} />
62 81
         <QRBox style={{ marginTop: '1.6em' }}>
63
-          <Tabs lineHeight={2} lineWidth={120} color='#03737b' titleActiveColor='#03737b'>
82
+          <Tabs lineHeight={2} lineWidth={120} color={color} titleActiveColor={color}>
64 83
             <Tab title='条码' titleStyle={tabTitleStyle}>
65 84
               <QRItem barData={barData}>
66 85
                 <BarCode ratio={0.7} height={80} code={barData.barcode} />
@@ -73,9 +92,17 @@ export default (props) => {
73 92
             </Tab>
74 93
           </Tabs>
75 94
         </QRBox>
95
+        <Button
96
+          plain
97
+          block
98
+          size='large'
99
+          color={color}
100
+          style={{ marginTop: '1em', ...borderBtnStyle }}
101
+          onClick={toHistory}
102
+        >查看历史记录</Button>
76 103
         <Dialog title='提示' message='未添加个人信息' show={idCardVisible} onConfirm={handleShowEditor} />
104
+        <Footer />
77 105
       </Main>
78
-      <Footer />
79 106
     </View>
80 107
   )
81 108
 }

+ 6
- 10
src/services/user.js 查看文件

@@ -1,5 +1,6 @@
1 1
 
2
-import request from '../utils/request'
2
+import request from '@/utils/request'
3
+import { getQueryString } from '@/utils/codeSegment'
3 4
 // utils/request
4 5
 
5 6
 
@@ -39,12 +40,7 @@ export const setUserInfo = (data) => request('/person', { data, method: 'PUT' })
39 40
  * @param {*} data 
40 41
  * @returns 
41 42
  */
42
-export const getBarcode = (id, data) => request(`/person/${id}/barcode`, { data, method: 'GET' })
43
-
44
-/**
45
- * 获取条形码列表
46
- * @param {*} data 
47
- * @returns 
48
- */
49
- export const getBarCodeList = (id, params) => request(`/person/${id}/barcode`, { params, method: 'GET' })
50
-
43
+export const getBarcode = (id, params) => {
44
+  const data = { queryStr : getQueryString(params) }
45
+  return request(`/person/${id}/barcode`, { data, method: 'GET' })
46
+}