@@ -173,9 +224,11 @@ export class TreeCheckboxes extends Checkboxes<
description={option.description}
/>
- {Array.isArray(option.children) && option.children.length ? (
+ {hasChildren ? (
- {option.children.map((option, key) => this.renderItem(option, key))}
+ {option.children!.map((option, key) =>
+ this.renderItem(option, key)
+ )}
) : null}
From 878bb8c8f3e8ac8c220cb1ff543e18fbb8248470 Mon Sep 17 00:00:00 2001
From: 2betop <2betop.cn@gmail.com>
Date: Thu, 28 May 2020 17:47:49 +0800
Subject: [PATCH 2/2] =?UTF-8?q?TreeCheckboxes,=20ChainedCheckboxes=20?=
=?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=89=E9=A1=B9=E5=BB=B6=E6=97=B6=E5=8A=A0?=
=?UTF-8?q?=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
examples/components/Form/Transfer.jsx | 40 +++++++
mock/form/deferOptions.js | 23 ++++
scss/components/form/_checks.scss | 9 +-
src/components/ChainedCheckboxes.tsx | 50 ++++++---
src/components/Checkboxes.tsx | 1 +
src/components/ListCheckboxes.tsx | 1 +
src/components/Select.tsx | 30 ++++++
src/components/TabsTransfer.tsx | 7 +-
src/components/Transfer.tsx | 9 +-
src/components/TreeCheckboxes.tsx | 74 +++++++------
src/renderers/Form/IconPicker.tsx | 6 +-
src/renderers/Form/Options.tsx | 24 +++++
src/renderers/Form/Transfer.tsx | 4 +-
src/store/formItem.ts | 150 +++++++++++++++++++-------
src/utils/helper.ts | 22 +++-
15 files changed, 346 insertions(+), 104 deletions(-)
create mode 100644 mock/form/deferOptions.js
diff --git a/examples/components/Form/Transfer.jsx b/examples/components/Form/Transfer.jsx
index a70feed8..c6177730 100644
--- a/examples/components/Form/Transfer.jsx
+++ b/examples/components/Form/Transfer.jsx
@@ -386,6 +386,46 @@ export default {
]
}
]
+ },
+
+ {
+ label: '延时加载',
+ type: 'transfer',
+ name: 'transfer7',
+ selectMode: 'tree',
+ deferApi: '/api/mock2/form/deferOptions?label=${label}',
+ options: [
+ {
+ label: '法师',
+ children: [
+ {
+ label: '诸葛亮',
+ value: 'zhugeliang'
+ }
+ ]
+ },
+ {
+ label: '战士',
+ defer: true
+ },
+ {
+ label: '打野',
+ children: [
+ {
+ label: '李白',
+ value: 'libai'
+ },
+ {
+ label: '韩信',
+ value: 'hanxin'
+ },
+ {
+ label: '云中君',
+ value: 'yunzhongjun'
+ }
+ ]
+ }
+ ]
}
]
}
diff --git a/mock/form/deferOptions.js b/mock/form/deferOptions.js
new file mode 100644
index 00000000..064ea377
--- /dev/null
+++ b/mock/form/deferOptions.js
@@ -0,0 +1,23 @@
+module.exports = function (req, res) {
+ let repeat = 2 + Math.round(Math.random() * 5);
+ const options = [];
+
+ while (repeat--) {
+ const value = Math.round(Math.random() * 1000000);
+ const label = value + '';
+
+ options.push({
+ label: label,
+ value: value,
+ defer: Math.random() > 0.7
+ });
+ }
+
+ res.json({
+ status: 0,
+ msg: '',
+ data: {
+ options: options
+ }
+ });
+};
diff --git a/scss/components/form/_checks.scss b/scss/components/form/_checks.scss
index f85c4c68..bbc0689f 100644
--- a/scss/components/form/_checks.scss
+++ b/scss/components/form/_checks.scss
@@ -404,6 +404,7 @@
&-sublist {
position: relative;
margin: 0 0 0 px2rem(35px);
+ display: none;
&:before {
width: 1px;
@@ -420,8 +421,8 @@
&-item {
position: relative;
- &.is-collapsed > .#{$ns}TreeCheckboxes-sublist {
- display: none;
+ &.is-expanded > .#{$ns}TreeCheckboxes-sublist {
+ display: block;
}
}
@@ -442,6 +443,7 @@
&-itemInner {
display: flex;
+ align-items: center;
height: $Form-input-height;
line-height: $Form-input-lineHeight;
font-size: $Form-input-fontSize;
@@ -452,6 +454,7 @@
> .#{$ns}Checkbox {
margin-right: 0;
+ margin-left: $gap-sm;
}
cursor: pointer;
user-select: none;
@@ -481,7 +484,7 @@
&-col {
flex-grow: 1;
- min-width: 120px;
+ min-width: 150px;
}
&-col:not(:last-child) {
diff --git a/src/components/ChainedCheckboxes.tsx b/src/components/ChainedCheckboxes.tsx
index 17d1d8f3..4725d16a 100644
--- a/src/components/ChainedCheckboxes.tsx
+++ b/src/components/ChainedCheckboxes.tsx
@@ -6,9 +6,10 @@ import Checkbox from './Checkbox';
import {Option} from './Select';
import {getTreeDepth} from '../utils/helper';
import times from 'lodash/times';
+import Spinner from './Spinner';
export interface ChainedCheckboxesState {
- selected: Array