Skip to content

Commit 8b66265

Browse files
committed
fix(bugs): fix canvas component border & switch style & add validate & tree plugin display sync & bind variable confirm disabled
1 parent 78a03de commit 8b66265

6 files changed

Lines changed: 73 additions & 27 deletions

File tree

packages/canvas/container/src/components/CanvasAction.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ export default {
251251
}
252252
253253
const hide = () => {
254-
getRenderer().setCondition(getCurrent().schema?.id, false)
254+
if (getCurrent().schema?.id) {
255+
getRenderer().setCondition(getCurrent().schema.id, false)
256+
useCanvas().pageState.nodesStatus[getCurrent().schema.id] = false
257+
}
255258
updateRect()
256259
}
257260

packages/canvas/container/src/container.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,18 @@ export const updateRect = (id?: string) => {
481481
const isBodySelected = !selectState.componentName && selectState.width > 0
482482

483483
if (id || isBodySelected) {
484-
setTimeout(() => setSelectRect(id))
484+
const element = querySelectById(id) || getDocument().body
485+
const duration = window.getComputedStyle(element).getPropertyValue('transition-duration')
486+
let waitTime = 300
487+
if (duration) {
488+
const unit = duration.slice(-2)
489+
if (unit === 'ms') {
490+
waitTime = parseFloat(duration)
491+
} else {
492+
waitTime = parseFloat(duration) * 1000
493+
}
494+
}
495+
setTimeout(() => setSelectRect(id), waitTime)
485496
} else {
486497
clearSelect()
487498
}

packages/configurator/src/html-attributes-configurator/HtmlAttributesConfigurator.vue

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="attr-header">
3-
<span class="header-title">自定义属性</span>
3+
<span class="header-title">原生属性</span>
44
<tiny-popover
55
v-model="state.visible"
66
placement="bottom"
@@ -11,11 +11,18 @@
1111
>
1212
<div class="attr-form">
1313
<icon-close class="icon-close" @click="closePopover"></icon-close>
14-
<tiny-form label-position="left" label-width="53px">
15-
<tiny-form-item label="name">
14+
<tiny-form
15+
ref="attrFormRef"
16+
:model="state.formData"
17+
:rules="rules"
18+
validate-type="text"
19+
label-position="left"
20+
label-width="53px"
21+
>
22+
<tiny-form-item label="name" prop="key">
1623
<tiny-input v-model="state.formData.key"></tiny-input>
1724
</tiny-form-item>
18-
<tiny-form-item label="value">
25+
<tiny-form-item label="value" prop="value">
1926
<tiny-input v-model="state.formData.value"></tiny-input>
2027
</tiny-form-item>
2128
<div class="footer">
@@ -83,6 +90,16 @@ export default {
8390
const attrs = ref([])
8491
const properties = ['style']
8592
93+
const attrFormRef = ref()
94+
95+
const rules = {
96+
key: [
97+
{ required: true, message: '名称必填', trigger: 'blur' },
98+
{ max: 20, message: '长度不大于20', trigger: 'change' }
99+
],
100+
value: [{ max: 200, message: '长度不大于200', trigger: 'change' }]
101+
}
102+
86103
watchEffect(() => {
87104
if (!useProperties().getSchema()?.props) {
88105
return
@@ -143,24 +160,29 @@ export default {
143160
}
144161
145162
const save = () => {
146-
state.visible = false
147-
const data = {}
148-
let index = -1
149-
150-
if (state.currentAttr.id) {
151-
index = attrs.value.findIndex((item) => item.id === state.currentAttr.id)
152-
data.id = state.currentAttr.id
153-
state.currentAttr = {}
154-
} else {
155-
data.id = utils.guid()
156-
index = attrs.value.length
157-
}
163+
attrFormRef.value.validate((valid) => {
164+
if (!valid) {
165+
return
166+
}
167+
state.visible = false
168+
const data = {}
169+
let index = -1
158170
159-
data.text = `${state.formData.key} = '${state.formData.value}'`
160-
data.data = { key: state.formData.key, value: state.formData.value }
171+
if (state.currentAttr.id) {
172+
index = attrs.value.findIndex((item) => item.id === state.currentAttr.id)
173+
data.id = state.currentAttr.id
174+
state.currentAttr = {}
175+
} else {
176+
data.id = utils.guid()
177+
index = attrs.value.length
178+
}
161179
162-
attrs.value.splice(index, 1, data)
163-
updateSchema()
180+
data.text = `${state.formData.key} = '${state.formData.value}'`
181+
data.data = { key: state.formData.key, value: state.formData.value }
182+
183+
attrs.value.splice(index, 1, data)
184+
updateSchema()
185+
})
164186
}
165187
166188
const edit = (attr) => {
@@ -186,7 +208,9 @@ export default {
186208
}
187209
188210
return {
211+
attrFormRef,
189212
state,
213+
rules,
190214
cancel,
191215
save,
192216
attrs,

packages/configurator/src/slot-configurator/SlotConfigurator.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export default {
185185
.e__switch-core::after {
186186
content: '';
187187
position: absolute;
188-
top: 1px;
188+
top: 2px;
189189
left: 1px;
190190
border-radius: 100%;
191191
transition: all 0.3s;

packages/configurator/src/variable-configurator/VariableConfigurator.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
:value="state.variable"
7171
:options="editorOptions"
7272
@editorDidMount="editorDidMount"
73+
@change="editorChange"
7374
></monaco-editor>
7475
<div v-if="isDataSource" class="datasource-poll-wrap">
7576
<tiny-tooltip
@@ -112,7 +113,7 @@
112113
<tiny-button type="danger" plain @click="remove">移除绑定</tiny-button>
113114
<div class="right">
114115
<tiny-button @click="cancel">取 消</tiny-button>
115-
<tiny-button type="info" @click="confirm">确 定</tiny-button>
116+
<tiny-button type="info" :disabled="confirmDisabled" @click="confirm">确 定</tiny-button>
116117
</div>
117118
</div>
118119
</template>
@@ -259,6 +260,8 @@ export default {
259260
260261
const isDataSource = computed(() => state.active === CONSTANTS.DATASOUCE)
261262
263+
const confirmDisabled = computed(() => !state.variable)
264+
262265
// 每次弹窗打开时都记录下绑定变量的旧值,用来判断保存按钮状态
263266
watch(
264267
() => state.isVisible,
@@ -270,6 +273,10 @@ export default {
270273
}
271274
)
272275
276+
const editorChange = (value) => {
277+
state.variable = value
278+
}
279+
273280
const bindKey = computed(() => props.modelValue?.value?.replace?.('this.state.', '') || '')
274281
275282
const editorOptions = {
@@ -542,7 +549,9 @@ export default {
542549
}
543550
544551
return {
552+
confirmDisabled,
545553
editorDidMount,
554+
editorChange,
546555
editorOptions,
547556
variableClick,
548557
remove,

packages/plugins/tree/src/Main.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ export default {
9696
const translateChild = (data) => {
9797
data.forEach((item) => {
9898
item.show = pageState.nodesStatus[item.id] !== false
99-
item.showEye = !item.show
10099
const child = item.children
101100
if (Array.isArray(child)) {
102101
translateChild(item.children)
@@ -151,8 +150,8 @@ export default {
151150
}
152151
153152
const showNode = (data) => {
154-
data.show = !data.show
155-
pageState.nodesStatus[data.id] = data.show
153+
pageState.nodesStatus[data.id] = !(pageState.nodesStatus[data.id] !== false)
154+
data.show = pageState.nodesStatus[data.id]
156155
157156
const { getRenderer, clearSelect } = useCanvas().canvasApi.value
158157

0 commit comments

Comments
 (0)