Yansen il y a 2 ans
Parent
révision
f3c90cedfd

+ 2
- 2
project.config.json Voir le fichier

@@ -1,8 +1,8 @@
1 1
 {
2 2
   "miniprogramRoot": "./dist",
3
-  "projectname": "myApp",
3
+  "projectname": "源盛设备绑定",
4 4
   "description": "xiaofang",
5
-  "appid": "wx1a0fa56e6d0b78b3",
5
+  "appid": "wxe44244d1a5ea3364",
6 6
   "setting": {
7 7
     "urlCheck": true,
8 8
     "es6": false,

+ 27
- 3
src/components/layout/index.jsx Voir le fichier

@@ -2,13 +2,17 @@ import React from 'react';
2 2
 import Taro from '@tarojs/taro';
3 3
 import { Tabbar, TabbarItem } from '@antmjs/vantui'
4 4
 import { View, Slot } from '@tarojs/components';
5
+import NavBar from '../navbar';
5 6
 import './style.less';
6 7
 
8
+let active = 0;
9
+
7 10
 export default (props) => {
8
-  const { active } = props;
11
+  const { className = '', style = {}, custom = true, title = "myApp", showHome = false } = props;
9 12
 
10 13
   const onTabChange = (e) => {
11 14
     const index = e.detail;
15
+    active = index;
12 16
     const tabPage = [
13 17
       '/pages/index/index',
14 18
       '/pages/mine/index',
@@ -18,10 +22,30 @@ export default (props) => {
18 22
     Taro.reLaunch({ url });
19 23
   }
20 24
 
25
+  const innerStyle = React.useMemo(() => {
26
+    if (!custom) return;
27
+
28
+    const { windowWidth } = Taro.getSystemInfoSync();
29
+    const { bottom, right } = Taro.getMenuButtonBoundingClientRect();
30
+    
31
+    const gap = windowWidth - right;
32
+    const navBarHeight = bottom + gap;
33
+
34
+    return {
35
+      paddingTop: `${navBarHeight}px`,
36
+    }
37
+  }, [custom]);
38
+
39
+  const clsName = `page ${className}`;
40
+  const sty = { ...style, ...innerStyle };
41
+
21 42
   return (
22
-    <View className="page">
43
+    <View className={clsName} style={sty}>
44
+      {
45
+        custom && <NavBar title={title} showHome={showHome} />
46
+      }
23 47
       {props.children}
24
-      <Tabbar active={active} onChange={onTabChange}>
48
+      <Tabbar active={active} activeColor="#07c160" onChange={onTabChange}>
25 49
         <TabbarItem>绑定设备</TabbarItem>
26 50
         <TabbarItem>
27 51
           我的

+ 3
- 1
src/components/layout/style.less Voir le fichier

@@ -3,5 +3,7 @@
3 3
   height: 100vh;
4 4
   position: relative;
5 5
   box-sizing: border-box;
6
-  padding-bottom: 50PX;
6
+  padding-bottom: calc(env(safe-area-inset-bottom) + 50PX);
7
+  overflow: auto;
8
+  background-image: linear-gradient(rgba(7,193,94, 0.1), transparent);
7 9
 }

+ 80
- 0
src/components/navbar/index.jsx Voir le fichier

@@ -0,0 +1,80 @@
1
+import React from 'react';
2
+import Taro from '@tarojs/taro';
3
+import { View } from '@tarojs/components';
4
+import { Icon } from '@antmjs/vantui';
5
+
6
+import './style.less'
7
+
8
+export default (props) => {
9
+  const { title, showHome = false } = props;
10
+
11
+  const [pgLen, setPgLen] = React.useState(0);
12
+  const [style1, style2, style3, style4] = React.useMemo(() => {
13
+    const { statusBarHeight, windowWidth } = Taro.getSystemInfoSync();
14
+    const { bottom, right, width, height, left, top } = Taro.getMenuButtonBoundingClientRect();
15
+
16
+    const gap = windowWidth - right;
17
+    
18
+    const wrapperStyle = {
19
+      paddingTop: `${statusBarHeight}px`,
20
+      height: `${bottom + gap}px`,
21
+      width: `${left}px`,
22
+    }
23
+
24
+    const barStyle = {
25
+      paddingTop: `${top - statusBarHeight}px`,
26
+      paddingLeft: `${gap}px`,
27
+      paddingRight: 0,
28
+      height: `${height}px`,
29
+      lineHeight: `${height}px`,
30
+    }
31
+
32
+    const navStyle = {
33
+      width: `${width}px`
34
+    }
35
+
36
+    const titleStype = {
37
+      padding: `0 ${gap}px`,
38
+    }
39
+
40
+    return [
41
+      wrapperStyle,
42
+      barStyle,
43
+      navStyle,
44
+      titleStype
45
+    ]
46
+  }, []);
47
+
48
+  const isBack = pgLen > 1;
49
+
50
+  const goHome = () => {
51
+    Taro.reLaunch({ url: '/pages/index/index' });
52
+  }
53
+
54
+  const goBack = () => {
55
+    Taro.navigateBack({
56
+      delta: 1
57
+    })
58
+  }
59
+
60
+  Taro.useDidShow(() => {
61
+    const pages = Taro.getCurrentPages();
62
+    setPgLen(pages ? pages.length : 0);
63
+  })
64
+
65
+  return (
66
+    <View className="navbar-wrapper" style={style1}>
67
+      <View className="navabar-container" style={style2}>
68
+        <View style={style3}>
69
+          {
70
+            showHome && <View className="navabar-icon" onClick={goHome}><Icon name="wap-home-o" size={36} /></View>
71
+          }
72
+          {
73
+            isBack && !showHome && <View className="navabar-icon" onClick={goBack}><Icon name="arrow-left" size={36} /></View>
74
+          }
75
+        </View>
76
+        <View style={style4}>{title}</View>
77
+      </View>
78
+    </View>
79
+  )
80
+}

+ 32
- 0
src/components/navbar/style.less Voir le fichier

@@ -0,0 +1,32 @@
1
+.navbar-wrapper {
2
+  box-sizing: border-box;
3
+  position: fixed;
4
+  top: 0;
5
+  left: 0;
6
+
7
+  .navabar-icon {
8
+    box-sizing: border-box;
9
+    padding: 0 8px;
10
+    display: inline-block;
11
+  }
12
+
13
+  .navabar-container {
14
+    box-sizing: border-box;
15
+    display: flex;
16
+
17
+    & > view {
18
+      &:first-child {
19
+        flex: none;
20
+      }
21
+  
22
+      &:last-child {
23
+        text-align: center;
24
+        flex: 1;
25
+        overflow: hidden;
26
+        white-space: nowrap;
27
+        text-overflow: ellipsis;
28
+        font-size: 16PX;
29
+      }
30
+    }
31
+  }
32
+}

+ 3
- 1
src/pages/index/index.config.js Voir le fichier

@@ -1,3 +1,5 @@
1 1
 export default {
2
-  navigationBarTitleText: '绑定设备'
2
+  navigationBarTitleText: '绑定设备',
3
+  enableShareAppMessage: true,
4
+  navigationStyle: 'custom'
3 5
 }

+ 14
- 3
src/pages/index/index.jsx Voir le fichier

@@ -56,13 +56,24 @@ export default (props) => {
56 56
         setDisabled(res.status === 1);
57 57
       })
58 58
     }
59
-  }, [id])
59
+  }, [id]);
60
+
61
+  // 分享页面
62
+  Taro.useShareAppMessage(() => {
63
+    return {
64
+      title: '源盛设备绑定',
65
+      imageUrl: 'https://h5.njyunzhi.com/images/nanyang_share.png'
66
+    }
67
+  });
68
+
69
+  console.log(wx.getMenuButtonBoundingClientRect())
70
+  console.log(wx.getSystemInfoSync())
60 71
 
61 72
   return (
62
-    <Layout active={0}>
73
+    <Layout active={0} title="绑定设备">
63 74
       {
64 75
         disabled && <NoticeBar text="车辆信息已入库, 禁止编辑" />
65
-      }      
76
+      }
66 77
       <Form className="bind-form" form={form} onFinish={onFinish}>
67 78
         <FormItem
68 79
           required

+ 1
- 1
src/pages/index/index.less Voir le fichier

@@ -2,7 +2,7 @@
2 2
 .bind-form {
3 3
   background: #fff;
4 4
   border-radius: 16px;
5
-  margin: 0 1em;
5
+  margin: 1em;
6 6
   width: calc(100% - 2em);
7 7
   overflow: hidden;
8 8
 

+ 15
- 11
src/pages/mine/components/List.jsx Voir le fichier

@@ -2,7 +2,7 @@ import React from 'react';
2 2
 import Taro from '@tarojs/taro';
3 3
 import { View } from '@tarojs/components';
4 4
 import VirtualList from '@tarojs/components/virtual-list';
5
-import { Cell, Loading } from '@antmjs/vantui';
5
+import { Cell, Loading, Empty } from '@antmjs/vantui';
6 6
 import useRequest from '@/utils/useRequest';
7 7
 import { getBoundList } from '@/services/bind';
8 8
 import Item from './Item';
@@ -61,16 +61,20 @@ export default (props) => {
61 61
 
62 62
   return (
63 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>
64
+      {
65
+        dataLen < 1 ? <Empty /> : (
66
+          <VirtualList
67
+            height={height}
68
+            itemData={list}
69
+            itemCount={dataLen}
70
+            itemSize={itemSize}
71
+            width="100%"
72
+            onScroll={onScroll}
73
+          >
74
+            {Row}
75
+          </VirtualList>
76
+        )
77
+      }
74 78
       {
75 79
         loading && <Loading />
76 80
       }

+ 2
- 1
src/pages/mine/index.config.js Voir le fichier

@@ -1,3 +1,4 @@
1 1
 export default {
2
-  navigationBarTitleText: '我的'
2
+  navigationBarTitleText: '我的',
3
+  navigationStyle: 'custom'
3 4
 }

+ 1
- 1
src/pages/mine/index.jsx Voir le fichier

@@ -9,7 +9,7 @@ import './index.less';
9 9
 export default (props) => {
10 10
 
11 11
   return (
12
-    <Layout active={1}>
12
+    <Layout title="我的" showHome>
13 13
       <List />
14 14
     </Layout>
15 15
   )