@agentprismform/render-vue 0.0.0-stage → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.mjs +2995 -0
- package/dist/style.css +2 -0
- package/package.json +40 -4
- package/src/components/FormGroup.vue +50 -0
- package/src/components/FormItem.vue +171 -0
- package/src/components/FormRender.vue +127 -0
- package/src/components/PrismForm.vue +608 -0
- package/src/components/controls/AddressControl.vue +255 -0
- package/src/components/controls/AgreementControl.vue +49 -0
- package/src/components/controls/CascaderControl.vue +159 -0
- package/src/components/controls/DateControl.vue +96 -0
- package/src/components/controls/ImageUploadControl.vue +135 -0
- package/src/components/controls/InputControl.vue +80 -0
- package/src/components/controls/ListControl.vue +149 -0
- package/src/components/controls/SearchControl.vue +193 -0
- package/src/components/controls/SelectControl.vue +206 -0
- package/src/components/controls/SliderControl.vue +61 -0
- package/src/components/controls/TaskControl.vue +39 -0
- package/src/components/controls/VerifyCodeControl.vue +135 -0
- package/src/components/controls/task/ApiTask.vue +99 -0
- package/src/components/controls/task/CustomerTask.vue +91 -0
- package/src/components/controls/task/H5JumpTask.vue +125 -0
- package/src/components/controls/task/InlineTask.vue +116 -0
- package/src/components/controls/task/NativeTask.vue +299 -0
- package/src/components/controls/task/SubFormTask.vue +156 -0
- package/src/composables/useFormRender.ts +63 -0
- package/src/composables/useTaskHandler.ts +11 -0
- package/src/helpers.ts +143 -0
- package/src/index.ts +8 -0
- package/src/taskHandlers.ts +4 -0
- package/README.md +0 -3
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* 原生页面 Task
|
|
4
|
+
* - signature → Canvas 签名板
|
|
5
|
+
* - map → 地图占位
|
|
6
|
+
* - 其余 → 模拟确认弹窗(checkCard, wxBill, signDoc, auth_contract, bank_bill_files, xinge_authorize)
|
|
7
|
+
*/
|
|
8
|
+
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
|
9
|
+
import type { FormItem } from '@agentprismform/core'
|
|
10
|
+
import { completeTask } from '@agentprismform/render-task'
|
|
11
|
+
|
|
12
|
+
const props = defineProps<{
|
|
13
|
+
item: FormItem
|
|
14
|
+
field: any
|
|
15
|
+
formCore: any
|
|
16
|
+
}>()
|
|
17
|
+
|
|
18
|
+
const taskType = computed(() => (props.item.props as any)?.taskType as string || '')
|
|
19
|
+
|
|
20
|
+
// ─── signature ────────────────────────────────────────────────
|
|
21
|
+
const sigVisible = ref(false)
|
|
22
|
+
const canvasRef = ref<HTMLCanvasElement | null>(null)
|
|
23
|
+
const isDrawing = ref(false)
|
|
24
|
+
const ctx = ref<CanvasRenderingContext2D | null>(null)
|
|
25
|
+
const hasDrawn = ref(false)
|
|
26
|
+
|
|
27
|
+
function openSignature() {
|
|
28
|
+
sigVisible.value = true
|
|
29
|
+
hasDrawn.value = false
|
|
30
|
+
nextTick(() => {
|
|
31
|
+
const cvs = canvasRef.value
|
|
32
|
+
if (!cvs) return
|
|
33
|
+
const dpr = window.devicePixelRatio || 1
|
|
34
|
+
const rect = cvs.getBoundingClientRect()
|
|
35
|
+
cvs.width = rect.width * dpr
|
|
36
|
+
cvs.height = rect.height * dpr
|
|
37
|
+
const c = cvs.getContext('2d')!
|
|
38
|
+
c.scale(dpr, dpr)
|
|
39
|
+
c.strokeStyle = '#333'
|
|
40
|
+
c.lineWidth = 3
|
|
41
|
+
c.lineCap = 'round'
|
|
42
|
+
c.lineJoin = 'round'
|
|
43
|
+
ctx.value = c
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getPos(e: MouseEvent | TouchEvent) {
|
|
48
|
+
const cvs = canvasRef.value!
|
|
49
|
+
const rect = cvs.getBoundingClientRect()
|
|
50
|
+
const clientX = 'touches' in e ? e.touches[0].clientX : e.clientX
|
|
51
|
+
const clientY = 'touches' in e ? e.touches[0].clientY : e.clientY
|
|
52
|
+
return { x: clientX - rect.left, y: clientY - rect.top }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function onStart(e: MouseEvent | TouchEvent) {
|
|
56
|
+
e.preventDefault()
|
|
57
|
+
isDrawing.value = true
|
|
58
|
+
hasDrawn.value = true
|
|
59
|
+
const { x, y } = getPos(e)
|
|
60
|
+
ctx.value!.beginPath()
|
|
61
|
+
ctx.value!.moveTo(x, y)
|
|
62
|
+
}
|
|
63
|
+
function onMove(e: MouseEvent | TouchEvent) {
|
|
64
|
+
e.preventDefault()
|
|
65
|
+
if (!isDrawing.value) return
|
|
66
|
+
const { x, y } = getPos(e)
|
|
67
|
+
ctx.value!.lineTo(x, y)
|
|
68
|
+
ctx.value!.stroke()
|
|
69
|
+
}
|
|
70
|
+
function onEnd() {
|
|
71
|
+
isDrawing.value = false
|
|
72
|
+
}
|
|
73
|
+
function clearSignature() {
|
|
74
|
+
const cvs = canvasRef.value!
|
|
75
|
+
const c = ctx.value!
|
|
76
|
+
c.clearRect(0, 0, cvs.width, cvs.height)
|
|
77
|
+
hasDrawn.value = false
|
|
78
|
+
}
|
|
79
|
+
function confirmSignature() {
|
|
80
|
+
const dataUrl = canvasRef.value!.toDataURL('image/png')
|
|
81
|
+
sigVisible.value = false
|
|
82
|
+
completeTask(props.formCore, props.item.key, {
|
|
83
|
+
signatureDataUrl: dataUrl,
|
|
84
|
+
_completed: true,
|
|
85
|
+
_completedAt: new Date().toISOString(),
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
function cancelSignature() {
|
|
89
|
+
sigVisible.value = false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ─── map ──────────────────────────────────────────────────────
|
|
93
|
+
const mapVisible = ref(false)
|
|
94
|
+
|
|
95
|
+
function openMap() {
|
|
96
|
+
mapVisible.value = true
|
|
97
|
+
}
|
|
98
|
+
function confirmMap() {
|
|
99
|
+
mapVisible.value = false
|
|
100
|
+
completeTask(props.formCore, props.item.key, {
|
|
101
|
+
lng: 116.404 + Math.random() * 0.1,
|
|
102
|
+
lat: 39.915 + Math.random() * 0.1,
|
|
103
|
+
address: `模拟选点地址 ${Date.now()}`,
|
|
104
|
+
_completed: true,
|
|
105
|
+
_completedAt: new Date().toISOString(),
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ─── generic native ───────────────────────────────────────────
|
|
110
|
+
const nativeVisible = ref(false)
|
|
111
|
+
|
|
112
|
+
function openNative() {
|
|
113
|
+
nativeVisible.value = true
|
|
114
|
+
}
|
|
115
|
+
function confirmNative() {
|
|
116
|
+
nativeVisible.value = false
|
|
117
|
+
completeTask(props.formCore, props.item.key, {
|
|
118
|
+
_completed: true,
|
|
119
|
+
_completedAt: new Date().toISOString(),
|
|
120
|
+
_mock: `已完成原生任务: ${taskType.value}`,
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function onOverlayClick(e: MouseEvent, close: () => void) {
|
|
125
|
+
e.stopPropagation()
|
|
126
|
+
if (e.target === e.currentTarget) close()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ─── open trigger ─────────────────────────────────────────────
|
|
130
|
+
function open() {
|
|
131
|
+
if (taskType.value === 'signature') openSignature()
|
|
132
|
+
else if (taskType.value === 'map') openMap()
|
|
133
|
+
else openNative()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const hasValue = computed(() => {
|
|
137
|
+
const v = props.field?.value
|
|
138
|
+
return v && typeof v === 'object' && v._completed
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
const taskIcon = computed(() => {
|
|
142
|
+
if (taskType.value === 'signature') return '✍️'
|
|
143
|
+
if (taskType.value === 'map') return '📍'
|
|
144
|
+
return '📱'
|
|
145
|
+
})
|
|
146
|
+
const taskColor = computed(() => {
|
|
147
|
+
if (taskType.value === 'signature') return '#eb2f96'
|
|
148
|
+
if (taskType.value === 'map') return '#2f54eb'
|
|
149
|
+
return '#fa8c16'
|
|
150
|
+
})
|
|
151
|
+
</script>
|
|
152
|
+
|
|
153
|
+
<template>
|
|
154
|
+
<div class="task-native" @click="open">
|
|
155
|
+
<div class="task-trigger" :class="{ completed: hasValue }">
|
|
156
|
+
<span class="task-icon">{{ taskIcon }}</span>
|
|
157
|
+
<span class="task-label">{{ hasValue ? '✅ 已完成' : (item.placeholder || `点击完成${item.label}`) }}</span>
|
|
158
|
+
<span class="task-arrow">▸</span>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<!-- Signature Modal -->
|
|
162
|
+
<div v-if="sigVisible" class="modal-overlay" @click="onOverlayClick($event, cancelSignature)">
|
|
163
|
+
<div class="sig-card">
|
|
164
|
+
<div class="sig-header">
|
|
165
|
+
<span>{{ item.label || '手写签名' }}</span>
|
|
166
|
+
<button class="modal-close" @click="cancelSignature">✕</button>
|
|
167
|
+
</div>
|
|
168
|
+
<div class="sig-body">
|
|
169
|
+
<canvas
|
|
170
|
+
ref="canvasRef"
|
|
171
|
+
class="sig-canvas"
|
|
172
|
+
@mousedown="onStart" @mousemove="onMove" @mouseup="onEnd" @mouseleave="onEnd"
|
|
173
|
+
@touchstart="onStart" @touchmove="onMove" @touchend="onEnd"
|
|
174
|
+
/>
|
|
175
|
+
<div v-if="!hasDrawn" class="sig-placeholder">在此处签名</div>
|
|
176
|
+
</div>
|
|
177
|
+
<div class="sig-footer">
|
|
178
|
+
<button class="btn-clear" @click="clearSignature">清除</button>
|
|
179
|
+
<button class="btn-confirm-sig" @click="confirmSignature" :disabled="!hasDrawn">确认签名</button>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<!-- Map Modal -->
|
|
185
|
+
<div v-if="mapVisible" class="modal-overlay" @click="onOverlayClick($event, confirmMap)">
|
|
186
|
+
<div class="map-card">
|
|
187
|
+
<div class="map-header">
|
|
188
|
+
<span>{{ item.label || '地图选点' }}</span>
|
|
189
|
+
<button class="modal-close" @click="confirmMap">✕</button>
|
|
190
|
+
</div>
|
|
191
|
+
<div class="map-placeholder">
|
|
192
|
+
<span class="map-pin">📍</span>
|
|
193
|
+
<p>地图选点(Demo 模拟)</p>
|
|
194
|
+
<p class="map-hint">点击任意位置确认选点</p>
|
|
195
|
+
</div>
|
|
196
|
+
<div class="map-footer">
|
|
197
|
+
<button class="btn-confirm-sig" @click="confirmMap">在此位置选点</button>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
<!-- Generic Native Modal -->
|
|
203
|
+
<div v-if="nativeVisible" class="modal-overlay" @click="onOverlayClick($event, () => nativeVisible = false)">
|
|
204
|
+
<div class="native-card">
|
|
205
|
+
<div class="native-icon">{{ taskIcon }}</div>
|
|
206
|
+
<div class="native-title">{{ item.label || '原生页面任务' }}</div>
|
|
207
|
+
<div class="native-hint">(Demo 模拟:实际将拉起原生页面)</div>
|
|
208
|
+
<div class="native-desc">taskType: {{ taskType }}</div>
|
|
209
|
+
<div class="native-actions">
|
|
210
|
+
<button class="btn-cancel" @click="nativeVisible = false">取消</button>
|
|
211
|
+
<button class="btn-confirm-sig" @click="confirmNative">模拟完成</button>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
</div>
|
|
216
|
+
</template>
|
|
217
|
+
|
|
218
|
+
<style scoped>
|
|
219
|
+
.task-native { user-select: none; }
|
|
220
|
+
.task-trigger {
|
|
221
|
+
display: flex; align-items: center; gap: 8px;
|
|
222
|
+
padding: 10px 12px; border: 1px solid v-bind(taskColor);
|
|
223
|
+
border-radius: 8px; background: #fff7e6; cursor: pointer;
|
|
224
|
+
}
|
|
225
|
+
.task-trigger:active { background: #ffe7ba; }
|
|
226
|
+
.task-trigger.completed { border-color: #52c41a; background: #f6ffed; }
|
|
227
|
+
.task-icon { font-size: 18px; }
|
|
228
|
+
.task-label { flex: 1; font-size: 14px; color: #333; }
|
|
229
|
+
.task-arrow { color: v-bind(taskColor); font-size: 16px; font-weight: bold; }
|
|
230
|
+
|
|
231
|
+
/* Modal base */
|
|
232
|
+
.modal-overlay {
|
|
233
|
+
position: fixed; inset: 0; background: rgba(0,0,0,0.45);
|
|
234
|
+
display: flex; align-items: center; justify-content: center;
|
|
235
|
+
z-index: 1000;
|
|
236
|
+
}
|
|
237
|
+
.modal-close { border: none; background: none; font-size: 18px; cursor: pointer; color: #999; }
|
|
238
|
+
|
|
239
|
+
/* Signature */
|
|
240
|
+
.sig-card {
|
|
241
|
+
width: 360px; background: #fff; border-radius: 12px; overflow: hidden;
|
|
242
|
+
}
|
|
243
|
+
.sig-header {
|
|
244
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
245
|
+
padding: 12px 16px; border-bottom: 1px solid #f0f0f0;
|
|
246
|
+
font-size: 15px; font-weight: 600;
|
|
247
|
+
}
|
|
248
|
+
.sig-body { position: relative; height: 200px; }
|
|
249
|
+
.sig-canvas { width: 100%; height: 100%; background: #fafafa; cursor: crosshair; }
|
|
250
|
+
.sig-placeholder {
|
|
251
|
+
position: absolute; inset: 0; display: flex; align-items: center;
|
|
252
|
+
justify-content: center; color: #ccc; font-size: 20px;
|
|
253
|
+
pointer-events: none; letter-spacing: 2px;
|
|
254
|
+
}
|
|
255
|
+
.sig-footer { display: flex; gap: 12px; padding: 12px 16px; border-top: 1px solid #f0f0f0; }
|
|
256
|
+
.btn-clear {
|
|
257
|
+
flex: 1; padding: 10px; border: 1px solid #d9d9d9;
|
|
258
|
+
border-radius: 6px; background: #fff; font-size: 14px; cursor: pointer;
|
|
259
|
+
}
|
|
260
|
+
.btn-confirm-sig {
|
|
261
|
+
flex: 1; padding: 10px; border: none; border-radius: 6px;
|
|
262
|
+
background: #eb2f96; color: #fff; font-size: 14px; cursor: pointer;
|
|
263
|
+
}
|
|
264
|
+
.btn-confirm-sig:disabled { opacity: 0.4; cursor: not-allowed; }
|
|
265
|
+
.btn-cancel {
|
|
266
|
+
flex: 1; padding: 10px; border: 1px solid #d9d9d9;
|
|
267
|
+
border-radius: 6px; background: #fff; font-size: 14px; cursor: pointer;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/* Map */
|
|
271
|
+
.map-card { width: 340px; background: #fff; border-radius: 12px; overflow: hidden; }
|
|
272
|
+
.map-header {
|
|
273
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
274
|
+
padding: 12px 16px; border-bottom: 1px solid #f0f0f0;
|
|
275
|
+
font-size: 15px; font-weight: 600;
|
|
276
|
+
}
|
|
277
|
+
.map-placeholder {
|
|
278
|
+
height: 200px; background: #e6f7ff; display: flex; flex-direction: column;
|
|
279
|
+
align-items: center; justify-content: center; gap: 8px;
|
|
280
|
+
}
|
|
281
|
+
.map-pin { font-size: 48px; }
|
|
282
|
+
.map-placeholder p { margin: 0; font-size: 14px; color: #333; }
|
|
283
|
+
.map-hint { font-size: 12px !important; color: #999 !important; }
|
|
284
|
+
.map-footer { padding: 12px 16px; border-top: 1px solid #f0f0f0; }
|
|
285
|
+
|
|
286
|
+
/* Generic native */
|
|
287
|
+
.native-card {
|
|
288
|
+
width: 280px; background: #fff; border-radius: 12px;
|
|
289
|
+
padding: 24px; text-align: center;
|
|
290
|
+
}
|
|
291
|
+
.native-icon { font-size: 40px; margin-bottom: 12px; }
|
|
292
|
+
.native-title { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
|
|
293
|
+
.native-hint { font-size: 11px; color: #faad14; margin-bottom: 4px; }
|
|
294
|
+
.native-desc {
|
|
295
|
+
font-size: 12px; color: #999; background: #f5f5f5;
|
|
296
|
+
padding: 4px 10px; border-radius: 4px; margin-bottom: 20px; display: inline-block;
|
|
297
|
+
}
|
|
298
|
+
.native-actions { display: flex; gap: 12px; }
|
|
299
|
+
</style>
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* 子表单 Task — 弹出 Modal 包含 mock 字段,用户填写后确认回写
|
|
4
|
+
*/
|
|
5
|
+
import { ref, computed } from 'vue'
|
|
6
|
+
import type { FormItem } from '@agentprismform/core'
|
|
7
|
+
import { completeTask } from '@agentprismform/render-task'
|
|
8
|
+
|
|
9
|
+
const props = defineProps<{
|
|
10
|
+
item: FormItem
|
|
11
|
+
field: any
|
|
12
|
+
formCore: any
|
|
13
|
+
}>()
|
|
14
|
+
|
|
15
|
+
const visible = ref(false)
|
|
16
|
+
const mockFields = ref<Record<string, string>>({})
|
|
17
|
+
|
|
18
|
+
// 根据 taskType 生成不同的 mock 字段
|
|
19
|
+
const fieldConfig = computed(() => {
|
|
20
|
+
const taskType = (props.item.props as any)?.taskType as string
|
|
21
|
+
const configs: Record<string, { label: string; key: string; placeholder: string }[]> = {
|
|
22
|
+
contact_info: [
|
|
23
|
+
{ label: '联系人姓名', key: 'name', placeholder: '请输入姓名' },
|
|
24
|
+
{ label: '关系', key: 'relation', placeholder: '如:朋友、同事' },
|
|
25
|
+
{ label: '联系电话', key: 'phone', placeholder: '请输入手机号' },
|
|
26
|
+
],
|
|
27
|
+
business_info: [
|
|
28
|
+
{ label: '企业名称', key: 'company', placeholder: '请输入企业名称' },
|
|
29
|
+
{ label: '经营范围', key: 'scope', placeholder: '请输入经营范围' },
|
|
30
|
+
],
|
|
31
|
+
card_info_auth: [
|
|
32
|
+
{ label: '姓名', key: 'name', placeholder: '请输入姓名' },
|
|
33
|
+
{ label: '身份证号', key: 'idNumber', placeholder: '请输入身份证号' },
|
|
34
|
+
],
|
|
35
|
+
default: [
|
|
36
|
+
{ label: '字段1', key: 'field1', placeholder: '请输入' },
|
|
37
|
+
{ label: '字段2', key: 'field2', placeholder: '请输入' },
|
|
38
|
+
],
|
|
39
|
+
}
|
|
40
|
+
return configs[taskType] || configs['default']
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
function open() {
|
|
44
|
+
// 初始化空值
|
|
45
|
+
mockFields.value = {}
|
|
46
|
+
fieldConfig.value.forEach(f => { mockFields.value[f.key] = '' })
|
|
47
|
+
visible.value = true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function confirm() {
|
|
51
|
+
visible.value = false
|
|
52
|
+
completeTask(props.formCore, props.item.key, {
|
|
53
|
+
...mockFields.value,
|
|
54
|
+
_completed: true,
|
|
55
|
+
_completedAt: new Date().toISOString(),
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function cancel() {
|
|
60
|
+
visible.value = false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function onOverlayClick(e: MouseEvent) {
|
|
64
|
+
e.stopPropagation()
|
|
65
|
+
if (e.target === e.currentTarget) cancel()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const hasValue = computed(() => {
|
|
69
|
+
const v = props.field?.value
|
|
70
|
+
return v && typeof v === 'object' && v._completed
|
|
71
|
+
})
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<template>
|
|
75
|
+
<div class="task-subform" @click="open">
|
|
76
|
+
<div class="task-trigger" :class="{ completed: hasValue }">
|
|
77
|
+
<span class="task-icon">📋</span>
|
|
78
|
+
<span class="task-label">{{ hasValue ? '✅ 已完成' : (item.placeholder || '点击填写子表单') }}</span>
|
|
79
|
+
<span class="task-arrow">▸</span>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
<!-- Modal -->
|
|
83
|
+
<div v-if="visible" class="modal-overlay" @click="onOverlayClick">
|
|
84
|
+
<div class="modal-card">
|
|
85
|
+
<div class="modal-header">
|
|
86
|
+
<span>{{ item.label || '子表单' }}</span>
|
|
87
|
+
<button class="modal-close" @click="cancel">✕</button>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="modal-body">
|
|
90
|
+
<div v-for="f in fieldConfig" :key="f.key" class="modal-field">
|
|
91
|
+
<label>{{ f.label }}</label>
|
|
92
|
+
<input
|
|
93
|
+
v-model="mockFields[f.key]"
|
|
94
|
+
:placeholder="f.placeholder"
|
|
95
|
+
class="modal-input"
|
|
96
|
+
/>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
<div class="modal-footer">
|
|
100
|
+
<button class="btn-cancel" @click="cancel">取消</button>
|
|
101
|
+
<button class="btn-confirm" @click="confirm">确认</button>
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
</template>
|
|
107
|
+
|
|
108
|
+
<style scoped>
|
|
109
|
+
.task-subform { user-select: none; }
|
|
110
|
+
.task-trigger {
|
|
111
|
+
display: flex; align-items: center; gap: 8px;
|
|
112
|
+
padding: 10px 12px; border: 1px solid #722ed1;
|
|
113
|
+
border-radius: 8px; background: #f9f0ff; cursor: pointer;
|
|
114
|
+
}
|
|
115
|
+
.task-trigger:active { background: #efdbff; }
|
|
116
|
+
.task-trigger.completed { border-color: #52c41a; background: #f6ffed; }
|
|
117
|
+
.task-icon { font-size: 18px; }
|
|
118
|
+
.task-label { flex: 1; font-size: 14px; color: #333; }
|
|
119
|
+
.task-arrow { color: #722ed1; font-size: 16px; font-weight: bold; }
|
|
120
|
+
|
|
121
|
+
/* Modal */
|
|
122
|
+
.modal-overlay {
|
|
123
|
+
position: fixed; inset: 0; background: rgba(0,0,0,0.45);
|
|
124
|
+
display: flex; align-items: flex-end; justify-content: center;
|
|
125
|
+
z-index: 1000;
|
|
126
|
+
}
|
|
127
|
+
.modal-card {
|
|
128
|
+
width: 100%; max-width: 480px; max-height: 70vh;
|
|
129
|
+
background: #fff; border-radius: 16px 16px 0 0; overflow: auto;
|
|
130
|
+
}
|
|
131
|
+
.modal-header {
|
|
132
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
133
|
+
padding: 16px 20px; border-bottom: 1px solid #f0f0f0;
|
|
134
|
+
font-size: 16px; font-weight: 600;
|
|
135
|
+
}
|
|
136
|
+
.modal-close { border: none; background: none; font-size: 18px; cursor: pointer; color: #999; }
|
|
137
|
+
.modal-body { padding: 16px 20px; }
|
|
138
|
+
.modal-field { margin-bottom: 14px; }
|
|
139
|
+
.modal-field label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; }
|
|
140
|
+
.modal-input {
|
|
141
|
+
width: 100%; padding: 10px 12px; border: 1px solid #d9d9d9;
|
|
142
|
+
border-radius: 6px; font-size: 14px; box-sizing: border-box;
|
|
143
|
+
}
|
|
144
|
+
.modal-input:focus { outline: none; border-color: #722ed1; }
|
|
145
|
+
.modal-footer {
|
|
146
|
+
display: flex; gap: 12px; padding: 16px 20px; border-top: 1px solid #f0f0f0;
|
|
147
|
+
}
|
|
148
|
+
.btn-cancel {
|
|
149
|
+
flex: 1; padding: 12px; border: 1px solid #d9d9d9;
|
|
150
|
+
border-radius: 8px; background: #fff; font-size: 14px; cursor: pointer;
|
|
151
|
+
}
|
|
152
|
+
.btn-confirm {
|
|
153
|
+
flex: 1; padding: 12px; border: none; border-radius: 8px;
|
|
154
|
+
background: #722ed1; color: #fff; font-size: 14px; cursor: pointer;
|
|
155
|
+
}
|
|
156
|
+
</style>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { reactive, onUnmounted, getCurrentInstance } from 'vue'
|
|
2
|
+
import type { FormSchema, FormCore } from '@agentprismform/core'
|
|
3
|
+
import { createFormRenderState } from '@agentprismform/render'
|
|
4
|
+
import type { ResolvedFormGroup } from '@agentprismform/render'
|
|
5
|
+
import type { ResolveOptions } from '@agentprismform/render'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Vue 3 composable:将 FormCore 的字段状态桥接到 form-render 的解析配置。
|
|
9
|
+
* @param schema - 表单 Schema
|
|
10
|
+
* @param formCore - FormCore 实例
|
|
11
|
+
* @param options - 解析选项(如 excludeTaskAndAgreement 控制是否过滤 task/agreement)
|
|
12
|
+
*/
|
|
13
|
+
export function useFormRender(schema: FormSchema, formCore: FormCore, options?: ResolveOptions) {
|
|
14
|
+
const state = createFormRenderState(schema, undefined, options)
|
|
15
|
+
|
|
16
|
+
const ctx = reactive<{
|
|
17
|
+
groups: ResolvedFormGroup[]
|
|
18
|
+
fields: Record<string, any>
|
|
19
|
+
}>({
|
|
20
|
+
groups: state.groups,
|
|
21
|
+
fields: {},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
function syncFields() {
|
|
25
|
+
const fs: Record<string, any> = {}
|
|
26
|
+
for (const key of Object.keys(formCore.fields)) {
|
|
27
|
+
fs[key] = { ...formCore.fields[key] }
|
|
28
|
+
}
|
|
29
|
+
Object.assign(ctx.fields, fs)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function handleAfterChange() {
|
|
33
|
+
syncFields()
|
|
34
|
+
const fs: Record<string, any> = {}
|
|
35
|
+
for (const key of Object.keys(formCore.fields)) {
|
|
36
|
+
fs[key] = formCore.fields[key]
|
|
37
|
+
}
|
|
38
|
+
state.update(fs)
|
|
39
|
+
// 原地更新数组,保持 reactive 引用有效
|
|
40
|
+
ctx.groups.splice(0, ctx.groups.length, ...state.groups)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
formCore.on('afterChange', handleAfterChange)
|
|
44
|
+
|
|
45
|
+
function destroy() {
|
|
46
|
+
formCore.off('afterChange', handleAfterChange)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// demo 等场景会在 setup 外调用;仅在组件 setup 内注册 onUnmounted
|
|
50
|
+
if (getCurrentInstance()) {
|
|
51
|
+
onUnmounted(destroy)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
syncFields()
|
|
55
|
+
const fs: Record<string, any> = {}
|
|
56
|
+
for (const key of Object.keys(formCore.fields)) {
|
|
57
|
+
fs[key] = formCore.fields[key]
|
|
58
|
+
}
|
|
59
|
+
state.update(fs)
|
|
60
|
+
ctx.groups = state.groups
|
|
61
|
+
|
|
62
|
+
return { groups: ctx.groups, fields: ctx.fields, formCore, destroy }
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task 工具 — 统一从 @agentprismform/render-task 导入
|
|
3
|
+
*/
|
|
4
|
+
export {
|
|
5
|
+
classifyTask,
|
|
6
|
+
resolveTaskByKey,
|
|
7
|
+
completeTask,
|
|
8
|
+
TASK_TYPE_LABELS,
|
|
9
|
+
TASK_CATEGORY_LABELS,
|
|
10
|
+
} from '@agentprismform/render-task'
|
|
11
|
+
export type { TaskUICategory } from '@agentprismform/render-task'
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* form-render-vue 纯逻辑工具函数
|
|
3
|
+
* 从 FormItem.vue 中提取的可测试纯逻辑,避免依赖 Vue 运行时。
|
|
4
|
+
*/
|
|
5
|
+
import { resolveTaskByKey } from '@agentprismform/render-task'
|
|
6
|
+
|
|
7
|
+
// ═══════════════════════════════════════════════════════════════
|
|
8
|
+
// FormItem — typeMap 与 effectiveItem
|
|
9
|
+
// ═══════════════════════════════════════════════════════════════
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 表单控件类型到组件名称的映射
|
|
13
|
+
* 注:运行时代码使用 Vue 组件引用,测试仅校验映射键值。
|
|
14
|
+
*/
|
|
15
|
+
export const TYPE_MAP: Record<string, string> = {
|
|
16
|
+
input: 'InputControl',
|
|
17
|
+
textarea: 'InputControl',
|
|
18
|
+
number: 'InputControl',
|
|
19
|
+
idcard: 'InputControl',
|
|
20
|
+
phone: 'InputControl',
|
|
21
|
+
bankCard: 'InputControl',
|
|
22
|
+
select: 'SelectControl',
|
|
23
|
+
cascader: 'CascaderControl',
|
|
24
|
+
address: 'AddressControl',
|
|
25
|
+
address5: 'AddressControl',
|
|
26
|
+
addressPinyin: 'AddressControl',
|
|
27
|
+
search: 'SearchControl',
|
|
28
|
+
agreement: 'AgreementControl',
|
|
29
|
+
task: 'TaskControl',
|
|
30
|
+
date: 'DateControl',
|
|
31
|
+
dateRange: 'DateControl',
|
|
32
|
+
verifyCode: 'VerifyCodeControl',
|
|
33
|
+
imageUpload: 'ImageUploadControl',
|
|
34
|
+
slider: 'SliderControl',
|
|
35
|
+
signature: 'TaskControl',
|
|
36
|
+
custom: 'InputControl',
|
|
37
|
+
list: 'ListControl',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 每种类型实际对应的运行时组件名 */
|
|
41
|
+
export type ControlComponentName =
|
|
42
|
+
| 'InputControl'
|
|
43
|
+
| 'SelectControl'
|
|
44
|
+
| 'CascaderControl'
|
|
45
|
+
| 'AddressControl'
|
|
46
|
+
| 'SearchControl'
|
|
47
|
+
| 'AgreementControl'
|
|
48
|
+
| 'TaskControl'
|
|
49
|
+
| 'ListControl'
|
|
50
|
+
| 'DateControl'
|
|
51
|
+
| 'VerifyCodeControl'
|
|
52
|
+
| 'ImageUploadControl'
|
|
53
|
+
| 'SliderControl'
|
|
54
|
+
|
|
55
|
+
/** 所有已声明的控件类型 */
|
|
56
|
+
export const ALL_CONTROL_TYPES = Object.keys(TYPE_MAP)
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 根据 item.key 和 item.type 解析应该使用的控件组件名。
|
|
60
|
+
*
|
|
61
|
+
* 规则:
|
|
62
|
+
* 1. 如果 key 命中已知 taskType → TaskControl(自动识别 task 字段)
|
|
63
|
+
* 2. 否则按 TYPE_MAP[type] 返回,未匹配则回退 InputControl
|
|
64
|
+
*/
|
|
65
|
+
export function resolveControlComponentName(key: string, type: string): ControlComponentName {
|
|
66
|
+
if (resolveTaskByKey(key)) return 'TaskControl'
|
|
67
|
+
return (TYPE_MAP[type] as ControlComponentName) || 'InputControl'
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 计算 effectiveItem:将 task 相关的 taskType / taskCategory 自动注入到 item.props 中。
|
|
72
|
+
*
|
|
73
|
+
* @param itemKey 表单字段 key
|
|
74
|
+
* @param itemType 原始 item.type(保留参数,与 Taro/RN 版签名一致)
|
|
75
|
+
* @param itemProps 原始 item.raw.props
|
|
76
|
+
* @returns 注入后的 props,若不命中则返回原始 props
|
|
77
|
+
*/
|
|
78
|
+
export function computeEffectiveProps(
|
|
79
|
+
itemKey: string,
|
|
80
|
+
_itemType: string,
|
|
81
|
+
itemProps: Record<string, any>,
|
|
82
|
+
): Record<string, any> {
|
|
83
|
+
const category = resolveTaskByKey(itemKey)
|
|
84
|
+
if (!category) return itemProps
|
|
85
|
+
|
|
86
|
+
const taskCategory =
|
|
87
|
+
category === 'customer'
|
|
88
|
+
? 'CUSTOMER_TASK'
|
|
89
|
+
: category === 'inline'
|
|
90
|
+
? 'inline'
|
|
91
|
+
: 'TASKS'
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...(itemProps || {}),
|
|
95
|
+
taskType: itemKey,
|
|
96
|
+
taskCategory,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ═══════════════════════════════════════════════════════════════
|
|
101
|
+
// FormItem — onChange 载荷标准化
|
|
102
|
+
// ═══════════════════════════════════════════════════════════════
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* onChange 载荷标准化结果
|
|
106
|
+
*/
|
|
107
|
+
export interface NormalizedPayload {
|
|
108
|
+
/** 标准化后的值 */
|
|
109
|
+
value: any
|
|
110
|
+
/** 事件类型 (inputChange / pickChange / searchChange 等) */
|
|
111
|
+
eventType?: string
|
|
112
|
+
/** 除 value 和 eventType 外的额外字段,统一归入 extraFields */
|
|
113
|
+
extraFields?: Record<string, any>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 将控件 change 事件的各种载荷格式标准化为统一结构。
|
|
118
|
+
*
|
|
119
|
+
* 支持格式:
|
|
120
|
+
* - 原始值 payload = 'someString' → { value: 'someString' }
|
|
121
|
+
* - 对象 payload = { value: 'x', eventType: 'pickChange' }
|
|
122
|
+
* - 带额外字段 payload = { value: 'x', eventType: 'pickChange', code: '001', name: '北京' }
|
|
123
|
+
*
|
|
124
|
+
* extraFields 包含除 value 和 eventType 之外的所有字段。
|
|
125
|
+
*/
|
|
126
|
+
export function normalizeControlPayload(payload: any): NormalizedPayload {
|
|
127
|
+
// 非对象:直接作为 value
|
|
128
|
+
if (typeof payload !== 'object' || payload === null) {
|
|
129
|
+
return { value: payload }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const value = payload.value !== undefined ? payload.value : payload
|
|
133
|
+
const eventType = payload.eventType
|
|
134
|
+
|
|
135
|
+
const { value: _v, eventType: _e, ...extra } = payload
|
|
136
|
+
const extraKeys = Object.keys(extra)
|
|
137
|
+
|
|
138
|
+
if (extraKeys.length > 0) {
|
|
139
|
+
return { value, eventType, extraFields: extra }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return { value, eventType }
|
|
143
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as PrismForm } from './components/PrismForm.vue'
|
|
2
|
+
export { default as FormRender } from './components/FormRender.vue'
|
|
3
|
+
export { default as FormGroup } from './components/FormGroup.vue'
|
|
4
|
+
export { default as FormItem } from './components/FormItem.vue'
|
|
5
|
+
export { useFormRender } from './composables/useFormRender'
|
|
6
|
+
export { setTaskHandlers } from './taskHandlers'
|
|
7
|
+
export { createFetchHostHandlers } from '@agentprismform/render'
|
|
8
|
+
export type { FetchHostHandlersOptions, UniversalHostHandlers } from '@agentprismform/render'
|
package/README.md
DELETED