瀏覽代碼

增加 app sdk

Yansen 1 年之前
父節點
當前提交
cc31e2c55d

+ 1
- 0
config/dev.js 查看文件

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

+ 1
- 0
config/prod.js 查看文件

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

+ 0
- 9
src/app.js 查看文件

@@ -3,21 +3,12 @@ import store, { Provider } from "@/store";
3 3
 import "./app.less";
4 4
 import { useEffect } from "react";
5 5
 import "@antmjs/vantui/lib/index.less";
6
-import { getLocation } from "./utils/map";
7 6
 
8 7
 const App = (props) => {
9 8
   // useEffect(() => {
10 9
   //   const userState = store.getState("user");
11 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 12
   return <Provider>{props.children}</Provider>;
22 13
 };
23 14
 

+ 7
- 7
src/components/Auth.jsx 查看文件

@@ -4,17 +4,17 @@ import { useModel } from "@/store";
4 4
 
5 5
 export default (props) => {
6 6
   const { roles = []  } = props;
7
-  console.log(props);
7
+  // console.log(props);
8 8
   const { duty } = useModel("user");
9
-  console.log("---------------------************-----------------");
9
+  // console.log("---------------------************-----------------");
10 10
 
11 11
   // const hasRights = roles.indexOf(duty) > -1;
12 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 20
   const filteredChildren = React.Children.toArray(props.children).filter(

+ 39
- 20
src/components/Uploader/index.jsx 查看文件

@@ -2,7 +2,7 @@ import React from "react";
2 2
 import Taro from "@tarojs/taro";
3 3
 import { View, Image, Video } from "@tarojs/components";
4 4
 import { Loading } from "@antmjs/vantui";
5
-import { uploadFiles } from "@/utils/request";
5
+import { uploadFileBase64, uploadFiles } from "@/utils/request";
6 6
 import icon from "@/assets/icons/uploader.png";
7 7
 import closeIcon from "@/assets/icons/close.png";
8 8
 import style from "./style.modules.less";
@@ -20,26 +20,45 @@ export default (props) => {
20 20
     if (disabled) return;
21 21
 
22 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 64
   const onDelete = (item) => {

+ 4
- 4
src/components/map/index.jsx 查看文件

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

+ 1
- 1
src/index.html 查看文件

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

+ 24
- 9
src/layouts/index.jsx 查看文件

@@ -12,7 +12,7 @@ import { useEffect } from "react";
12 12
 export default (props) => {
13 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 17
   const containerClass = `${laySty["page-conatiner"]} ${
18 18
     tabBar ? laySty["with-tabbar"] : ""
@@ -21,16 +21,31 @@ export default (props) => {
21 21
   React.useEffect(() => {
22 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 51
   // React.useEffect(() => {

+ 2
- 0
src/pages/feedback/issue/index.jsx 查看文件

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

+ 6
- 2
src/store/user.js 查看文件

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

+ 24
- 20
src/utils/authorize.js 查看文件

@@ -1,4 +1,5 @@
1 1
 import Taro from "@tarojs/taro";
2
+import { translate } from "./map";
2 3
 
3 4
 export default function getAuthorize(scope) {
4 5
   return new Promise((resolve, reject) => {
@@ -25,28 +26,31 @@ export default function getAuthorize(scope) {
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 55
   // return new Promise((resolve, reject) => {
52 56
   //   const url = `${MAPHOST}/ws/location/v1/ip?key=${key}`;
@@ -68,4 +72,4 @@ export const h5GetLocation = () => {
68 72
   //   //   console.error("请求失败", error);
69 73
   //   // });
70 74
   // });
71
-};
75
+// };

+ 29
- 33
src/utils/map.js 查看文件

@@ -1,17 +1,15 @@
1 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 3
 // https://lbs.qq.com/service/webService/webServiceGuide/webServiceGcoder
8 4
 // location 为 gcj02 编码
9 5
 export function geocoder(location, getPoi = 0) {
6
+  console.log('----待解析地址----', location)
10 7
   if (!location || location.length < 3) {
11 8
     return Promise.reject(new Error("待解析地址为空"));
12 9
   }
13 10
 
14 11
   return new Promise((resolve, reject) => {
12
+    // eslint-disable-next-line no-undef
15 13
     const url = `${MAPHOST}/ws/geocoder/v1/?location=${location}&key=${QMAP_WEBSERVICE_KEY}&get_poi=${getPoi}`;
16 14
 
17 15
     Taro.request({ url })
@@ -31,35 +29,33 @@ export function geocoder(location, getPoi = 0) {
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 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 查看文件

@@ -104,6 +104,7 @@ export const uploadFiles = async (files, url) => {
104 104
       formData.append("file", files[i].originalFileObj);
105 105
       formData.append("fileType", files[i].fileType);
106 106
 
107
+      // eslint-disable-next-line no-undef
107 108
       fetch(url || `${HOST}/api/ma/file`, {
108 109
         method: "POST",
109 110
         headers: { authorization: token },
@@ -117,33 +118,35 @@ export const uploadFiles = async (files, url) => {
117 118
 
118 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 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
+};