Yansen hace 2 años
padre
commit
f24151f974

+ 0
- 1
config/dev.js Ver fichero

@@ -3,7 +3,6 @@ module.exports = {
3 3
     NODE_ENV: '"development"'
4 4
   },
5 5
   defineConstants: {
6
-    // HOST: '"https://machine.njyunzhi.com"',
7 6
     HOST: '"http://192.168.89.147:7083"',
8 7
   },
9 8
   mini: {},

+ 1
- 2
config/prod.js Ver fichero

@@ -3,8 +3,7 @@ module.exports = {
3 3
     NODE_ENV: '"production"'
4 4
   },
5 5
   defineConstants: {
6
-    // HOST: '"https://machine.njyunzhi.com"',
7
-    HOST: '"http://192.168.89.147:7083"',
6
+    HOST: '"https://dtc.machine.njyunzhi.com"',
8 7
   },
9 8
   mini: {},
10 9
   h5: {

+ 9
- 9
src/app.config.js Ver fichero

@@ -10,13 +10,13 @@ export default {
10 10
     navigationBarTitleText: 'WeChat',
11 11
     navigationBarTextStyle: 'black'    
12 12
   },
13
-  tabBar: {
14
-    list: [{
15
-      pagePath: "pages/index/index",
16
-      text: "设备绑定"
17
-    }, {
18
-      pagePath: "pages/mine/index",
19
-      text: "我的"
20
-    }]
21
-  },
13
+  // tabBar: {
14
+  //   list: [{
15
+  //     pagePath: "pages/index/index",
16
+  //     text: "设备绑定"
17
+  //   }, {
18
+  //     pagePath: "pages/mine/index",
19
+  //     text: "我的"
20
+  //   }]
21
+  // },
22 22
 }

+ 32
- 0
src/components/layout/index.jsx Ver fichero

@@ -0,0 +1,32 @@
1
+import React from 'react';
2
+import Taro from '@tarojs/taro';
3
+import { Tabbar, TabbarItem } from '@antmjs/vantui'
4
+import { View, Slot } from '@tarojs/components';
5
+import './style.less';
6
+
7
+export default (props) => {
8
+  const { active } = props;
9
+
10
+  const onTabChange = (e) => {
11
+    const index = e.detail;
12
+    const tabPage = [
13
+      '/pages/index/index',
14
+      '/pages/mine/index',
15
+    ]
16
+
17
+    const url = tabPage[index];
18
+    Taro.redirectTo({ url });
19
+  }
20
+
21
+  return (
22
+    <View className="page">
23
+      {props.children}
24
+      <Tabbar active={active} onChange={onTabChange}>
25
+        <TabbarItem>绑定设备</TabbarItem>
26
+        <TabbarItem>
27
+          我的
28
+        </TabbarItem>
29
+      </Tabbar>
30
+    </View>
31
+  )
32
+}

+ 7
- 0
src/components/layout/style.less Ver fichero

@@ -0,0 +1,7 @@
1
+.page {
2
+  width: 100%;
3
+  height: 100vh;
4
+  position: relative;
5
+  box-sizing: border-box;
6
+  padding-bottom: 50PX;
7
+}

+ 3
- 2
src/pages/index/index.jsx Ver fichero

@@ -2,6 +2,7 @@ import React from 'react';
2 2
 import Taro from '@tarojs/taro';
3 3
 import { View } from '@tarojs/components';
4 4
 import Uploader from '@/components/Uploader';
5
+import Layout from '@/components/layout';
5 6
 import { Button, Form, FormItem, Radio, RadioGroup, Icon, Field } from '@antmjs/vantui';
6 7
 import { saveBind } from '@/services/bind';
7 8
 import useRequest from '@/utils/useRequest';
@@ -35,7 +36,7 @@ export default (props) => {
35 36
   }
36 37
 
37 38
   return (
38
-    <View>
39
+    <Layout active={0}>
39 40
       <Form className="bind-form" form={form} onFinish={onFinish}>
40 41
         <FormItem
41 42
           required
@@ -107,6 +108,6 @@ export default (props) => {
107 108
           </Button>
108 109
         </View>
109 110
       </Form>
110
-    </View>
111
+    </Layout>
111 112
   )
112 113
 }

+ 67
- 0
src/pages/mine/components/Item.jsx Ver fichero

@@ -0,0 +1,67 @@
1
+import React from 'react';
2
+import { View } from '@tarojs/components';
3
+import { Row, Col, Image, Icon } from '@antmjs/vantui';
4
+import './style.less'
5
+
6
+export default (props) => {
7
+  const { data } = props;
8
+
9
+  return (
10
+    <View className="device-card">
11
+      <View className="device-card-header">
12
+        <Image
13
+          width="64px"
14
+          height="64px"
15
+          src={data?.machineryThumb}
16
+        />
17
+      </View>
18
+      <View className="device-card-body">        
19
+        <Row>
20
+          <Col span={16}>
21
+            <View className="device-card-title">{ data?.machineryName }</View>
22
+            <View className="device-card-subtitle">{ data?.deviceNo }</View>
23
+          </Col>
24
+          <Col span={8}>
25
+            <View className="device-card-title">{ data?.userName }</View>
26
+            <View className="device-card-subtitle">{ data?.phone }</View>
27
+          </Col>
28
+        </Row>
29
+      </View>
30
+      <View className="device-card-footer">
31
+        <Icon name="arrow" />
32
+      </View>
33
+    </View>
34
+
35
+    // <Row>
36
+    //   <Col span={4}>
37
+    //   </Col>
38
+    //   <Col span={10}>
39
+    //     <View>{ data?.machineryName }</View>
40
+    //     <View>{ data?.deviceNo }</View>
41
+    //   </Col>
42
+    //   <Col span={6}>
43
+    //     <View>{ data?.userName }</View>
44
+    //     <View>{ data?.phone }</View>
45
+    //   </Col>
46
+    //   <Col span={4}>
47
+    //   </Col>
48
+    // </Row>
49
+  )
50
+
51
+  // return (
52
+  //   <Row>
53
+  //     <Col span="4">
54
+  //       { data?.deviceKind === 'feifang' ? '飞防' : '深松' }
55
+  //     </Col>
56
+  //     <Col span="6">
57
+  //       { data?.deviceNo }
58
+  //     </Col>
59
+  //     <Col span="10">
60
+  //       { data?.machineryName }
61
+  //     </Col>
62
+  //     <Col span="4">
63
+  //       { data?.onlineStatus === 1 ? '在线' : '离线' }
64
+  //     </Col>
65
+  //   </Row>
66
+  // )
67
+}

+ 82
- 0
src/pages/mine/components/List.jsx Ver fichero

@@ -0,0 +1,82 @@
1
+import React from 'react';
2
+import Taro from '@tarojs/taro';
3
+import { View } from '@tarojs/components';
4
+import VirtualList from '@tarojs/components/virtual-list';
5
+import { Cell, Loading } from '@antmjs/vantui';
6
+import useRequest from '@/utils/useRequest';
7
+import { getBoundList } from '@/services/bind';
8
+import Item from './Item';
9
+
10
+const Row = (props) => {
11
+  const { data, index } = props;
12
+  const item = data[index];
13
+  const onClick = () => Taro.navigateTo({ url: `/pages/index/index?id=${item.serialNo}` });
14
+
15
+  return (
16
+    <Item data={item} onClick={onClick} />
17
+  );
18
+}
19
+
20
+export default (props) => {
21
+
22
+  const [pageInfo, setPageInfo] = React.useState({ current: 0, size: 10, total: 0, page: 0 });
23
+  const [list, setList] = React.useState([]);
24
+  const [loading, request] = useRequest(getBoundList);
25
+
26
+  const height = 500;
27
+  const itemSize = 100;
28
+  const dataLen = list.length;
29
+
30
+  // 所有数据读取完毕
31
+  const isFinished = pageInfo.current > 0 && pageInfo.current * pageInfo.size >= pageInfo.total;
32
+
33
+  const queryData = (params) => {
34
+    request(params).then(res => {
35
+      const { records, ...page } = res;
36
+      if (page.current === 1) {
37
+        setList(records || []);
38
+      } else {
39
+        setList(list.concat(records || []));
40
+      }
41
+      setPageInfo(page);
42
+    }, []);
43
+  };
44
+
45
+  const onScroll = ({scrollDirection, scrollOffset}) => {
46
+    
47
+    if (
48
+      // 数据还有
49
+      !isFinished &&
50
+      // 避免重复加载数据
51
+      !loading &&
52
+      // 只有往前滚动我们才触发
53
+      scrollDirection === 'forward' &&
54
+      // 5 = (列表高度 / 单项列表高度)
55
+      // 100 = 滚动提前加载量,可根据样式情况调整
56
+      scrollOffset > ((dataLen - Math.ceil(height / itemSize) ) * itemSize + 100)
57
+    ) {
58
+      queryData({ pageNum: pageInfo.current + 1 , pageSize: 10 })
59
+    }
60
+  }
61
+
62
+  return (
63
+    <View>
64
+      <VirtualList
65
+        height={height}
66
+        itemData={list}
67
+        itemCount={dataLen}
68
+        itemSize={itemSize}
69
+        width="100%"
70
+        onScroll={onScroll}
71
+      >
72
+        {Row}
73
+      </VirtualList>
74
+      {
75
+        loading && <Loading />
76
+      }
77
+      {
78
+        isFinished && <View className="finish-tip">我是有底线的 ~</View>
79
+      }
80
+    </View>
81
+  )
82
+}

+ 54
- 0
src/pages/mine/components/style.less Ver fichero

@@ -0,0 +1,54 @@
1
+
2
+@height: 64PX;
3
+.device-card {
4
+  display: flex;
5
+  height: @height;
6
+  padding: 12PX 1em;
7
+  margin-bottom: 12PX;
8
+  background-color: #fff;
9
+  border-bottom: 1px solid #ebedf0;
10
+
11
+  .device-card-header {
12
+    flex: none;
13
+    width: 64PX;
14
+    height: @height;
15
+  }
16
+
17
+  .device-card-footer {
18
+    flex: none;
19
+    width: 24PX;
20
+
21
+    display: flex;
22
+    justify-content: center;
23
+    align-items: center;
24
+
25
+    & > view {
26
+      flex: none;
27
+    }
28
+  }
29
+
30
+  .device-card-body {
31
+    flex: 1;
32
+    box-sizing: border-box;
33
+    padding: 0 1em;
34
+    overflow: hidden;
35
+  }
36
+
37
+  .device-card-title, .device-card-subtitle {
38
+    height: (@height / 2);
39
+    line-height: (@height / 2);
40
+  }
41
+
42
+  .device-card-title {
43
+    font-size: 28px;
44
+    color: rgba(0, 0, 0, 1);
45
+    text-overflow: ellipsis;
46
+    overflow: hidden;
47
+    white-space: nowrap;
48
+  }
49
+
50
+  .device-card-subtitle {
51
+    font-size: 0.8em;
52
+    color: rgba(0, 0, 0, 0.5);
53
+  }
54
+}

+ 10
- 25
src/pages/mine/index.jsx Ver fichero

@@ -1,31 +1,16 @@
1
-import { Component } from 'react'
2
-import { View } from '@tarojs/components'
3
-import { Cell, Row, Col } from '@antmjs/vantui'
4
-import './index.less'
1
+import React from 'react';
2
+import Taro from '@tarojs/taro';
3
+import { View } from '@tarojs/components';
4
+import { Cell, Row, Col } from '@antmjs/vantui';
5
+import Layout from '@/components/layout';
6
+import List from './components/List';
7
+import './index.less';
5 8
 
6 9
 export default (props) => {
7 10
 
8 11
   return (
9
-    <View>
10
-      <Cell>
11
-        <Row>
12
-          <Col span="4">
13
-            <View >深松</View>
14
-          </Col>
15
-          <Col span="4">
16
-            <View >012346</View>
17
-          </Col>
18
-          <Col span="10">
19
-            <View >雷肯Smaragd整地机</View>
20
-          </Col>
21
-          <Col span="3">
22
-            <View >离线</View>
23
-          </Col>
24
-          <Col span="3">
25
-            <View >{'>>'}</View>
26
-          </Col>
27
-        </Row>
28
-      </Cell>
29
-    </View>
12
+    <Layout active={1}>
13
+      <List />
14
+    </Layout>
30 15
   )
31 16
 }

+ 4
- 0
src/pages/mine/index.less Ver fichero

@@ -1 +1,5 @@
1 1
 
2
+.finish-tip {
3
+  text-align: center;
4
+  color: rgba(0, 0, 0, 0.2);
5
+}

+ 3
- 1
src/services/bind.js Ver fichero

@@ -1,3 +1,5 @@
1 1
 import request from "@/utils/request";
2 2
 
3
-export const saveBind = data => request('/tcBind', { method: 'post', data })
3
+export const saveBind = data => request('/tcBind', { method: 'post', data });
4
+
5
+export const getBoundList = params => request('/tcBind', { params });