RTLForm.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* eslint-disable max-len */
  2. /* eslint-disable max-lines-per-function */
  3. import React from 'react';
  4. import { Form, Row, Col, Button } from '@douyinfe/semi-ui';
  5. import { IconUpload } from '@douyinfe/semi-icons';
  6. class RTLForm extends React.Component {
  7. constructor() {
  8. super();
  9. this.state = {
  10. initValues: {
  11. name: 'semi',
  12. business: ['hotsoon'],
  13. role: 'ued',
  14. switch: true,
  15. files: [
  16. {
  17. uid: '1',
  18. name: 'vigo.png',
  19. status: 'success',
  20. size: '130KB',
  21. preview: true,
  22. url:
  23. 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/vigo.png',
  24. },
  25. {
  26. uid: '3',
  27. name: 'jiafang.jpeg',
  28. status: 'uploading',
  29. size: '222KB',
  30. percent: 50,
  31. preview: true,
  32. fileInstance: new File([new ArrayBuffer(2048)], 'jiafang.jpeg', {
  33. type: 'image/jpeg',
  34. }),
  35. url:
  36. 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/root-web-sites/bag.jpeg',
  37. },
  38. ],
  39. },
  40. };
  41. this.getFormApi = this.getFormApi.bind(this);
  42. }
  43. getFormApi(formApi) {
  44. this.formApi = formApi;
  45. }
  46. render() {
  47. const {
  48. Section,
  49. Input,
  50. InputNumber,
  51. Select,
  52. DatePicker,
  53. TimePicker,
  54. TextArea,
  55. CheckboxGroup,
  56. Checkbox,
  57. RadioGroup,
  58. Radio,
  59. Slider,
  60. Rating,
  61. Switch,
  62. } = Form;
  63. const { initValues } = this.state;
  64. const style = {
  65. width: '90%',
  66. };
  67. const treeData = [
  68. {
  69. label: '亚洲',
  70. value: 'Asia',
  71. key: '0',
  72. children: [
  73. {
  74. label: '中国',
  75. value: 'China',
  76. key: '0-0',
  77. children: [
  78. {
  79. label: '北京',
  80. value: 'Beijing',
  81. key: '0-0-0',
  82. },
  83. {
  84. label: '上海',
  85. value: 'Shanghai',
  86. key: '0-0-1',
  87. },
  88. ],
  89. },
  90. ],
  91. },
  92. {
  93. label: '北美洲',
  94. value: 'North America',
  95. key: '1',
  96. },
  97. ];
  98. return (
  99. <div
  100. style={{
  101. width: 1200,
  102. }}
  103. >
  104. <Form
  105. getFormApi={this.getFormApi}
  106. initValues={initValues}
  107. style={{
  108. padding: 10,
  109. width: '100%',
  110. }}
  111. onValueChange={v => console.log(v)}
  112. >
  113. <Section text={'基本信息'}>
  114. <Row>
  115. <Col span={12}>
  116. <Input
  117. field="name"
  118. label="名称(Input)"
  119. initValue={'mikeya'}
  120. style={style}
  121. trigger="blur"
  122. />
  123. </Col>
  124. <Col span={12}>
  125. <DatePicker
  126. field="date"
  127. label="日期(DatePicker)"
  128. style={style}
  129. initValue={new Date()}
  130. placeholder="请选择生效日期"
  131. />
  132. </Col>
  133. </Row>
  134. <Row>
  135. <Col span={12}>
  136. <Select field="role" style={style} label="角色(Select)" placeholder="请选择你的角色">
  137. <Select.Option value="operate">运营</Select.Option>
  138. <Select.Option value="rd">开发</Select.Option>
  139. <Select.Option value="pm">产品</Select.Option>
  140. <Select.Option value="ued">设计</Select.Option>
  141. </Select>
  142. </Col>
  143. <Col span={12}>
  144. <Select
  145. field="business"
  146. multiple
  147. style={style}
  148. placeholder="请选择业务线"
  149. label="业务线(多选Select)"
  150. extraText={(
  151. <div
  152. style={{
  153. color: 'rgba(var(--semi-blue-5), 1)',
  154. fontSize: 14,
  155. userSelect: 'none',
  156. cursor: 'pointer',
  157. }}
  158. >
  159. 没有找到合适的业务线?
  160. </div>
  161. )}
  162. >
  163. <Select.Option value="dy">抖音</Select.Option>
  164. <Select.Option value="hotsoon">火山小视频</Select.Option>
  165. <Select.Option value="toutiao">今日头条</Select.Option>
  166. </Select>
  167. </Col>
  168. </Row>
  169. <Row>
  170. <Col span={12}>
  171. <Form.Cascader
  172. placeholder="请选择所在地区"
  173. treeData={treeData}
  174. field="area"
  175. label="地区(Cascader)"
  176. style={style}
  177. />
  178. </Col>
  179. <Col span={12}>
  180. <Form.TreeSelect
  181. field="tree"
  182. style={style}
  183. label="节点(TreeSelect)"
  184. placeholder="请选择服务节点"
  185. treeData={treeData}
  186. filterTreeNode
  187. />
  188. </Col>
  189. </Row>
  190. <Row>
  191. <Col span={24}>
  192. <Form.Upload
  193. field="files"
  194. label="证明文件(Upload)"
  195. action="//semi.design/api/upload"
  196. >
  197. <Button icon={<IconUpload />} theme="light">
  198. 点击上传
  199. </Button>
  200. </Form.Upload>
  201. </Col>
  202. </Row>
  203. </Section>
  204. <Section text="资源详情">
  205. <Row>
  206. <Col span={12}>
  207. <TextArea
  208. style={{ ...style, height: 120 }}
  209. field="description"
  210. label="申请理由(TextArea)"
  211. placeholder="请填写申请资源理由"
  212. />
  213. </Col>
  214. <Col span={12}>
  215. <CheckboxGroup
  216. field="type"
  217. direction="horizontal"
  218. label="申请类型(CheckboxGroup)"
  219. initValue={['user', 'admin']}
  220. rules={[
  221. {
  222. required: true,
  223. },
  224. ]}
  225. >
  226. <Checkbox value="admin">admin</Checkbox>
  227. <Checkbox value="user">user</Checkbox>
  228. <Checkbox value="guest">guest</Checkbox>
  229. <Checkbox value="root">root</Checkbox>
  230. </CheckboxGroup>
  231. <RadioGroup
  232. field="isMonopolize"
  233. label="是否独占资源(Radio)"
  234. rules={[
  235. {
  236. type: 'boolean',
  237. },
  238. {
  239. required: true,
  240. message: '必须选择是否独占 ',
  241. },
  242. ]}
  243. >
  244. <Radio value={true}>是</Radio>
  245. <Radio value={false}>否</Radio>
  246. </RadioGroup>
  247. </Col>
  248. </Row>
  249. <Row>
  250. <Col span={12}>
  251. <TimePicker
  252. field="time"
  253. label="截止时刻(TimePicker)"
  254. style={{
  255. width: '90%',
  256. }}
  257. />
  258. </Col>
  259. <Col span={12}>
  260. <InputNumber
  261. field="number"
  262. label="申请数量(InputNumber)"
  263. initValue={20}
  264. style={style}
  265. />
  266. </Col>
  267. </Row>
  268. <Row>
  269. <Col span={12}>
  270. <Slider
  271. field="range"
  272. label="资源使用报警阈值(%)(Slider)"
  273. initValue={10}
  274. style={{
  275. width: '90%',
  276. }}
  277. />
  278. </Col>
  279. <Col span={12}>
  280. <Switch field="switch" label="开关(Switch)" />
  281. </Col>
  282. </Row>
  283. <Row>
  284. <Col span={12}>
  285. <Rating
  286. field="rating"
  287. label="满意度(Rating)"
  288. initValue={2}
  289. style={{
  290. width: '90%',
  291. }}
  292. />
  293. </Col>
  294. </Row>
  295. </Section>
  296. <Checkbox value="false" field="agree" noLabel={true}>
  297. 我已阅读并清楚相关规定(Checkbox)
  298. </Checkbox>
  299. <Button type="primary" htmlType="submit" className="btn-margin-right">
  300. 提交(submit)
  301. </Button>
  302. <Button htmlType="reset">重置(reset)</Button>
  303. </Form>
  304. </div>
  305. );
  306. }
  307. }
  308. export default RTLForm;