张涛 1 년 전
부모
커밋
7e068c608a

+ 5
- 16
config/index.js 파일 보기

@@ -61,11 +61,12 @@ export default defineConfig(async (merge, { command, mode }) => {
61 61
     //   },
62 62
     // },
63 63
     h5: {
64
-      publicPath: "/",
65
-      staticDirectory: "static",
66
-      outputDir: "dist",
64
+      // publicPath: "/",
65
+      // staticDirectory: "static",
66
+      // outputDir: "dist",
67 67
       router: {
68
-        mode: "hash",
68
+        // mode: "hash",
69
+        basename:"/h5"
69 70
       },
70 71
       esnextModules: ["@antmjs"],
71 72
       postcss: {
@@ -77,18 +78,6 @@ export default defineConfig(async (merge, { command, mode }) => {
77 78
         pxtransform: {
78 79
           enable: true,
79 80
           config: {
80
-            // 设置rpx转换为目标单位为rem
81
-            // unitToRem: true,
82
-            // // 设计稿宽度与 rem 基准值,默认设计稿宽度为 750,即 1rem = 75px
83
-            // designWidth: 750,
84
-            // // 可选,选择器黑名单
85
-            // selectorBlackList: [],
86
-            // // // 可选,替换rpx为其他单位后缀,例如 'px' 或 'rem'
87
-            // propList: ["*"],
88
-            // // 可选,媒体查询中是否禁用转换
89
-            // mediaQuery: false,
90
-            // // 可选,是否转换页面根节点字体大小,如body: font-size: 16px
91
-            // minPixelValue: 0,
92 81
           },
93 82
         },
94 83
         cssModules: {

+ 3
- 2
config/prod.js 파일 보기

@@ -4,9 +4,10 @@ module.exports = {
4 4
   },
5 5
   defineConstants: {
6 6
     // HOST: '"http://192.168.89.147:9087"',
7
-    HOST: '"https://wmcj.ycjcjy.com"',
7
+    // HOST: '"https://wmcj.ycjcjy.com"',
8
+    HOST: '""',
8 9
     AD_IMAGE: '"https://h5.njyunzhi.com/images/citizen_banner.png"',
9
-    DEFAULT_POS: '"31.416373,116.373904"', // gcj02
10
+    DEFAULT_POS: '"116.34761502876347,31.40974743425614"', // 霍山县人民政府 gcj02
10 11
     VERSION: '"1.1.29-20240224"',
11 12
   },
12 13
   mini: {},

+ 4
- 12
src/app.js 파일 보기

@@ -1,21 +1,13 @@
1 1
 import Taro from "@tarojs/taro";
2
-import store, { Provider, getState } from "@/store";
2
+import store, { Provider } from "@/store";
3 3
 import "./app.less";
4
-import { useEffect, useMemo } from "react";
5
-// import wxsdk from "./utils/wx";
4
+import { useEffect } from "react";
6 5
 import "@antmjs/vantui/lib/index.less";
7
-// import '@antmjs/vantui/lib/index.css'
8 6
 
9 7
 const App = (props) => {
10
-  const init = () => {
11
-    const userState = store.getState("user");
12
-
13
-    userState.login(123);
14
-    userState.current();
15
-  };
16
-
17 8
   useEffect(() => {
18
-    init();
9
+    const userState = store.getState("user");
10
+    // userState.current();
19 11
   }, []);
20 12
 
21 13
   return <Provider>{props.children}</Provider>;

+ 31
- 9
src/components/Auth.jsx 파일 보기

@@ -1,16 +1,38 @@
1
-import React from 'react';
2
-import { View } from '@tarojs/components';
3
-import { useModel } from '@/store';
1
+import React from "react";
2
+import { View } from "@tarojs/components";
3
+import { useModel } from "@/store";
4 4
 
5 5
 export default (props) => {
6
-  const { roles = [] } = props;
7
-  const { duty } = useModel('user');
6
+  const { roles = []  } = props;
7
+  console.log(props);
8
+  const { duty } = useModel("user");
9
+  console.log("---------------------************-----------------");
8 10
 
9
-  const hasRights = roles.indexOf(duty) > -1;
11
+  // const hasRights = roles.indexOf(duty) > -1;
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);
10 18
 
11
-  return !roles.length || hasRights ? props.children : (
12
-    <View style={{width: '100%', height: '100%', display: 'grid', placeItems: 'center'}}>
19
+
20
+  const filteredChildren = React.Children.toArray(props.children).filter(
21
+    child => React.isValidElement(child)
22
+  );
23
+
24
+  return !roles.length || hasRights ? (
25
+   <div>{filteredChildren}</div>
26
+  ) : (
27
+    <View
28
+      style={{
29
+        width: "100%",
30
+        height: "100%",
31
+        display: "grid",
32
+        placeItems: "center",
33
+      }}
34
+    >
13 35
       <View>暂无权限</View>
14 36
     </View>
15 37
   );
16
-}
38
+};

+ 1
- 1
src/index.html 파일 보기

@@ -8,7 +8,7 @@
8 8
   <meta name="format-detection" content="telephone=no,address=no">
9 9
   <meta name="apple-mobile-web-app-status-bar-style" content="white">
10 10
   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
11
-  <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
11
+  <!-- <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> -->
12 12
   <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
13 13
   <title>civilized-miniapp</title>
14 14
   <script><%= htmlWebpackPlugin.options.script %></script>

+ 4
- 5
src/layouts/index.jsx 파일 보기

@@ -11,14 +11,13 @@ import laySty from "./layout.module.less";
11 11
 export default (props) => {
12 12
   const { className, style, roles, tabBar = false, loading } = props;
13 13
 
14
-  // person,
15 14
   const { user, duty } = useModel("user");
16 15
   const containerClass = `${laySty["page-conatiner"]} ${
17 16
     tabBar ? laySty["with-tabbar"] : ""
18 17
   } ${className}`;
19 18
 
20
-  const userRef = useRef();
21
-  const personRef = useRef();
19
+  // const userRef = useRef();
20
+  // const personRef = useRef();
22 21
 
23 22
   // React.useEffect(() => {
24 23
   //   if (!userRef.current && !personRef.current) {
@@ -74,14 +73,14 @@ export default (props) => {
74 73
       <Dialog id="vanDialog" />
75 74
       <NavLoading loading={loading} />
76 75
       <View className={containerClass} style={style}>
77
-        {/* {!person && (
76
+        {/* {!user && (
78 77
           <View className={laySty.loading}>
79 78
             <Loading size="32px" vertical>
80 79
               加载中...
81 80
             </Loading>
82 81
           </View>
83 82
         )} */}
84
-        <Auth roles={roles}>{props.children}</Auth>
83
+        <Auth roles={roles} >{props.children}</Auth>
85 84
 
86 85
         {!tabBar && <View className={laySty["pdm-space"]}></View>}
87 86
       </View>

+ 26
- 23
src/pages/home/components/Head.jsx 파일 보기

@@ -1,40 +1,43 @@
1
-import React from 'react';
2
-import Taro from '@tarojs/taro';
3
-import { View, Image, Button } from '@tarojs/components';
4
-import { ActionSheet, Cell } from '@antmjs/vantui';
5
-import { ROLES, ROLE_CITIZEN } from '@/utils/user';
6
-import logo from '@/assets/image/logo.png';
7
-import Icon from '@/assets/icons/avatar.png';
8
-import style from './head.module.less';
1
+import React from "react";
2
+import Taro from "@tarojs/taro";
3
+import { View, Image, Button } from "@tarojs/components";
4
+import { ActionSheet, Cell } from "@antmjs/vantui";
5
+import { ROLES, ROLE_CITIZEN } from "@/utils/user";
6
+import logo from "@/assets/image/logo.png";
7
+import Icon from "@/assets/icons/avatar.png";
8
+import style from "./head.module.less";
9 9
 
10 10
 export default (props) => {
11 11
   const { userModel } = props;
12
-  const { user, person, duty, updateDuty, authProfile } = userModel || {};
12
+  const { user,  duty, updateDuty, authProfile } = userModel || {};
13 13
   const { dutyList = [] } = user || {};
14 14
   const role = ROLES[duty || ROLE_CITIZEN];
15 15
 
16 16
   const [show, setShow] = React.useState(false);
17 17
 
18
+  // const [name, avatar] = React.useMemo(() => {
19
+  //   return [
20
+  //     user?.name || person?.name || '市民',
21
+  //     user?.avatar || person?.avatar || logo,
22
+  //   ];
23
+  // }, [user, person]);
18 24
   const [name, avatar] = React.useMemo(() => {
19
-    return [
20
-      user?.name || person?.name || '市民',
21
-      user?.avatar || person?.avatar || logo,
22
-    ];
23
-  }, [user, person]);
25
+    return [user?.name || "市民", user?.avatar || logo];
26
+  }, [user]);
24 27
 
25 28
   const actions = React.useMemo(() => {
26
-    return dutyList.map(x => ({ name: ROLES[x], value: x }));
29
+    return dutyList.map((x) => ({ name: ROLES[x], value: x }));
27 30
   }, [dutyList]);
28 31
 
29 32
   const onClick = () => {
30 33
     if (dutyList.length < 2) return;
31 34
     setShow(true);
32
-  }
35
+  };
33 36
 
34 37
   const onSelect = (e) => {
35
-    console.log(e)
36
-    updateDuty(e.detail.value)
37
-  }
38
+    console.log(e);
39
+    updateDuty(e.detail.value);
40
+  };
38 41
 
39 42
   const onGetUserProfile = () => {
40 43
     // 新版本小程序已开始不支持获取头像, 昵称了
@@ -44,12 +47,12 @@ export default (props) => {
44 47
     //     authProfile(res);
45 48
     //   }
46 49
     // })
47
-  }
50
+  };
48 51
 
49 52
   return (
50 53
     <View className={style.head}>
51 54
       <View className={style.profile}>
52
-        <View style={{ letterSpacing: '2px' }}>Hi, {name}!</View>
55
+        <View style={{ letterSpacing: "2px" }}>Hi, {name}!</View>
53 56
         <View className={style.badge} onClick={onClick}>
54 57
           <View className={style.icon}>
55 58
             <Image src={Icon} />
@@ -71,5 +74,5 @@ export default (props) => {
71 74
         </Button>
72 75
       </View>
73 76
     </View>
74
-  )
75
-}
77
+  );
78
+};

src/pages/login/components/Form.jsx → src/pages/login/components/Form1.jsx 파일 보기

@@ -1,120 +1,120 @@
1
-import React from "react";
2
-import Taro from "@tarojs/taro";
3
-import { View } from "@tarojs/components";
4
-import { Form, FormItem, Field, Button } from "@antmjs/vantui";
5
-import { useModel } from "@/store";
6
-import user from "@/assets/image/user.png";
7
-import password from "@/assets/image/password.png";
8
-import { warn } from "@/utils/message";
9
-import "./form.less";
10
-
11
-export default (props) => {
12
-  const { onSuccess } = props;
13
-
14
-  const { signin } = useModel("user");
15
-  const form = Form.useForm();
16
-  const [accErr, setAccErr] = React.useState();
17
-  const [pwdErr, setPwdErr] = React.useState();
18
-  const [loading, setLoading] = React.useState(false);
19
-
20
-  const onFinish = (errs, res) => {
21
-    console.log(11111111);
22
-    if (!res.account) {
23
-      setAccErr("账户不能为空");
24
-      return;
25
-    } else {
26
-      setAccErr();
27
-    }
28
-    if (!res.password) {
29
-      setPwdErr("密码不能为空");
30
-      return;
31
-    } else {
32
-      setPwdErr();
33
-    }
34
-
35
-    setLoading(true);
36
-    signin(res)
37
-      .then(() => {
38
-        onSuccess();
39
-        setLoading(false);
40
-      })
41
-      .catch((err) => {
42
-        setLoading(false);
43
-      });
44
-  };
45
-
46
-  const onForgetPwd = () => {
47
-    // Taro.navigateTo({
48
-    //   url: '/pages/reset-password/index'
49
-    // });
50
-    warn(true, "请联系管理人员");
51
-  };
52
-
53
-  const handleClick = () => {
54
-    form.validateFields((err, res) => {
55
-      if (!res.account) {
56
-        setAccErr("账户不能为空");
57
-        return;
58
-      } else {
59
-        setAccErr();
60
-      }
61
-      if (!res.password) {
62
-        setPwdErr("密码不能为空");
63
-        return;
64
-      } else {
65
-        setPwdErr();
66
-      }
67
-  
68
-      setLoading(true);
69
-      signin(res)
70
-        .then(() => {
71
-          onSuccess();
72
-          setLoading(false);
73
-        })
74
-        .catch((err) => {
75
-          setLoading(false);
76
-        });
77
-    });
78
-    console.log(11111);
79
-  };
80
-  return (
81
-    <View className="login-form">
82
-      {/* onFinish={onFinish} */}
83
-      <Form form={form} >
84
-        <FormItem name="account" valueFormat={(e) => e.detail}>
85
-          <Field
86
-            border
87
-            label="账号"
88
-            leftIcon={user}
89
-            errorMessage={accErr}
90
-            placeholder="请输入您的登录账号"
91
-          ></Field>
92
-        </FormItem>
93
-        <FormItem name="password" valueFormat={(e) => e.detail}>
94
-          <Field
95
-            password
96
-            label="密码"
97
-            leftIcon={password}
98
-            errorMessage={pwdErr}
99
-            placeholder="请输入您的登录密码"
100
-          ></Field>
101
-        </FormItem>
102
-        <View className="forget-password" onClick={onForgetPwd}>
103
-          忘记密码?
104
-        </View>
105
-        <View>
106
-          <Button
107
-            block
108
-            type="primary"
109
-            // formType="submit"
110
-            loading={loading}
111
-            disabled={loading}
112
-            onClick={handleClick}
113
-          >
114
-            登录
115
-          </Button>
116
-        </View>
117
-      </Form>
118
-    </View>
119
-  );
120
-};
1
+import React from "react";
2
+import Taro from "@tarojs/taro";
3
+import { View } from "@tarojs/components";
4
+import { Form, FormItem, Field, Button } from "@antmjs/vantui";
5
+import { useModel } from "@/store";
6
+import user from "@/assets/image/user.png";
7
+import password from "@/assets/image/password.png";
8
+import { warn } from "@/utils/message";
9
+import "./form.less";
10
+
11
+export default (props) => {
12
+  const { onSuccess } = props;
13
+
14
+  const { signin } = useModel("user");
15
+  const form = Form.useForm();
16
+  const [accErr, setAccErr] = React.useState();
17
+  const [pwdErr, setPwdErr] = React.useState();
18
+  const [loading, setLoading] = React.useState(false);
19
+
20
+  const onFinish = (errs, res) => {
21
+    console.log(11111111);
22
+    if (!res.account) {
23
+      setAccErr("账户不能为空");
24
+      return;
25
+    } else {
26
+      setAccErr();
27
+    }
28
+    if (!res.password) {
29
+      setPwdErr("密码不能为空");
30
+      return;
31
+    } else {
32
+      setPwdErr();
33
+    }
34
+
35
+    setLoading(true);
36
+    signin(res)
37
+      .then(() => {
38
+        onSuccess();
39
+        setLoading(false);
40
+      })
41
+      .catch((err) => {
42
+        setLoading(false);
43
+      });
44
+  };
45
+
46
+  const onForgetPwd = () => {
47
+    // Taro.navigateTo({
48
+    //   url: '/pages/reset-password/index'
49
+    // });
50
+    warn(true, "请联系管理人员");
51
+  };
52
+
53
+  const handleClick = () => {
54
+    form.validateFields((err, res) => {
55
+      if (!res.account) {
56
+        setAccErr("账户不能为空");
57
+        return;
58
+      } else {
59
+        setAccErr();
60
+      }
61
+      if (!res.password) {
62
+        setPwdErr("密码不能为空");
63
+        return;
64
+      } else {
65
+        setPwdErr();
66
+      }
67
+  
68
+      setLoading(true);
69
+      signin(res)
70
+        .then(() => {
71
+          onSuccess();
72
+          setLoading(false);
73
+        })
74
+        .catch((err) => {
75
+          setLoading(false);
76
+        });
77
+    });
78
+    console.log(11111);
79
+  };
80
+  return (
81
+    <View className="login-form">
82
+      {/* onFinish={onFinish} */}
83
+      <Form form={form} >
84
+        <FormItem name="account" valueFormat={(e) => e.detail}>
85
+          <Field
86
+            border
87
+            label="账号"
88
+            leftIcon={user}
89
+            errorMessage={accErr}
90
+            placeholder="请输入您的登录账号"
91
+          ></Field>
92
+        </FormItem>
93
+        <FormItem name="password" valueFormat={(e) => e.detail}>
94
+          <Field
95
+            password
96
+            label="密码"
97
+            leftIcon={password}
98
+            errorMessage={pwdErr}
99
+            placeholder="请输入您的登录密码"
100
+          ></Field>
101
+        </FormItem>
102
+        <View className="forget-password" onClick={onForgetPwd}>
103
+          忘记密码?
104
+        </View>
105
+        <View>
106
+          <Button
107
+            block
108
+            type="primary"
109
+            // formType="submit"
110
+            loading={loading}
111
+            disabled={loading}
112
+            onClick={handleClick}
113
+          >
114
+            登录
115
+          </Button>
116
+        </View>
117
+      </Form>
118
+    </View>
119
+  );
120
+};

+ 123
- 0
src/pages/login/components/Forms.jsx 파일 보기

@@ -0,0 +1,123 @@
1
+import React, { useRef, useState } from "react";
2
+import { Button, Form, Input, View } from "@tarojs/components";
3
+// import { Form, FormItem, Field, Button } from "@antmjs/vantui";
4
+import { useModel } from "@/store";
5
+import user from "@/assets/image/user.png";
6
+import password from "@/assets/image/password.png";
7
+import { warn } from "@/utils/message";
8
+import "./form.less";
9
+
10
+export default (props) => {
11
+  const { onSuccess } = props;
12
+
13
+  const { signin } = useModel("user");
14
+  // const form = Form.useForm();
15
+  const formRef = useRef();
16
+  const [accErr, setAccErr] = useState("");
17
+  const [pwdErr, setPwdErr] = useState("");
18
+  const [loading, setLoading] = useState(false);
19
+
20
+  const onFinish = (errs, res) => {
21
+    console.log(res);
22
+    if (!res.account) {
23
+      setAccErr("账户不能为空");
24
+      return;
25
+    } else {
26
+      setAccErr();
27
+    }
28
+    if (!res.password) {
29
+      setPwdErr("密码不能为空");
30
+      return;
31
+    } else {
32
+      setPwdErr();
33
+    }
34
+
35
+    setLoading(true);
36
+    signin(res)
37
+      .then(() => {
38
+        onSuccess();
39
+        setLoading(false);
40
+      })
41
+      .catch((err) => {
42
+        setLoading(false);
43
+      });
44
+  };
45
+
46
+  const onForgetPwd = () => {
47
+    // Taro.navigateTo({
48
+    //   url: '/pages/reset-password/index'
49
+    // });
50
+    warn(true, "请联系管理人员");
51
+  };
52
+
53
+  // const handleClick = () => {
54
+  //   form.validateFields((err, res) => {
55
+  //     if (!res.account) {
56
+  //       setAccErr("账户不能为空");
57
+  //       return;
58
+  //     } else {
59
+  //       setAccErr();
60
+  //     }
61
+  //     if (!res.password) {
62
+  //       setPwdErr("密码不能为空");
63
+  //       return;
64
+  //     } else {
65
+  //       setPwdErr();
66
+  //     }
67
+
68
+  //     setLoading(true);
69
+  //     signin(res)
70
+  //       .then(() => {
71
+  //         onSuccess();
72
+  //         setLoading(false);
73
+  //       })
74
+  //       .catch((err) => {
75
+  //         setLoading(false);
76
+  //       });
77
+  //   });
78
+  // };
79
+  return (
80
+    <View className="login-form">
81
+      <Form ref={formRef} onSubmit={onFinish}>
82
+        {/* <FormItem name="account" valueFormat={(e) => e.detail}> */}
83
+
84
+        <View style={{display: 'flex'}}>
85
+          <View className="page-section-title">账号</View>
86
+          <Input
87
+            border
88
+            name="account"
89
+            leftIcon={user}
90
+            errorMessage={accErr}
91
+            placeholder="请输入您的登录账号"
92
+          ></Input>
93
+        </View>
94
+
95
+        {/* </FormItem> */}
96
+        {/* <FormItem name="password" valueFormat={(e) => e.detail}>
97
+          <Field
98
+            password
99
+            label="密码"
100
+            leftIcon={password}
101
+            errorMessage={pwdErr}
102
+            placeholder="请输入您的登录密码"
103
+          ></Field>
104
+        </FormItem> */}
105
+        {/* <View className="forget-password" onClick={onForgetPwd}>
106
+          忘记密码?
107
+        </View> */}
108
+        <View>
109
+          <Button
110
+            block
111
+            type="primary"
112
+            formType="submit"
113
+            loading={loading}
114
+            // disabled={loading}
115
+            // onClick={handleClick}
116
+          >
117
+            登录
118
+          </Button>
119
+        </View>
120
+      </Form>
121
+    </View>
122
+  );
123
+};

+ 5
- 3
src/pages/login/index.jsx 파일 보기

@@ -3,9 +3,11 @@ 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 Form from "./components/Form";
7
-import Bottom from "./components/Bottom";
6
+// import Form1 from "./components/Form1";
7
+// import Bottom from "./components/Bottom";
8 8
 import './index.less'
9
+import Forms from './components/Forms';
10
+import Form1 from './components/Form1';
9 11
 
10 12
 export default (props) => {
11 13
 
@@ -19,7 +21,7 @@ export default (props) => {
19 21
     <Page>
20 22
       <View className="login-box">
21 23
         <Head />
22
-        <Form onSuccess={onSuccess} />
24
+        <Form1 onSuccess={onSuccess} />
23 25
         {/* H5此无功能 */}
24 26
         {/* <Bottom onSuccess={onSuccess} /> */}
25 27
       </View>

+ 3
- 3
src/pages/my/index.jsx 파일 보기

@@ -15,7 +15,7 @@ import styles from './style.module.less';
15 15
 
16 16
 export default (props) => {
17 17
 
18
-  const { user, person, duty, signOut, changePwd } = useModel('user');
18
+  const { user,  duty, signOut, changePwd } = useModel('user');
19 19
   const [org, setOrg] = React.useState();
20 20
 
21 21
   const [
@@ -67,8 +67,8 @@ export default (props) => {
67 67
       <VABC
68 68
         header={(
69 69
           <Head
70
-            avatar={user?.avatar || person?.avatar || logo}
71
-            name={user?.name || person?.name || '市民'}
70
+            avatar={user?.avatar || logo}
71
+            name={user?.name  || '市民'}
72 72
             onChangePwd={onChangePwd}
73 73
             onExit={onExit}
74 74
           />

+ 3
- 3
src/store/user.js 파일 보기

@@ -64,8 +64,8 @@ export default function useUser() {
64 64
   const current = () => {
65 65
     currentUser()
66 66
       .then((res) => {
67
-        setUser(res.user);
68
-        initDuty(res.user);
67
+        setUser(res?.user);
68
+        initDuty(res?.user);
69 69
       })
70 70
       .catch((e) => {
71 71
         console.log(e);
@@ -76,7 +76,7 @@ export default function useUser() {
76 76
     return authPhone(code).then((res) => {
77 77
       setUser(res.user);
78 78
       initDuty(res.user);
79
-      setPerson(res.person);
79
+      // setPerson(res.person);
80 80
     });
81 81
   };
82 82