lisenzhou 2 年前
父节点
当前提交
077d6de521
共有 4 个文件被更改,包括 191 次插入32 次删除
  1. 1
    0
      src/app.config.js
  2. 112
    0
      src/pages/user/add/index.jsx
  3. 66
    32
      src/pages/user/list/index.jsx
  4. 12
    0
      src/pages/user/list/index.module.less

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

@@ -27,6 +27,7 @@ export default defineAppConfig({
27 27
     "pages/feedback/issue/index",
28 28
     "pages/feedback/issuelist/index",
29 29
     "pages/user/list/index",
30
+    "pages/user/add/index",
30 31
   ],
31 32
   subpackages: [
32 33
     {

+ 112
- 0
src/pages/user/add/index.jsx 查看文件

@@ -0,0 +1,112 @@
1
+import React from "react";
2
+import Taro from "@tarojs/taro";
3
+import { View } from "@tarojs/components";
4
+import Page from "@/layouts/index";
5
+import {
6
+  Button,
7
+  Field,
8
+  Cell,
9
+  CellGroup,
10
+  CheckboxGroup,
11
+  Checkbox,
12
+} from "@antmjs/vantui";
13
+import { ROLE_ORG_MANAGER, ROLE_ORG_USER } from "@/utils/user";
14
+
15
+import { warn } from "@/utils/message";
16
+import { postSysUser } from "@/services/sysuser";
17
+
18
+export default (props) => {
19
+  const [loading, setLoading] = React.useState(false);
20
+  const [identity, setIdentity] = React.useState([]);
21
+  const [formData, setFormData] = React.useState({});
22
+
23
+  const setField = (name, value) => {
24
+    setFormData((data) => ({
25
+      ...data,
26
+      [name]: value,
27
+    }));
28
+  };
29
+  const onSubmit = () => {
30
+    try {
31
+      warn(!formData.name, "请填写姓名");
32
+      warn(!formData.phone, "请填写手机号");
33
+      warn(identity.length < 1, "请选择身份");
34
+    } catch (e) {
35
+      return;
36
+    }
37
+
38
+    setLoading(true);
39
+    postSysUser({ ...formData, dutyList: identity })
40
+      .then(() => {
41
+        setLoading(false);
42
+        Taro.navigateBack({
43
+          delta: 1,
44
+          fail: () => {
45
+            Taro.reLaunch({
46
+              url: "/pages/user/list/index",
47
+            });
48
+          },
49
+        });
50
+      })
51
+      .catch(() => {
52
+        setLoading(false);
53
+      });
54
+  };
55
+
56
+  return (
57
+    <Page>
58
+      <CellGroup>
59
+        <Field
60
+          required
61
+          label="姓名"
62
+          placeholder="请输入姓名"
63
+          value={formData.name}
64
+          onChange={(e) => setField("name", e.detail)}
65
+        />
66
+        <Field
67
+          required
68
+          label="手机号"
69
+          placeholder="请输入手机号"
70
+          value={formData.phone}
71
+          onChange={(e) => setField("phone", e.detail)}
72
+        />
73
+        <Cell
74
+          title="身份"
75
+          required
76
+          titleWidth="100px"
77
+          titleStyle={{
78
+            maxWidth: "6.2em",
79
+            minWidth: "6.2em",
80
+            marginRight: "12px",
81
+          }}
82
+        >
83
+          <View style={{ display: "flex" }}>
84
+            <CheckboxGroup
85
+              direction="horizontal"
86
+              value={identity}
87
+              onChange={(e) => {
88
+                console.info(e);
89
+                setIdentity([...e.detail]);
90
+              }}
91
+            >
92
+              <Checkbox name={ROLE_ORG_USER}>单位人员</Checkbox>
93
+              <Checkbox name={ROLE_ORG_MANAGER}>单位管理员</Checkbox>
94
+            </CheckboxGroup>
95
+          </View>
96
+        </Cell>
97
+
98
+        {/* // 单位人员
99
+export const ROLE_ORG_USER = 'org_user';
100
+
101
+// 单位管理员
102
+export const ROLE_ORG_MANAGER = 'org_manager'; */}
103
+      </CellGroup>
104
+
105
+      <View style={{ padding: "var(--main-space)", background: "#fff" }}>
106
+        <Button block type="primary" loading={loading} onClick={onSubmit}>
107
+          提交
108
+        </Button>
109
+      </View>
110
+    </Page>
111
+  );
112
+};

+ 66
- 32
src/pages/user/list/index.jsx 查看文件

@@ -1,48 +1,82 @@
1
-import React from 'react';
2
-import Taro from '@tarojs/taro';
3
-import { View } from '@tarojs/components';
4
-import { Cell, Button, Dialog } from '@antmjs/vantui';
5
-import Page from '@/layouts/index';
6
-import PowerList from '@/components/PowerList';
7
-import { getSysUser, deleteSysUser } from '@/services/sysuser';
1
+import React from "react";
2
+import Taro from "@tarojs/taro";
3
+import { View } from "@tarojs/components";
4
+import { Cell, Button, Dialog } from "@antmjs/vantui";
5
+import Page from "@/layouts/index";
6
+import PowerList from "@/components/PowerList";
7
+import { getSysUser, deleteSysUser } from "@/services/sysuser";
8
+import styles from "./index.module.less";
8 9
 
9 10
 export default (props) => {
10
-
11 11
   const [loading, setLoading] = React.useState(false);
12 12
   const listRef = React.useRef();
13 13
 
14
+  const onAdd = () => {
15
+    Taro.navigateTo({
16
+      url: "/pages/user/add/index",
17
+    });
18
+  };
19
+
14 20
   const onDelete = (user) => {
15 21
     Dialog.confirm({
16
-      title: '确认删除用户?',      
22
+      title: "确认删除用户?",
17 23
     }).then((e) => {
18 24
       const { action } = e.detail;
19
-      if (action === 'confirm') {
25
+      if (action === "confirm") {
20 26
         setLoading(true);
21
-        deleteSysUser(user.id).then(() => {
22
-          setLoading(false);
27
+        deleteSysUser(user.id)
28
+          .then(() => {
29
+            setLoading(false);
23 30
 
24
-          // 刷新列表
25
-          listRef.current.refresh();
26
-        }).catch(() => {
27
-          setLoading(false);
28
-        })
31
+            // 刷新列表
32
+            listRef.current.refresh();
33
+          })
34
+          .catch(() => {
35
+            setLoading(false);
36
+          });
29 37
       }
30
-    })
31
-  }
32
-  
38
+    });
39
+  };
40
+
33 41
   return (
34 42
     <Page loading={loading}>
35
-      <PowerList
36
-        ref={listRef}
37
-        request={getSysUser}
38
-        onLoadingChange={setLoading}
39
-        renderItem={(item) => (
40
-          <Cell key={item.userId} title={item.name} label={item.createDate.substring(0, 10)}>
41
-            <Button plain type="danger" size="small" onClick={() => onDelete(item)}>删除</Button>
42
-          </Cell>
43
-        )}
44
-      />
43
+      <view className={styles["user-warpper"]}>
44
+        <view className={styles["user-warpper-list"]}>
45
+          <PowerList
46
+            ref={listRef}
47
+            request={getSysUser}
48
+            onLoadingChange={setLoading}
49
+            renderItem={(item) => (
50
+              <Cell
51
+                key={item.userId}
52
+                title={item.name}
53
+                label={item.createDate.substring(0, 10)}
54
+              >
55
+                <Button
56
+                  plain
57
+                  type="danger"
58
+                  size="small"
59
+                  onClick={() => onDelete(item)}
60
+                >
61
+                  删除
62
+                </Button>
63
+              </Cell>
64
+            )}
65
+          />
66
+        </view>
45 67
 
68
+        <Button
69
+          type="primary"
70
+          size="large"
71
+          onClick={() => onAdd()}
72
+          style={{
73
+            margin: "var(--main-space)",
74
+            width: "calc(100% - var(--main-space) * 2)",
75
+          }}
76
+        >
77
+          添加
78
+        </Button>
79
+      </view>
46 80
     </Page>
47
-  )
48
-}
81
+  );
82
+};

+ 12
- 0
src/pages/user/list/index.module.less 查看文件

@@ -0,0 +1,12 @@
1
+// height: calc(100% - env(safe-area-inset-bottom));
2
+.user-warpper {
3
+  height: 100%;
4
+  display: flex;
5
+  flex-direction: column;
6
+  .user-warpper-list {
7
+    height: calc(100% - 78px);
8
+  }
9
+  .user-warpper-btn {
10
+    width: 100%;
11
+  }
12
+}