提交
This commit is contained in:
1 parent
417d6c9c51
commit
c8fe0cdc20
102 files changed
+19847
-12224
No files matched your search
@@ -29,6 +29,8 @@
|
||||
const frameRef = ref<HTMLIFrameElement | null>(null)
|
||||
const frameReady = ref(false)
|
||||
let reqSeq = 0
|
||||
/** 最近一次推入 iframe 的 schema JSON,用于避免保存回写后重复 setRule 清空画布 */
|
||||
let lastPushedJson = ''
|
||||
const pending = new Map<
|
||||
number,
|
||||
{ resolve: (v: { rule: unknown; option: unknown }) => void; reject: (e: Error) => void }
|
||||
@@ -62,6 +64,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
function schemaJson(schema: unknown) {
|
||||
return JSON.stringify(toPlainSchema(schema))
|
||||
}
|
||||
|
||||
function postToFrame(payload: Record<string, unknown>) {
|
||||
try {
|
||||
frameRef.value?.contentWindow?.postMessage(payload, '*')
|
||||
@@ -70,11 +76,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
function pushSchemaToFrame() {
|
||||
/** force=true 时即使内容相同也重新 setRule(用于切回表单 Tab 强制回显) */
|
||||
function pushSchemaToFrame(force = false) {
|
||||
if (!frameReady.value) return
|
||||
const schema = toPlainSchema(props.modelValue)
|
||||
const json = JSON.stringify(schema)
|
||||
if (!force && json === lastPushedJson) return
|
||||
lastPushedJson = json
|
||||
postToFrame({
|
||||
type: MSG.SET,
|
||||
schema: toPlainSchema(props.modelValue)
|
||||
schema
|
||||
})
|
||||
}
|
||||
|
||||
@@ -88,7 +99,7 @@
|
||||
|
||||
function onFrameLoad() {
|
||||
if (frameReady.value) {
|
||||
pushSchemaToFrame()
|
||||
pushSchemaToFrame(true)
|
||||
pushFlowRefs()
|
||||
}
|
||||
}
|
||||
@@ -98,11 +109,13 @@
|
||||
if (!data || typeof data !== 'object') return
|
||||
if (data.type === MSG.READY) {
|
||||
frameReady.value = true
|
||||
pushSchemaToFrame()
|
||||
lastPushedJson = ''
|
||||
pushSchemaToFrame(true)
|
||||
pushFlowRefs()
|
||||
// 宿主刚就绪时再补推一次,避免 setRule 早于内部 dragForm 初始化
|
||||
window.setTimeout(() => pushSchemaToFrame(), 50)
|
||||
window.setTimeout(() => pushSchemaToFrame(), 200)
|
||||
// 宿主刚就绪时再补推,避免 setRule 早于内部 dragForm / 菜单初始化
|
||||
window.setTimeout(() => pushSchemaToFrame(true), 50)
|
||||
window.setTimeout(() => pushSchemaToFrame(true), 200)
|
||||
window.setTimeout(() => pushSchemaToFrame(true), 500)
|
||||
return
|
||||
}
|
||||
if (data.type === MSG.SCHEMA && typeof data.requestId === 'number') {
|
||||
@@ -110,6 +123,8 @@
|
||||
if (!wait) return
|
||||
pending.delete(data.requestId)
|
||||
const schema = toPlainSchema(data.schema)
|
||||
// 与父级即将回写的内容对齐,避免 watch 再次 setRule
|
||||
lastPushedJson = JSON.stringify(schema)
|
||||
wait.resolve(schema)
|
||||
}
|
||||
}
|
||||
@@ -136,12 +151,17 @@
|
||||
})
|
||||
}
|
||||
|
||||
/** 切回「表单设计」Tab 时强制把父级 schema 灌回画布 */
|
||||
function reapplySchema() {
|
||||
pushSchemaToFrame(true)
|
||||
pushFlowRefs()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
() => schemaJson(props.modelValue),
|
||||
() => {
|
||||
pushSchemaToFrame()
|
||||
},
|
||||
{ deep: true }
|
||||
pushSchemaToFrame(false)
|
||||
}
|
||||
)
|
||||
|
||||
watch(
|
||||
@@ -162,7 +182,7 @@
|
||||
pending.clear()
|
||||
})
|
||||
|
||||
defineExpose({ fetchSchema })
|
||||
defineExpose({ fetchSchema, reapplySchema })
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in new issue
Block a user