Yansen 2 년 전
부모
커밋
f23429a44c

+ 1
- 0
config/dev.js 파일 보기

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

+ 1
- 0
config/prod.js 파일 보기

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

+ 0
- 2
src/app.config.js 파일 보기

@@ -16,8 +16,6 @@ export default defineAppConfig({
16 16
     // 'pages/checkStand/index',
17 17
     "pages/checkStand/list/index",
18 18
     "pages/checkStand/detail/index",
19
-    "pages/reporting/index",
20
-    "pages/reporting/detail/index",
21 19
     "pages/reset-password/index",
22 20
     "pages/check/list/index",
23 21
     "pages/check/loc/list/index",

+ 80
- 40
src/components/map/index.jsx 파일 보기

@@ -6,66 +6,106 @@ import { getLocation } from '@/utils/authorize';
6 6
 import iconPath from '@/assets/icons/marker.png';
7 7
 import style from './style.module.less';
8 8
 
9
-// location 逻辑
10
-// 如果 props.location 有值, 那么放弃地图定位的点, 使用 props.location
11
-// 否则使用 地图定位的点
12
-// 如果地图定位失败 或者 props.location 为空, 那么不产生数据交互
13
-// 但是地图上默认使用 霍山县人民政府 的定位
14 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 15
   const [
19
-    markers,
20
-    lngLat,
16
+    // markers,
17
+    center,
21 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 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 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 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 95
   return (
62 96
     <View className={style['map-wrapper']}>
63 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 109
       </Map>
70 110
     </View>
71 111
   )

+ 2
- 2
src/components/map/style.module.less 파일 보기

@@ -12,8 +12,8 @@
12 12
     left: 0;
13 13
     .control {
14 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 파일 보기

@@ -10,7 +10,6 @@ import AgePicker from './AgePicker';
10 10
 export default (props) => {
11 11
   const { checkItemInfo, checkType, answer, readonly, onChange, onLoadingChange } = props;
12 12
 
13
-  const [loc, setLoc] = React.useState();
14 13
   const [showAgePicker, setShowAgePicker] = React.useState(false);
15 14
 
16 15
   const setLoading = (v) => {
@@ -21,7 +20,6 @@ export default (props) => {
21 20
 
22 21
   const setFieldChange = (key, val) => {
23 22
     onChange({
24
-      location: loc,
25 23
       ...answer || {},
26 24
       [key]: val,
27 25
     })
@@ -46,7 +44,11 @@ export default (props) => {
46 44
 
47 45
   return (
48 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 52
       <CellGroup>
51 53
         {
52 54
           checkType == 'loc' && (
@@ -56,18 +58,22 @@ export default (props) => {
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 72
         <Field
60 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 75
           placeholder={checkType == 'loc' ? '请输入地址' : '请填写小区名称'}
69 76
           value={answer?.addr}
70
-          leftIcon={mapIcon}
71 77
           onChange={e => setFieldChange('addr', e.detail)}
72 78
         />
73 79
       </CellGroup>

+ 1
- 1
src/pages/check/edit/index.jsx 파일 보기

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

+ 5
- 4
src/pages/check/loc/edit/components/LocForm.jsx 파일 보기

@@ -9,8 +9,6 @@ import mapIcon from '@/assets/icons/marker.png';
9 9
 export default (props) => {
10 10
   const { checkItemInfo, answer, readonly, onChange, onLoadingChange } = props;
11 11
 
12
-  const [loc, setLoc] = React.useState();
13
-
14 12
   const setLoading = (v) => {
15 13
     if (onLoadingChange) {
16 14
       onLoadingChange(v)
@@ -19,7 +17,6 @@ export default (props) => {
19 17
   
20 18
   const setFieldChange = (key, val) => {
21 19
     onChange({
22
-      location: loc,
23 20
       ...answer || {},
24 21
       [key]: val,
25 22
     })
@@ -42,7 +39,11 @@ export default (props) => {
42 39
   
43 40
   return (
44 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 47
       <CellGroup>
47 48
         <Cell
48 49
           title="点位"

+ 2
- 1
src/pages/feedback/issue/index.jsx 파일 보기

@@ -64,8 +64,9 @@ export default (props) => {
64 64
   return (
65 65
     <Page tabBar="feedback">
66 66
       <Map
67
+        readOnly={readOnly}
67 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 72
       <CellGroup>

+ 2
- 1
src/pages/issue/components/Issue/index.jsx 파일 보기

@@ -144,8 +144,9 @@ export default (props) => {
144 144
       />
145 145
 
146 146
       <Map
147
+        readOnly={readOnly}
147 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 152
       <CellGroup>

+ 0
- 20
src/pages/reporting/detail/components/Issue.jsx 파일 보기

@@ -1,20 +0,0 @@
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 파일 보기

@@ -1,17 +0,0 @@
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 파일 보기

@@ -1,21 +0,0 @@
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 파일 보기

@@ -1,16 +0,0 @@
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 파일 보기

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

+ 0
- 41
src/pages/reporting/detail/index.jsx 파일 보기

@@ -1,41 +0,0 @@
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 파일 보기

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

+ 0
- 9
src/pages/reporting/index.jsx 파일 보기

@@ -1,9 +0,0 @@
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 파일 보기

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