convert.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* eslint-disable no-unused-vars */
  2. import React, { useState, useLayoutEffect, useEffect, useRef } from 'react';
  3. import { storiesOf } from '@storybook/react';
  4. import { Button, Modal, TreeSelect, Row, Col, Avatar, Tabs, TabPane, Badge } from '@douyinfe/semi-ui';
  5. import {
  6. Form,
  7. useFormState,
  8. useFormApi,
  9. useFieldApi,
  10. useFieldState,
  11. withFormState,
  12. withFormApi,
  13. withField,
  14. ArrayField,
  15. } from '../../index';
  16. import {
  17. UseFormApiDemo,
  18. UseFormStateDemo,
  19. UseFieldApiDemo,
  20. UseFieldStateDemo,
  21. WithFormStateDemo,
  22. WithFormApiDemo,
  23. ComponentUsingFormState,
  24. CustomStringify
  25. } from '../Hook/hookDemo';
  26. const { Input, Select, DatePicker, Switch, Slider, CheckboxGroup, Checkbox, RadioGroup, Radio, TimePicker } = Form;
  27. class ConvertDemo extends React.Component {
  28. constructor(props) {
  29. super(props);
  30. this.formApi = null;
  31. }
  32. handleChange = val => {
  33. let finalVal = val;
  34. let firstClassOption = ['Asia', 'North America'];
  35. // 在这里去做你的value替换逻辑
  36. console.log(`originVal:${ val}`);
  37. if (val.length === 1) {
  38. // do nothing
  39. } else {
  40. if (val.every(item => firstClassOption.includes(item))) {
  41. finalVal = val[val.length - 1];
  42. }
  43. }
  44. console.log(`finalVal:${ finalVal}`);
  45. return finalVal;
  46. };
  47. render() {
  48. const treeData = [
  49. {
  50. label: '亚洲',
  51. value: 'Asia',
  52. key: '0',
  53. children: [
  54. {
  55. label: '中国',
  56. value: 'China',
  57. key: '0-0',
  58. children: [
  59. {
  60. label: '北京',
  61. value: 'Beijing',
  62. key: '0-0-0',
  63. },
  64. {
  65. label: '上海',
  66. value: 'Shanghai',
  67. key: '0-0-1',
  68. },
  69. ],
  70. },
  71. ],
  72. },
  73. {
  74. label: '北美洲',
  75. value: 'North America',
  76. key: '1',
  77. },
  78. ];
  79. return (
  80. <Form getFormApi={this.getFormApi}>
  81. <Form.TreeSelect
  82. field="tree"
  83. label="节点(TreeSelect)"
  84. placeholder="请选择服务节点"
  85. treeData={treeData}
  86. convert={this.handleChange}
  87. filterTreeNode
  88. multiple
  89. />
  90. </Form>
  91. );
  92. }
  93. }
  94. export { ConvertDemo };