瀏覽代碼

feat: 增加默认H5处理

Yansen 11 月之前
父節點
當前提交
3bccc67087
共有 6 個文件被更改,包括 63 次插入42 次删除
  1. 1
    1
      config/dev.js
  2. 1
    1
      config/prod.js
  3. 39
    36
      src/components/Uploader/index.jsx
  4. 5
    0
      src/index.html
  5. 4
    4
      src/pages/login/index.jsx
  6. 13
    0
      src/utils/authorize.js

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

@@ -9,7 +9,7 @@ module.exports = {
9 9
     MAPHOST: '"/api2"',
10 10
     QMAP_WEBSERVICE_KEY: '"HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA"',
11 11
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
12
-    DEFAULT_POS: '"116.34761502876347,31.40974743425614"', // 霍山县人民政府 gcj02
12
+    DEFAULT_POS: '"101.718514,26.582455"', // 攀枝花市人民政府 gcj02
13 13
     VERSION: '"1.1.13-20230325"',
14 14
   },
15 15
   // isWatch:true,

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

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

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

@@ -18,47 +18,50 @@ export default (props) => {
18 18
     e.stopPropagation();
19 19
 
20 20
     if (disabled) return;
21
-
21
+    
22 22
     setLoading(true);
23 23
 
24 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) => {
25
+    if (IS_APP_CLIENT) {  
26
+      // eslint-disable-next-line no-undef
27
+      SmartCity.chooseImage({
28
+        count : 1 // 图片张数
29
+      },function(res){
30
+          console.log("--------上传图片---------", res);
31
+          const base64 = res[0].imageData;
32
+          const fileName = res[0].name;
33
+          const fileType = res[0].type;
34
+  
35
+          uploadFileBase64(base64, fileName, fileType).then(resp => {
36
+            setLoading(false);
37
+            onChange((value || []).concat(resp));
38
+          }).catch((err) => {
39
+            console.error(err);
40
+            setLoading(false);
41
+          });
42
+      });
43
+    } else {
44
+      Taro.chooseMedia({
45
+        maxDuration: 60,
46
+        // sizeType: "compressed",
47
+        success: (res) => {
48
+          const { tempFiles } = res;
49
+          uploadFiles(tempFiles)
50
+            .then((resp) => {
51
+              setLoading(false);
52
+              onChange((value || []).concat(resp));
53
+            })
54
+            .catch((err) => {
55
+              console.error(err);
56
+              setLoading(false);
57
+            });
58
+        },
59
+        fail: (err) => {
37 60
           console.error(err);
38 61
           setLoading(false);
39
-        });
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
-    // });
62
+        },
63
+      });
64
+    }
62 65
   };
63 66
 
64 67
   const onDelete = (item) => {

+ 5
- 0
src/index.html 查看文件

@@ -24,6 +24,11 @@
24 24
       // var vConsole = new window.VConsole();
25 25
     </script>
26 26
 
27
+    <script>
28
+      // 是否 app 端打开
29
+      var IS_APP_CLIENT = SmartCity.isSmartCityApp();
30
+    </script>
31
+
27 32
     <title>文明城市</title>
28 33
     <script>
29 34
       <%= htmlWebpackPlugin.options.script %>

+ 4
- 4
src/pages/login/index.jsx 查看文件

@@ -3,13 +3,13 @@ import Taro from '@tarojs/taro';
3 3
 import { View } from '@tarojs/components';
4 4
 import Page from '@/layouts/index';
5 5
 import Head from "./components/Head";
6
-// import Form1 from "./components/Form1";
7 6
 import Bottom from "./components/Bottom";
8
-import './index.less'
9
-import Forms from './components/Forms';
10 7
 import Form1 from './components/Form1';
8
+import './index.less'
11 9
 
12 10
 export default (props) => {
11
+  // eslint-disable-next-line no-undef
12
+  const isApp = IS_APP_CLIENT;
13 13
 
14 14
   const onSuccess = () => {
15 15
     Taro.reLaunch({
@@ -23,7 +23,7 @@ export default (props) => {
23 23
         <Head />
24 24
         <Form1 onSuccess={onSuccess} />
25 25
         {/* H5此无功能 */}
26
-        <Bottom onSuccess={onSuccess} />
26
+        {isApp && <Bottom onSuccess={onSuccess} />}
27 27
       </View>
28 28
     </Page>
29 29
   )

+ 13
- 0
src/utils/authorize.js 查看文件

@@ -27,6 +27,19 @@ export default function getAuthorize(scope) {
27 27
 }
28 28
 
29 29
 export const getLocation = () => {
30
+  // eslint-disable-next-line no-undef
31
+  if (!IS_APP_CLIENT) {
32
+    // 非 app 端, 直接使用默认位置
33
+    // eslint-disable-next-line no-undef
34
+    const parts = DEFAULT_POS.split(',')
35
+    return Promise.resolve({
36
+      location: {
37
+        lat: parts[1],
38
+        lng: parts[0],
39
+      },
40
+    });
41
+  }
42
+
30 43
   return new Promise((resolve, reject) => {
31 44
     // eslint-disable-next-line no-undef
32 45
     SmartCity.getLocation(function(res){