Yansen 2 years ago
parent
commit
f23429a44c

+ 1
- 0
config/dev.js View File

6
     // HOST: '"http://127.0.0.1:9087"',
6
     // HOST: '"http://127.0.0.1:9087"',
7
     HOST: '"http://localhost:9087"',
7
     HOST: '"http://localhost:9087"',
8
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
8
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
9
+    DEFAULT_POS: '"116.3476917447715,31.409912844296578"', // 霍山县人民政府 gcj02
9
   },
10
   },
10
   mini: {},
11
   mini: {},
11
   h5: {},
12
   h5: {},

+ 1
- 0
config/prod.js View File

5
   defineConstants: {
5
   defineConstants: {
6
     HOST: '"https://t.njyz.tech"',
6
     HOST: '"https://t.njyz.tech"',
7
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
7
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
8
+    DEFAULT_POS: '"116.3476917447715,31.409912844296578"', // 霍山县人民政府 gcj02
8
   },
9
   },
9
   mini: {},
10
   mini: {},
10
   h5: {
11
   h5: {

+ 0
- 2
src/app.config.js View File

16
     // 'pages/checkStand/index',
16
     // 'pages/checkStand/index',
17
     "pages/checkStand/list/index",
17
     "pages/checkStand/list/index",
18
     "pages/checkStand/detail/index",
18
     "pages/checkStand/detail/index",
19
-    "pages/reporting/index",
20
-    "pages/reporting/detail/index",
21
     "pages/reset-password/index",
19
     "pages/reset-password/index",
22
     "pages/check/list/index",
20
     "pages/check/list/index",
23
     "pages/check/loc/list/index",
21
     "pages/check/loc/list/index",

+ 80
- 40
src/components/map/index.jsx View File

6
 import iconPath from '@/assets/icons/marker.png';
6
 import iconPath from '@/assets/icons/marker.png';
7
 import style from './style.module.less';
7
 import style from './style.module.less';
8
 
8
 
9
-// location 逻辑
10
-// 如果 props.location 有值, 那么放弃地图定位的点, 使用 props.location
11
-// 否则使用 地图定位的点
12
-// 如果地图定位失败 或者 props.location 为空, 那么不产生数据交互
13
-// 但是地图上默认使用 霍山县人民政府 的定位
14
 export default (props) => {
9
 export default (props) => {
15
-  const { location, onLocChange } = props;
10
+  const { readOnly, location, onChange } = props;
11
+
12
+  const id = React.useMemo(() => `map-${Math.random().toString(36).substring(2, 10)}`, []);
13
+  const mapCtxRef = React.useRef();
16
 
14
 
17
-  const [currentPos, setCurPos] = React.useState();
18
   const [
15
   const [
19
-    markers,
20
-    lngLat,
16
+    // markers,
17
+    center,
21
   ] = React.useMemo(() => {
18
   ] = React.useMemo(() => {
22
-    const loc = location || currentPos || '116.354259,31.415587';
19
+    // eslint-disable-next-line no-undef
20
+    const loc = location || DEFAULT_POS;
23
     const [longitude, latitude] = loc.split(',');
21
     const [longitude, latitude] = loc.split(',');
24
 
22
 
25
-    const mks = [{
26
-      id: 1,
27
-      longitude,
28
-      latitude,
29
-      iconPath,
30
-      width: 17,
31
-      height: 20
32
-    }];
23
+    // const mks = [{
24
+    //   id: 1,
25
+    //   longitude,
26
+    //   latitude,
27
+    //   iconPath,
28
+    //   width: 17,
29
+    //   height: 20
30
+    // }];
33
 
31
 
34
     return [
32
     return [
35
-      mks,
36
-      [longitude, latitude]
33
+      // mks,
34
+      {longitude, latitude}
37
     ]
35
     ]
38
-  }, [location, currentPos]);
36
+  }, [location]);
39
 
37
 
40
-  React.useEffect(() => {
41
-    getLocation().then((res) => {
42
-      setCurPos([res.longitude, res.latitude].join(','));
43
-    }).catch((err) => {
44
-      console.error(err);
45
-      Taro.showToast({
46
-        title: '定位失败',
47
-        icon: 'none',
38
+  const moveTo = (ctx, point) => {
39
+    ctx.moveToLocation({
40
+      ...point,
41
+      fail: console.error,
42
+    })
43
+  }
44
+
45
+  const getContext = React.useCallback(() => {
46
+    const query = Taro.createSelectorQuery();
47
+    query.select(`#${id}`).context(res => {
48
+      mapCtxRef.current = res.context;
49
+
50
+      // 修改中心图标 - 暂时不起作用, wx bug
51
+      mapCtxRef.current.setLocMarkerIcon({
52
+        iconPath,
53
+        fail: console.error,
48
       })
54
       })
55
+    }).exec();
56
+  }, [id]);
57
+
58
+  const fixedLocation = () => {
59
+    return new Promise((resolve) => {
60
+      getLocation({ type: 'gcj02' }).then((res) => {
61
+        resolve(res);
62
+      }).catch((err) => {
63
+        console.error(err);
64
+        Taro.showToast({
65
+          title: '定位失败',
66
+          icon: 'none',
67
+        })
68
+      });
49
     });
69
     });
50
-  }, []);
70
+  }
51
 
71
 
72
+  const onRefresh = () => {
73
+    if (mapCtxRef.current) {
74
+      fixedLocation().then((res) => {
75
+        const { longitude, latitude } = res;
76
+        onChange([res.longitude, res.latitude].join(','));
77
+        moveTo(mapCtxRef.current, {longitude, latitude});
78
+      })
79
+    }
80
+  }
81
+  
52
   React.useEffect(() => {
82
   React.useEffect(() => {
53
-    if (!location && !currentPos) return;
54
-
55
-    const loc = location || currentPos;
56
-    if (loc) {
57
-      onLocChange(loc);
83
+    if (!readOnly) {
84
+      fixedLocation().then((res) => {
85
+        const { longitude, latitude } = res;
86
+        onChange([longitude, latitude].join(','));
87
+      })
58
     }
88
     }
59
-  }, [location, currentPos]);
89
+  }, [readOnly]);
90
+
91
+  React.useEffect(() => {
92
+    getContext();
93
+  }, [getContext]);
60
 
94
 
61
   return (
95
   return (
62
     <View className={style['map-wrapper']}>
96
     <View className={style['map-wrapper']}>
63
       <Map
97
       <Map
64
-        longitude={lngLat[0]}
65
-        latitude={lngLat[1]}
66
-        markers={markers}
98
+        id={id}
99
+        showLocation
100
+        longitude={center.longitude}
101
+        latitude={center.latitude}
102
+        // markers={markers}
67
       >
103
       >
68
-        <CoverView className={style['control']}><Icon name="aim" size="26px" color="rgb(18,183,245)" /></CoverView>
104
+        {!readOnly && (
105
+          <CoverView className={style['control']} onClick={onRefresh}>
106
+            <Icon name="aim" size="24px" color="#1A7565" />
107
+          </CoverView>
108
+        )}
69
       </Map>
109
       </Map>
70
     </View>
110
     </View>
71
   )
111
   )

+ 2
- 2
src/components/map/style.module.less View File

12
     left: 0;
12
     left: 0;
13
     .control {
13
     .control {
14
       position: absolute;
14
       position: absolute;
15
-      bottom: 14%;
16
-      right: 4%;
15
+      bottom: var(--main-space);
16
+      right: var(--main-space);
17
     }
17
     }
18
   }
18
   }
19
 }
19
 }

+ 17
- 11
src/pages/check/edit/components/LocForm.jsx View File

10
 export default (props) => {
10
 export default (props) => {
11
   const { checkItemInfo, checkType, answer, readonly, onChange, onLoadingChange } = props;
11
   const { checkItemInfo, checkType, answer, readonly, onChange, onLoadingChange } = props;
12
 
12
 
13
-  const [loc, setLoc] = React.useState();
14
   const [showAgePicker, setShowAgePicker] = React.useState(false);
13
   const [showAgePicker, setShowAgePicker] = React.useState(false);
15
 
14
 
16
   const setLoading = (v) => {
15
   const setLoading = (v) => {
21
 
20
 
22
   const setFieldChange = (key, val) => {
21
   const setFieldChange = (key, val) => {
23
     onChange({
22
     onChange({
24
-      location: loc,
25
       ...answer || {},
23
       ...answer || {},
26
       [key]: val,
24
       [key]: val,
27
     })
25
     })
46
 
44
 
47
   return (
45
   return (
48
     <View>
46
     <View>
49
-      <Map location={answer?.location} onLocChange={setLoc} />
47
+      <Map
48
+        readOnly={readonly}
49
+        location={answer?.location}
50
+        onChange={e => setFieldChange('location', e)}
51
+      />
50
       <CellGroup>
52
       <CellGroup>
51
         {
53
         {
52
           checkType == 'loc' && (
54
           checkType == 'loc' && (
56
             />
58
             />
57
           )
59
           )
58
         }
60
         }
61
+        {
62
+          checkType == 'survey' && (
63
+            <Field
64
+              label="社区"
65
+              placeholder="请填写社区名称"
66
+              readonly={readonly}
67
+              value={answer?.communityName}
68
+              onChange={e => setFieldChange('communityName', e.detail)}
69
+            />
70
+          )
71
+        }
59
         <Field
72
         <Field
60
           readonly={readonly}
73
           readonly={readonly}
61
-          placeholder={checkType == 'loc' ? '请输入地址' : '请填写社区名称'}
62
-          // value={answer}
63
-          leftIcon={mapIcon}
64
-        // onChange={e => setFieldChange('', e.detail)}
65
-        />
66
-        <Field
67
-          readonly={readonly}
74
+          label={checkType == 'loc' ? '地址' : '小区'}
68
           placeholder={checkType == 'loc' ? '请输入地址' : '请填写小区名称'}
75
           placeholder={checkType == 'loc' ? '请输入地址' : '请填写小区名称'}
69
           value={answer?.addr}
76
           value={answer?.addr}
70
-          leftIcon={mapIcon}
71
           onChange={e => setFieldChange('addr', e.detail)}
77
           onChange={e => setFieldChange('addr', e.detail)}
72
         />
78
         />
73
       </CellGroup>
79
       </CellGroup>

+ 1
- 1
src/pages/check/edit/index.jsx View File

44
     if (index == -1 && n != -1) {
44
     if (index == -1 && n != -1) {
45
       if (!readonly) {
45
       if (!readonly) {
46
         try {
46
         try {
47
+          warn(typ == 'survey' && !answer?.communityName, '请填写社区名称');
47
           warn(!answer?.addr, typ == 'loc' ? '请填写地址' : '请填写小区名称');
48
           warn(!answer?.addr, typ == 'loc' ? '请填写地址' : '请填写小区名称');
48
-          // warn(!answer, typ == 'loc' ? '请填写地址' : '请填写社区名称');
49
           warn(!answer?.location, '未能获取定位信息, 请重试');
49
           warn(!answer?.location, '未能获取定位信息, 请重试');
50
           warn(typ == 'survey' && !answer?.sex, '请选择性别');
50
           warn(typ == 'survey' && !answer?.sex, '请选择性别');
51
           warn(typ == 'survey' && !answer?.age, '请选择年龄段');
51
           warn(typ == 'survey' && !answer?.age, '请选择年龄段');

+ 5
- 4
src/pages/check/loc/edit/components/LocForm.jsx View File

9
 export default (props) => {
9
 export default (props) => {
10
   const { checkItemInfo, answer, readonly, onChange, onLoadingChange } = props;
10
   const { checkItemInfo, answer, readonly, onChange, onLoadingChange } = props;
11
 
11
 
12
-  const [loc, setLoc] = React.useState();
13
-
14
   const setLoading = (v) => {
12
   const setLoading = (v) => {
15
     if (onLoadingChange) {
13
     if (onLoadingChange) {
16
       onLoadingChange(v)
14
       onLoadingChange(v)
19
   
17
   
20
   const setFieldChange = (key, val) => {
18
   const setFieldChange = (key, val) => {
21
     onChange({
19
     onChange({
22
-      location: loc,
23
       ...answer || {},
20
       ...answer || {},
24
       [key]: val,
21
       [key]: val,
25
     })
22
     })
42
   
39
   
43
   return (
40
   return (
44
     <View>
41
     <View>
45
-      <Map location={answer?.location} onLocChange={setLoc} />
42
+      <Map
43
+        readOnly={readonly}
44
+        location={answer?.location}
45
+        onChange={(e) => setFieldChange('location', e)}
46
+      />
46
       <CellGroup>
47
       <CellGroup>
47
         <Cell
48
         <Cell
48
           title="点位"
49
           title="点位"

+ 2
- 1
src/pages/feedback/issue/index.jsx View File

64
   return (
64
   return (
65
     <Page tabBar="feedback">
65
     <Page tabBar="feedback">
66
       <Map
66
       <Map
67
+        readOnly={readOnly}
67
         location={formData.location}
68
         location={formData.location}
68
-        onLocChange={e => !formData.location && setFieldChange('location', e)}
69
+        onChange={e => !formData.location && setFieldChange('location', e)}
69
       />
70
       />
70
 
71
 
71
       <CellGroup>
72
       <CellGroup>

+ 2
- 1
src/pages/issue/components/Issue/index.jsx View File

144
       />
144
       />
145
 
145
 
146
       <Map
146
       <Map
147
+        readOnly={readOnly}
147
         location={formData.location}
148
         location={formData.location}
148
-        onLocChange={e => !formData.location && setFieldChange('location', e)}
149
+        onChange={e => !formData.location && setFieldChange('location', e)}
149
       />
150
       />
150
 
151
 
151
       <CellGroup>
152
       <CellGroup>

+ 0
- 20
src/pages/reporting/detail/components/Issue.jsx View File

1
-import React from 'react';
2
-import { View } from '@tarojs/components';
3
-import style from './issue.module.less';
4
-
5
-export default (props) => {
6
-  
7
-  return (
8
-    <View className={style['issue-container']}>
9
-      <View class={style.card}>
10
-        <View className={style.title}>状态</View>
11
-      </View>
12
-      <View class={style.card}>
13
-        <View className={style.title}>问题描述</View>
14
-      </View>
15
-      <View class={style.card}>
16
-        <View className={style.title}>拍照</View>
17
-      </View>
18
-    </View>
19
-  )
20
-}

+ 0
- 17
src/pages/reporting/detail/components/Map.jsx View File

1
-import React from 'react';
2
-import { View } from '@tarojs/components';
3
-import Map from '@/components/map';
4
-import style from './map.module.less';
5
-
6
-export default (props) => {
7
-  const { location } = props;
8
-  
9
-  return (
10
-    <View className={style['map-box']}>
11
-      <Map location={location} />
12
-      <View className={style.address}>
13
-        阳光丽景小区
14
-      </View>
15
-    </View>
16
-  )
17
-}

+ 0
- 21
src/pages/reporting/detail/components/issue.module.less View File

1
-
2
-.issue-container {
3
-  margin-top: var(--main-space);
4
-
5
-  .card {
6
-    background: #fff;
7
-    padding: 0 var(--main-space);
8
-
9
-    & + .card {
10
-      margin-top: 2.67vw;
11
-    }
12
-  }
13
-
14
-  .title {
15
-    height: 90px;
16
-    font-size: 32px;
17
-    font-weight: bold;
18
-    color: #202020;
19
-    line-height: 90px;
20
-  }
21
-}

+ 0
- 16
src/pages/reporting/detail/components/map.module.less View File

1
-
2
-.map-box {
3
-  width: 100vw;
4
-
5
-  .address {
6
-    width: 100%;
7
-    background: #fff;
8
-    height: 90px;
9
-    font-size: 24px;
10
-    font-weight: 500;
11
-    color: #202020;
12
-    line-height: 90px;
13
-    padding: 0 var(--main-space);
14
-  }
15
-  
16
-}

+ 0
- 3
src/pages/reporting/detail/index.config.js View File

1
-export default definePageConfig({
2
-  navigationBarTitleText: '详情'
3
-})

+ 0
- 41
src/pages/reporting/detail/index.jsx View File

1
-import React from 'react';
2
-import Taro from '@tarojs/taro';
3
-import { View } from '@tarojs/components';
4
-import { Notify } from '@antmjs/vantui';
5
-import Page from '@/layouts/index';
6
-import getAuthorize from '@/utils/authorize';
7
-import Map from './components/Map';
8
-import Issue from './components/Issue';
9
-
10
-export default (props) => {
11
-
12
-  const [loc, setLoc] = React.useState();
13
-
14
-  React.useMemo(() => {
15
-    getAuthorize('scope.userLocation').then(() => {
16
-      Taro.getLocation({
17
-        success(res) {
18
-          setLoc(`${res.longitude},${res.latitude}`);
19
-        },
20
-        fail() {
21
-          Notify.show({
22
-            message: '获取位置失败, 请退出重试',
23
-            type: 'warning',
24
-          })
25
-        }
26
-      });
27
-    }).catch((err) => {
28
-      Notify.show({
29
-        message: '未能获取位置, 程序部分功能将不能正常使用',
30
-        type: 'warning',
31
-      })
32
-    });
33
-  }, []);
34
-
35
-  return (
36
-    <Page>
37
-      <Map location={loc} />
38
-      <Issue />
39
-    </Page>
40
-  )
41
-}

+ 0
- 3
src/pages/reporting/index.config.js View File

1
-export default definePageConfig({
2
-  navigationBarTitleText: '我的上报'
3
-})

+ 0
- 9
src/pages/reporting/index.jsx View File

1
-import React from 'react';
2
-import { View } from '@tarojs/components';
3
-
4
-export default (props) => {
5
-  
6
-  return (
7
-    <View></View>
8
-  )
9
-}

+ 2
- 1
src/utils/authorize.js View File

25
   });
25
   });
26
 }
26
 }
27
 
27
 
28
-export const getLocation = () => {
28
+export const getLocation = (options) => {
29
   return new Promise((resolve, reject) => {
29
   return new Promise((resolve, reject) => {
30
     getAuthorize('scope.userLocation').then(() => {
30
     getAuthorize('scope.userLocation').then(() => {
31
       Taro.getLocation({
31
       Taro.getLocation({
32
+        ...options || {},
32
         success(res) {
33
         success(res) {
33
           resolve(res);
34
           resolve(res);
34
         },
35
         },