test-er.vue 16.2 KB
Newer Older
S
1  
shenjizhe 已提交
1
<template>
S
shenjizhe 已提交
2 3
	<view>
		<view class="main-box">
S
1  
shenjizhe 已提交
4
			<!-- 	<uni-popup ref="popup" type="dialog">
S
1  
shenjizhe 已提交
5
			    <uni-popup-dialog mode="input" message="成功消息" :duration="2000" :before-close="true" @close="close" @confirm="confirm"></uni-popup-dialog>
S
1  
shenjizhe 已提交
6
			</uni-popup> -->
S
shenjizhe 已提交
7
			<uni-fab ref="entityFab" class="menuStyle" :content="menuContent" @trigger="menuClick"></uni-fab>
S
1  
shenjizhe 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
			<view class="content-window">
				<scroll-view class="entity-area" scroll-y="true">
					<movable-area ref="contentArea">
						<thirdlucky-uml-entity
							v-for="(table, index) in tables"
							:ref="table.key"
							:x="table.x"
							:y="table.y"
							:key="table.key"
							:entityName="table.name"
							:title="table.title"
							:columns="table.columns"
							:style="{ order: index }"
							@start="onStart"
							@end="onEnd"
						/>
					</movable-area>
				</scroll-view>
				<view ref="consoleView" class="console-view">
					<textarea ref="consoleText" class="text-area" v-model="texts" @linechange="onLineChange" disabled="true" :selection-end="positionY"></textarea>
					<!-- <rich-text ref="consoleText" class="text-area" :nodes="nodes"></rich-text> -->
				</view>
			</view>
S
shenjizhe 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
			<movable-area ref="toolBar" class="tool-bar">
				<view class="title-bar">工具栏</view>
				<thirdlucky-uml-entity ref="entityTool" :x="offsetX" :y="offsetY" entityName="entity" title="实体" @start="onStartTool" @end="onEndTool" />
			</movable-area>
			<view ref="propertyBar" class="property-bar">
				<view class="title-bar">实体信息</view>
				<view class="entity_info">
					<uni-forms-item class="form-item" label="名称"><uni-easyinput :focus="focus.entityName" v-model="_entityName" placeholder="请输入表名" /></uni-forms-item>
					<uni-forms-item class="form-item" label="标题"><uni-easyinput v-model="_entityTitle" placeholder="请输入标题" /></uni-forms-item>
					<uni-forms-item class="form-item" label="描述"><uni-easyinput v-model="_entityInfo" placeholder="请输入描述" /></uni-forms-item>
				</view>
				<scroll-view class="property-table" scroll-y="true">
					<thirdlucky-data-table ref="tableView" actions="+-" border stripe :datas="_columns" :columns="schemas" @selected="onSelected"></thirdlucky-data-table>
				</scroll-view>
				<view class="property-info">
					<thirdlucky-data-form ref="propertyView" :formData="column" :columns="columnSchemas" @confirm="onConfirm" @changed="onChanged"></thirdlucky-data-form>
				</view>
S
1  
shenjizhe 已提交
48
			</view>
S
1  
shenjizhe 已提交
49
		</view>
S
1  
shenjizhe 已提交
50 51 52
	</view>
</template>
<script>
S
1  
shenjizhe 已提交
53
let defaultX = 20;
S
1  
shenjizhe 已提交
54
let defaultY = 40;
S
1  
shenjizhe 已提交
55
let defaultTable = { key: 'default' };
S
1  
shenjizhe 已提交
56

S
1  
shenjizhe 已提交
57 58
let spaceX = 180;
let spaceY = 260;
S
shenjizhe 已提交
59 60
let rowCount = 5;

S
1  
shenjizhe 已提交
61
let idColumn = { name: 'id', type: 'bigint', info: '主键', pk: true };
S
1  
shenjizhe 已提交
62 63
let descriptionColumn = { name: 'description', type: 'text', info: '描述', pk: false };
let passwordColumn = { name: 'password', type: 'password', info: '密码', pk: false };
S
1  
shenjizhe 已提交
64 65 66
export default {
	data() {
		return {
S
1  
shenjizhe 已提交
67
			positionY: 0,
S
shenjizhe 已提交
68
			selected: 0,
S
1  
shenjizhe 已提交
69
			texts: '',
S
1  
shenjizhe 已提交
70 71 72
			config: {
				followName: true
			},
S
1  
shenjizhe 已提交
73 74
			x: 0,
			y: 0,
S
1  
shenjizhe 已提交
75
			menuContent: [{ text: '删除' }, { text: '读取' }, { text: '建库' }, { text: '读库' }, { text: '代码' }],
S
1  
shenjizhe 已提交
76 77
			offsetX: defaultX,
			offsetY: defaultY,
S
1  
shenjizhe 已提交
78
			tables: [],
S
1  
shenjizhe 已提交
79
			columnSchemas: [
S
1  
shenjizhe 已提交
80 81
				{
					name: 'name',
S
1  
shenjizhe 已提交
82 83
					info: '列名',
					tips: '',
S
1  
shenjizhe 已提交
84 85 86
					type: 'text'
				},
				{
S
1  
shenjizhe 已提交
87 88 89
					name: 'type',
					info: '类型',
					tips: '',
S
1  
shenjizhe 已提交
90
					type: 'enum',
S
shenjizhe 已提交
91
					values: [
S
1  
shenjizhe 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
						{
							text: '文本',
							value: 'varchar'
						},
						{
							text: '长文本',
							value: 'text'
						},
						{
							text: '字符',
							value: 'char'
						},
						{
							text: '超长文本',
							value: 'longtext'
						},
						{
							text: 'json',
							value: 'json'
						},
						{
							text: '长对象',
							value: 'blob'
						},
						{
							text: '超长对象',
							value: 'longblob'
						},
						{
							text: '二进制',
							value: 'binary'
						},
						{
							text: '变二进制',
							value: 'varbinary'
						},
						{
							text: '长整型',
							value: 'bigint'
						},
						{
							text: '整型',
							value: 'int'
						},
						{
							text: '整型8',
							value: 'tinyint'
						},
						{
							text: '整型16',
							value: 'smallint'
						},
						{
							text: '十进制',
							value: 'decimal'
						},
						{
							text: '浮点',
							value: 'float'
						},
						{
							text: '双浮点',
							value: 'double'
						},
						{
							text: '日期',
							value: 'date'
						},
						{
							text: '日期时间',
							value: 'datetime'
						},
						{
							text: '时间',
							value: 'time'
						},
S
1  
shenjizhe 已提交
168

S
1  
shenjizhe 已提交
169 170 171 172 173 174 175 176
						{
							text: '时间戳',
							value: 'timestamp'
						},
						{
							text: '开关',
							value: 'bit'
						}
S
1  
shenjizhe 已提交
177
					]
S
1  
shenjizhe 已提交
178 179
				},
				{
S
1  
shenjizhe 已提交
180 181 182
					name: 'info',
					info: '描述',
					tips: '',
S
1  
shenjizhe 已提交
183
					type: 'text'
S
1  
shenjizhe 已提交
184 185 186 187 188 189
				},
				{
					name: 'pk',
					info: '主键',
					tips: '',
					type: 'switch'
S
1  
shenjizhe 已提交
190 191
				}
			],
S
1  
shenjizhe 已提交
192 193 194 195 196 197
			schemas: [
				{
					name: 'name',
					info: '列名',
					tips: '',
					type: 'text'
S
1  
shenjizhe 已提交
198
				}
S
1  
shenjizhe 已提交
199
			],
S
1  
shenjizhe 已提交
200
			table: defaultTable,
S
1  
shenjizhe 已提交
201 202 203 204 205
			column: {},
			focus: {
				entityName: false,
				columnName: false
			}
S
1  
shenjizhe 已提交
206 207
		};
	},
S
shenjizhe 已提交
208

S
1  
shenjizhe 已提交
209
	computed: {
S
1  
shenjizhe 已提交
210 211
		_entityName: {
			get() {
S
1  
shenjizhe 已提交
212
				return this.table.name;
S
1  
shenjizhe 已提交
213 214
			},
			set(val) {
S
1  
shenjizhe 已提交
215 216 217 218 219 220 221 222 223
				this.table.name = val;
			}
		},
		_entityTitle: {
			get() {
				return this.table.title;
			},
			set(val) {
				this.table.title = val;
S
1  
shenjizhe 已提交
224 225 226 227
			}
		},
		_entityInfo: {
			get() {
S
1  
shenjizhe 已提交
228
				return this.table.info;
S
1  
shenjizhe 已提交
229 230
			},
			set(val) {
S
1  
shenjizhe 已提交
231
				this.table.info = val;
S
1  
shenjizhe 已提交
232
			}
S
1  
shenjizhe 已提交
233
		},
S
1  
shenjizhe 已提交
234 235 236
		_columns: {
			get() {
				if (this.table != 'undefined') {
S
1  
shenjizhe 已提交
237
					return this.table.columns;
S
1  
shenjizhe 已提交
238
				} else {
S
1  
shenjizhe 已提交
239 240
					return null;
				}
S
1  
shenjizhe 已提交
241
			}
S
1  
shenjizhe 已提交
242 243
		}
	},
S
1  
shenjizhe 已提交
244
	methods: {
S
1  
shenjizhe 已提交
245 246 247 248 249
		appendText(text) {
			console.log(text);
			let line =  "\t" + text + "\n";
			this.texts += line;
		},
S
1  
shenjizhe 已提交
250 251
		confirm() {},

S
shenjizhe 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
		t2e() {
			let entities = [];
			for (let table of this.tables) {
				entities.push(this.table2Entity(table));
			}
			return entities;
		},
		e2t(entities) {
			let tables = [];
			for (let entity of entities) {
				if (entity.show) {
					tables.push(this.entity2Table(entity));
				}
			}
			this.tables = tables;
		},
S
1  
shenjizhe 已提交
268 269 270 271 272
		table2Entity(table) {
			let fields = [];
			for (let column of table.columns) {
				fields.push(this.column2Field(column));
			}
S
1  
shenjizhe 已提交
273
			return { name: table.name, title: table.title, comment: table.info, show: true, fields: fields };
S
1  
shenjizhe 已提交
274 275 276 277 278 279 280 281 282
		},
		entity2Table(entity) {
			let columns = [];
			for (let field of entity.fields) {
				columns.push(this.field2Column(field));
			}
			return { name: entity.name, title: entity.title, info: entity.comment, domainId: entity.domainId, columns: columns };
		},

S
shenjizhe 已提交
283
		column2Field(column) {
S
1  
shenjizhe 已提交
284
			return { name: column.name, comment: column.info, show: true, pk: column.pk, type: column.type };
S
1  
shenjizhe 已提交
285 286 287
		},

		field2Column(field) {
S
1  
shenjizhe 已提交
288
			return { entityId: field.entityId, name: field.name, info: field.comment, show: field.show, pk: field.pk, type: field.type };
S
1  
shenjizhe 已提交
289 290
		},

S
1  
shenjizhe 已提交
291
		delteEntity() {
S
1  
shenjizhe 已提交
292
			if (this.table != null || this.table != defaulTable) {
S
1  
shenjizhe 已提交
293
				let index = this.tables.indexOf(this.table);
S
1  
shenjizhe 已提交
294 295
				this.tables.splice(index, 1);
				this.table = defaultTable;
S
1  
shenjizhe 已提交
296 297 298
			}
			this.$refs.entityFab.close();
		},
S
shenjizhe 已提交
299 300
		arrangeEntities() {
			for (let i = 0; i < this.tables.length; i++) {
S
1  
shenjizhe 已提交
301
				let table = this.tables[i];
S
shenjizhe 已提交
302 303 304
				let v = parseInt(i / rowCount);
				table.x = (i % rowCount) * spaceX + defaultX;
				table.y = v * spaceY + defaultY;
S
1  
shenjizhe 已提交
305 306
			}
		},
S
shenjizhe 已提交
307
		loadEntities() {
S
1  
shenjizhe 已提交
308
			this.appendText('读取模型...');
S
1  
shenjizhe 已提交
309 310 311 312 313 314 315 316 317 318 319

			let _this = this;
			uni.showModal({
				title: '请输入领域id',
				content: '1',
				editable: true,
				success: function(res) {
					if (res.confirm) {
						let i = parseInt(res.content);
						_this.loadByModel(i);
					} else if (res.cancel) {
S
1  
shenjizhe 已提交
320
						this.appendText('用户点击取消');
S
1  
shenjizhe 已提交
321 322 323 324 325
					}
				}
			});
		},
		loadByModel(domainId) {
S
shenjizhe 已提交
326
			this.api.loadEntities(
S
1  
shenjizhe 已提交
327
				domainId,
S
1  
shenjizhe 已提交
328
				res => {
S
1  
shenjizhe 已提交
329 330 331 332 333
					uni.showToast({
						title: '读取成功:' + domainId,
						icon: 'succes',
						duration: 2000
					});
S
shenjizhe 已提交
334 335
					this.e2t(res.data.data);
					this.arrangeEntities();
S
1  
shenjizhe 已提交
336 337
				},
				res => {
S
1  
shenjizhe 已提交
338
					uni.showToast({
S
1  
shenjizhe 已提交
339
						title: '读取失败:' + res.errMsg,
S
1  
shenjizhe 已提交
340 341 342
						icon: 'error',
						duration: 2000
					});
S
1  
shenjizhe 已提交
343 344
				}
			);
S
shenjizhe 已提交
345
		},
S
1  
shenjizhe 已提交
346

S
1  
shenjizhe 已提交
347
		createDb() {
S
1  
shenjizhe 已提交
348
			this.appendText('建库...');
S
1  
shenjizhe 已提交
349 350 351 352 353 354 355 356 357 358
			let _this = this;
			uni.showModal({
				title: '请输入数据源id',
				content: '1',
				editable: true,
				success: function(res) {
					if (res.confirm) {
						let i = parseInt(res.content);
						_this.createDataSource(i);
					} else if (res.cancel) {
S
1  
shenjizhe 已提交
359
						this.appendText('用户点击取消');
S
1  
shenjizhe 已提交
360 361 362 363 364
					}
				}
			});
		},
		createDataSource(sourceId) {
S
1  
shenjizhe 已提交
365 366
			let entities = this.t2e();
			this.api.createDb(
S
1  
shenjizhe 已提交
367
				sourceId,
S
1  
shenjizhe 已提交
368 369
				entities,
				res => {
S
1  
shenjizhe 已提交
370 371 372 373 374
					uni.showToast({
						title: '建库成功:' + sourceId,
						icon: 'succes',
						duration: 2000
					});
S
1  
shenjizhe 已提交
375 376
				},
				res => {
S
1  
shenjizhe 已提交
377
					uni.showToast({
S
1  
shenjizhe 已提交
378
						title: '建库失败:' + res.errMsg,
S
1  
shenjizhe 已提交
379 380 381
						icon: 'error',
						duration: 2000
					});
S
1  
shenjizhe 已提交
382 383 384
				}
			);
		},
S
1  
shenjizhe 已提交
385
		loadDb() {
S
1  
shenjizhe 已提交
386
			this.appendText('读库...');
S
1  
shenjizhe 已提交
387 388 389 390 391 392 393 394 395 396 397

			let _this = this;
			uni.showModal({
				title: '请输入数据源id',
				content: '1',
				editable: true,
				success: function(res) {
					if (res.confirm) {
						let i = parseInt(res.content);
						_this.loadDataSource(i);
					} else if (res.cancel) {
S
1  
shenjizhe 已提交
398
						this.appendText('用户点击取消');
S
1  
shenjizhe 已提交
399 400 401 402 403 404
					}
				}
			});
		},

		loadDataSource(sourceId) {
S
1  
shenjizhe 已提交
405
			this.api.loadDb(
S
1  
shenjizhe 已提交
406
				sourceId,
S
1  
shenjizhe 已提交
407
				res => {
S
1  
shenjizhe 已提交
408
					let data = res.data;
S
1  
shenjizhe 已提交
409
					if (data.errCode == 0) {
S
1  
shenjizhe 已提交
410 411 412 413 414 415 416
						uni.showToast({
							title: '读库成功:' + sourceId,
							icon: 'succes',
							duration: 2000
						});
						this.e2t(res.data.data);
						this.arrangeEntities();
S
1  
shenjizhe 已提交
417
					} else {
S
1  
shenjizhe 已提交
418 419 420 421 422 423
						uni.showToast({
							title: '读库失败:' + data.message,
							icon: 'error',
							duration: 2000
						});
					}
S
1  
shenjizhe 已提交
424 425
				},
				res => {
S
1  
shenjizhe 已提交
426
					uni.showToast({
S
1  
shenjizhe 已提交
427
						title: '读库失败:' + res.errMsg,
S
1  
shenjizhe 已提交
428 429 430
						icon: 'error',
						duration: 2000
					});
S
1  
shenjizhe 已提交
431 432 433
				}
			);
		},
S
1  
shenjizhe 已提交
434

S
1  
shenjizhe 已提交
435
		generateCode() {
S
1  
shenjizhe 已提交
436 437
			this.appendText('生成代码...');

S
1  
shenjizhe 已提交
438 439 440 441 442 443 444 445 446 447
			let _this = this;
			uni.showModal({
				title: '请输入组件id',
				content: '1',
				editable: true,
				success: function(res) {
					if (res.confirm) {
						let i = parseInt(res.content);
						_this.createCode(i);
					} else if (res.cancel) {
S
1  
shenjizhe 已提交
448
						this.appendText('用户点击取消');
S
1  
shenjizhe 已提交
449 450 451 452
					}
				}
			});
		},
S
1  
shenjizhe 已提交
453 454

		createCode(componentId) {
S
1  
shenjizhe 已提交
455
			this.api.generateCode(
S
1  
shenjizhe 已提交
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
				componentId,
				res => {
					let data = res.data;
					if (data.errCode == 0) {
						uni.showToast({
							title: '生成成功:' + componentId,
							icon: 'succes',
							duration: 2000
						});
					} else {
						uni.showToast({
							title: '生成失败:' + data.message,
							icon: 'error',
							duration: 2000
						});
					}
				},
				res => {
S
1  
shenjizhe 已提交
474
					this.appendText('生成失败:' + res.errMsg);
S
1  
shenjizhe 已提交
475 476 477 478 479 480 481 482
					uni.showToast({
						title: '生成失败:' + res.errMsg,
						icon: 'error',
						duration: 2000
					});
				}
			);
		},
S
1  
shenjizhe 已提交
483

S
1  
shenjizhe 已提交
484
		saveEntities() {
S
1  
shenjizhe 已提交
485
			this.appendText('存储模型...');
S
1  
shenjizhe 已提交
486 487 488 489 490 491 492 493 494 495 496

			let _this = this;
			uni.showModal({
				title: '请输入领域id',
				content: '1',
				editable: true,
				success: function(res) {
					if (res.confirm) {
						let i = parseInt(res.content);
						_this.saveModel(i);
					} else if (res.cancel) {
S
1  
shenjizhe 已提交
497
						this.appendText('用户点击取消');
S
1  
shenjizhe 已提交
498 499 500 501 502
					}
				}
			});
		},
		saveModel(domainId) {
S
shenjizhe 已提交
503 504
			let entities = this.t2e();
			this.api.saveEntities(
S
1  
shenjizhe 已提交
505
				domainId,
S
shenjizhe 已提交
506 507
				entities,
				res => {
S
1  
shenjizhe 已提交
508 509 510 511 512
					uni.showToast({
						title: '提交成功:' + domainId,
						icon: 'succes',
						duration: 2000
					});
S
shenjizhe 已提交
513 514
				},
				res => {
S
1  
shenjizhe 已提交
515
					uni.showToast({
S
1  
shenjizhe 已提交
516
						title: '提交失败:' + res.errMsg,
S
1  
shenjizhe 已提交
517 518 519
						icon: 'error',
						duration: 2000
					});
S
shenjizhe 已提交
520 521
				}
			);
S
shenjizhe 已提交
522
		},
S
1  
shenjizhe 已提交
523 524
		menuClick(e) {
			switch (e.index) {
S
1  
shenjizhe 已提交
525
				case 0:
S
1  
shenjizhe 已提交
526
					this.delteEntity();
S
1  
shenjizhe 已提交
527
					break;
S
1  
shenjizhe 已提交
528
				case 1:
S
shenjizhe 已提交
529
					this.loadEntities();
S
1  
shenjizhe 已提交
530
					break;
S
1  
shenjizhe 已提交
531 532 533
				case 2:
					this.createDb();
					break;
S
1  
shenjizhe 已提交
534 535 536
				case 3:
					this.loadDb();
					break;
S
1  
shenjizhe 已提交
537 538 539
				case 4:
					this.generateCode();
					break;
S
1  
shenjizhe 已提交
540
			}
S
1  
shenjizhe 已提交
541
			this.$refs.entityFab.close();
S
1  
shenjizhe 已提交
542
		},
S
1  
shenjizhe 已提交
543
		deleteColumn(col) {
S
1  
shenjizhe 已提交
544 545
			let columns = this.table.columns;
			let index = columns.indexOf(col);
S
1  
shenjizhe 已提交
546
			columns.splice(index, 1);
S
1  
shenjizhe 已提交
547
			if (columns.length == 0) {
S
1  
shenjizhe 已提交
548 549 550
				this.refreshColumns();
			}
		},
S
shenjizhe 已提交
551 552 553 554
		addColumn(col) {
			let propertyView = this.$refs.propertyView;
			propertyView.focusItem(0);
		},
S
1  
shenjizhe 已提交
555
		refreshColumns() {
S
1  
shenjizhe 已提交
556
			let columns = this.table.columns;
S
1  
shenjizhe 已提交
557
			if (columns != null && columns.length > 0) {
S
1  
shenjizhe 已提交
558
				let column = columns[0];
S
1  
shenjizhe 已提交
559 560 561
				this.onSelected(0, 'select', column);
			} else {
				this.onSelected(-1, 'select', {});
S
1  
shenjizhe 已提交
562
			}
S
1  
shenjizhe 已提交
563
		},
S
1  
shenjizhe 已提交
564 565
		onSelected(rindex, action, column) {
			this.column = column;
S
1  
shenjizhe 已提交
566 567 568 569
			switch (action) {
				case 'edit':
					break;
				case 'delete':
S
1  
shenjizhe 已提交
570
					this.deleteColumn(column);
S
1  
shenjizhe 已提交
571 572 573
					break;
				case 'select':
					break;
S
shenjizhe 已提交
574 575 576
				case 'add':
					this.addColumn(column);
					break;
S
1  
shenjizhe 已提交
577
			}
S
1  
shenjizhe 已提交
578
		},
S
shenjizhe 已提交
579
		followName(colName, val) {
S
1  
shenjizhe 已提交
580
			let column = this.types.forName(val);
S
1  
shenjizhe 已提交
581 582
			if (column != null) {
				this.types.copyWithoutName(column, this.column);
S
1  
shenjizhe 已提交
583 584
			}
		},
S
shenjizhe 已提交
585
		onChanged(colName, newVal, oldVal) {
S
1  
shenjizhe 已提交
586
			this.appendText('changed:new=' + colName + ',old=' + oldVal);
S
1  
shenjizhe 已提交
587
			if (this.config.followName) {
S
shenjizhe 已提交
588
				this.followName(colName, newVal);
S
1  
shenjizhe 已提交
589
			}
S
1  
shenjizhe 已提交
590
		},
S
1  
shenjizhe 已提交
591
		onConfirm(action, data) {
S
1  
shenjizhe 已提交
592 593 594 595 596
			if (action == 'submit') {
				this.saveEntities();
			} else {
				this.appendText('提交取消');
			}
S
1  
shenjizhe 已提交
597
		},
S
1  
shenjizhe 已提交
598
		resetTool() {
S
1  
shenjizhe 已提交
599 600 601 602 603
			if (this.offsetX == defaultX) {
				this.offsetX += 0.0000001;
			} else {
				this.offsetX = defaultX;
			}
S
1  
shenjizhe 已提交
604
		},
S
1  
shenjizhe 已提交
605
		onStart(key, event, x, y, table) {
S
1  
shenjizhe 已提交
606
			this.focus.entityName = false;
S
1  
shenjizhe 已提交
607
		},
S
1  
shenjizhe 已提交
608
		onEnd(key, event, x, y, table) {
S
1  
shenjizhe 已提交
609
			this.showEntity(key);
S
1\  
shenjizhe 已提交
610
		},
S
1  
shenjizhe 已提交
611 612 613
		onStartTool(key, event, x, y, table) {
			this.focus.entityName = false;
		},
S
1  
shenjizhe 已提交
614
		onEndTool(key, event, x, y, table) {
S
1  
shenjizhe 已提交
615
			this.addEntity(x, y);
S
1  
shenjizhe 已提交
616
		},
S
1  
shenjizhe 已提交
617 618 619
		onLineChange(e) {
			this.positionY = e.detail.height;
		},
S
1  
shenjizhe 已提交
620 621 622
		addEntity(x, y) {
			let tool = this.$refs.toolBar;
			let w = tool.width;
S
1  
shenjizhe 已提交
623 624
			let _x = x - w + defaultX;
			let _y = y + defaultY;
S
1  
shenjizhe 已提交
625

S
1  
shenjizhe 已提交
626
			if (_x >= 0) {
S
1  
shenjizhe 已提交
627 628
				let number = this.getNewNumber();
				let table = this.createTableWithNumber(_x, _y, number);
S
1  
shenjizhe 已提交
629
				this.tables.push(table);
S
1  
shenjizhe 已提交
630
				this.showEntity(table.name);
S
1  
shenjizhe 已提交
631
			}
S
1  
shenjizhe 已提交
632
			this.resetTool();
S
1  
shenjizhe 已提交
633
		},
S
1  
shenjizhe 已提交
634
		showEntity(key) {
S
1  
shenjizhe 已提交
635
			let table = this.tables.find(t => t.name == key);
S
1  
shenjizhe 已提交
636 637 638
			if (this.table != table) {
				this.table = table;
				this.refreshColumns();
S
1  
shenjizhe 已提交
639
				this.focus.entityName = true;
S
1  
shenjizhe 已提交
640
			}
S
1  
shenjizhe 已提交
641
		},
S
1  
shenjizhe 已提交
642
		getNewNumber() {
S
1  
shenjizhe 已提交
643 644 645 646 647 648 649 650 651 652 653
			let number = this.tables.length;
			while (true) {
				let name = 'entity' + number;
				let i = this.tables.findIndex(tab => {
					return tab.name == name;
				});
				if (i < 0) {
					break;
				}
				number++;
			}
S
1  
shenjizhe 已提交
654
			return number;
S
1  
shenjizhe 已提交
655
		},
S
1  
shenjizhe 已提交
656
		createTableWithNumber(x, y, number) {
S
1  
shenjizhe 已提交
657 658
			let title = '实体' + number;
			let name = 'entity' + number;
S
1  
shenjizhe 已提交
659
			return { x: x, y: y, index: number, title: title, name: name, info: '', columns: [this.tools.clone(idColumn)] };
S
1  
shenjizhe 已提交
660
		}
S
1  
shenjizhe 已提交
661 662 663 664 665
	}
};
</script>

<style lang="scss">
S
1  
shenjizhe 已提交
666
$window-height: 93vh;
S
1  
shenjizhe 已提交
667
$border-width: 5rpx;
S
1  
shenjizhe 已提交
668 669
$control-width: 200rpx;
$control-height: 200rpx;
S
1  
shenjizhe 已提交
670

S
1  
shenjizhe 已提交
671 672 673 674 675 676
$tool-bar-index: 100;
$content-bar-index: 0;
$property-bar-index: 200;
$menu-index: 201;

$title-bar-backcolor: #2d8cf0;
S
1  
shenjizhe 已提交
677
$property-bar-back-color: #ffffff;
S
1  
shenjizhe 已提交
678

S
1  
shenjizhe 已提交
679
.main-box {
S
1  
shenjizhe 已提交
680 681
	display: flex;
	flex-direction: row;
S
1  
shenjizhe 已提交
682
	justify-content: space-between;
S
1  
shenjizhe 已提交
683 684
}
.tool-bar {
S
1  
shenjizhe 已提交
685
	order: 1;
S
1  
shenjizhe 已提交
686
	flex: 1;
S
1  
shenjizhe 已提交
687
	height: $window-height;
S
1  
shenjizhe 已提交
688
	background-color: #c1c1c1;
S
1  
shenjizhe 已提交
689 690
	border-style: solid;
	border-width: $border-width;
S
1  
shenjizhe 已提交
691
	z-index: $tool-bar-index;
S
1  
shenjizhe 已提交
692 693
}
.content-window {
S
1  
shenjizhe 已提交
694
	order: 2;
S
1  
shenjizhe 已提交
695
	flex: 7;
S
1  
shenjizhe 已提交
696 697 698 699
	margin-left: -$border-width;
	height: $window-height;
	border-style: solid;
	border-width: $border-width;
S
1  
shenjizhe 已提交
700
	background-color: #282c35;
701
	display: flex;
S
1  
shenjizhe 已提交
702
	flex-direction: column;
703
	flex-wrap: wrap;
S
1  
shenjizhe 已提交
704
	z-index: $content-bar-index;
S
1  
shenjizhe 已提交
705
}
S
1  
shenjizhe 已提交
706 707 708 709 710 711 712 713 714 715 716 717 718
.entity-area {
	flex: 4;
}
.console-view {
	background: white;
	border-style: solid;
	border-width: $border-width;
	flex: 1;
}
.text-area {
	width: 100%;
	height: 100%;
}
S
1  
shenjizhe 已提交
719
.property-bar {
S
1  
shenjizhe 已提交
720
	order: 3;
S
1  
shenjizhe 已提交
721
	flex: 2;
S
1  
shenjizhe 已提交
722 723
	border-style: solid;
	border-width: $border-width;
S
shenjizhe 已提交
724
	margin-left: -$border-width;
S
1  
shenjizhe 已提交
725
	height: $window-height;
S
1  
shenjizhe 已提交
726 727 728 729 730 731 732 733 734 735
	background-color: $property-bar-back-color;
	z-index: $property-bar-index;
}
.menuStyle {
	z-index: $menu-index;
}
.title-bar {
	width: 100%;
	background-color: $title-bar-backcolor;
	color: white;
S
1  
shenjizhe 已提交
736
}
S
1  
shenjizhe 已提交
737
.property-table {
S
1  
shenjizhe 已提交
738
	order: 1;
S
1  
shenjizhe 已提交
739
	height: 30%;
S
1  
shenjizhe 已提交
740
}
S
1  
shenjizhe 已提交
741
.property-info {
S
1  
shenjizhe 已提交
742 743
	order: 2;
	flex: 1;
S
1  
shenjizhe 已提交
744
	position: absolute;
S
1  
shenjizhe 已提交
745 746 747
	bottom: 0;
	height: 40%;
	width: 20%;
S
1  
shenjizhe 已提交
748
}
S
1  
shenjizhe 已提交
749 750 751 752 753 754 755 756
.table-info {
	display: flex;
	flex-direction: row;
}
.table-info-label {
	font-size: 0.95em;
	bottom: 0;
}
S
1  
shenjizhe 已提交
757 758 759 760
.entity_info {
	padding: 20rpx 15rpx 0rpx 10rpx;
	border-width: 1rpx;
}
S
1  
shenjizhe 已提交
761 762 763 764
.div-class {
	display: flex;
	flex-direction: column;
}
S
1  
shenjizhe 已提交
765
</style>