|
|
@@ -1,6 +1,6 @@
|
|
|
<!-- FormCreate 全屏宿主(无 Tailwind) -->
|
|
|
<template>
|
|
|
- <div class="oa-fc-host">
|
|
|
+ <div class="oa-fc-host" :class="{ 'oa-fc-host--lock-required': lockRequired }">
|
|
|
<fc-designer
|
|
|
ref="designerRef"
|
|
|
class="oa-fc-host__designer"
|
|
|
@@ -8,13 +8,24 @@
|
|
|
:config="designerConfig"
|
|
|
:locale="fcLocale"
|
|
|
/>
|
|
|
+ <div v-show="showCondFlag" class="oa-cond-flag">
|
|
|
+ <div class="oa-cond-flag__row">
|
|
|
+ <el-switch :model-value="flagOn" @change="onFlagChange" />
|
|
|
+ <div>
|
|
|
+ <div class="oa-cond-flag__title">参与流程条件分支</div>
|
|
|
+ <div class="oa-cond-flag__tip">勾选后该字段必填且不可改为选填;可在「3 流程设计」条件中选用</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
|
+ import { ElMessage } from 'element-plus'
|
|
|
import formCreateZh from '@form-create/designer/locale/zh-cn'
|
|
|
import { registerOaDesignerAttachment } from '@/components/oa-approval/oa-form-components'
|
|
|
+ import { CONDITION_ELIGIBLE_TYPES } from '@/components/oa-approval/oa-condition-fields'
|
|
|
|
|
|
defineOptions({ name: 'OaFcHostApp' })
|
|
|
|
|
|
@@ -41,19 +52,102 @@
|
|
|
READY: 'oa-fc:ready',
|
|
|
SET: 'oa-fc:set-schema',
|
|
|
GET: 'oa-fc:get-schema',
|
|
|
- SCHEMA: 'oa-fc:schema'
|
|
|
+ SCHEMA: 'oa-fc:schema',
|
|
|
+ FLOW_REFS: 'oa-fc:set-flow-refs'
|
|
|
} as const
|
|
|
|
|
|
+ const flowConditionFields = ref<string[]>([])
|
|
|
+ const showCondFlag = ref(false)
|
|
|
+ const flagOn = ref(false)
|
|
|
+ const lockRequired = ref(false)
|
|
|
+ let pollTimer: number | null = null
|
|
|
+ let lastActiveId = ''
|
|
|
+
|
|
|
function getDesigner(): DesignerApi | null {
|
|
|
const inst = designerRef.value as any
|
|
|
if (!inst) return null
|
|
|
- // Vue3 组件实例可能挂在 expose / proxy 上
|
|
|
if (typeof inst.setRule === 'function') return inst
|
|
|
if (inst.$ && typeof inst.$.exposed?.setRule === 'function') return inst.$.exposed
|
|
|
if (typeof inst.setupState?.setRule === 'function') return inst.setupState
|
|
|
return inst
|
|
|
}
|
|
|
|
|
|
+ function getSetupState(): any {
|
|
|
+ const inst = designerRef.value as any
|
|
|
+ if (!inst) return null
|
|
|
+ return inst.setupState || inst.$?.setupState || inst.$.exposed?.setupState || null
|
|
|
+ }
|
|
|
+
|
|
|
+ function getActiveRule(): any {
|
|
|
+ const state = getSetupState()
|
|
|
+ return state?.activeRule || null
|
|
|
+ }
|
|
|
+
|
|
|
+ function readFlag(rule: any): boolean {
|
|
|
+ return rule?.useInCondition === true || rule?.props?.useInCondition === true
|
|
|
+ }
|
|
|
+
|
|
|
+ function applyFlagToRule(rule: any, on: boolean) {
|
|
|
+ rule.useInCondition = on
|
|
|
+ if (!rule.props || typeof rule.props !== 'object') rule.props = {}
|
|
|
+ rule.props.useInCondition = on
|
|
|
+ if (on) {
|
|
|
+ rule.$required = true
|
|
|
+ rule.required = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function syncActivePanel() {
|
|
|
+ const rule = getActiveRule()
|
|
|
+ const type = String(rule?.type || '')
|
|
|
+ const eligible = !!(rule?.field && CONDITION_ELIGIBLE_TYPES.has(type))
|
|
|
+ showCondFlag.value = eligible
|
|
|
+ if (!eligible) {
|
|
|
+ flagOn.value = false
|
|
|
+ lockRequired.value = false
|
|
|
+ lastActiveId = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const id = String(rule._fc_id || rule.field || '')
|
|
|
+ const on = readFlag(rule)
|
|
|
+ flagOn.value = on
|
|
|
+ lockRequired.value = on
|
|
|
+ if (on) applyFlagToRule(rule, true)
|
|
|
+ lastActiveId = id
|
|
|
+ }
|
|
|
+
|
|
|
+ function onFlagChange(val: string | number | boolean) {
|
|
|
+ const on = !!val
|
|
|
+ const rule = getActiveRule()
|
|
|
+ if (!rule?.field) return
|
|
|
+ if (!on) {
|
|
|
+ const field = String(rule.field)
|
|
|
+ if (flowConditionFields.value.includes(field)) {
|
|
|
+ ElMessage.warning('请先在流程设计中删除对该字段的条件')
|
|
|
+ flagOn.value = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ applyFlagToRule(rule, false)
|
|
|
+ flagOn.value = false
|
|
|
+ lockRequired.value = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ applyFlagToRule(rule, true)
|
|
|
+ flagOn.value = true
|
|
|
+ lockRequired.value = true
|
|
|
+ // 同步校验面板必填开关
|
|
|
+ try {
|
|
|
+ const state = getSetupState()
|
|
|
+ const vapi = state?.validateForm?.api
|
|
|
+ if (vapi?.setValue) {
|
|
|
+ const cur = typeof vapi.formData === 'function' ? vapi.formData() : {}
|
|
|
+ vapi.setValue({ ...cur, $required: true })
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ /* ignore */
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function readSchema() {
|
|
|
const d = getDesigner()
|
|
|
return {
|
|
|
@@ -82,6 +176,7 @@
|
|
|
d.setOption(JSON.parse(JSON.stringify(option)))
|
|
|
}
|
|
|
pendingSchema = null
|
|
|
+ window.setTimeout(() => syncActivePanel(), 80)
|
|
|
} catch (e) {
|
|
|
console.warn('[oa-fc-host] applySchema failed', e)
|
|
|
if (attempt < 5) {
|
|
|
@@ -102,6 +197,12 @@
|
|
|
{ type: MSG.SCHEMA, schema: readSchema(), requestId: data.requestId },
|
|
|
'*'
|
|
|
)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (data.type === MSG.FLOW_REFS) {
|
|
|
+ flowConditionFields.value = Array.isArray(data.fields)
|
|
|
+ ? data.fields.map((x: unknown) => String(x))
|
|
|
+ : []
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -129,12 +230,23 @@
|
|
|
if (pendingSchema) {
|
|
|
void applySchema(pendingSchema)
|
|
|
}
|
|
|
+ pollTimer = window.setInterval(() => {
|
|
|
+ const rule = getActiveRule()
|
|
|
+ const id = rule ? String(rule._fc_id || rule.field || '') : ''
|
|
|
+ if (id !== lastActiveId || (rule && readFlag(rule) !== flagOn.value)) {
|
|
|
+ syncActivePanel()
|
|
|
+ }
|
|
|
+ }, 250)
|
|
|
})
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
window.removeEventListener('message', onMessage)
|
|
|
brandObserver?.disconnect()
|
|
|
brandObserver = null
|
|
|
+ if (pollTimer != null) {
|
|
|
+ window.clearInterval(pollTimer)
|
|
|
+ pollTimer = null
|
|
|
+ }
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
@@ -151,6 +263,7 @@
|
|
|
}
|
|
|
|
|
|
.oa-fc-host {
|
|
|
+ position: relative;
|
|
|
box-sizing: border-box;
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
@@ -165,6 +278,46 @@
|
|
|
height: 100% !important;
|
|
|
}
|
|
|
|
|
|
+ .oa-cond-flag {
|
|
|
+ position: absolute;
|
|
|
+ top: 56px;
|
|
|
+ right: 12px;
|
|
|
+ z-index: 30;
|
|
|
+ width: 292px;
|
|
|
+ padding: 12px;
|
|
|
+ background: #ecfdf5;
|
|
|
+ border: 1px dashed #a7f3d0;
|
|
|
+ border-radius: 8px;
|
|
|
+ box-shadow: 0 2px 8px rgb(15 23 42 / 8%);
|
|
|
+ }
|
|
|
+
|
|
|
+ .oa-cond-flag__row {
|
|
|
+ display: flex;
|
|
|
+ gap: 10px;
|
|
|
+ align-items: flex-start;
|
|
|
+ }
|
|
|
+
|
|
|
+ .oa-cond-flag__title {
|
|
|
+ font-size: 13px;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #059669;
|
|
|
+ }
|
|
|
+
|
|
|
+ .oa-cond-flag__tip {
|
|
|
+ margin-top: 2px;
|
|
|
+ font-size: 12px;
|
|
|
+ line-height: 1.4;
|
|
|
+ color: #64748b;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 参与分支时锁定「是否必填」 */
|
|
|
+ .oa-fc-host--lock-required ._fc-r .el-form-item:has([name='$required']),
|
|
|
+ .oa-fc-host--lock-required ._fc-r .el-form-item:has(.fc-required),
|
|
|
+ .oa-fc-host--lock-required ._fc-validate {
|
|
|
+ pointer-events: none;
|
|
|
+ opacity: 0.55;
|
|
|
+ }
|
|
|
+
|
|
|
/* 防止宿主环境意外丢弃 aside 宽度 */
|
|
|
.oa-fc-host .el-aside._fc-l-menu {
|
|
|
width: 40px !important;
|
|
|
@@ -201,7 +354,6 @@
|
|
|
overflow: auto;
|
|
|
}
|
|
|
|
|
|
- /* 兜底:若短暂出现水印节点,先视觉藏住(最终由 JS 移除) */
|
|
|
.oa-fc-host ._fc-m-con > a[href*='form-create.com'] {
|
|
|
clip-path: inset(50%) !important;
|
|
|
transform: scale(0) !important;
|