Your Name 2 年之前
父節點
當前提交
659568c278
共有 5 個檔案被更改,包括 171 行新增56 行删除
  1. 1
    34
      src/app.config.js
  2. 137
    0
      src/layouts/TabBar.jsx
  3. 18
    20
      src/layouts/index.jsx
  4. 14
    1
      src/layouts/layout.module.less
  5. 1
    1
      src/pages/home/index.jsx

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

@@ -1,3 +1,4 @@
1
+// eslint-disable-next-line no-undef
1 2
 export default defineAppConfig({
2 3
   pages: [
3 4
     'pages/home/index',
@@ -10,40 +11,6 @@ export default defineAppConfig({
10 11
     'pages/reporting/detail/index',
11 12
     'pages/reset-password/index',
12 13
   ],
13
-  tabBar: {
14
-    list: [
15
-      {
16
-        pagePath: "pages/home/index",
17
-        text: "首页",
18
-        iconPath: "/assets/tabbar/page.png",
19
-        selectedIconPath: "/assets/tabbar/page click.png"
20
-      },
21
-      {
22
-        pagePath: "pages/reporting/index",
23
-        text: "公告",
24
-        iconPath: "/assets/tabbar/notice.png",
25
-        selectedIconPath: "/assets/tabbar/notice click.png"
26
-      },
27
-      {
28
-        pagePath: "pages/index3/index",
29
-        text: "发布",
30
-        iconPath: "/assets/tabbar/release.png",
31
-        selectedIconPath: "/assets/tabbar/release click.png"
32
-      },
33
-      {
34
-        pagePath: "pages/index4/index",
35
-        text: "测评标准",
36
-        iconPath: "/assets/tabbar/evaluation.png",
37
-        selectedIconPath: "/assets/tabbar/evaluation click.png"
38
-      },
39
-      {
40
-        pagePath: "pages/index5/index",
41
-        text: "我的",
42
-        iconPath: "/assets/tabbar/my.png",
43
-        selectedIconPath: "/assets/tabbar/my click.png"
44
-      },
45
-    ],
46
-  },
47 14
   window: {
48 15
     // backgroundColor: '#1A7565',
49 16
     backgroundTextStyle: 'light',

+ 137
- 0
src/layouts/TabBar.jsx 查看文件

@@ -0,0 +1,137 @@
1
+import React from 'react';
2
+import Taro from '@tarojs/taro';
3
+import { Image } from '@tarojs/components';
4
+import { Tabbar, TabbarItem } from '@antmjs/vantui';
5
+import homeIcon from '@/assets/tabbar/page.png';
6
+import homeActiveIcon from '@/assets/tabbar/page click.png';
7
+import noticeIcon from '@/assets/tabbar/notice.png';
8
+import noticeActiveIcon from '@/assets/tabbar/notice click.png';
9
+import issueIcon from '@/assets/tabbar/release.png';
10
+import issueActiveIcon from '@/assets/tabbar/release click.png';
11
+import checkIcon from '@/assets/tabbar/evaluation.png';
12
+import checkActiveIcon from '@/assets/tabbar/evaluation click.png';
13
+import mineIcon from '@/assets/tabbar/my.png';
14
+import mineActiveIcon from '@/assets/tabbar/my click.png';
15
+
16
+const tabPages = {
17
+  home: '/pages/home/index',
18
+  notice: '/pages/index3/index',
19
+  issue: '/pages/issue/add/index',
20
+  check: '/pages/index4/index',
21
+  mine: '/pages/index5/index',
22
+}
23
+
24
+export default (props) => {
25
+  const { active = -1, className } = props;
26
+
27
+  const onChange = (e) => {
28
+    Taro.reLaunch({
29
+      url: tabPages[e.detail]
30
+    })
31
+  }
32
+
33
+  return (
34
+    <Tabbar
35
+      activeColor="#1A7565"
36
+      className={className}
37
+      active={active}
38
+      onChange={onChange}
39
+    >
40
+      <TabbarItem
41
+        name="home"
42
+        renderIcon={
43
+          <Image
44
+            src={homeIcon}
45
+            mode="aspectFit"
46
+            style="width: 30px; height: 18px;"
47
+          ></Image>
48
+        }
49
+        renderIconActive={
50
+          <Image
51
+            src={homeActiveIcon}
52
+            mode="aspectFit"
53
+            style="width: 30px; height: 18px;"
54
+          ></Image>
55
+        }
56
+      >
57
+        首页
58
+      </TabbarItem>
59
+      <TabbarItem
60
+        name="notice"
61
+        renderIcon={
62
+          <Image
63
+            src={noticeIcon}
64
+            mode="aspectFit"
65
+            style="width: 30px; height: 18px;"
66
+          ></Image>
67
+        }
68
+        renderIconActive={
69
+          <Image
70
+            src={noticeActiveIcon}
71
+            mode="aspectFit"
72
+            style="width: 30px; height: 18px;"
73
+          ></Image>
74
+        }
75
+      >
76
+        公告
77
+      </TabbarItem>
78
+      <TabbarItem
79
+        name="issue"
80
+        renderIcon={
81
+          <Image
82
+            src={issueIcon}
83
+            mode="aspectFit"
84
+            style="width: 30px; height: 18px;"
85
+          ></Image>
86
+        }
87
+        renderIconActive={
88
+          <Image
89
+            src={issueActiveIcon}
90
+            mode="aspectFit"
91
+            style="width: 30px; height: 18px;"
92
+          ></Image>
93
+        }
94
+      >
95
+        发布
96
+      </TabbarItem>
97
+      <TabbarItem
98
+        name="check"
99
+        renderIcon={
100
+          <Image
101
+            src={checkIcon}
102
+            mode="aspectFit"
103
+            style="width: 30px; height: 18px;"
104
+          ></Image>
105
+        }
106
+        renderIconActive={
107
+          <Image
108
+            src={checkActiveIcon}
109
+            mode="aspectFit"
110
+            style="width: 30px; height: 18px;"
111
+          ></Image>
112
+        }
113
+      >
114
+        测评标准
115
+      </TabbarItem>
116
+      <TabbarItem
117
+        name="mine"
118
+        renderIcon={
119
+          <Image
120
+            src={mineIcon}
121
+            mode="aspectFit"
122
+            style="width: 30px; height: 18px;"
123
+          ></Image>
124
+        }
125
+        renderIconActive={
126
+          <Image
127
+            src={mineActiveIcon}
128
+            mode="aspectFit"
129
+            style="width: 30px; height: 18px;"
130
+          ></Image>
131
+        }
132
+      >
133
+        我的
134
+      </TabbarItem>
135
+    </Tabbar>
136
+  )
137
+}

+ 18
- 20
src/layouts/index.jsx 查看文件

@@ -1,26 +1,19 @@
1 1
 import React from 'react';
2 2
 import Taro from '@tarojs/taro';
3
-import { View } from '@tarojs/components';
3
+import { View, Image } from '@tarojs/components';
4 4
 import { useModel } from '@/store';
5 5
 import { Loading } from '@antmjs/vantui';
6 6
 import Auth from '@/components/Auth';
7
+import TabBar from './TabBar';
7 8
 import laySty from './layout.module.less';
8 9
 
9 10
 export default (props) => {
10
-  const { className, style, roles, showTabBar } = props;
11
+  const { className, style, roles, tabBar = false } = props;
11 12
 
12 13
   const { person, user } = useModel('user');
13 14
 
14 15
   const classNames = `${laySty['page-wrapper']} ${className}`;
15 16
 
16
-  React.useMemo(() => {
17
-    if (showTabBar) {
18
-      Taro.showTabBar();
19
-    } else {
20
-      Taro.hideTabBar();
21
-    }
22
-  }, [showTabBar]);
23
-
24 17
   React.useEffect(() => {
25 18
     if (person && !user) {
26 19
       const currentPage = Taro.getCurrentPages().slice().pop();      
@@ -34,18 +27,23 @@ export default (props) => {
34 27
 
35 28
   return (
36 29
     <View className={classNames} style={style}>
30
+      <View className={laySty['page-conatiner']}>
31
+        {
32
+          !person && (
33
+            <View className={laySty.loading}>
34
+              <Loading size="32px" vertical>
35
+                加载中...
36
+              </Loading>
37
+            </View>
38
+          )
39
+        }
40
+        <Auth roles={roles}>
41
+        {props.children}
42
+        </Auth>
43
+      </View>
37 44
       {
38
-        !person && (
39
-          <View className={laySty.loading}>
40
-            <Loading size="32px" vertical>
41
-              加载中...
42
-            </Loading>
43
-          </View>
44
-        )
45
+        tabBar && <TabBar className={laySty['page-tabbar']} active={tabBar} />
45 46
       }
46
-      <Auth roles={roles}>
47
-      {props.children}
48
-      </Auth>
49 47
     </View>
50 48
   )
51 49
 }

+ 14
- 1
src/layouts/layout.module.less 查看文件

@@ -1,7 +1,20 @@
1 1
 
2 2
 .page-wrapper {
3 3
   position: relative;
4
-  height: 100%;
4
+  width: 100%;
5
+  box-sizing: content-box;
6
+  height: calc(100% - env(safe-area-inset-bottom));
7
+  padding-bottom: env(safe-area-inset-bottom);
8
+
9
+  .page-conatiner {
10
+    width: 100%;
11
+    height: calc(100% - var(--tabbar-height, 100rpx));
12
+    overflow: hidden;
13
+  }
14
+
15
+  .page-tabbar {
16
+    flex: none;
17
+  }
5 18
 
6 19
   .loading {
7 20
     position: fixed;

+ 1
- 1
src/pages/home/index.jsx 查看文件

@@ -12,7 +12,7 @@ export default (props) => {
12 12
   const { user } = useModel('user');
13 13
 
14 14
   return (
15
-    <Page showTabBar className='index'>
15
+    <Page tabBar="home" className='index'>
16 16
       <Head user={user} />
17 17
       <BannerCard />
18 18
       <MenuCard />