Browse Source

增加 app sdk

Yansen 1 year ago
parent
commit
cc31e2c55d

+ 1
- 0
config/dev.js View File

7
     HOST: '""',
7
     HOST: '""',
8
     // HOST: '"https://wmcj.huoshannews.com"',
8
     // HOST: '"https://wmcj.huoshannews.com"',
9
     MAPHOST: '"/api2"',
9
     MAPHOST: '"/api2"',
10
+    QMAP_WEBSERVICE_KEY: '"HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA"',
10
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
11
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
11
     DEFAULT_POS: '"116.34761502876347,31.40974743425614"', // 霍山县人民政府 gcj02
12
     DEFAULT_POS: '"116.34761502876347,31.40974743425614"', // 霍山县人民政府 gcj02
12
     VERSION: '"1.1.13-20230325"',
13
     VERSION: '"1.1.13-20230325"',

+ 1
- 0
config/prod.js View File

7
     // HOST: '"https://wmcj.ycjcjy.com"',
7
     // HOST: '"https://wmcj.ycjcjy.com"',
8
     HOST: '"http://api.wmcj.ycjcjy.com"',
8
     HOST: '"http://api.wmcj.ycjcjy.com"',
9
     MAPHOST: '"http://api.wmcj.ycjcjy.com/api2"',
9
     MAPHOST: '"http://api.wmcj.ycjcjy.com/api2"',
10
+    QMAP_WEBSERVICE_KEY: '"HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA"',
10
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
11
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
11
     DEFAULT_POS: '"116.34761502876347,31.40974743425614"', // 霍山县人民政府 gcj02
12
     DEFAULT_POS: '"116.34761502876347,31.40974743425614"', // 霍山县人民政府 gcj02
12
     VERSION: '"1.1.29-20240224"',
13
     VERSION: '"1.1.29-20240224"',

+ 0
- 9
src/app.js View File

3
 import "./app.less";
3
 import "./app.less";
4
 import { useEffect } from "react";
4
 import { useEffect } from "react";
5
 import "@antmjs/vantui/lib/index.less";
5
 import "@antmjs/vantui/lib/index.less";
6
-import { getLocation } from "./utils/map";
7
 
6
 
8
 const App = (props) => {
7
 const App = (props) => {
9
   // useEffect(() => {
8
   // useEffect(() => {
10
   //   const userState = store.getState("user");
9
   //   const userState = store.getState("user");
11
   //   userState.current();
10
   //   userState.current();
12
   // }, []);
11
   // }, []);
13
-
14
-  useEffect(() => {
15
-    navigator.geolocation.getCurrentPosition((position) => {
16
-      console.log(position)
17
-      doSomething(position.coords.latitude, position.coords.longitude);
18
-    });
19
-  },[]);
20
-
21
   return <Provider>{props.children}</Provider>;
12
   return <Provider>{props.children}</Provider>;
22
 };
13
 };
23
 
14
 

+ 7
- 7
src/components/Auth.jsx View File

4
 
4
 
5
 export default (props) => {
5
 export default (props) => {
6
   const { roles = []  } = props;
6
   const { roles = []  } = props;
7
-  console.log(props);
7
+  // console.log(props);
8
   const { duty } = useModel("user");
8
   const { duty } = useModel("user");
9
-  console.log("---------------------************-----------------");
9
+  // console.log("---------------------************-----------------");
10
 
10
 
11
   // const hasRights = roles.indexOf(duty) > -1;
11
   // const hasRights = roles.indexOf(duty) > -1;
12
   const hasRights = roles.includes(duty);
12
   const hasRights = roles.includes(duty);
13
-  console.log(duty);
14
-  console.log("!roles.length", !roles.length);
15
-  console.log("hasRights", hasRights);
16
-  console.log("roles", roles);
17
-  console.log("!roles.length || hasRights", !roles.length || hasRights);
13
+  // console.log(duty);
14
+  // console.log("!roles.length", !roles.length);
15
+  // console.log("hasRights", hasRights);
16
+  // console.log("roles", roles);
17
+  // console.log("!roles.length || hasRights", !roles.length || hasRights);
18
 
18
 
19
 
19
 
20
   const filteredChildren = React.Children.toArray(props.children).filter(
20
   const filteredChildren = React.Children.toArray(props.children).filter(

+ 39
- 20
src/components/Uploader/index.jsx View File

2
 import Taro from "@tarojs/taro";
2
 import Taro from "@tarojs/taro";
3
 import { View, Image, Video } from "@tarojs/components";
3
 import { View, Image, Video } from "@tarojs/components";
4
 import { Loading } from "@antmjs/vantui";
4
 import { Loading } from "@antmjs/vantui";
5
-import { uploadFiles } from "@/utils/request";
5
+import { uploadFileBase64, uploadFiles } from "@/utils/request";
6
 import icon from "@/assets/icons/uploader.png";
6
 import icon from "@/assets/icons/uploader.png";
7
 import closeIcon from "@/assets/icons/close.png";
7
 import closeIcon from "@/assets/icons/close.png";
8
 import style from "./style.modules.less";
8
 import style from "./style.modules.less";
20
     if (disabled) return;
20
     if (disabled) return;
21
 
21
 
22
     setLoading(true);
22
     setLoading(true);
23
-    Taro.chooseMedia({
24
-      maxDuration: 60,
25
-      // sizeType: "compressed",
26
-      success: (res) => {
27
-        const { tempFiles } = res;
28
-        uploadFiles(tempFiles)
29
-          .then((resp) => {
30
-            setLoading(false);
31
-            onChange((value || []).concat(resp));
32
-          })
33
-          .catch((err) => {
34
-            console.error(err);
35
-            setLoading(false);
36
-          });
37
-      },
38
-      fail: (err) => {
39
-        console.error(err);
40
-        setLoading(false);
41
-      },
23
+
24
+    // eslint-disable-next-line no-undef
25
+    SmartCity.chooseImage({
26
+      count : 1 // 图片张数
27
+    },function(res){
28
+        console.log("--------上传图片---------", res);
29
+        const base64 = res[0].imageData;
30
+        const fileName = res[0].name;
31
+        const fileType = res[0].type;
32
+
33
+        uploadFileBase64(base64, fileName, fileType).then(resp => {
34
+          setLoading(false);
35
+          onChange((value || []).concat(resp));
36
+        }).catch((err) => {
37
+          console.error(err);
38
+          setLoading(false);
39
+        });
42
     });
40
     });
41
+
42
+    // Taro.chooseMedia({
43
+    //   maxDuration: 60,
44
+    //   // sizeType: "compressed",
45
+    //   success: (res) => {
46
+    //     const { tempFiles } = res;
47
+    //     uploadFiles(tempFiles)
48
+    //       .then((resp) => {
49
+    //         setLoading(false);
50
+    //         onChange((value || []).concat(resp));
51
+    //       })
52
+    //       .catch((err) => {
53
+    //         console.error(err);
54
+    //         setLoading(false);
55
+    //       });
56
+    //   },
57
+    //   fail: (err) => {
58
+    //     console.error(err);
59
+    //     setLoading(false);
60
+    //   },
61
+    // });
43
   };
62
   };
44
 
63
 
45
   const onDelete = (item) => {
64
   const onDelete = (item) => {

+ 4
- 4
src/components/map/index.jsx View File

2
 import Taro from "@tarojs/taro";
2
 import Taro from "@tarojs/taro";
3
 import { View, Map } from "@tarojs/components";
3
 import { View, Map } from "@tarojs/components";
4
 import { Icon, Loading } from "@antmjs/vantui";
4
 import { Icon, Loading } from "@antmjs/vantui";
5
-import { getLocation, h5GetLocation } from "@/utils/authorize";
6
-// import { getLocation } from "@/utils/map";
5
+import { getLocation } from "@/utils/authorize";
7
 import iconPath from "@/assets/icons/marker.png";
6
 import iconPath from "@/assets/icons/marker.png";
8
 import style from "./style.module.less";
7
 import style from "./style.module.less";
9
 
8
 
91
       Taro.showLoading({
90
       Taro.showLoading({
92
         title: "加载中",
91
         title: "加载中",
93
       });
92
       });
94
-      return h5GetLocation()
93
+      return getLocation()
95
         .then((res) => {
94
         .then((res) => {
96
           Taro.hideLoading();
95
           Taro.hideLoading();
97
-          resolve(res.result);
96
+          resolve(res);
98
         })
97
         })
99
         .catch((err) => {
98
         .catch((err) => {
100
           console.error(err);
99
           console.error(err);
114
       // 获取定位
113
       // 获取定位
115
       fixedLocation().then((res) => {
114
       fixedLocation().then((res) => {
116
         const { lng, lat } = res.location;
115
         const { lng, lat } = res.location;
116
+        console.log('----获取到定位-----', res);
117
         onChange([lng, lat].join(","));
117
         onChange([lng, lat].join(","));
118
       });
118
       });
119
     }
119
     }

+ 1
- 1
src/index.html View File

24
       var vConsole = new window.VConsole();
24
       var vConsole = new window.VConsole();
25
     </script>
25
     </script>
26
 
26
 
27
-    <title>civilized-miniapp</title>
27
+    <title>文明城市</title>
28
     <script>
28
     <script>
29
       <%= htmlWebpackPlugin.options.script %>
29
       <%= htmlWebpackPlugin.options.script %>
30
     </script>
30
     </script>

+ 24
- 9
src/layouts/index.jsx View File

12
 export default (props) => {
12
 export default (props) => {
13
   const { className, style, roles, tabBar = false, loading } = props;
13
   const { className, style, roles, tabBar = false, loading } = props;
14
 
14
 
15
-  const { person, user, duty } = useModel('user');
15
+  const { person, user, duty, current } = useModel('user');
16
 
16
 
17
   const containerClass = `${laySty["page-conatiner"]} ${
17
   const containerClass = `${laySty["page-conatiner"]} ${
18
     tabBar ? laySty["with-tabbar"] : ""
18
     tabBar ? laySty["with-tabbar"] : ""
21
   React.useEffect(() => {
21
   React.useEffect(() => {
22
     const currentPage = Taro.getCurrentPages().slice().pop();
22
     const currentPage = Taro.getCurrentPages().slice().pop();
23
 
23
 
24
-    if (!person || !user) {
25
-      if (!currentPage.route.includes("pages/login/index")) {
26
-        Taro.navigateTo({
27
-          url: "/pages/login/index",
28
-        });
24
+    if (!user) {
25
+      current().then((res) => {
26
+        console.log('---当前人员----', res);
27
+      }).catch((err) => {
28
+        console.log('---当前人员--报错了--');
29
+        console.error(err);
29
 
30
 
30
-        return;
31
-      }
31
+        if (!currentPage.route.includes("pages/login/index")) {
32
+          Taro.navigateTo({
33
+            url: "/pages/login/index",
34
+          });
35
+        }
36
+      });
32
     }
37
     }
33
-  }, [person, user]);
38
+
39
+    // if (!person || !user) {
40
+    //   if (!currentPage.route.includes("pages/login/index")) {
41
+    //     Taro.navigateTo({
42
+    //       url: "/pages/login/index",
43
+    //     });
44
+
45
+    //     return;
46
+    //   }
47
+    // }
48
+  }, [current, user]);
34
 
49
 
35
 
50
 
36
   // React.useEffect(() => {
51
   // React.useEffect(() => {

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

73
   const onLocationChange = (loc) => {
73
   const onLocationChange = (loc) => {
74
     setFieldChange("location", loc);
74
     setFieldChange("location", loc);
75
 
75
 
76
+    console.log('-------onLocationChange------', loc)
77
+
76
     if (loc) {
78
     if (loc) {
77
       // 交换经纬度位置
79
       // 交换经纬度位置
78
       const [x, y] = loc.split(",");
80
       const [x, y] = loc.split(",");

+ 6
- 2
src/store/user.js View File

4
 import {
4
 import {
5
   login,
5
   login,
6
   signin,
6
   signin,
7
+  signup,
7
   currentUser,
8
   currentUser,
8
   authPhone,
9
   authPhone,
9
   authUser,
10
   authUser,
10
 } from "@/services/wxma";
11
 } from "@/services/wxma";
11
 import { changePassword } from "@/services/sysuser";
12
 import { changePassword } from "@/services/sysuser";
12
-import { signup } from '@/services/wxma';
13
 import { ROLE_CITIZEN } from "@/utils/user";
13
 import { ROLE_CITIZEN } from "@/utils/user";
14
 import { setToken } from "@/utils/token";
14
 import { setToken } from "@/utils/token";
15
-import { resolve } from "path";
16
 
15
 
17
 export default function useUser() {
16
 export default function useUser() {
18
   const [person, setPerson] = React.useState();
17
   const [person, setPerson] = React.useState();
79
     return new Promise((resolve, reject) => {
78
     return new Promise((resolve, reject) => {
80
       currentUser()
79
       currentUser()
81
         .then((res) => {
80
         .then((res) => {
81
+          if (res?.person) {
82
+            setPerson(res.person);
83
+          }
84
+
82
           setUser(res?.user);
85
           setUser(res?.user);
83
           initDuty(res?.user);
86
           initDuty(res?.user);
84
           resolve(res?.user);
87
           resolve(res?.user);
107
 
110
 
108
   const signOut = () => {
111
   const signOut = () => {
109
     console.log(111111)
112
     console.log(111111)
113
+    setPerson(null);
110
     setUser(null);
114
     setUser(null);
111
     initDuty(null);
115
     initDuty(null);
112
     setToken();
116
     setToken();

+ 24
- 20
src/utils/authorize.js View File

1
 import Taro from "@tarojs/taro";
1
 import Taro from "@tarojs/taro";
2
+import { translate } from "./map";
2
 
3
 
3
 export default function getAuthorize(scope) {
4
 export default function getAuthorize(scope) {
4
   return new Promise((resolve, reject) => {
5
   return new Promise((resolve, reject) => {
25
   });
26
   });
26
 }
27
 }
27
 
28
 
28
-export const getLocation = async (options) => {
29
-  // try {
30
-  return await new Promise((resolve, reject) => {
31
-    wx.getLocation({
32
-      ...(options || {}),
33
-      success(res) {
34
-        resolve(res);
35
-      },
36
-      fail(err) {
37
-        console.error(err);
38
-        reject(err);
39
-      },
29
+export const getLocation = () => {
30
+  return new Promise((resolve, reject) => {
31
+    // eslint-disable-next-line no-undef
32
+    SmartCity.getLocation(function(res){
33
+      // 百度坐标
34
+      // {
35
+      //   "longitude": "经度 ",
36
+      //   "latitude": "纬度",
37
+      //   "provinces": "省",
38
+      //   "city": "市",
39
+      //   "area": "区",
40
+      //   "address": "地址",
41
+      //   "parameter": "传给客户端的参数",
42
+      // }
43
+      console.log('定位地址:' , res);
44
+
45
+      translate(res.latitude, res.longitude).then(res2 => {
46
+        resolve({ ...res, location: res2 });
47
+      }).catch(reject);
40
     });
48
     });
41
   });
49
   });
42
-  // } catch (err_1) {
43
-  //   console.error(err_1);
44
-  //   reject(err_1);
45
-  // }
46
 };
50
 };
47
-const key = "HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA";
48
-export const h5GetLocation = () => {
49
-  return new TMap.service.IPLocation().locate();
51
+
52
+// export const h5GetLocation = () => {
53
+  // return new TMap.service.IPLocation().locate();
50
 
54
 
51
   // return new Promise((resolve, reject) => {
55
   // return new Promise((resolve, reject) => {
52
   //   const url = `${MAPHOST}/ws/location/v1/ip?key=${key}`;
56
   //   const url = `${MAPHOST}/ws/location/v1/ip?key=${key}`;
68
   //   //   console.error("请求失败", error);
72
   //   //   console.error("请求失败", error);
69
   //   // });
73
   //   // });
70
   // });
74
   // });
71
-};
75
+// };

+ 29
- 33
src/utils/map.js View File

1
 import Taro from "@tarojs/taro";
1
 import Taro from "@tarojs/taro";
2
-import gcoord from "gcoord";
3
-
4
-// 腾讯地图接口 - 个人开发者
5
-const QMAP_WEBSERVICE_KEY = "HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA";
6
 
2
 
7
 // https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
3
 // https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
8
 // location 为 gcj02 编码
4
 // location 为 gcj02 编码
9
 export function geocoder(location, getPoi = 0) {
5
 export function geocoder(location, getPoi = 0) {
6
+  console.log('----待解析地址----', location)
10
   if (!location || location.length < 3) {
7
   if (!location || location.length < 3) {
11
     return Promise.reject(new Error("待解析地址为空"));
8
     return Promise.reject(new Error("待解析地址为空"));
12
   }
9
   }
13
 
10
 
14
   return new Promise((resolve, reject) => {
11
   return new Promise((resolve, reject) => {
12
+    // eslint-disable-next-line no-undef
15
     const url = `${MAPHOST}/ws/geocoder/v1/?location=${location}&key=${QMAP_WEBSERVICE_KEY}&get_poi=${getPoi}`;
13
     const url = `${MAPHOST}/ws/geocoder/v1/?location=${location}&key=${QMAP_WEBSERVICE_KEY}&get_poi=${getPoi}`;
16
 
14
 
17
     Taro.request({ url })
15
     Taro.request({ url })
31
   });
29
   });
32
 }
30
 }
33
 
31
 
34
-// 使用 HTML H5 API 获取当前定位信息
35
-// 返回 promise 对象
36
-// resolve 结果是 { lng, lat }
37
-export function getLocation() {
32
+/**
33
+ * 坐标系转换 - 转换为腾讯坐标系
34
+ * https://lbs.qq.com/service/webService/webServiceGuide/webServiceTranslate
35
+ * @param {*} lat 纬度
36
+ * @param {*} lng 经度
37
+ * @param {*} type , 1 GPS坐标, 2 sogou经纬度, 3 baidu经纬度, 4 mapbar经纬度, 6 sogou墨卡托
38
+ */
39
+export function translate(lat, lng, type = 3) {
38
   return new Promise((resolve, reject) => {
40
   return new Promise((resolve, reject) => {
39
-    return navigator.geolocation.getCurrentPosition(
40
-      (position) => {
41
-        console.log("----定位结果-->", JSON.stringify(position));
42
-        const { longitude, latitude } = position.coords;
43
-
44
-        const data = gcoord.transform(
45
-          [longitude, latitude],
46
-          gcoord.WGS84,
47
-          gcoord.GCJ02
48
-        );
41
+    const locs = `${lat},${lng}`
49
 
42
 
50
-        const result = {
51
-          location: { lng: data[0], lat: data[1] },
52
-        };
53
-
54
-        resolve(result);
55
-      },
56
-      (err) => {
57
-        console.error("----定位失败-->", JSON.stringify(err));
58
-        reject(err);
59
-      },
60
-      {
61
-        enableHighAccuracy: true,
62
-      }
63
-    );
43
+    // eslint-disable-next-line no-undef
44
+    const url = `${MAPHOST}/ws/coord/v1/translate?locations=${locs}&type=${type}&key=${QMAP_WEBSERVICE_KEY}&output=json`;
45
+    Taro.request({ url })
46
+      .then(({ data }) => {
47
+        const { status, message, locations } = data || {};
48
+        if (status != 0) {
49
+          console.error(data);
50
+          reject(new Error(message));
51
+        } else {
52
+          // { lat, lng }
53
+          resolve(locations[0]);
54
+        }
55
+      })
56
+      .catch((err) => {
57
+        console.error(err);
58
+        reject(new Error(err.errMsg));
59
+      });
64
   });
60
   });
65
-}
61
+}

+ 28
- 25
src/utils/request.js View File

104
       formData.append("file", files[i].originalFileObj);
104
       formData.append("file", files[i].originalFileObj);
105
       formData.append("fileType", files[i].fileType);
105
       formData.append("fileType", files[i].fileType);
106
 
106
 
107
+      // eslint-disable-next-line no-undef
107
       fetch(url || `${HOST}/api/ma/file`, {
108
       fetch(url || `${HOST}/api/ma/file`, {
108
         method: "POST",
109
         method: "POST",
109
         headers: { authorization: token },
110
         headers: { authorization: token },
117
 
118
 
118
           resolve(_data.data);
119
           resolve(_data.data);
119
         });
120
         });
120
-      // Taro.uploadFile({
121
-      //   // eslint-disable-next-line no-undef
122
-      //   url: url || `${HOST}/api/ma/file`,
123
-      //   filePath: files[i].tempFilePath, //
124
-      //   header: {
125
-      //     authorization: token,
126
-      //   },
127
-      //   name: "file",
128
-      //   formData: {
129
-      //     file: files[i].originalFileObj,
130
-      //     fileType: files[i].fileType,
131
-      //   },
132
-      //   success: function (res) {
133
-      //     // debugger
134
-      //     const _data = JSON.parse(res.data);
135
-      //     // if (_data.code !== CODE_SUCCESS) {
136
-      //     //   reject(new Error(_data.message))
137
-      //     // }
138
-
139
-      //     resolve(_data.data);
140
-      //   },
141
-      //   fail(err) {
142
-      //     reject(err);
143
-      //   },
144
-      // });
145
     });
121
     });
146
   }
122
   }
147
 
123
 
148
   return Promise.all(uploads);
124
   return Promise.all(uploads);
149
 };
125
 };
126
+
127
+
128
+export const uploadFileBase64 = async (base64, fileName, fileType) => {
129
+  const uploads = [];
130
+  const token = getToken();
131
+  const formData = new FormData();
132
+  formData.append("base64", base64);
133
+  formData.append("fileName", fileName);
134
+  formData.append("fileType", fileType);
135
+
136
+  return new Promise((resolve, reject) => {
137
+    // eslint-disable-next-line no-undef
138
+    fetch(`${HOST}/api/ma/file/base64`, {
139
+      method: "POST",
140
+      headers: { authorization: token },
141
+      body: formData,
142
+    })
143
+      .then((res) => res.json()) // Add this line to parse the response as JSON
144
+      .then((_data) => {
145
+        if (_data.code !== 1000) {
146
+          reject(new Error(_data.message));
147
+        }
148
+
149
+        resolve(_data.data);
150
+      });
151
+  });
152
+};