amis-editor 4.1.0-beta.1 → 4.1.0-beta.20
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/component/Breadcrumb.d.ts +23 -2
- package/dist/component/Editor.d.ts +19 -0
- package/dist/component/Panel/RenderersPanel.d.ts +1 -2
- package/dist/component/RegionWrapper.d.ts +14 -7
- package/dist/component/RendererThumb.d.ts +5 -5
- package/dist/component/VRenderer.d.ts +4 -0
- package/dist/component/base/SearchCustomRendererPanel.d.ts +15 -0
- package/dist/component/base/SearchPanel.d.ts +83 -0
- package/dist/component/base/SearchRendererPanel.d.ts +2 -42
- package/dist/exports.min.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.min.js +1 -1
- package/dist/manager.d.ts +14 -3
- package/dist/plugin/Card.d.ts +1 -0
- package/dist/plugin/Cards.d.ts +1 -0
- package/dist/plugin/Carousel.d.ts +1 -0
- package/dist/plugin/Chart.d.ts +1 -0
- package/dist/plugin/Collapse.d.ts +1 -0
- package/dist/plugin/Custom.d.ts +3 -0
- package/dist/plugin/CustomRegion.d.ts +43 -0
- package/dist/plugin/Flex.d.ts +1 -0
- package/dist/plugin/Form/Control.d.ts +1 -0
- package/dist/plugin/Form/Form.d.ts +19 -3
- package/dist/plugin/Form/InputURL.d.ts +1 -0
- package/dist/plugin/Grid.d.ts +1 -0
- package/dist/plugin/HBox.d.ts +1 -0
- package/dist/plugin/Json.d.ts +1 -0
- package/dist/plugin/List.d.ts +1 -0
- package/dist/plugin/Mapping.d.ts +1 -0
- package/dist/plugin/Markdown.d.ts +1 -0
- package/dist/plugin/Nav.d.ts +1 -0
- package/dist/plugin/Panel/Outline.d.ts +8 -0
- package/dist/plugin/Progress.d.ts +1 -0
- package/dist/plugin/QRCode.d.ts +1 -0
- package/dist/plugin/Reset.d.ts +0 -1
- package/dist/plugin/Service.d.ts +1 -0
- package/dist/plugin/Sparkline.d.ts +1 -0
- package/dist/plugin/Status.d.ts +1 -0
- package/dist/plugin/Steps.d.ts +1 -0
- package/dist/plugin/Submit.d.ts +0 -1
- package/dist/plugin/TableView.d.ts +1 -0
- package/dist/plugin/Tasks.d.ts +1 -0
- package/dist/plugin/TooltipWrapper.d.ts +1 -0
- package/dist/plugin/Video.d.ts +1 -0
- package/dist/plugin/WebComponent.d.ts +1 -0
- package/dist/plugin/Wizard.d.ts +11 -2
- package/dist/plugin/Wrapper.d.ts +1 -0
- package/dist/plugin.d.ts +2 -2
- package/dist/store/editor.d.ts +20 -2
- package/dist/store/node.d.ts +6 -0
- package/dist/style.css +1 -1
- package/dist/util.d.ts +7 -2
- package/package.json +6 -3
- package/src/component/schemaTpl.tsx +2155 -0
- package/src/plugin/Alert.tsx +87 -0
- package/src/plugin/AnchorNav.tsx +233 -0
- package/src/plugin/Audio.tsx +161 -0
- package/src/plugin/Avatar.tsx +77 -0
- package/src/plugin/Breadcrumb.tsx +107 -0
- package/src/plugin/Button.tsx +283 -0
- package/src/plugin/ButtonGroup.tsx +88 -0
- package/src/plugin/ButtonToolbar.tsx +89 -0
- package/src/plugin/CRUD.tsx +1832 -0
- package/src/plugin/Card.tsx +290 -0
- package/src/plugin/Cards.tsx +315 -0
- package/src/plugin/Carousel.tsx +386 -0
- package/src/plugin/Chart.tsx +218 -0
- package/src/plugin/CodeView.tsx +60 -0
- package/src/plugin/Collapse.tsx +143 -0
- package/src/plugin/CollapseGroup.tsx +167 -0
- package/src/plugin/Container.tsx +44 -0
- package/src/plugin/Custom.tsx +128 -0
- package/src/plugin/CustomRegion.tsx +150 -0
- package/src/plugin/Date.tsx +81 -0
- package/src/plugin/Datetime.tsx +75 -0
- package/src/plugin/Dialog.tsx +178 -0
- package/src/plugin/Divider.tsx +36 -0
- package/src/plugin/Drawer.tsx +217 -0
- package/src/plugin/DropDownButton.tsx +234 -0
- package/src/plugin/Each.tsx +152 -0
- package/src/plugin/ErrorRenderer.tsx +15 -0
- package/src/plugin/Flex.tsx +156 -0
- package/src/plugin/Form/ButtonGroupSelect.tsx +86 -0
- package/src/plugin/Form/ButtonToolbar.tsx +121 -0
- package/src/plugin/Form/ChainedSelect.tsx +70 -0
- package/src/plugin/Form/Checkbox.tsx +87 -0
- package/src/plugin/Form/Checkboxes.tsx +167 -0
- package/src/plugin/Form/CodeEditor.tsx +91 -0
- package/src/plugin/Form/Combo.tsx +582 -0
- package/src/plugin/Form/ConditionBuilder.tsx +324 -0
- package/src/plugin/Form/Control.tsx +139 -0
- package/src/plugin/Form/DiffEditor.tsx +117 -0
- package/src/plugin/Form/FieldSet.tsx +175 -0
- package/src/plugin/Form/Form.tsx +692 -0
- package/src/plugin/Form/Formula.tsx +91 -0
- package/src/plugin/Form/Group.tsx +300 -0
- package/src/plugin/Form/Hidden.tsx +56 -0
- package/src/plugin/Form/InputArray.tsx +228 -0
- package/src/plugin/Form/InputCity.tsx +93 -0
- package/src/plugin/Form/InputColor.tsx +123 -0
- package/src/plugin/Form/InputDate.tsx +175 -0
- package/src/plugin/Form/InputDateRange.tsx +225 -0
- package/src/plugin/Form/InputDateTime.tsx +183 -0
- package/src/plugin/Form/InputDateTimeRange.tsx +221 -0
- package/src/plugin/Form/InputEmail.tsx +33 -0
- package/src/plugin/Form/InputExcel.tsx +85 -0
- package/src/plugin/Form/InputFile.tsx +228 -0
- package/src/plugin/Form/InputGroup.tsx +105 -0
- package/src/plugin/Form/InputImage.tsx +277 -0
- package/src/plugin/Form/InputKV.tsx +72 -0
- package/src/plugin/Form/InputMonth.tsx +35 -0
- package/src/plugin/Form/InputMonthRange.tsx +195 -0
- package/src/plugin/Form/InputNumber.tsx +97 -0
- package/src/plugin/Form/InputPassword.tsx +33 -0
- package/src/plugin/Form/InputQuarter.tsx +35 -0
- package/src/plugin/Form/InputQuarterRange.tsx +195 -0
- package/src/plugin/Form/InputRange.tsx +121 -0
- package/src/plugin/Form/InputRating.tsx +78 -0
- package/src/plugin/Form/InputRepeat.tsx +69 -0
- package/src/plugin/Form/InputRichText.tsx +197 -0
- package/src/plugin/Form/InputSubForm.tsx +198 -0
- package/src/plugin/Form/InputTable.tsx +434 -0
- package/src/plugin/Form/InputTag.tsx +81 -0
- package/src/plugin/Form/InputText.tsx +186 -0
- package/src/plugin/Form/InputTime.tsx +95 -0
- package/src/plugin/Form/InputTree.tsx +240 -0
- package/src/plugin/Form/InputURL.tsx +34 -0
- package/src/plugin/Form/InputYear.tsx +35 -0
- package/src/plugin/Form/Item.tsx +325 -0
- package/src/plugin/Form/ListSelect.tsx +84 -0
- package/src/plugin/Form/LocationPicker.tsx +75 -0
- package/src/plugin/Form/MatrixCheckboxes.tsx +147 -0
- package/src/plugin/Form/NestedSelect.tsx +222 -0
- package/src/plugin/Form/Picker.tsx +217 -0
- package/src/plugin/Form/Radios.tsx +130 -0
- package/src/plugin/Form/Select.tsx +216 -0
- package/src/plugin/Form/Static.tsx +335 -0
- package/src/plugin/Form/Switch.tsx +116 -0
- package/src/plugin/Form/TabsTransfer.tsx +270 -0
- package/src/plugin/Form/Textarea.tsx +94 -0
- package/src/plugin/Form/Transfer.tsx +379 -0
- package/src/plugin/Form/TreeSelect.tsx +263 -0
- package/src/plugin/Form/UUID.tsx +48 -0
- package/src/plugin/Grid.tsx +799 -0
- package/src/plugin/HBox.tsx +727 -0
- package/src/plugin/IFrame.tsx +72 -0
- package/src/plugin/Image.tsx +318 -0
- package/src/plugin/Images.tsx +238 -0
- package/src/plugin/Json.tsx +76 -0
- package/src/plugin/Link.tsx +95 -0
- package/src/plugin/List.tsx +278 -0
- package/src/plugin/ListItem.tsx +233 -0
- package/src/plugin/Log.tsx +52 -0
- package/src/plugin/Mapping.tsx +156 -0
- package/src/plugin/Markdown.tsx +47 -0
- package/src/plugin/Nav.tsx +186 -0
- package/src/plugin/Operation.tsx +97 -0
- package/src/plugin/Others/Action.tsx +428 -0
- package/src/plugin/Others/BasicToolbar.tsx +591 -0
- package/src/plugin/Others/DataDebug.tsx +134 -0
- package/src/plugin/Others/TableCell.tsx +480 -0
- package/src/plugin/Others/Unknown.tsx +37 -0
- package/src/plugin/Page.tsx +308 -0
- package/src/plugin/Panel/AvailableRenderers.tsx +41 -0
- package/src/plugin/Panel/Code.tsx +44 -0
- package/src/plugin/Panel/Name.tsx +26 -0
- package/src/plugin/Panel/Outline.tsx +40 -0
- package/src/plugin/Panel.tsx +243 -0
- package/src/plugin/Plain.tsx +91 -0
- package/src/plugin/Progress.tsx +132 -0
- package/src/plugin/Property.tsx +139 -0
- package/src/plugin/QRCode.tsx +98 -0
- package/src/plugin/Reset.tsx +23 -0
- package/src/plugin/Service.tsx +167 -0
- package/src/plugin/Sparkline.tsx +40 -0
- package/src/plugin/Status.tsx +78 -0
- package/src/plugin/Steps.tsx +140 -0
- package/src/plugin/Submit.tsx +23 -0
- package/src/plugin/Table.tsx +440 -0
- package/src/plugin/TableView.tsx +711 -0
- package/src/plugin/Tabs.tsx +364 -0
- package/src/plugin/Tasks.tsx +276 -0
- package/src/plugin/Time.tsx +75 -0
- package/src/plugin/TooltipWrapper.tsx +193 -0
- package/src/plugin/Tpl.tsx +162 -0
- package/src/plugin/Video.tsx +160 -0
- package/src/plugin/WebComponent.tsx +56 -0
- package/src/plugin/Wizard.tsx +743 -0
- package/src/plugin/Wrapper.tsx +107 -0
- package/src/plugin.ts +1046 -0
- package/dist/150a58f3318ca7541ed9.png +0 -0
- package/dist/471adb97c322b226e589.png +0 -0
- package/dist/4de5f42360bc5946c3c2.png +0 -0
- package/dist/4e9968bba3855f088fed.png +0 -0
- package/dist/7f09c38ebc687fea847a.png +0 -0
- package/dist/c94073576487510314ea.png +0 -0
@@ -0,0 +1,711 @@
|
|
1
|
+
/**
|
2
|
+
* @file table view 组件的可视化编辑
|
3
|
+
*/
|
4
|
+
|
5
|
+
import {Button} from 'amis';
|
6
|
+
import React from 'react';
|
7
|
+
import {registerEditorPlugin} from '../manager';
|
8
|
+
import {
|
9
|
+
BaseEventContext,
|
10
|
+
BasePlugin,
|
11
|
+
BasicPanelItem,
|
12
|
+
BasicToolbarItem,
|
13
|
+
BuildPanelEventContext,
|
14
|
+
RegionConfig,
|
15
|
+
RendererInfo,
|
16
|
+
VRendererConfig
|
17
|
+
} from '../plugin';
|
18
|
+
import {getSchemaTpl} from '../component/schemaTpl';
|
19
|
+
import {VRenderer} from '../component/VRenderer';
|
20
|
+
import {TableViewEditor} from '../component/TableViewEditor';
|
21
|
+
import {TableViewSchema, TdObject} from 'amis/lib/renderers/TableView';
|
22
|
+
import {JSONGetById, JSONPipeOut} from '../util';
|
23
|
+
import {RegionWrapper as Region} from '../component/RegionWrapper';
|
24
|
+
|
25
|
+
/**
|
26
|
+
* 尚未实现的功能:
|
27
|
+
* * 按列删除,需要将一些 colspan 减一
|
28
|
+
* * 水平/垂直拆分单元格,增加周围节点的 colspan 和 rowspan
|
29
|
+
*/
|
30
|
+
|
31
|
+
// td 节点模板
|
32
|
+
const TD_TEMPLATE = {
|
33
|
+
body: {
|
34
|
+
type: 'tpl',
|
35
|
+
tpl: '---'
|
36
|
+
}
|
37
|
+
} as {body: {type: 'tpl'}};
|
38
|
+
|
39
|
+
/**
|
40
|
+
* 遍历表格,算出每个单元格在最终渲染时的实际行和列,后续许多操作都需要以这个作为依据
|
41
|
+
* 比如插入列的时候,不能根据单元格在数组的位置,而是要根据单元格实际渲染时所属列
|
42
|
+
*/
|
43
|
+
function getCellRealPosition(table: TableViewSchema) {
|
44
|
+
if (!table) {
|
45
|
+
return {
|
46
|
+
trs: []
|
47
|
+
};
|
48
|
+
}
|
49
|
+
// 记录有哪些行列被合并了,这样后续计算的时候就要跳过这些行列
|
50
|
+
const spannedCell: boolean[][] = [];
|
51
|
+
const trs = table.trs || [];
|
52
|
+
|
53
|
+
let currentRow = 0; // 当前渲染的实际行
|
54
|
+
for (const tr of trs) {
|
55
|
+
const tds = tr.tds || [];
|
56
|
+
|
57
|
+
let currentCol = 0; // 当前渲染的实际列
|
58
|
+
for (const td of tds) {
|
59
|
+
// 跳过被合并的行
|
60
|
+
while (spannedCell[currentRow] && spannedCell[currentRow][currentCol]) {
|
61
|
+
currentCol = currentCol + 1;
|
62
|
+
}
|
63
|
+
const rowspan = td.rowspan || 1;
|
64
|
+
const colspan = td.colspan || 1;
|
65
|
+
// 标记后续行合并情况
|
66
|
+
if (rowspan > 1 || colspan > 1) {
|
67
|
+
for (let i = 0; i < rowspan; i++) {
|
68
|
+
const spanRow = currentRow + i;
|
69
|
+
if (!spannedCell[spanRow]) {
|
70
|
+
spannedCell[spanRow] = [];
|
71
|
+
}
|
72
|
+
for (let j = 0; j < colspan; j++) {
|
73
|
+
const spanCol = currentCol + j;
|
74
|
+
spannedCell[spanRow][spanCol] = true;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
(td as any).$$row = currentRow;
|
79
|
+
(td as any).$$col = currentCol;
|
80
|
+
currentCol = currentCol + 1;
|
81
|
+
}
|
82
|
+
|
83
|
+
currentRow = currentRow + 1;
|
84
|
+
}
|
85
|
+
return table;
|
86
|
+
}
|
87
|
+
|
88
|
+
export class TableViewPlugin extends BasePlugin {
|
89
|
+
// 关联渲染器名字
|
90
|
+
rendererName = 'table-view';
|
91
|
+
$schema = '/schemas/TableViewSchema.json';
|
92
|
+
|
93
|
+
// 组件名称
|
94
|
+
name = '表格视图';
|
95
|
+
isBaseComponent = true;
|
96
|
+
icon = 'fa fa-columns';
|
97
|
+
description = '表格类型的展现';
|
98
|
+
docLink = '/amis/zh-CN/components/table-view';
|
99
|
+
tags = ['容器'];
|
100
|
+
scaffold = {
|
101
|
+
type: 'table-view',
|
102
|
+
trs: [
|
103
|
+
{
|
104
|
+
background: '#F7F7F7',
|
105
|
+
tds: [
|
106
|
+
{
|
107
|
+
body: {
|
108
|
+
type: 'tpl',
|
109
|
+
tpl: '地区'
|
110
|
+
}
|
111
|
+
},
|
112
|
+
{
|
113
|
+
body: {
|
114
|
+
type: 'tpl',
|
115
|
+
tpl: '城市'
|
116
|
+
}
|
117
|
+
},
|
118
|
+
{
|
119
|
+
body: {
|
120
|
+
type: 'tpl',
|
121
|
+
tpl: '销量'
|
122
|
+
}
|
123
|
+
}
|
124
|
+
]
|
125
|
+
},
|
126
|
+
{
|
127
|
+
tds: [
|
128
|
+
{
|
129
|
+
rowspan: 2,
|
130
|
+
body: {
|
131
|
+
type: 'tpl',
|
132
|
+
tpl: '华北'
|
133
|
+
}
|
134
|
+
},
|
135
|
+
{
|
136
|
+
body: {
|
137
|
+
type: 'tpl',
|
138
|
+
tpl: '北京'
|
139
|
+
}
|
140
|
+
},
|
141
|
+
{
|
142
|
+
body: {
|
143
|
+
type: 'tpl',
|
144
|
+
tpl: '${beijing}'
|
145
|
+
}
|
146
|
+
}
|
147
|
+
]
|
148
|
+
},
|
149
|
+
{
|
150
|
+
tds: [
|
151
|
+
{
|
152
|
+
body: {
|
153
|
+
type: 'tpl',
|
154
|
+
tpl: '天津'
|
155
|
+
}
|
156
|
+
},
|
157
|
+
{
|
158
|
+
body: {
|
159
|
+
type: 'tpl',
|
160
|
+
tpl: '${tianjing}'
|
161
|
+
}
|
162
|
+
}
|
163
|
+
]
|
164
|
+
}
|
165
|
+
]
|
166
|
+
};
|
167
|
+
previewSchema = {
|
168
|
+
...this.scaffold
|
169
|
+
};
|
170
|
+
|
171
|
+
regions: Array<RegionConfig> = [
|
172
|
+
{
|
173
|
+
key: 'body',
|
174
|
+
label: '内容区',
|
175
|
+
renderMethod: 'renderTdBody',
|
176
|
+
preferTag: '展示'
|
177
|
+
}
|
178
|
+
];
|
179
|
+
|
180
|
+
panelTitle = '表格视图';
|
181
|
+
panelBody = [
|
182
|
+
getSchemaTpl('tabs', [
|
183
|
+
{
|
184
|
+
title: '常规',
|
185
|
+
body: [
|
186
|
+
{type: 'input-text', label: '宽度', name: 'width', clearable: true},
|
187
|
+
{
|
188
|
+
type: 'input-text',
|
189
|
+
label: '默认内边距',
|
190
|
+
name: 'padding',
|
191
|
+
clearable: true
|
192
|
+
},
|
193
|
+
{
|
194
|
+
type: 'switch',
|
195
|
+
name: 'border',
|
196
|
+
mode: 'inline',
|
197
|
+
className: 'w-full',
|
198
|
+
label: '是否显示边框'
|
199
|
+
},
|
200
|
+
{
|
201
|
+
label: '边框颜色',
|
202
|
+
type: 'input-color',
|
203
|
+
name: 'borderColor'
|
204
|
+
}
|
205
|
+
]
|
206
|
+
},
|
207
|
+
{
|
208
|
+
title: '外观',
|
209
|
+
body: [getSchemaTpl('className'), getSchemaTpl('style')]
|
210
|
+
},
|
211
|
+
{
|
212
|
+
title: '显隐',
|
213
|
+
body: [getSchemaTpl('visible')]
|
214
|
+
}
|
215
|
+
])
|
216
|
+
];
|
217
|
+
|
218
|
+
fieldWrapperResolve = (dom: HTMLElement) => dom;
|
219
|
+
|
220
|
+
overrides = {
|
221
|
+
renderTd(this: any, td: any, colIndex: number, rowIndex: number) {
|
222
|
+
const dom = this.super(td, colIndex, rowIndex);
|
223
|
+
const info: RendererInfo = this.props.$$editor;
|
224
|
+
|
225
|
+
if (!info || !td.$$id) {
|
226
|
+
return dom;
|
227
|
+
}
|
228
|
+
|
229
|
+
const plugin = info.plugin as TableViewPlugin;
|
230
|
+
const id = td.$$id;
|
231
|
+
return (
|
232
|
+
<VRenderer
|
233
|
+
plugin={info.plugin}
|
234
|
+
renderer={info.renderer}
|
235
|
+
key={id}
|
236
|
+
$schema="/schemas/TdObject.json"
|
237
|
+
hostId={info.id}
|
238
|
+
memberIndex={colIndex} // TODO: colIndex 其实不对,需要增加 schema filter 功能来让插件能
|
239
|
+
name={`${`单元格 ${rowIndex + 1},${colIndex + 1}`}`}
|
240
|
+
id={id}
|
241
|
+
draggable={false}
|
242
|
+
wrapperResolve={plugin.fieldWrapperResolve}
|
243
|
+
schemaPath={`${info.schemaPath}/td`}
|
244
|
+
path={`${this.props.$path}/tr/${rowIndex}/td/${colIndex}`}
|
245
|
+
data={this.props.data}
|
246
|
+
children={dom}
|
247
|
+
/>
|
248
|
+
);
|
249
|
+
},
|
250
|
+
renderTr(this: any, tr: any, rowIndex: number) {
|
251
|
+
const dom = this.super(tr, rowIndex);
|
252
|
+
const info: RendererInfo = this.props.$$editor;
|
253
|
+
|
254
|
+
if (!info || !tr.$$id) {
|
255
|
+
return dom;
|
256
|
+
}
|
257
|
+
|
258
|
+
const plugin = info.plugin as TableViewPlugin;
|
259
|
+
const id = tr.$$id;
|
260
|
+
return (
|
261
|
+
<VRenderer
|
262
|
+
plugin={info.plugin}
|
263
|
+
renderer={info.renderer}
|
264
|
+
key={id}
|
265
|
+
$schema="/schemas/TrObject.json"
|
266
|
+
hostId={info.id}
|
267
|
+
memberIndex={rowIndex}
|
268
|
+
name={`${`行 ${rowIndex + 1}`}`}
|
269
|
+
id={id}
|
270
|
+
draggable={false}
|
271
|
+
wrapperResolve={plugin.fieldWrapperResolve}
|
272
|
+
schemaPath={`${info.schemaPath}/tr`}
|
273
|
+
path={`${this.props.$path}/tr/${rowIndex}`}
|
274
|
+
data={this.props.data}
|
275
|
+
children={dom}
|
276
|
+
/>
|
277
|
+
);
|
278
|
+
}
|
279
|
+
};
|
280
|
+
|
281
|
+
tdVRendererConfig: VRendererConfig = {
|
282
|
+
panelTitle: '单元格',
|
283
|
+
panelBodyCreator: (context: BaseEventContext) => {
|
284
|
+
return [
|
285
|
+
{
|
286
|
+
label: '单元格背景色',
|
287
|
+
type: 'input-color',
|
288
|
+
name: 'background'
|
289
|
+
},
|
290
|
+
{
|
291
|
+
label: '文字颜色',
|
292
|
+
type: 'input-color',
|
293
|
+
name: 'color'
|
294
|
+
},
|
295
|
+
{
|
296
|
+
type: 'switch',
|
297
|
+
name: 'bold',
|
298
|
+
mode: 'inline',
|
299
|
+
className: 'w-full',
|
300
|
+
label: '文字加粗'
|
301
|
+
},
|
302
|
+
{
|
303
|
+
type: 'input-number',
|
304
|
+
name: 'padding',
|
305
|
+
label: '内边距'
|
306
|
+
},
|
307
|
+
{
|
308
|
+
type: 'select',
|
309
|
+
name: 'align',
|
310
|
+
label: '水平对齐',
|
311
|
+
options: [
|
312
|
+
{
|
313
|
+
label: '左',
|
314
|
+
value: 'left'
|
315
|
+
},
|
316
|
+
{
|
317
|
+
label: '中',
|
318
|
+
value: 'center'
|
319
|
+
},
|
320
|
+
{
|
321
|
+
label: '右',
|
322
|
+
value: 'right'
|
323
|
+
}
|
324
|
+
]
|
325
|
+
},
|
326
|
+
{
|
327
|
+
type: 'select',
|
328
|
+
name: 'valign',
|
329
|
+
label: '垂直对齐',
|
330
|
+
options: [
|
331
|
+
{
|
332
|
+
label: '顶',
|
333
|
+
value: 'top'
|
334
|
+
},
|
335
|
+
{
|
336
|
+
label: '中',
|
337
|
+
value: 'middle'
|
338
|
+
},
|
339
|
+
{
|
340
|
+
label: '底',
|
341
|
+
value: 'bottom'
|
342
|
+
}
|
343
|
+
]
|
344
|
+
},
|
345
|
+
{
|
346
|
+
type: 'input-number',
|
347
|
+
name: 'rowspan',
|
348
|
+
label: '跨几行'
|
349
|
+
},
|
350
|
+
{
|
351
|
+
type: 'input-number',
|
352
|
+
name: 'colspan',
|
353
|
+
label: '跨几列'
|
354
|
+
},
|
355
|
+
getSchemaTpl('style')
|
356
|
+
];
|
357
|
+
}
|
358
|
+
};
|
359
|
+
|
360
|
+
trVRendererConfig: VRendererConfig = {
|
361
|
+
panelTitle: ' 行',
|
362
|
+
panelBodyCreator: (context: BaseEventContext) => {
|
363
|
+
return [
|
364
|
+
{
|
365
|
+
label: '行背景色',
|
366
|
+
type: 'input-color',
|
367
|
+
name: 'background'
|
368
|
+
},
|
369
|
+
{
|
370
|
+
label: '行高度',
|
371
|
+
type: 'input-number',
|
372
|
+
name: 'height'
|
373
|
+
}
|
374
|
+
];
|
375
|
+
}
|
376
|
+
};
|
377
|
+
|
378
|
+
renderRenderer(props: any) {
|
379
|
+
const $$editor = props.$$editor;
|
380
|
+
const renderer = $$editor.renderer;
|
381
|
+
const schema = props.$schema;
|
382
|
+
getCellRealPosition(schema);
|
383
|
+
return (
|
384
|
+
<TableViewEditor schema={schema} manager={this.manager}>
|
385
|
+
<renderer.component {...props} />
|
386
|
+
</TableViewEditor>
|
387
|
+
);
|
388
|
+
}
|
389
|
+
|
390
|
+
// 根据路径判断是选中单元格还是行
|
391
|
+
buildEditorPanel(
|
392
|
+
context: BuildPanelEventContext,
|
393
|
+
panels: Array<BasicPanelItem>
|
394
|
+
) {
|
395
|
+
super.buildEditorPanel(context, panels);
|
396
|
+
if (context.info.schemaPath.endsWith('/td')) {
|
397
|
+
panels.push({
|
398
|
+
key: 'td',
|
399
|
+
order: 100,
|
400
|
+
icon: this.tdVRendererConfig.panelIcon || 'fa fa-tablet',
|
401
|
+
title: this.tdVRendererConfig.panelTitle || '格子',
|
402
|
+
render: this.manager.makeSchemaFormRender({
|
403
|
+
controls: this.tdVRendererConfig.panelControlsCreator
|
404
|
+
? this.tdVRendererConfig.panelControlsCreator(context)
|
405
|
+
: this.tdVRendererConfig.panelControls!,
|
406
|
+
body: this.tdVRendererConfig.panelBodyCreator
|
407
|
+
? this.tdVRendererConfig.panelBodyCreator(context)
|
408
|
+
: this.tdVRendererConfig.panelBody!
|
409
|
+
})
|
410
|
+
});
|
411
|
+
} else if (context.info.schemaPath.endsWith('/tr')) {
|
412
|
+
panels.push({
|
413
|
+
key: 'tr',
|
414
|
+
order: 100,
|
415
|
+
icon: this.trVRendererConfig.panelIcon || 'fa fa-tablet',
|
416
|
+
title: this.trVRendererConfig.panelTitle || '格子',
|
417
|
+
render: this.manager.makeSchemaFormRender({
|
418
|
+
controls: this.trVRendererConfig.panelControlsCreator
|
419
|
+
? this.trVRendererConfig.panelControlsCreator(context)
|
420
|
+
: this.trVRendererConfig.panelControls!,
|
421
|
+
body: this.trVRendererConfig.panelBodyCreator
|
422
|
+
? this.trVRendererConfig.panelBodyCreator(context)
|
423
|
+
: this.trVRendererConfig.panelBody!
|
424
|
+
})
|
425
|
+
});
|
426
|
+
}
|
427
|
+
}
|
428
|
+
|
429
|
+
/**
|
430
|
+
* 插入行,需要处理前面有 rowspan 的情况
|
431
|
+
*
|
432
|
+
* +---+---+---+
|
433
|
+
* | a | b | c |
|
434
|
+
* + +---+---+
|
435
|
+
* | | d | e |
|
436
|
+
* + +---+---+
|
437
|
+
* | | f | g |
|
438
|
+
* +---+---+---+
|
439
|
+
*
|
440
|
+
* 比如在 d 位置的前面插入行,需要将 a 的 rowspan 加一,然后再插入两个单元格
|
441
|
+
*/
|
442
|
+
insertRow(tdId: string, position: 'above' | 'below') {
|
443
|
+
const store = this.manager.store;
|
444
|
+
const paths = store.getNodePathById(tdId);
|
445
|
+
const tableId = paths[paths.length - 3].id;
|
446
|
+
const table = store.getSchema(tableId);
|
447
|
+
getCellRealPosition(table);
|
448
|
+
|
449
|
+
const td = JSONGetById(table, tdId);
|
450
|
+
|
451
|
+
if (!td) {
|
452
|
+
console.warn('找不到对应的 td id');
|
453
|
+
return;
|
454
|
+
}
|
455
|
+
|
456
|
+
let insertRow = td.$$row;
|
457
|
+
if (position === 'below') {
|
458
|
+
insertRow = insertRow + 1;
|
459
|
+
}
|
460
|
+
|
461
|
+
// 通过第一行来确认表格一共多少列
|
462
|
+
const firstRow = table.trs[0];
|
463
|
+
const firstRowLastTd = firstRow.tds[firstRow.tds.length - 1];
|
464
|
+
if (!firstRowLastTd) {
|
465
|
+
console.warn('第一列没内容');
|
466
|
+
return;
|
467
|
+
}
|
468
|
+
let colSize = firstRowLastTd.$$col + (firstRowLastTd.colspan || 1);
|
469
|
+
let insertIndex = table.trs.length;
|
470
|
+
for (let trIndex = 0; trIndex < table.trs.length; trIndex++) {
|
471
|
+
for (const td of table.trs[trIndex].tds || []) {
|
472
|
+
const tdRow = td.$$row;
|
473
|
+
const rowspan = td.rowspan || 1;
|
474
|
+
const colspan = td.colspan || 1;
|
475
|
+
// 如果覆盖到要插入的行,则增加 rowspan,并在这个插入的行中减去对应
|
476
|
+
if (rowspan > 1) {
|
477
|
+
const isOverlapping = tdRow + rowspan > insertRow;
|
478
|
+
if (isOverlapping) {
|
479
|
+
td.rowspan = rowspan + 1;
|
480
|
+
colSize = colSize - colspan;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
if (tdRow === insertRow) {
|
484
|
+
insertIndex = trIndex;
|
485
|
+
break;
|
486
|
+
}
|
487
|
+
}
|
488
|
+
}
|
489
|
+
|
490
|
+
const insertTds = [];
|
491
|
+
for (let i = 0; i < colSize; i++) {
|
492
|
+
insertTds.push(TD_TEMPLATE);
|
493
|
+
}
|
494
|
+
table.trs.splice(insertIndex, 0, {tds: insertTds});
|
495
|
+
this.manager.store.changeValueById(tableId, table);
|
496
|
+
}
|
497
|
+
|
498
|
+
/**
|
499
|
+
* 插入列
|
500
|
+
*
|
501
|
+
* +---+---+---+
|
502
|
+
* | a | b |
|
503
|
+
* + +---+
|
504
|
+
* | | c |
|
505
|
+
* +---+---+---+
|
506
|
+
* | d | e | f |
|
507
|
+
* +---+---+---+
|
508
|
+
*
|
509
|
+
* 比如在 c 位置左侧插入列,应该将 a 的 colspan 加一,然后在最后一行增加一个单元格
|
510
|
+
*/
|
511
|
+
insertCol(tdId: string, position: 'left' | 'right') {
|
512
|
+
const store = this.manager.store;
|
513
|
+
const paths = store.getNodePathById(tdId);
|
514
|
+
const tableId = paths[paths.length - 3].id;
|
515
|
+
const table = store.getSchema(tableId);
|
516
|
+
getCellRealPosition(table);
|
517
|
+
const td = JSONGetById(table, tdId);
|
518
|
+
if (!td) {
|
519
|
+
console.warn('找不到对应的 td id');
|
520
|
+
return;
|
521
|
+
}
|
522
|
+
|
523
|
+
let insertCol = td.$$col;
|
524
|
+
if (position === 'right') {
|
525
|
+
insertCol = insertCol + 1;
|
526
|
+
}
|
527
|
+
|
528
|
+
for (const tr of table.trs || []) {
|
529
|
+
const tds = tr.tds || [];
|
530
|
+
let isInserted = false;
|
531
|
+
for (let tdIndex = 0; tdIndex < tds.length; tdIndex++) {
|
532
|
+
const td = tds[tdIndex];
|
533
|
+
const tdColspan = td.colspan || 1;
|
534
|
+
const tdCol = td.$$col;
|
535
|
+
// 如果要插入的行被覆盖了,则对节点加一并跳过插入
|
536
|
+
if (tdColspan > 1) {
|
537
|
+
const isOverlapping = tdCol + tdColspan > insertCol;
|
538
|
+
if (isOverlapping) {
|
539
|
+
td.colspan = tdColspan + 1;
|
540
|
+
isInserted = true;
|
541
|
+
break;
|
542
|
+
}
|
543
|
+
}
|
544
|
+
if (insertCol <= tdCol) {
|
545
|
+
tds.splice(tdIndex, 0, TD_TEMPLATE);
|
546
|
+
isInserted = true;
|
547
|
+
break;
|
548
|
+
}
|
549
|
+
}
|
550
|
+
// 如果没找到对应的节点,那可能是插入到最后一条或者这一列节点数量不够,此时就要插入到最后
|
551
|
+
if (!isInserted) {
|
552
|
+
tds.push(TD_TEMPLATE);
|
553
|
+
}
|
554
|
+
}
|
555
|
+
this.manager.store.changeValueById(tableId, table);
|
556
|
+
}
|
557
|
+
|
558
|
+
/**
|
559
|
+
* 拆分有跨行或跨列的单元格
|
560
|
+
*
|
561
|
+
* +---+---+---+
|
562
|
+
* | a | b |
|
563
|
+
* + +---+
|
564
|
+
* | | c |
|
565
|
+
* +---+---+---+
|
566
|
+
* | d | e | f |
|
567
|
+
* +---+---+---+
|
568
|
+
*
|
569
|
+
* 比如拆分 a,最后要变成
|
570
|
+
*
|
571
|
+
* +---+---+---+
|
572
|
+
* | a | g | b |
|
573
|
+
* +---+---+---+
|
574
|
+
* | h | i | c |
|
575
|
+
* +---+---+---+
|
576
|
+
* | d | e | f |
|
577
|
+
* +---+---+---+
|
578
|
+
*
|
579
|
+
* 因此要新增 g、h、i 三个单元格
|
580
|
+
*/
|
581
|
+
splitCell(tdId: string) {
|
582
|
+
const store = this.manager.store;
|
583
|
+
const paths = store.getNodePathById(tdId);
|
584
|
+
const tableId = paths[paths.length - 3].id;
|
585
|
+
const table = store.getSchema(tableId);
|
586
|
+
getCellRealPosition(table);
|
587
|
+
const td = JSONGetById(table, tdId);
|
588
|
+
if (!td) {
|
589
|
+
console.warn('找不到对应的 td id');
|
590
|
+
return;
|
591
|
+
}
|
592
|
+
|
593
|
+
const rowspan = td.rowspan || 1;
|
594
|
+
const colspan = td.colspan || 1;
|
595
|
+
|
596
|
+
// 将这个单元格的跨行和跨列都设置为 1
|
597
|
+
td.colspan = 1;
|
598
|
+
td.rowspan = 1;
|
599
|
+
|
600
|
+
// 算出需要补充哪些单元格及位置
|
601
|
+
const tdRow = td.$$row;
|
602
|
+
const tdCol = td.$$col;
|
603
|
+
const insertTds = [];
|
604
|
+
for (var i = 0; i < rowspan; i++) {
|
605
|
+
for (var j = 0; j < colspan; j++) {
|
606
|
+
// 跳过第一个,也就是这个单元格自己的位置
|
607
|
+
if (i === 0 && j === 0) {
|
608
|
+
continue;
|
609
|
+
}
|
610
|
+
insertTds.push({row: tdRow + i, col: tdCol + j});
|
611
|
+
}
|
612
|
+
}
|
613
|
+
|
614
|
+
// 需要将列大的放前面,主要是因为后面需要反向遍历才能动态删数据
|
615
|
+
insertTds.sort((a: any, b: any) => {
|
616
|
+
return b.col - a.col;
|
617
|
+
});
|
618
|
+
|
619
|
+
for (const tr of table.trs) {
|
620
|
+
for (let tdIndex = 0; tdIndex < tr.tds.length; tdIndex++) {
|
621
|
+
const td = tr.tds[tdIndex];
|
622
|
+
const currentRow = td.$$row;
|
623
|
+
const currentCol = td.$$col;
|
624
|
+
let insertIndex = insertTds.length;
|
625
|
+
while (insertIndex--) {
|
626
|
+
const insertTd = insertTds[insertIndex];
|
627
|
+
if (currentRow === insertTd.row) {
|
628
|
+
if (insertTd.col <= currentCol) {
|
629
|
+
tr.tds.splice(tdIndex, 0, TD_TEMPLATE);
|
630
|
+
} else {
|
631
|
+
tr.tds.push(TD_TEMPLATE);
|
632
|
+
}
|
633
|
+
insertTds.splice(insertIndex, 1);
|
634
|
+
}
|
635
|
+
}
|
636
|
+
}
|
637
|
+
}
|
638
|
+
|
639
|
+
// 如果前面有单元格找不到位置,那意味着是下面这种情况,这个单元格跨两行且是最后一行
|
640
|
+
// 这时 table.tr 其实只有一行数据,需要在添加一行数据
|
641
|
+
// +---+---+
|
642
|
+
// | a |
|
643
|
+
// + +
|
644
|
+
// | |
|
645
|
+
// +---+---+
|
646
|
+
if (insertTds.length) {
|
647
|
+
const newTds = [];
|
648
|
+
for (var i = 0; i < insertTds.length; i++) {
|
649
|
+
newTds.push(TD_TEMPLATE);
|
650
|
+
}
|
651
|
+
table.trs.push({tds: newTds});
|
652
|
+
}
|
653
|
+
|
654
|
+
this.manager.store.changeValueById(tableId, table);
|
655
|
+
}
|
656
|
+
|
657
|
+
buildEditorToolbar(
|
658
|
+
{schema, info}: BaseEventContext,
|
659
|
+
toolbars: Array<BasicToolbarItem>
|
660
|
+
) {
|
661
|
+
if (info.schemaPath.endsWith('/td')) {
|
662
|
+
const tdId = schema.$$id;
|
663
|
+
toolbars.push({
|
664
|
+
icon: 'fa fa-chevron-left',
|
665
|
+
order: 100,
|
666
|
+
tooltip: '左侧新增列',
|
667
|
+
onClick: () => {
|
668
|
+
this.insertCol(tdId, 'left');
|
669
|
+
}
|
670
|
+
});
|
671
|
+
toolbars.push({
|
672
|
+
icon: 'fa fa-chevron-down',
|
673
|
+
order: 100,
|
674
|
+
tooltip: '下方新增行',
|
675
|
+
onClick: () => {
|
676
|
+
this.insertRow(tdId, 'below');
|
677
|
+
}
|
678
|
+
});
|
679
|
+
toolbars.push({
|
680
|
+
icon: 'fa fa-chevron-up',
|
681
|
+
order: 100,
|
682
|
+
tooltip: '上方新增行',
|
683
|
+
onClick: () => {
|
684
|
+
this.insertRow(tdId, 'above');
|
685
|
+
}
|
686
|
+
});
|
687
|
+
toolbars.push({
|
688
|
+
icon: 'fa fa-chevron-right',
|
689
|
+
order: 100,
|
690
|
+
tooltip: '右侧新增列',
|
691
|
+
onClick: () => {
|
692
|
+
this.insertCol(tdId, 'right');
|
693
|
+
}
|
694
|
+
});
|
695
|
+
const colspan = schema.colspan || 1;
|
696
|
+
const rowspan = schema.rowspan || 1;
|
697
|
+
if (colspan > 1 || rowspan > 1) {
|
698
|
+
toolbars.push({
|
699
|
+
icon: 'fa fa-columns',
|
700
|
+
order: 100,
|
701
|
+
tooltip: '拆分单元格',
|
702
|
+
onClick: () => {
|
703
|
+
this.splitCell(tdId);
|
704
|
+
}
|
705
|
+
});
|
706
|
+
}
|
707
|
+
}
|
708
|
+
}
|
709
|
+
}
|
710
|
+
|
711
|
+
registerEditorPlugin(TableViewPlugin);
|