SiteConfig.jsx 6.22 KB
Newer Older
Maofei94's avatar
Maofei94 committed
1
import React, { useState, useEffect } from 'react';
Maofei94's avatar
Maofei94 committed
2
import { Form, Select, Input, Button, Radio, notification, Spin } from 'antd';
3
import { editWebsite, getWebsite, addWebsite } from '@/services/mobileConfig/api';
4
import PicturesWall from '@/components/Upload/index';
皮倩雯's avatar
皮倩雯 committed
5
import { stripBasename } from 'history/pathutils';
Maofei94's avatar
Maofei94 committed
6 7 8
const { Item } = Form;
const { Option } = Select;
const SiteConfig = props => {
皮倩雯's avatar
皮倩雯 committed
9
  const { miniTitle, submitCallback, addCallback, parentKey, clientName, singleList } = props;
Maofei94's avatar
Maofei94 committed
10
  const [config, setConfig] = useState(''); // 网站配置信息
11
  const [loginList, setLoginList] = useState([{ text: '默认界面', value: 'default' }]); // 系统登陆页
Maofei94's avatar
Maofei94 committed
12
  const [styleList, setStyleList] = useState([
Maofei94's avatar
Maofei94 committed
13 14
    { text: '熊猫产品', value: 'default' },
    { text: '通用项目', value: 'project' },
Maofei94's avatar
Maofei94 committed
15
  ]); // 系统风格
16
  const [themeList, setThemeList] = useState([{ text: '默认皮肤', value: 'default' }]); // 系统皮肤
Maofei94's avatar
Maofei94 committed
17
  const [loading, setLoading] = useState(false);
皮倩雯's avatar
皮倩雯 committed
18 19
  const [keepText, setKeepText] = useState([]);
  const [name, setName] = useState('');
Maofei94's avatar
Maofei94 committed
20 21 22
  const [form] = Form.useForm();
  const layout = {
    layout: 'horizontal',
Maofei94's avatar
Maofei94 committed
23
    labelCol: { span: 7 },
Maofei94's avatar
Maofei94 committed
24
    wrapperCol: { span: 8 },
Maofei94's avatar
Maofei94 committed
25 26
  };
  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
27 28 29 30 31 32
    console.log(singleList);
    let aa = [];
    singleList.map(i => {
      aa.push(i.text);
    });
    setKeepText(aa);
Maofei94's avatar
Maofei94 committed
33
    console.log(miniTitle, 'miniTitle');
Maofei94's avatar
Maofei94 committed
34 35 36
    if (!miniTitle) {
      return;
    }
Maofei94's avatar
Maofei94 committed
37
    setLoading(true);
Maofei94's avatar
Maofei94 committed
38 39 40
    getWebsite({
      _version: 9999,
      _dc: Date.now(),
Maofei94's avatar
Maofei94 committed
41
      title: miniTitle,
Maofei94's avatar
Maofei94 committed
42 43 44
    })
      .then(res => {
        setLoading(false);
Maofei94's avatar
Maofei94 committed
45 46
        let obj = {};
        let arr = Object.keys(form.getFieldsValue());
Maofei94's avatar
Maofei94 committed
47
        arr.map(k => {
48
          obj[k] = res.data[k];
Maofei94's avatar
Maofei94 committed
49
        });
皮倩雯's avatar
皮倩雯 committed
50 51
        console.log(obj);
        setName(obj.title);
Maofei94's avatar
Maofei94 committed
52 53 54 55
        form.setFieldsValue(obj);
      })
      .catch(err => {
        setLoading(false);
Maofei94's avatar
Maofei94 committed
56
      });
Maofei94's avatar
Maofei94 committed
57
  }, [miniTitle]);
Maofei94's avatar
Maofei94 committed
58 59 60 61
  // 单选值改变
  const radioChange = e => {};
  // 提交选择
  const submit = value => {
62 63
    form.validateFields().then(valid => {
      if (valid) {
Maofei94's avatar
Maofei94 committed
64
        setLoading(true);
65
        const obj = { ...form.getFieldsValue() };
Maofei94's avatar
Maofei94 committed
66
        let params = { ...obj, mode: 'single', client: clientName };
67
        editWebsite(params)
Maofei94's avatar
Maofei94 committed
68 69
          .then(res => {
            setLoading(false);
70
            if (res.code === 0) {
Maofei94's avatar
Maofei94 committed
71
              submitCallback(obj.title);
Maofei94's avatar
Maofei94 committed
72 73 74 75 76 77 78 79 80 81 82 83
              notification.success({
                message: '提示',
                duration: 3,
                description: '编辑成功',
              });
            } else {
              notification.error({
                message: '提示',
                duration: 3,
                description: res.message || '编辑失败',
              });
            }
Maofei94's avatar
Maofei94 committed
84
          })
Maofei94's avatar
Maofei94 committed
85 86 87
          .catch(err => {
            setLoading(false);
          });
88 89
      }
    });
Maofei94's avatar
Maofei94 committed
90 91
  };
  return (
Maofei94's avatar
Maofei94 committed
92
    <Spin spinning={loading} tip="loading...">
Maofei94's avatar
Maofei94 committed
93 94
      <div style={{ minHeight: 'calc(100vh  - 252px)', marginTop: '20px' }}>
        <Form form={form} name={`form-${miniTitle}`} {...layout}>
Maofei94's avatar
Maofei94 committed
95 96 97 98 99 100 101 102
          <Item
            label="应用名称:"
            name="title"
            rules={[
              {
                required: true,
                message: '请输入应用名称',
              },
皮倩雯's avatar
皮倩雯 committed
103 104 105 106 107 108 109 110 111
              {
                validator: (rule, value) => {
                  let data = form.getFieldValue().title;
                  if (keepText.indexOf(data) != -1 && data != name) {
                    return Promise.reject('标题已存在');
                  }
                  return Promise.resolve();
                },
              },
Maofei94's avatar
Maofei94 committed
112 113 114 115
            ]}
          >
            <Input placeholder="请输入应用名称" allowClear />
          </Item>
116
          <Item label="虚拟目录:">
Maofei94's avatar
Maofei94 committed
117 118
            <Input value={clientName} disabled />
          </Item>
Maofei94's avatar
Maofei94 committed
119 120 121 122 123 124 125 126 127 128
          <Item
            label="系统图标:"
            name="shortcutIcon"
            rules={[
              {
                required: true,
                message: '请选择系统图标',
              },
            ]}
          >
Maofei94's avatar
Maofei94 committed
129
            <PicturesWall picType="icon" />
Maofei94's avatar
Maofei94 committed
130
          </Item>
Maofei94's avatar
Maofei94 committed
131

Maofei94's avatar
Maofei94 committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
          <Item
            label="登陆页面:"
            name="loginTemplate"
            rules={[
              {
                required: true,
                message: '请选择登陆页面',
              },
            ]}
          >
            <Select placeholder="请选择登陆页面">
              {loginList &&
                loginList.map((item, index) => (
                  <Option value={item.value} key={`item${index}`}>
                    {item.text}
                  </Option>
                ))}
            </Select>
          </Item>
          <Item
            label="系统皮肤:"
            name="theme"
            rules={[
              {
                required: true,
                message: '请选择系统皮肤',
              },
            ]}
          >
            <Select placeholder="请选择系统皮肤">
              {themeList &&
                themeList.map((item, index) => (
                  <Option value={item.value} key={`item${index}`}>
                    {item.text}
                  </Option>
                ))}
            </Select>
          </Item>
          <Item
            label="系统风格:"
            name="style"
            rules={[
              {
                required: true,
                message: '请选择系统风格',
              },
            ]}
          >
            <Select placeholder="请选择系统风格">
              {styleList &&
                styleList.map((item, index) => (
                  <Option value={item.value} key={`item${index}`}>
                    {item.text}
                  </Option>
                ))}
            </Select>
          </Item>
Maofei94's avatar
Maofei94 committed
189
          <Item label="开启云登陆:" name="cloudLogin" initialValue={false}>
Maofei94's avatar
Maofei94 committed
190 191 192 193 194 195 196 197 198 199 200 201
            <Radio.Group onChange={radioChange}>
              <Radio value></Radio>
              <Radio value={false}></Radio>
            </Radio.Group>
          </Item>
          <Item wrapperCol={{ span: 6, offset: 7 }}>
            <Button type="primary" onClick={submit}>
              提交
            </Button>
          </Item>
        </Form>
      </div>
Maofei94's avatar
Maofei94 committed
202
    </Spin>
Maofei94's avatar
Maofei94 committed
203 204 205
  );
};
export default SiteConfig;