SiteConfig.jsx 8.45 KB
Newer Older
Maofei94's avatar
Maofei94 committed
1
import React, { useState, useEffect } from 'react';
2
import { Form, Select, Input, Button, Radio, notification, Spin, Tag } 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(''); // 网站配置信息
涂伟's avatar
涂伟 committed
11
  const [loginList, setLoginList] = useState([
12
    { text: '科技蓝', value: 'default.html' },
涂伟's avatar
涂伟 committed
13 14 15
    { text: 'h5_科技蓝', value: 'h5_default' },
    { text: 'h5_江西水务', value: 'h5_jiangxi' },
  ]); // 系统登陆页
16
  const [h5LoginList, setH5LoginList] = useState([
涂伟's avatar
涂伟 committed
17 18
    { text: '科技蓝', value: 'h5_default' },
    { text: '江西水务', value: 'h5_jiangxi' },
19
  ]); // H5登陆页
Maofei94's avatar
Maofei94 committed
20
  const [styleList, setStyleList] = useState([
Maofei94's avatar
Maofei94 committed
21 22
    { text: '熊猫产品', value: 'default' },
    { text: '通用项目', value: 'project' },
Maofei94's avatar
Maofei94 committed
23
  ]); // 系统风格
24
  const [themeList, setThemeList] = useState([{ text: '默认皮肤', value: 'default' }]); // 系统皮肤
Maofei94's avatar
Maofei94 committed
25
  const [loading, setLoading] = useState(false);
皮倩雯's avatar
皮倩雯 committed
26 27
  const [keepText, setKeepText] = useState([]);
  const [name, setName] = useState('');
Maofei94's avatar
Maofei94 committed
28 29 30
  const [form] = Form.useForm();
  const layout = {
    layout: 'horizontal',
Maofei94's avatar
Maofei94 committed
31
    labelCol: { span: 7 },
Maofei94's avatar
Maofei94 committed
32
    wrapperCol: { span: 8 },
Maofei94's avatar
Maofei94 committed
33 34
  };
  useEffect(() => {
皮倩雯's avatar
皮倩雯 committed
35 36 37 38 39 40
    console.log(singleList);
    let aa = [];
    singleList.map(i => {
      aa.push(i.text);
    });
    setKeepText(aa);
Maofei94's avatar
Maofei94 committed
41
    console.log(miniTitle, 'miniTitle');
Maofei94's avatar
Maofei94 committed
42 43 44
    if (!miniTitle) {
      return;
    }
Maofei94's avatar
Maofei94 committed
45
    setLoading(true);
Maofei94's avatar
Maofei94 committed
46 47 48
    getWebsite({
      _version: 9999,
      _dc: Date.now(),
Maofei94's avatar
Maofei94 committed
49
      title: miniTitle,
Maofei94's avatar
Maofei94 committed
50 51 52
    })
      .then(res => {
        setLoading(false);
Maofei94's avatar
Maofei94 committed
53 54
        let obj = {};
        let arr = Object.keys(form.getFieldsValue());
Maofei94's avatar
Maofei94 committed
55
        arr.map(k => {
56
          obj[k] = res.data[k];
Maofei94's avatar
Maofei94 committed
57
        });
皮倩雯's avatar
皮倩雯 committed
58 59
        console.log(obj);
        setName(obj.title);
Maofei94's avatar
Maofei94 committed
60 61 62 63
        form.setFieldsValue(obj);
      })
      .catch(err => {
        setLoading(false);
Maofei94's avatar
Maofei94 committed
64
      });
Maofei94's avatar
Maofei94 committed
65
  }, [miniTitle]);
Maofei94's avatar
Maofei94 committed
66 67 68 69
  // 单选值改变
  const radioChange = e => {};
  // 提交选择
  const submit = value => {
70 71
    form.validateFields().then(valid => {
      if (valid) {
Maofei94's avatar
Maofei94 committed
72
        setLoading(true);
73
        const obj = { ...form.getFieldsValue() };
Maofei94's avatar
Maofei94 committed
74
        let params = { ...obj, mode: 'single', client: clientName };
75
        editWebsite(params)
Maofei94's avatar
Maofei94 committed
76 77
          .then(res => {
            setLoading(false);
78
            if (res.code === 0) {
Maofei94's avatar
Maofei94 committed
79
              submitCallback(obj.title);
Maofei94's avatar
Maofei94 committed
80 81 82 83 84 85 86 87 88 89 90 91
              notification.success({
                message: '提示',
                duration: 3,
                description: '编辑成功',
              });
            } else {
              notification.error({
                message: '提示',
                duration: 3,
                description: res.message || '编辑失败',
              });
            }
Maofei94's avatar
Maofei94 committed
92
          })
Maofei94's avatar
Maofei94 committed
93 94 95
          .catch(err => {
            setLoading(false);
          });
96 97
      }
    });
Maofei94's avatar
Maofei94 committed
98 99
  };
  return (
Maofei94's avatar
Maofei94 committed
100
    <Spin spinning={loading} tip="loading...">
Maofei94's avatar
Maofei94 committed
101 102
      <div style={{ minHeight: 'calc(100vh  - 252px)', marginTop: '20px' }}>
        <Form form={form} name={`form-${miniTitle}`} {...layout}>
Maofei94's avatar
Maofei94 committed
103 104 105 106 107 108 109 110
          <Item
            label="应用名称:"
            name="title"
            rules={[
              {
                required: true,
                message: '请输入应用名称',
              },
皮倩雯's avatar
皮倩雯 committed
111 112 113 114 115 116 117 118 119
              {
                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
120 121 122 123
            ]}
          >
            <Input placeholder="请输入应用名称" allowClear />
          </Item>
124
          <Item label="虚拟目录:">
Maofei94's avatar
Maofei94 committed
125 126
            <Input value={clientName} disabled />
          </Item>
Maofei94's avatar
Maofei94 committed
127 128 129 130 131 132 133 134 135
          <Item
            label="系统图标:"
            name="shortcutIcon"
            rules={[
              {
                required: true,
                message: '请选择系统图标',
              },
            ]}
涂伟's avatar
涂伟 committed
136
            style={{ display: 'none' }}
Maofei94's avatar
Maofei94 committed
137
          >
Maofei94's avatar
Maofei94 committed
138
            <PicturesWall picType="icon" />
Maofei94's avatar
Maofei94 committed
139
          </Item>
涂伟's avatar
涂伟 committed
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
          <Item
            label="开机动画:"
            name="bootAnimation"
            rules={[
              {
                required: true,
                message: '请选择开机动画',
              },
            ]}
          >
            <PicturesWall picType="bootAnimation" />
          </Item>
          <Item
            label="登录页:"
            name="loginPageImage"
            rules={[
              {
                required: true,
                message: '请选择登录页',
              },
            ]}
          >
            <PicturesWall picType="loginPageImage" />
          </Item>
          <Item
            label="主页焦点图:"
            name="homePageImage"
            rules={[
              {
                required: true,
                message: '请选择主页焦点图',
              },
            ]}
          >
            <PicturesWall picType="homePageImage" />
          </Item>
Maofei94's avatar
Maofei94 committed
176

Maofei94's avatar
Maofei94 committed
177
          <Item
178
            label="APP登陆页面:"
Maofei94's avatar
Maofei94 committed
179 180 181 182 183 184 185 186 187 188 189 190
            name="loginTemplate"
            rules={[
              {
                required: true,
                message: '请选择登陆页面',
              },
            ]}
          >
            <Select placeholder="请选择登陆页面">
              {loginList &&
                loginList.map((item, index) => (
                  <Option value={item.value} key={`item${index}`}>
191 192 193 194 195
                    {item.value.includes('h5') ? (
                      <Tag color="green">h5</Tag>
                    ) : (
                      <Tag color="blue">flutter</Tag>
                    )}
Maofei94's avatar
Maofei94 committed
196 197 198 199 200 201
                    {item.text}
                  </Option>
                ))}
            </Select>
          </Item>
          <Item
202 203 204 205 206 207 208 209 210 211 212 213 214
            label="H5登陆页面:"
            name="h5loginTemplate"
            rules={[
              {
                required: true,
                message: '请选择登陆页面',
              },
            ]}
          >
            <Select placeholder="请选择登陆页面">
              {h5LoginList &&
                h5LoginList.map((item, index) => (
                  <Option value={item.value} key={`item${index}`}>
215 216 217 218 219
                    {item.value.includes('h5') ? (
                      <Tag color="green">h5</Tag>
                    ) : (
                      <Tag color="blue">flutter</Tag>
                    )}
220 221 222 223 224 225
                    {item.text}
                  </Option>
                ))}
            </Select>
          </Item>
          {/* <Item
Maofei94's avatar
Maofei94 committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
            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
263
          <Item label="开启云登陆:" name="cloudLogin" initialValue={false}>
Maofei94's avatar
Maofei94 committed
264 265 266 267
            <Radio.Group onChange={radioChange}>
              <Radio value>是</Radio>
              <Radio value={false}>否</Radio>
            </Radio.Group>
268
          </Item> */}
Maofei94's avatar
Maofei94 committed
269 270 271 272 273 274 275
          <Item wrapperCol={{ span: 6, offset: 7 }}>
            <Button type="primary" onClick={submit}>
              提交
            </Button>
          </Item>
        </Form>
      </div>
Maofei94's avatar
Maofei94 committed
276
    </Spin>
Maofei94's avatar
Maofei94 committed
277 278 279
  );
};
export default SiteConfig;