李志伟 před 3 roky
rodič
revize
39b7e6be56

+ 48
- 0
src/components/SettingRow/index.jsx Zobrazit soubor

@@ -0,0 +1,48 @@
1
+import { Input, Button, Tooltip, message } from 'antd';
2
+import { useState } from 'react';
3
+import { CheckOutlined, UndoOutlined } from '@ant-design/icons';
4
+
5
+const SettingRow = (props) => {
6
+  const { value, onChange } = props;
7
+  const [val, setVal] = useState(value.settingValue);
8
+  const [isShow, setIsShow] = useState(false);
9
+  const handleInput = () => {
10
+    setIsShow(true);
11
+  };
12
+  const handleClick = () => {
13
+    if (val) {
14
+      onChange(value, val);
15
+    } else {
16
+      message.info(value.settingDesc + '不能为空');
17
+      setVal(value.settingValue);
18
+    }
19
+  };
20
+  const handleChange = (e) => {
21
+    setVal(e.target.value);
22
+  };
23
+  const handleReset = () => {
24
+    setVal(value.settingValue);
25
+    setIsShow(false);
26
+  };
27
+  return (
28
+    <div style={{ textAlign: 'center' }}>
29
+      {value.settingDesc}:
30
+      <Input style={{ width: '400px' }} value={val} onChange={handleChange} onInput={handleInput} />
31
+      <Button
32
+        type="text"
33
+        style={{ color: '#1890ff', visibility: isShow ? 'inherit' : 'hidden' }}
34
+        icon={<CheckOutlined />}
35
+        onClick={handleClick}
36
+      />
37
+      <Tooltip placement="top" title={'重置' + value.settingDesc}>
38
+        <Button
39
+          type="text"
40
+          style={{ color: 'green', visibility: isShow ? 'inherit' : 'hidden' }}
41
+          icon={<UndoOutlined />}
42
+          onClick={handleReset}
43
+        />
44
+      </Tooltip>
45
+    </div>
46
+  );
47
+};
48
+export default SettingRow;

+ 2
- 8
src/pages/SystemManagement/Administrator/index.jsx Zobrazit soubor

@@ -280,6 +280,7 @@ export default (props) => {
280 280
       title: '邮箱',
281 281
       dataIndex: 'email',
282 282
       key: 'email',
283
+      search: false,
283 284
     },
284 285
     {
285 286
       title: '注册时间',
@@ -293,14 +294,7 @@ export default (props) => {
293 294
       dataIndex: 'status',
294 295
       key: 'status',
295 296
       width: 80,
296
-      renderFormItem: () => {
297
-        return (
298
-          <Select placeholder="请选择">
299
-            <Option value={1}>启用</Option>
300
-            <Option value={0}>禁用</Option>
301
-          </Select>
302
-        );
303
-      },
297
+      search: false,
304 298
       render: (_, record) => {
305 299
         return record.status === 1 ? '启用' : '未启用';
306 300
       },

+ 55
- 21
src/pages/SystemManagement/BasicParameters/index.jsx Zobrazit soubor

@@ -1,15 +1,16 @@
1
-import { Input, Card, InputNumber, Button, message } from "antd"
2
-import { useEffect, useState } from 'react'
3
-import { Form } from "antd";
1
+import { Input, Card, InputNumber, Button, message } from 'antd';
2
+import { useEffect, useState } from 'react';
3
+import { Form } from 'antd';
4 4
 import { history } from 'umi';
5
-import ProCard from '@ant-design/pro-card'
5
+import ProCard from '@ant-design/pro-card';
6
+import { getSetting, updateSetting } from '@/services/setting';
7
+import SettingRow from '@/components/SettingRow';
6 8
 
7
-
8
-const FormItem = Form.Item
9
+const FormItem = Form.Item;
9 10
 export default (props) => {
10
-
11
-  const [form] = Form.useForm()
12
-  const [loading, setLoading] = useState(false)
11
+  const [form] = Form.useForm();
12
+  const [loading, setLoading] = useState(false);
13
+  const [data, setData] = useState([]);
13 14
 
14 15
   const formItemLayout = {
15 16
     //布局
@@ -17,25 +18,58 @@ export default (props) => {
17 18
     wrapperCol: { span: 14 },
18 19
   };
19 20
 
20
-  const Submit = values => {
21
-    console.log("🚀 ~ file: index.jsx ~ line 21 ~ values", values)
21
+  const Submit = (values) => {
22
+    console.log('🚀 ~ file: index.jsx ~ line 21 ~ values', values);
22 23
   };
23
-
24
+  const handleChange = (item, val) => {
25
+    updateSetting(item.settingId, { ...item, settingValue: val })
26
+      .then(() => {
27
+        message.success('修改' + item.settingDesc + '成功');
28
+      })
29
+      .catch((err) => {
30
+        setLoading(false);
31
+        message.error(err.message || err);
32
+      });
33
+  };
34
+  useEffect(() => {
35
+    getSetting().then((res) => {
36
+      setData(res.records);
37
+    });
38
+  }, []);
24 39
   return (
25
-    <Card >
40
+    <Card>
26 41
       <ProCard tabs={{ type: 'card' }} style={{ marginTop: '16px' }}>
27 42
         <ProCard.TabPane key={1} tab="基本参数">
28
-          <Form {...formItemLayout} onFinish={Submit} form={form} >
29
-            <FormItem label="平台联系电话" name="shopName" rules={[{ required: true, message: '请输入' }]}>
30
-              <Input placeholder="请输入" type={"number"} maxLength={11} style={{ width: '350px' }} />
43
+          {data.map((item) => {
44
+            return <SettingRow key={item.settingId} value={item} onChange={handleChange} />;
45
+          })}
46
+          {/* <Form {...formItemLayout} onFinish={Submit} form={form}>
47
+            <FormItem
48
+              label="平台联系电话"
49
+              name="shopName"
50
+              rules={[{ required: true, message: '请输入' }]}
51
+            >
52
+              <Input
53
+                placeholder="请输入"
54
+                type={'number'}
55
+                maxLength={11}
56
+                style={{ width: '350px' }}
57
+              />
31 58
             </FormItem>
32 59
 
33
-            <FormItem label=" " colon={false} >
34
-              <Button type='primary' loading={loading} htmlType="Submit" style={{ marginLeft: '4em' }}>保存</Button>
60
+            <FormItem label=" " colon={false}>
61
+              <Button
62
+                type="primary"
63
+                loading={loading}
64
+                htmlType="Submit"
65
+                style={{ marginLeft: '4em' }}
66
+              >
67
+                保存
68
+              </Button>
35 69
             </FormItem>
36
-          </Form>
70
+          </Form> */}
37 71
         </ProCard.TabPane>
38 72
       </ProCard>
39 73
     </Card>
40
-  )
41
-}
74
+  );
75
+};

+ 14
- 0
src/services/setting.js Zobrazit soubor

@@ -0,0 +1,14 @@
1
+import request from '@/utils/request';
2
+/**
3
+ * 系统基本数据更新
4
+ * @param {*} data
5
+ * @returns
6
+ */
7
+export const updateSetting = (id, data) => request(`/setting/${id}`, { method: 'put', data });
8
+
9
+/**
10
+ * 查询系统基本信息
11
+ * @param {*} params
12
+ * @returns
13
+ */
14
+export const getSetting = (params) => request('/setting', { params });