amis 1.6.5-beta.3 → 1.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Schema.d.ts +3 -2
- package/lib/Schema.js +0 -1
- package/lib/Schema.js.map +2 -2
- package/lib/components/Alert2.js +4 -2
- package/lib/components/Alert2.js.map +2 -2
- package/lib/components/AssociatedSelection.d.ts +84 -84
- package/lib/components/Avatar.d.ts +20 -20
- package/lib/components/Breadcrumb.d.ts +130 -0
- package/lib/components/Breadcrumb.js +161 -0
- package/lib/components/Breadcrumb.js.map +13 -0
- package/lib/components/Card.d.ts +20 -20
- package/lib/components/ChainedSelection.d.ts +84 -84
- package/lib/components/CityArea.js +3 -0
- package/lib/components/CityArea.js.map +2 -2
- package/lib/components/Collapse.d.ts +20 -20
- package/lib/components/CollapseGroup.d.ts +20 -20
- package/lib/components/DatePicker.d.ts +84 -84
- package/lib/components/DateRangePicker.d.ts +2 -2
- package/lib/components/DateRangePicker.js +36 -45
- package/lib/components/DateRangePicker.js.map +2 -2
- package/lib/components/GroupedSelection.d.ts +84 -84
- package/lib/components/Layout.d.ts +21 -21
- package/lib/components/ListGroup.d.ts +21 -21
- package/lib/components/PopUp.js +2 -1
- package/lib/components/PopUp.js.map +2 -2
- package/lib/components/Radios.d.ts +21 -21
- package/lib/components/Range.js.map +2 -2
- package/lib/components/Selection.d.ts +84 -84
- package/lib/components/TableSelection.d.ts +84 -84
- package/lib/components/Tabs.d.ts +52 -23
- package/lib/components/Tabs.js +198 -46
- package/lib/components/Tabs.js.map +2 -2
- package/lib/components/TooltipWrapper.d.ts +21 -20
- package/lib/components/TooltipWrapper.js +2 -2
- package/lib/components/TooltipWrapper.js.map +2 -2
- package/lib/components/Transfer.d.ts +84 -84
- package/lib/components/TransferDropDown.d.ts +84 -84
- package/lib/components/Tree.d.ts +84 -84
- package/lib/components/TreeSelection.d.ts +84 -84
- package/lib/components/calendar/Calendar.js +5 -0
- package/lib/components/calendar/Calendar.js.map +2 -2
- package/lib/components/calendar/DaysView.js.map +1 -1
- package/lib/components/icons.js +8 -0
- package/lib/components/icons.js.map +2 -2
- package/lib/components/index.d.ts +2 -1
- package/lib/components/index.js +4 -2
- package/lib/components/index.js.map +2 -2
- package/lib/icons/cloud-upload.js +17 -0
- package/lib/icons/image.js +7 -0
- package/lib/icons/refresh.js +9 -0
- package/lib/icons/trash.js +10 -0
- package/lib/icons/upload.js +3 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/index.js.map +2 -2
- package/lib/locale/en-US.js +3 -1
- package/lib/locale/en-US.js.map +2 -2
- package/lib/locale/zh-CN.js +4 -2
- package/lib/locale/zh-CN.js.map +2 -2
- package/lib/renderers/Action.d.ts +1 -1
- package/lib/renderers/Action.js.map +2 -2
- package/lib/renderers/Breadcrumb.d.ts +41 -6
- package/lib/renderers/Breadcrumb.js +23 -19
- package/lib/renderers/Breadcrumb.js.map +2 -2
- package/lib/renderers/ButtonGroup.d.ts +2 -2
- package/lib/renderers/ButtonGroup.js.map +1 -1
- package/lib/renderers/Form/ChainedSelect.d.ts +4 -1
- package/lib/renderers/Form/ChainedSelect.js +83 -34
- package/lib/renderers/Form/ChainedSelect.js.map +2 -2
- package/lib/renderers/Form/Checkbox.d.ts +3 -0
- package/lib/renderers/Form/Checkbox.js +38 -1
- package/lib/renderers/Form/Checkbox.js.map +2 -2
- package/lib/renderers/Form/Combo.d.ts +4 -3
- package/lib/renderers/Form/Combo.js +81 -32
- package/lib/renderers/Form/Combo.js.map +2 -2
- package/lib/renderers/Form/DiffEditor.d.ts +1 -1
- package/lib/renderers/Form/InputCity.d.ts +84 -84
- package/lib/renderers/Form/InputCity.js +4 -1
- package/lib/renderers/Form/InputCity.js.map +2 -2
- package/lib/renderers/Form/InputColor.js +3 -1
- package/lib/renderers/Form/InputColor.js.map +2 -2
- package/lib/renderers/Form/InputDate.js +3 -1
- package/lib/renderers/Form/InputDate.js.map +2 -2
- package/lib/renderers/Form/InputDateRange.js +3 -1
- package/lib/renderers/Form/InputDateRange.js.map +2 -2
- package/lib/renderers/Form/InputExcel.d.ts +4 -0
- package/lib/renderers/Form/InputExcel.js +33 -6
- package/lib/renderers/Form/InputExcel.js.map +2 -2
- package/lib/renderers/Form/InputFile.d.ts +8 -1
- package/lib/renderers/Form/InputFile.js +71 -42
- package/lib/renderers/Form/InputFile.js.map +2 -2
- package/lib/renderers/Form/InputImage.d.ts +4 -1
- package/lib/renderers/Form/InputImage.js +21 -9
- package/lib/renderers/Form/InputImage.js.map +2 -2
- package/lib/renderers/Form/InputRange.d.ts +27 -9
- package/lib/renderers/Form/InputRange.js +88 -23
- package/lib/renderers/Form/InputRange.js.map +2 -2
- package/lib/renderers/Form/InputSubForm.js +2 -1
- package/lib/renderers/Form/InputSubForm.js.map +2 -2
- package/lib/renderers/Form/InputTag.js +2 -1
- package/lib/renderers/Form/InputTag.js.map +2 -2
- package/lib/renderers/Form/MatrixCheckboxes.js +2 -1
- package/lib/renderers/Form/MatrixCheckboxes.js.map +2 -2
- package/lib/renderers/Form/NestedSelect.d.ts +9 -6
- package/lib/renderers/Form/NestedSelect.js +247 -130
- package/lib/renderers/Form/NestedSelect.js.map +2 -2
- package/lib/renderers/Form/Options.js +2 -1
- package/lib/renderers/Form/Options.js.map +2 -2
- package/lib/renderers/Form/Radios.js +2 -1
- package/lib/renderers/Form/Radios.js.map +2 -2
- package/lib/renderers/Form/Select.js +6 -3
- package/lib/renderers/Form/Select.js.map +2 -2
- package/lib/renderers/Form/Switch.d.ts +7 -6
- package/lib/renderers/Form/Switch.js +4 -1
- package/lib/renderers/Form/Switch.js.map +2 -2
- package/lib/renderers/Log.js +2 -1
- package/lib/renderers/Log.js.map +2 -2
- package/lib/renderers/PopOver.js +1 -1
- package/lib/renderers/PopOver.js.map +2 -2
- package/lib/renderers/Tabs.d.ts +58 -5
- package/lib/renderers/Tabs.js +170 -58
- package/lib/renderers/Tabs.js.map +2 -2
- package/lib/renderers/TooltipWrapper.d.ts +104 -0
- package/lib/renderers/TooltipWrapper.js +59 -0
- package/lib/renderers/TooltipWrapper.js.map +13 -0
- package/lib/renderers/Video.d.ts +6 -0
- package/lib/renderers/Video.js +13 -6
- package/lib/renderers/Video.js.map +2 -2
- package/lib/store/form.js +4 -13
- package/lib/store/form.js.map +2 -2
- package/lib/store/table.js +1 -1
- package/lib/store/table.js.map +2 -2
- package/lib/themes/ang-ie11.css +742 -160
- package/lib/themes/ang.css +793 -163
- package/lib/themes/ang.css.map +1 -1
- package/lib/themes/antd-ie11.css +757 -175
- package/lib/themes/antd.css +793 -163
- package/lib/themes/antd.css.map +1 -1
- package/lib/themes/cxd-ie11.css +1249 -667
- package/lib/themes/cxd.css +970 -321
- package/lib/themes/cxd.css.map +1 -1
- package/lib/themes/dark-ie11.css +742 -160
- package/lib/themes/dark.css +793 -163
- package/lib/themes/dark.css.map +1 -1
- package/lib/themes/default-ie11.css +1249 -667
- package/lib/themes/default.css +970 -321
- package/lib/themes/default.css.map +1 -1
- package/package.json +1 -1
- package/schema.json +16012 -736
- package/scss/_properties.scss +56 -2
- package/scss/components/_alert.scss +1 -1
- package/scss/components/_breadcrumb.scss +90 -1
- package/scss/components/_button-group.scss +15 -0
- package/scss/components/_city-area.scss +2 -0
- package/scss/components/_popup.scss +13 -3
- package/scss/components/_tabs.scss +629 -132
- package/scss/components/_tooltip.scss +72 -0
- package/scss/components/form/_file.scss +82 -24
- package/scss/components/form/_image.scss +30 -25
- package/scss/components/form/_number.scss +2 -0
- package/scss/components/form/_switch.scss +1 -3
- package/scss/themes/_cxd-colors.scss +47 -47
- package/scss/themes/_cxd-variables.scss +20 -0
- package/sdk/ang-ie11.css +879 -196
- package/sdk/ang.css +931 -200
- package/sdk/antd-ie11.css +951 -268
- package/sdk/antd.css +931 -200
- package/sdk/barcode.js +51 -51
- package/sdk/charts.js +14 -14
- package/sdk/codemirror.js +7 -7
- package/sdk/color-picker.js +65 -65
- package/sdk/cropperjs.js +2 -2
- package/sdk/cxd-ie11.css +1386 -703
- package/sdk/cxd.css +1107 -357
- package/sdk/dark-ie11.css +879 -196
- package/sdk/dark.css +931 -200
- package/sdk/exceljs.js +1 -1
- package/sdk/markdown.js +69 -69
- package/sdk/papaparse.js +1 -1
- package/sdk/renderers/Form/CityDB.js +1 -1
- package/sdk/rest.js +17 -17
- package/sdk/rich-text.js +62 -62
- package/sdk/sdk-ie11.css +1386 -703
- package/sdk/sdk.css +1107 -357
- package/sdk/sdk.js +1260 -1248
- package/sdk/thirds/hls.js/hls.js +1 -1
- package/sdk/thirds/mpegts.js/mpegts.js +1 -1
- package/sdk/tinymce.js +57 -57
- package/src/Schema.ts +5 -2
- package/src/components/Alert2.tsx +9 -3
- package/src/components/Breadcrumb.tsx +294 -0
- package/src/components/CityArea.tsx +3 -0
- package/src/components/DateRangePicker.tsx +40 -68
- package/src/components/PopUp.tsx +6 -5
- package/src/components/Range.tsx +7 -1
- package/src/components/Tabs.tsx +300 -54
- package/src/components/TooltipWrapper.tsx +4 -1
- package/src/components/calendar/Calendar.tsx +5 -0
- package/src/components/calendar/DaysView.tsx +2 -2
- package/src/components/icons.tsx +8 -0
- package/src/components/index.tsx +2 -0
- package/src/icons/cloud-upload.svg +22 -0
- package/src/icons/image.svg +1 -0
- package/src/icons/refresh.svg +7 -0
- package/src/icons/trash.svg +8 -0
- package/src/icons/upload.svg +4 -9
- package/src/index.tsx +1 -0
- package/src/locale/en-US.ts +3 -1
- package/src/locale/zh-CN.ts +4 -2
- package/src/renderers/Action.tsx +2 -1
- package/src/renderers/Breadcrumb.tsx +89 -45
- package/src/renderers/ButtonGroup.tsx +2 -2
- package/src/renderers/Form/ChainedSelect.tsx +56 -12
- package/src/renderers/Form/Checkbox.tsx +30 -1
- package/src/renderers/Form/Combo.tsx +84 -26
- package/src/renderers/Form/InputCity.tsx +13 -1
- package/src/renderers/Form/InputColor.tsx +2 -0
- package/src/renderers/Form/InputDate.tsx +2 -0
- package/src/renderers/Form/InputDateRange.tsx +2 -0
- package/src/renderers/Form/InputExcel.tsx +27 -5
- package/src/renderers/Form/InputFile.tsx +167 -115
- package/src/renderers/Form/InputImage.tsx +61 -35
- package/src/renderers/Form/InputRange.tsx +95 -40
- package/src/renderers/Form/InputSubForm.tsx +2 -1
- package/src/renderers/Form/InputTag.tsx +3 -1
- package/src/renderers/Form/MatrixCheckboxes.tsx +3 -1
- package/src/renderers/Form/NestedSelect.tsx +75 -26
- package/src/renderers/Form/Options.tsx +3 -1
- package/src/renderers/Form/Radios.tsx +3 -1
- package/src/renderers/Form/Select.tsx +6 -2
- package/src/renderers/Form/Switch.tsx +16 -9
- package/src/renderers/Log.tsx +2 -1
- package/src/renderers/PopOver.tsx +1 -1
- package/src/renderers/Tabs.tsx +254 -93
- package/src/renderers/TooltipWrapper.tsx +219 -0
- package/src/renderers/Video.tsx +21 -6
- package/src/store/form.ts +0 -9
- package/src/store/table.ts +1 -1
package/src/renderers/Tabs.tsx
CHANGED
@@ -8,10 +8,11 @@ import {
|
|
8
8
|
isDisabled,
|
9
9
|
isObject,
|
10
10
|
createObject,
|
11
|
-
getVariable
|
11
|
+
getVariable,
|
12
|
+
isObjectShallowModified
|
12
13
|
} from '../utils/helper';
|
13
14
|
import findIndex from 'lodash/findIndex';
|
14
|
-
import {Tabs as CTabs, Tab} from '../components/Tabs';
|
15
|
+
import {Tabs as CTabs, Tab, TabsMode} from '../components/Tabs';
|
15
16
|
import {ClassNamesFn} from '../theme';
|
16
17
|
import {
|
17
18
|
BaseSchema,
|
@@ -87,6 +88,14 @@ export interface TabSchema extends Omit<BaseSchema, 'type'> {
|
|
87
88
|
* 如果是水平排版,这个属性可以细化水平排版的左右宽度占比。
|
88
89
|
*/
|
89
90
|
horizontal?: FormSchemaHorizontal;
|
91
|
+
/**
|
92
|
+
* 是否可关闭,优先级高于 tabs 的 closable
|
93
|
+
*/
|
94
|
+
closable?: boolean;
|
95
|
+
/**
|
96
|
+
* 是否禁用
|
97
|
+
*/
|
98
|
+
disabled?: boolean;
|
90
99
|
}
|
91
100
|
|
92
101
|
/**
|
@@ -114,7 +123,7 @@ export interface TabsSchema extends BaseSchema {
|
|
114
123
|
/**
|
115
124
|
* 展示形式
|
116
125
|
*/
|
117
|
-
tabsMode?:
|
126
|
+
tabsMode?: TabsMode;
|
118
127
|
|
119
128
|
/**
|
120
129
|
* 内容类名
|
@@ -150,9 +159,41 @@ export interface TabsSchema extends BaseSchema {
|
|
150
159
|
*/
|
151
160
|
subFormHorizontal?: FormSchemaHorizontal;
|
152
161
|
/**
|
153
|
-
*
|
162
|
+
* 是否支持新增
|
163
|
+
*/
|
164
|
+
addable?: boolean;
|
165
|
+
/**
|
166
|
+
* 是否支持删除
|
167
|
+
*/
|
168
|
+
closable?: boolean;
|
169
|
+
/**
|
170
|
+
* 是否支持拖拽
|
171
|
+
*/
|
172
|
+
draggable?: boolean;
|
173
|
+
/**
|
174
|
+
* 是否显示提示
|
175
|
+
*/
|
176
|
+
showTip?: boolean;
|
177
|
+
/**
|
178
|
+
* tooltip 提示的类名
|
179
|
+
*/
|
180
|
+
showTipClassName?: string;
|
181
|
+
/**
|
182
|
+
* 是否可编辑标签名
|
183
|
+
*/
|
184
|
+
editable?: boolean;
|
185
|
+
/**
|
186
|
+
* 是否导航支持内容溢出滚动。属性废弃,为了兼容暂且保留
|
154
187
|
*/
|
155
188
|
scrollable?: boolean;
|
189
|
+
/**
|
190
|
+
* 编辑器模式,侧边的位置
|
191
|
+
*/
|
192
|
+
sidePosition?: 'left' | 'right';
|
193
|
+
/**
|
194
|
+
* 自定义增加按钮文案
|
195
|
+
*/
|
196
|
+
addBtnText?: string;
|
156
197
|
}
|
157
198
|
|
158
199
|
export interface TabsProps
|
@@ -163,9 +204,15 @@ export interface TabsProps
|
|
163
204
|
tabRender?: (tab: TabSchema, props: TabsProps, index: number) => JSX.Element;
|
164
205
|
}
|
165
206
|
|
207
|
+
interface TabSource extends TabSchema {
|
208
|
+
ctx?: any;
|
209
|
+
}
|
210
|
+
|
166
211
|
export interface TabsState {
|
167
212
|
activeKey: any;
|
168
213
|
prevKey: any;
|
214
|
+
localTabs: Array<TabSource>;
|
215
|
+
isFromSource: boolean;
|
169
216
|
}
|
170
217
|
|
171
218
|
export type TabsRendererEvent = 'change';
|
@@ -181,19 +228,20 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
181
228
|
|
182
229
|
renderTab?: (tab: TabSchema, props: TabsProps, index: number) => JSX.Element;
|
183
230
|
activeKey: any;
|
231
|
+
newTabDefaultId: number = 3;
|
184
232
|
|
185
233
|
constructor(props: TabsProps) {
|
186
234
|
super(props);
|
187
235
|
|
188
236
|
const location = props.location || window.location;
|
189
|
-
const tabs = props
|
237
|
+
const {tabs, source, data} = props;
|
190
238
|
let activeKey: any = 0;
|
191
239
|
|
192
240
|
if (typeof props.activeKey !== 'undefined') {
|
193
241
|
activeKey = props.activeKey;
|
194
242
|
} else if (location && Array.isArray(tabs)) {
|
195
243
|
const hash = location.hash.substring(1);
|
196
|
-
const tab:
|
244
|
+
const tab: TabSource = find(tabs, tab => tab.hash === hash) as TabSource;
|
197
245
|
|
198
246
|
if (tab) {
|
199
247
|
activeKey = tab.hash;
|
@@ -204,17 +252,50 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
204
252
|
activeKey = activeKey || (tabs[0] && tabs[0].hash) || 0;
|
205
253
|
}
|
206
254
|
|
255
|
+
const [localTabs, isFromSource] = this.initTabArray(tabs, source, data);
|
256
|
+
|
207
257
|
this.state = {
|
208
258
|
prevKey: undefined,
|
209
|
-
activeKey: (this.activeKey = activeKey)
|
259
|
+
activeKey: (this.activeKey = activeKey),
|
260
|
+
localTabs,
|
261
|
+
isFromSource
|
210
262
|
};
|
211
263
|
}
|
212
264
|
|
265
|
+
// 初始化 tabs 数组,当从 source 获取数据源时
|
266
|
+
@autobind
|
267
|
+
initTabArray(tabs: Array<TabSource>, source?: string, data?: any): [Array<TabSource>, boolean] {
|
268
|
+
if (!tabs) {
|
269
|
+
return [[], false];
|
270
|
+
}
|
271
|
+
|
272
|
+
const arr = resolveVariableAndFilter(source, data, '| raw');
|
273
|
+
if (!Array.isArray(arr)) {
|
274
|
+
return [tabs, false];
|
275
|
+
}
|
276
|
+
|
277
|
+
tabs = Array.isArray(tabs) ? tabs : [tabs];
|
278
|
+
|
279
|
+
const sourceTabs: Array<TabSource> = [];
|
280
|
+
arr.forEach((value, index) => {
|
281
|
+
const ctx = createObject(
|
282
|
+
data,
|
283
|
+
isObject(value) ? {index, ...value} : {item: value, index}
|
284
|
+
);
|
285
|
+
|
286
|
+
sourceTabs.push(...tabs.map((tab: TabSource) => ({...tab, ctx})));
|
287
|
+
});
|
288
|
+
|
289
|
+
return [sourceTabs, true];
|
290
|
+
}
|
291
|
+
|
213
292
|
componentDidMount() {
|
214
293
|
this.autoJumpToNeighbour(this.activeKey);
|
215
294
|
|
216
295
|
let {name, value, onChange, source, tabs, data} = this.props;
|
217
296
|
|
297
|
+
const localTabs = this.state.localTabs;
|
298
|
+
|
218
299
|
// 如果没有配置 name ,说明不需要同步表单值
|
219
300
|
if (
|
220
301
|
!name ||
|
@@ -228,7 +309,7 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
228
309
|
value = value ?? getVariable(data, name);
|
229
310
|
|
230
311
|
// 如果有值,切到对应的 tab
|
231
|
-
if (value && Array.isArray(
|
312
|
+
if (value && Array.isArray(localTabs)) {
|
232
313
|
const key = this.resolveKeyByValue(value);
|
233
314
|
key !== undefined && this.handleSelect(key);
|
234
315
|
} else {
|
@@ -241,17 +322,37 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
241
322
|
|
242
323
|
componentDidUpdate(preProps: TabsProps, prevState: any) {
|
243
324
|
const props = this.props;
|
325
|
+
let localTabs = this.state.localTabs;
|
244
326
|
|
245
|
-
|
327
|
+
// 响应外部修改 tabs
|
328
|
+
const isTabsModified = isObjectShallowModified({
|
329
|
+
tabs: props.tabs,
|
330
|
+
source: resolveVariableAndFilter(props.source, props.data, '| raw')
|
331
|
+
}, {
|
332
|
+
tabs: preProps.tabs,
|
333
|
+
source: resolveVariableAndFilter(preProps.source, preProps.data, '| raw')
|
334
|
+
}, false);
|
335
|
+
|
336
|
+
if (isTabsModified) {
|
337
|
+
const [newLocalTabs, isFromSource] = this.initTabArray(props.tabs, props.source, props.data);
|
338
|
+
|
339
|
+
this.setState({
|
340
|
+
localTabs: newLocalTabs,
|
341
|
+
isFromSource
|
342
|
+
});
|
343
|
+
localTabs = newLocalTabs;
|
344
|
+
}
|
345
|
+
|
346
|
+
if (props.location && preProps.location && props.location.hash !== preProps.location.hash) {
|
246
347
|
const hash = props.location.hash.substring(1);
|
247
348
|
if (!hash) {
|
248
349
|
return;
|
249
350
|
}
|
250
351
|
|
251
|
-
const tab:
|
252
|
-
|
352
|
+
const tab: TabSource = find(
|
353
|
+
localTabs,
|
253
354
|
tab => tab.hash === hash
|
254
|
-
) as
|
355
|
+
) as TabSource;
|
255
356
|
if (tab && tab.hash && tab.hash !== this.state.activeKey) {
|
256
357
|
this.setState({
|
257
358
|
activeKey: (this.activeKey = tab.hash),
|
@@ -259,29 +360,29 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
259
360
|
});
|
260
361
|
}
|
261
362
|
} else if (
|
262
|
-
Array.isArray(
|
263
|
-
Array.isArray(
|
264
|
-
JSON.stringify(
|
265
|
-
JSON.stringify(
|
363
|
+
Array.isArray(localTabs) &&
|
364
|
+
Array.isArray(prevState.localTabs) &&
|
365
|
+
JSON.stringify(localTabs.map(item => item.hash)) !==
|
366
|
+
JSON.stringify(prevState.localTabs.map((item: TabSource) => item.hash))
|
266
367
|
) {
|
267
368
|
let activeKey: any = this.state.activeKey;
|
268
369
|
const location = props.location;
|
269
|
-
let tab:
|
370
|
+
let tab: TabSource | null = null;
|
270
371
|
|
271
|
-
if (location && Array.isArray(
|
372
|
+
if (location && Array.isArray(localTabs)) {
|
272
373
|
const hash = location.hash.substring(1);
|
273
|
-
tab = find(
|
374
|
+
tab = find(localTabs, tab => tab.hash === hash) as TabSource;
|
274
375
|
}
|
275
376
|
|
276
377
|
if (tab) {
|
277
378
|
activeKey = tab.hash;
|
278
379
|
} else if (
|
279
|
-
!
|
280
|
-
!
|
380
|
+
!localTabs ||
|
381
|
+
!localTabs.some((item, index) =>
|
281
382
|
item.hash ? item.hash === activeKey : index === activeKey
|
282
383
|
)
|
283
384
|
) {
|
284
|
-
activeKey = (
|
385
|
+
activeKey = (localTabs && localTabs[0] && localTabs[0].hash) || 0;
|
285
386
|
}
|
286
387
|
|
287
388
|
this.setState({
|
@@ -323,54 +424,55 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
323
424
|
}
|
324
425
|
|
325
426
|
resolveTabByKey(key: any) {
|
326
|
-
const
|
427
|
+
const localTabs = this.state.localTabs;
|
327
428
|
|
328
|
-
if (!Array.isArray(
|
429
|
+
if (!Array.isArray(localTabs)) {
|
329
430
|
return;
|
330
431
|
}
|
331
432
|
|
332
|
-
return find(
|
433
|
+
return find(localTabs, (tab: TabSource, index) =>
|
333
434
|
tab.hash ? tab.hash === key : index === key
|
334
435
|
);
|
335
436
|
}
|
336
437
|
|
337
438
|
resolveKeyByValue(value: any) {
|
338
|
-
const
|
439
|
+
const localTabs = this.state.localTabs;
|
339
440
|
|
340
|
-
if (!Array.isArray(
|
441
|
+
if (!Array.isArray(localTabs)) {
|
341
442
|
return;
|
342
443
|
}
|
343
444
|
|
344
|
-
const tab:
|
345
|
-
|
445
|
+
const tab: TabSource = find(
|
446
|
+
localTabs,
|
346
447
|
tab => ((tab as any).value ?? tab.title) === value
|
347
|
-
) as
|
448
|
+
) as TabSource;
|
348
449
|
|
349
|
-
return tab && tab.hash ? tab.hash :
|
450
|
+
return tab && tab.hash ? tab.hash : localTabs.indexOf(tab);
|
350
451
|
}
|
351
452
|
|
352
453
|
@autobind
|
353
454
|
autoJumpToNeighbour(key: any) {
|
354
455
|
const {tabs, data} = this.props;
|
456
|
+
const localTabs = this.state.localTabs;
|
355
457
|
|
356
|
-
if (!Array.isArray(
|
458
|
+
if (!Array.isArray(localTabs)) {
|
357
459
|
return;
|
358
460
|
}
|
359
461
|
|
360
462
|
// 当前 tab 可能不可见,所以需要自动切到一个可见的 tab, 向前找,找一圈
|
361
|
-
const tabIndex = findIndex(
|
463
|
+
const tabIndex = findIndex(localTabs, (tab: TabSource, index) =>
|
362
464
|
tab.hash ? tab.hash === key : index === key
|
363
465
|
);
|
364
466
|
|
365
|
-
if (
|
366
|
-
let len =
|
467
|
+
if (localTabs[tabIndex] && !isVisible(localTabs[tabIndex], this.props.data)) {
|
468
|
+
let len = localTabs.length;
|
367
469
|
let i = tabIndex - 1 + len;
|
368
470
|
let tries = len - 1;
|
369
471
|
|
370
472
|
while (tries--) {
|
371
473
|
const index = i-- % len;
|
372
|
-
if (isVisible(
|
373
|
-
let activeKey =
|
474
|
+
if (isVisible(localTabs[index], data)) {
|
475
|
+
let activeKey = localTabs[index].hash || index;
|
374
476
|
this.setState({
|
375
477
|
activeKey: (this.activeKey = activeKey)
|
376
478
|
});
|
@@ -380,6 +482,60 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
380
482
|
}
|
381
483
|
}
|
382
484
|
|
485
|
+
@autobind
|
486
|
+
handleAdd() {
|
487
|
+
const localTabs = this.state.localTabs.concat();
|
488
|
+
|
489
|
+
localTabs.push({
|
490
|
+
title: `新增tab${this.newTabDefaultId++}`,
|
491
|
+
body: '新增tab 内容'
|
492
|
+
} as TabSource);
|
493
|
+
|
494
|
+
this.setState({
|
495
|
+
localTabs: localTabs
|
496
|
+
}, () => {
|
497
|
+
this.switchTo(this.state.localTabs.length - 1);
|
498
|
+
});
|
499
|
+
}
|
500
|
+
|
501
|
+
@autobind
|
502
|
+
handleClose(index: number, key: string | number) {
|
503
|
+
const originTabs = this.state.localTabs.concat();
|
504
|
+
|
505
|
+
originTabs.splice(index, 1);
|
506
|
+
|
507
|
+
this.setState({
|
508
|
+
localTabs: originTabs
|
509
|
+
});
|
510
|
+
}
|
511
|
+
|
512
|
+
@autobind
|
513
|
+
handleEdit(index: number, text: string) {
|
514
|
+
const originTabs = this.state.localTabs.concat();
|
515
|
+
originTabs[index].title = text;
|
516
|
+
|
517
|
+
this.setState({
|
518
|
+
localTabs: originTabs
|
519
|
+
});
|
520
|
+
}
|
521
|
+
|
522
|
+
@autobind
|
523
|
+
async handleDragChange(e: any){
|
524
|
+
const activeTab = this.resolveTabByKey(this.activeKey);
|
525
|
+
const originTabs: TabSource[] = this.state.localTabs.concat();
|
526
|
+
|
527
|
+
originTabs.splice(e.newIndex, 0, originTabs.splice(e.oldIndex, 1)[0]);
|
528
|
+
|
529
|
+
this.setState({
|
530
|
+
localTabs: originTabs
|
531
|
+
}, () => {
|
532
|
+
if (activeTab) {
|
533
|
+
const newActiveTabIndex = originTabs.indexOf(activeTab);
|
534
|
+
this.switchTo(newActiveTabIndex);
|
535
|
+
}
|
536
|
+
});
|
537
|
+
}
|
538
|
+
|
383
539
|
@autobind
|
384
540
|
handleSelect(key: any) {
|
385
541
|
const {env, onSelect, id} = this.props;
|
@@ -438,21 +594,22 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
438
594
|
|
439
595
|
@autobind
|
440
596
|
switchTo(index: number) {
|
441
|
-
const
|
597
|
+
const localTabs = this.state.localTabs;
|
442
598
|
|
443
|
-
Array.isArray(
|
444
|
-
|
599
|
+
Array.isArray(localTabs) &&
|
600
|
+
localTabs[index] &&
|
445
601
|
this.setState({
|
446
|
-
activeKey: (this.activeKey =
|
602
|
+
activeKey: (this.activeKey = localTabs[index].hash || index)
|
447
603
|
});
|
448
604
|
}
|
449
605
|
|
450
606
|
@autobind
|
451
607
|
currentIndex(): number {
|
452
|
-
const {tabs} = this.props;
|
608
|
+
// const {tabs} = this.props;
|
609
|
+
const localTabs = this.state.localTabs;
|
453
610
|
|
454
|
-
return Array.isArray(
|
455
|
-
? findIndex(
|
611
|
+
return Array.isArray(localTabs)
|
612
|
+
? findIndex(localTabs, (tab: TabSource, index) =>
|
456
613
|
tab.hash
|
457
614
|
? tab.hash === this.state.activeKey
|
458
615
|
: index === this.state.activeKey
|
@@ -489,11 +646,17 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
489
646
|
formHorizontal,
|
490
647
|
subFormMode,
|
491
648
|
subFormHorizontal,
|
492
|
-
|
649
|
+
addable,
|
650
|
+
closable,
|
651
|
+
draggable,
|
652
|
+
showTip,
|
653
|
+
showTipClassName,
|
654
|
+
editable,
|
655
|
+
sidePosition,
|
656
|
+
addBtnText
|
493
657
|
} = this.props;
|
494
658
|
|
495
659
|
const mode = tabsMode || dMode;
|
496
|
-
const arr = resolveVariableAndFilter(source, data, '| raw');
|
497
660
|
let mountOnEnter = this.props.mountOnEnter;
|
498
661
|
|
499
662
|
// 如果在form下面,其他tabs默认需要渲染出来
|
@@ -502,54 +665,41 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
502
665
|
mountOnEnter = false;
|
503
666
|
}
|
504
667
|
|
505
|
-
|
506
|
-
if (!tabs) {
|
507
|
-
return null;
|
508
|
-
}
|
509
|
-
|
510
|
-
tabs = Array.isArray(tabs) ? tabs : [tabs];
|
668
|
+
const {localTabs: tabs, isFromSource} = this.state;
|
511
669
|
let children: Array<JSX.Element | null> = [];
|
512
670
|
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
tab.horizontal || subFormHorizontal || formHorizontal
|
546
|
-
}
|
547
|
-
)}
|
548
|
-
</Tab>
|
549
|
-
) : null
|
550
|
-
)
|
551
|
-
);
|
552
|
-
});
|
671
|
+
// 是否从 source 数据中生成
|
672
|
+
if (isFromSource) {
|
673
|
+
children = tabs.map((tab: TabSource, index: number) =>
|
674
|
+
isVisible(tab, tab.ctx) ? (
|
675
|
+
<Tab
|
676
|
+
{...(tab as any)}
|
677
|
+
title={filter(tab.title, tab.ctx)}
|
678
|
+
disabled={isDisabled(tab, tab.ctx)}
|
679
|
+
key={index}
|
680
|
+
eventKey={index}
|
681
|
+
mountOnEnter={mountOnEnter}
|
682
|
+
unmountOnExit={
|
683
|
+
typeof tab.reload === 'boolean'
|
684
|
+
? tab.reload
|
685
|
+
: typeof tab.unmountOnExit === 'boolean'
|
686
|
+
? tab.unmountOnExit
|
687
|
+
: unmountOnExit
|
688
|
+
}
|
689
|
+
>
|
690
|
+
{render(
|
691
|
+
`item/${index}`,
|
692
|
+
(tab as any)?.type ? (tab as any) : tab.tab || tab.body,
|
693
|
+
{
|
694
|
+
data: tab.ctx,
|
695
|
+
formMode: tab.mode || subFormMode || formMode,
|
696
|
+
formHorizontal:
|
697
|
+
tab.horizontal || subFormHorizontal || formHorizontal
|
698
|
+
}
|
699
|
+
)}
|
700
|
+
</Tab>
|
701
|
+
) : null
|
702
|
+
);
|
553
703
|
} else {
|
554
704
|
children = tabs.map((tab, index) =>
|
555
705
|
isVisible(tab, data) ? (
|
@@ -591,13 +741,24 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|
591
741
|
classPrefix={ns}
|
592
742
|
classnames={cx}
|
593
743
|
mode={mode}
|
744
|
+
closable={closable}
|
594
745
|
className={className}
|
595
746
|
contentClassName={contentClassName}
|
596
747
|
linksClassName={linksClassName}
|
597
748
|
onSelect={this.handleSelect}
|
598
749
|
activeKey={this.state.activeKey}
|
599
750
|
toolbar={this.renderToolbar()}
|
600
|
-
|
751
|
+
addable={addable}
|
752
|
+
onAdd={this.handleAdd}
|
753
|
+
onClose={this.handleClose}
|
754
|
+
draggable={draggable}
|
755
|
+
onDragChange={this.handleDragChange}
|
756
|
+
showTip={showTip}
|
757
|
+
showTipClassName={showTipClassName}
|
758
|
+
editable={editable}
|
759
|
+
onEdit={this.handleEdit}
|
760
|
+
sidePosition={sidePosition}
|
761
|
+
addBtnText={addBtnText}
|
601
762
|
>
|
602
763
|
{children}
|
603
764
|
</CTabs>
|