test-er.vue 6.0 KB
Newer Older
S
1  
shenjizhe 已提交
1
<template>
S
1  
shenjizhe 已提交
2
	<view class="main-box">
S
1  
shenjizhe 已提交
3 4 5
		<uni-popup ref="popupDelete" type="dialog">
			<uni-popup-dialog title="删除确认" message="成功消息" :duration="2000" :before-close="true" @close="deleteCancel" @confirm="deleteConfirm"></uni-popup-dialog>
		</uni-popup>
S
1  
shenjizhe 已提交
6 7 8
		<movable-area ref="contentArea" class="content-window">
			<thirdlucky-uml-entity
				v-for="(table, index) in tables"
S
1  
shenjizhe 已提交
9
				:ref="table.key"
S
1  
shenjizhe 已提交
10 11 12
				:x="table.x"
				:y="table.y"
				:key="table.key"
S
1  
shenjizhe 已提交
13
				:entityName="table.name"
S
1  
shenjizhe 已提交
14
				:title="table.title"
S
1  
shenjizhe 已提交
15
				:columns="table.columns"
S
1  
shenjizhe 已提交
16 17 18 19 20 21
				:style="{ order: index }"
				@start="onStart"
				@end="onEnd"
			/>
		</movable-area>
		<movable-area ref="toolBar" class="tool-bar">
S
1  
shenjizhe 已提交
22
			<thirdlucky-uml-entity ref="entityTool" :x="offsetX" :y="offsetY" entityName="entity" title="实体" @start="onStartTool" @end="onEndTool" />
S
1  
shenjizhe 已提交
23
		</movable-area>
S
1  
shenjizhe 已提交
24
		<view ref="propertyBar" class="property-bar">
S
1  
shenjizhe 已提交
25 26
			<view style="margin: 20rpx 15rpx 0rpx 10rpx">
				<uni-forms-item class="form-item" label="名称"><uni-easyinput v-model="_entityName" placeholder="请输入表名" /></uni-forms-item>
S
1  
shenjizhe 已提交
27
				<uni-forms-item class="form-item" label="标题"><uni-easyinput v-model="_entityTitle" placeholder="请输入标题" /></uni-forms-item>
S
1  
shenjizhe 已提交
28 29
				<uni-forms-item class="form-item" label="描述"><uni-easyinput v-model="_entityInfo" placeholder="请输入描述" /></uni-forms-item>
			</view>
S
1  
shenjizhe 已提交
30
			<scroll-view class="property-table" scroll-y="true">
S
1  
shenjizhe 已提交
31
				<thirdlucky-data-table ref="tableView" actions="+-" border stripe :datas="datas" :columns="schemas" @selected="onSelected"></thirdlucky-data-table>
S
1  
shenjizhe 已提交
32
			</scroll-view>
S
1  
shenjizhe 已提交
33
			<view class="property-info"><thirdlucky-data-form ref="propertyView" :formData="formData" :columns="columns" @confirm="onConfirm"></thirdlucky-data-form></view>
S
1  
shenjizhe 已提交
34
		</view>
S
1  
shenjizhe 已提交
35 36 37 38
	</view>
</template>

<script>
S
1  
shenjizhe 已提交
39 40 41
let defaultX = 20;
let defaultY = 20;

S
1  
shenjizhe 已提交
42 43 44
export default {
	data() {
		return {
S
1  
shenjizhe 已提交
45 46
			x: 0,
			y: 0,
S
1  
shenjizhe 已提交
47 48
			offsetX: defaultX,
			offsetY: defaultY,
S
1  
shenjizhe 已提交
49 50 51 52
			tables: [
				{
					x: 0,
					y: 0,
S
1  
shenjizhe 已提交
53
					name: 'test',
S
1  
shenjizhe 已提交
54
					title: 'test',
S
1  
shenjizhe 已提交
55
					info: '说明',
S
1  
shenjizhe 已提交
56 57 58 59 60 61 62 63
					columns: [
						{
							name: 'name',
							info: '列名',
							tips: '',
							type: 'text'
						}
					]
S
1  
shenjizhe 已提交
64 65 66 67
				},
				{
					x: 100,
					y: 100,
S
1  
shenjizhe 已提交
68
					name: 'test1',
S
1  
shenjizhe 已提交
69
					title: 'test1',
S
1  
shenjizhe 已提交
70
					info: '说明2',
S
1  
shenjizhe 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84
					columns: [
						{
							name: 'id',
							info: '主键',
							tips: '',
							type: 'number'
						},
						{
							name: 'name',
							info: '列名',
							tips: '',
							type: 'text'
						}
					]
S
1  
shenjizhe 已提交
85
				}
S
1  
shenjizhe 已提交
86
			],
S
1  
shenjizhe 已提交
87 88 89
			columns: [
				{
					name: 'name',
S
1  
shenjizhe 已提交
90 91
					info: '列名',
					tips: '',
S
1  
shenjizhe 已提交
92 93 94
					type: 'text'
				},
				{
S
1  
shenjizhe 已提交
95 96 97 98
					name: 'type',
					info: '类型',
					tips: '',
					type: 'text'
S
1  
shenjizhe 已提交
99 100
				},
				{
S
1  
shenjizhe 已提交
101 102 103
					name: 'info',
					info: '描述',
					tips: '',
S
1  
shenjizhe 已提交
104
					type: 'text'
S
1  
shenjizhe 已提交
105 106
				}
			],
S
1  
shenjizhe 已提交
107 108 109 110 111 112
			schemas: [
				{
					name: 'name',
					info: '列名',
					tips: '',
					type: 'text'
S
1  
shenjizhe 已提交
113
				}
S
1  
shenjizhe 已提交
114
			],
S
1  
shenjizhe 已提交
115
			table: {},
S
1  
shenjizhe 已提交
116 117
			datas: [],
			formData: {}
S
1  
shenjizhe 已提交
118 119
		};
	},
S
1  
shenjizhe 已提交
120 121 122 123 124
	computed: {
		tableDats() {
			return datas.map(function(data) {
				data.name;
			});
S
1  
shenjizhe 已提交
125 126 127
		},
		_entityName: {
			get() {
S
1  
shenjizhe 已提交
128
				return this.table.name;
S
1  
shenjizhe 已提交
129 130
			},
			set(val) {
S
1  
shenjizhe 已提交
131 132 133 134 135 136 137 138 139
				this.table.name = val;
			}
		},
		_entityTitle: {
			get() {
				return this.table.title;
			},
			set(val) {
				this.table.title = val;
S
1  
shenjizhe 已提交
140 141 142 143
			}
		},
		_entityInfo: {
			get() {
S
1  
shenjizhe 已提交
144
				return this.table.info;
S
1  
shenjizhe 已提交
145 146
			},
			set(val) {
S
1  
shenjizhe 已提交
147
				this.table.info = val;
S
1  
shenjizhe 已提交
148
			}
S
1  
shenjizhe 已提交
149 150
		}
	},
S
1  
shenjizhe 已提交
151
	methods: {
S
1  
shenjizhe 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164
		deleteConfirm() {
			console.log("confirm!!!");
			this.$refs.popupDelete.close();
		},
		deleteCancel() {
			console.log("cancel!!!");
			this.$refs.popupDelete.close();
		},
		deleteColumn(data) {
			// 通过组件定义的ref调用uni-popup方法 ,如果传入参数 ,type 属性将失效 ,仅支持 ['top','left','bottom','right','center']
			this.$refs.popupDelete.open('center');
		},
		onSelected(rindex, action, data) {
S
1  
shenjizhe 已提交
165
			this.formData = data;
S
1  
shenjizhe 已提交
166 167 168 169 170 171 172 173 174
			switch (action) {
				case 'edit':
					break;
				case 'delete':
					this.deleteColumn(data);
					break;
				case 'select':
					break;
			}
S
1  
shenjizhe 已提交
175
		},
S
1  
shenjizhe 已提交
176
		onConfirm(action, data) {},
S
1  
shenjizhe 已提交
177
		resetTool() {
S
1  
shenjizhe 已提交
178 179 180 181 182
			if (this.offsetX == defaultX) {
				this.offsetX += 0.0000001;
			} else {
				this.offsetX = defaultX;
			}
S
1  
shenjizhe 已提交
183
		},
S
1  
shenjizhe 已提交
184
		onStart(key, event, x, y, table) {
185
			console.log(key + ':' + event + ':' + x + ':' + y);
S
1  
shenjizhe 已提交
186
		},
S
1  
shenjizhe 已提交
187
		onEnd(key, event, x, y, table) {
S
1  
shenjizhe 已提交
188
			this.showEntity(key);
S
1\  
shenjizhe 已提交
189
		},
S
1  
shenjizhe 已提交
190
		onStartTool(key, event, x, y, table) {
S
1  
shenjizhe 已提交
191
			console.log(key + ':' + event + ':' + x + ':' + y);
S
1  
shenjizhe 已提交
192
		},
S
1  
shenjizhe 已提交
193
		onEndTool(key, event, x, y, table) {
S
1  
shenjizhe 已提交
194 195
			console.log(key + ':' + event + ':' + x + ':' + y);
			this.addEntity(x, y);
S
1  
shenjizhe 已提交
196
		},
S
1  
shenjizhe 已提交
197 198 199 200
		addEntity(x, y) {
			let count = this.tables.length;
			let tool = this.$refs.toolBar;
			let w = tool.width;
S
1  
shenjizhe 已提交
201 202 203 204
			this.resetTool();

			let _x = x - w + defaultX;
			let _y = y + defaultY;
S
1  
shenjizhe 已提交
205

S
1  
shenjizhe 已提交
206
			if (_x >= 0) {
S
1  
shenjizhe 已提交
207
				let title = '实体' + count;
S
1  
shenjizhe 已提交
208 209 210
				let name = 'entity' + count;

				let table = { x: _x, y: _y, title: title, name: name, info: '', columns: [] };
S
1  
shenjizhe 已提交
211
				this.tables.push(table);
S
1  
shenjizhe 已提交
212
				this.showEntity(name);
S
1  
shenjizhe 已提交
213
			}
S
1  
shenjizhe 已提交
214
		},
S
1  
shenjizhe 已提交
215
		showEntity(key) {
S
1  
shenjizhe 已提交
216
			let table = this.tables.find(t => t.name == key);
S
1  
shenjizhe 已提交
217
			this.datas = table.columns;
S
1  
shenjizhe 已提交
218
			this.table = table;
S
1  
shenjizhe 已提交
219
		}
S
1  
shenjizhe 已提交
220 221 222 223 224
	}
};
</script>

<style lang="scss">
S
1  
shenjizhe 已提交
225
$window-height: 93vh;
S
1  
shenjizhe 已提交
226
$border-width: 5rpx;
S
1  
shenjizhe 已提交
227 228
$control-width: 200rpx;
$control-height: 200rpx;
S
1  
shenjizhe 已提交
229

S
1  
shenjizhe 已提交
230
.main-box {
S
1  
shenjizhe 已提交
231 232
	display: flex;
	flex-direction: row;
S
1  
shenjizhe 已提交
233
	justify-content: space-between;
S
1  
shenjizhe 已提交
234 235
}
.tool-bar {
S
1  
shenjizhe 已提交
236
	order: 1;
S
1  
shenjizhe 已提交
237
	flex: 1;
S
1  
shenjizhe 已提交
238
	height: $window-height;
S
1  
shenjizhe 已提交
239
	background-color: white;
S
1  
shenjizhe 已提交
240 241 242 243
	border-style: solid;
	border-width: $border-width;
}
.content-window {
S
1  
shenjizhe 已提交
244
	order: 2;
S
1  
shenjizhe 已提交
245
	flex: 7;
S
1  
shenjizhe 已提交
246 247
	margin-left: -$border-width;
	height: $window-height;
S
1  
shenjizhe 已提交
248

S
1  
shenjizhe 已提交
249 250
	border-style: solid;
	border-width: $border-width;
S
1  
shenjizhe 已提交
251
	background-color: gray;
252 253 254

	display: flex;
	flex-direction: row;
255
	flex-wrap: wrap;
S
1  
shenjizhe 已提交
256 257
}
.property-bar {
S
1  
shenjizhe 已提交
258 259
	display: flex;
	flex-direction: column;
S
1  
shenjizhe 已提交
260
	justify-content: end;
S
1  
shenjizhe 已提交
261
	order: 3;
S
1  
shenjizhe 已提交
262
	flex: 2;
S
1  
shenjizhe 已提交
263 264 265
	margin-left: -$border-width;
	border-style: solid;
	border-width: $border-width;
S
1  
shenjizhe 已提交
266 267 268
	height: $window-height;
	background-color: white;
}
S
1  
shenjizhe 已提交
269
.property-table {
S
1  
shenjizhe 已提交
270
	order: 1;
S
1  
shenjizhe 已提交
271
	height: 60%;
S
1  
shenjizhe 已提交
272
}
S
1  
shenjizhe 已提交
273
.property-info {
S
1  
shenjizhe 已提交
274 275
	order: 2;
	flex: 1;
S
1  
shenjizhe 已提交
276 277
	position: absolute;
	bottom: -39rpx;
S
1  
shenjizhe 已提交
278
}
S
1  
shenjizhe 已提交
279 280 281 282 283 284 285 286
.table-info {
	display: flex;
	flex-direction: row;
}
.table-info-label {
	font-size: 0.95em;
	bottom: 0;
}
S
1  
shenjizhe 已提交
287
</style>