messageConfig.jsx 3.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
import React, { useEffect, useState } from 'react'
import { Card, Form, Input, Button, Select, message } from 'antd'
import styles from './messageConfig.less';
import { GetMessageConfigInfo, SaveSystemInfo, ConnectMessPlatform, GetBasicInfo, GetDataBaseConfig } from '@/services/platform/hostmanager'


const layout = {
    labelCol: { span: 8 },
    wrapperCol: { span: 16 },

};
const tailLayout = {
    wrapperCol: { offset: 8, span: 16 },

};
const MessageConfig = () => {


    const [currentAddress, setCurrentAddress] = useState("")
    const [currentDataBase, setCurrentDataBase] = useState({});
    const [currentSiteInfo, setcurrentSiteInfo] = useState("");

    const [form] = Form.useForm();
    const onFinish = (values) => {
        //先测试连接再保存
        //1.测试链接
        ConnectMessPlatform({
            messAddress: values.messageAddress,
            sqlServerIP: currentDataBase.ip,
            loginName: currentDataBase.userName,
            password: currentDataBase.password,
            sqlName: currentDataBase.dbName,
            siteCode: currentSiteInfo
        }).then(res => {
            if (res.code === 0) {
                //2.保存连接
                SaveSystemInfo({
                    configName: "消息平台连接地址",
                    configValue: values.messageAddress
                }).then(
                    res => {
                        if (res.code === 0) {
                            message.info("配置保存成功")
                        } else {
                            message.errorInfo(res.msg)
                        }
                    }
                )
            } else {
                message.errorInfo(res.msg)
            }
        })

    };

    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };



    useEffect(() => {
        GetMessageConfigInfo().then(
            res => {
                if (res.code == 0) {
                    setCurrentAddress(res.data)
                    form.setFieldsValue({ messageAddress: res.data });
                    GetDataBaseConfig().then(
                        res => {
                            if (res.code === 0) {
                                setCurrentDataBase(res.data)
                                GetBasicInfo().then(
                                    res => {
                                        if (res.code === 0) {
                                            setcurrentSiteInfo(res.data)
                                        }
                                    }
                                )
                            }
                        }
                    )
                } else {
                    message.info("获取消息平台配置失败!")
                }

            }
        )


    }, [])



    return (
        <div className={styles.message_container}>
mayongxin's avatar
mayongxin committed
96
            <Card title={`消息平台`} style={{ width: "100%" }}>
97 98 99 100 101 102 103 104 105 106 107 108

                <Form
                    {...layout}
                    form={form}
                    name="basic"
                    initialValues={{ remember: true }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                >
                    <Form.Item
                        label="服务器地址(平台)"
                        name="messageAddress"
109
                        rules={[{ required: true, message: '请输入域名(IP):端口,例如:192.168.19.102:8131' }]}
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

                    >
                        <Input />
                    </Form.Item>
                    <Form.Item {...tailLayout}>
                        <Button type="primary" htmlType="submit" disabled={currentSiteInfo.length > 0 ? false : true}>
                            保存连接
                        </Button>
                    </Form.Item>
                </Form>
            </Card>
        </div>
    )
}
export default MessageConfig