convert.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. Icon
  16. } from '../../index';
  17. import {
  18. UseFormApiDemo,
  19. UseFormStateDemo,
  20. UseFieldApiDemo,
  21. UseFieldStateDemo,
  22. WithFormStateDemo,
  23. WithFormApiDemo,
  24. ComponentUsingFormState,
  25. CustomStringify
  26. } from '../Hook/hookDemo';
  27. const { Input, Select, DatePicker, Switch, Slider, CheckboxGroup, Checkbox, RadioGroup, Radio, TimePicker } = Form;
  28. class ConvertDemo extends React.Component {
  29. constructor(props) {
  30. super(props);
  31. this.formApi = null;
  32. }
  33. handleChange = val => {
  34. let finalVal = val;
  35. let firstClassOption = ['Asia', 'North America'];
  36. // 在这里去做你的value替换逻辑
  37. console.log(`originVal:${ val}`);
  38. if (val.length === 1) {
  39. // do nothing
  40. } else {
  41. if (val.every(item => firstClassOption.includes(item))) {
  42. finalVal = val[val.length - 1];
  43. }
  44. }
  45. console.log(`finalVal:${ finalVal}`);
  46. return finalVal;
  47. };
  48. render() {
  49. const treeData = [
  50. {
  51. label: '亚洲',
  52. value: 'Asia',
  53. key: '0',
  54. children: [
  55. {
  56. label: '中国',
  57. value: 'China',
  58. key: '0-0',
  59. children: [
  60. {
  61. label: '北京',
  62. value: 'Beijing',
  63. key: '0-0-0',
  64. },
  65. {
  66. label: '上海',
  67. value: 'Shanghai',
  68. key: '0-0-1',
  69. },
  70. ],
  71. },
  72. ],
  73. },
  74. {
  75. label: '北美洲',
  76. value: 'North America',
  77. key: '1',
  78. },
  79. ];
  80. return (
  81. <Form getFormApi={this.getFormApi}>
  82. <Form.TreeSelect
  83. field="tree"
  84. label="节点(TreeSelect)"
  85. placeholder="请选择服务节点"
  86. treeData={treeData}
  87. convert={this.handleChange}
  88. filterTreeNode
  89. multiple
  90. />
  91. </Form>
  92. );
  93. }
  94. }
  95. export { ConvertDemo };