@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,255 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, watch } from 'vue'
|
|
3
|
+
import type { FormItem } from '@agentprismform/core'
|
|
4
|
+
import type { FetchLinkageFn, LinkageOption } from '@agentprismform/render'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
item: FormItem
|
|
8
|
+
field: any
|
|
9
|
+
formCore: any
|
|
10
|
+
onFetchLinkage?: FetchLinkageFn
|
|
11
|
+
}>()
|
|
12
|
+
const emit = defineEmits(['change'])
|
|
13
|
+
|
|
14
|
+
const url = computed(() => props.item?.props?.linkageUrl || 'service/geo_code')
|
|
15
|
+
const mapLevel = computed(() => props.item?.props?.mapLevel || 3)
|
|
16
|
+
|
|
17
|
+
const showPanel = ref(false)
|
|
18
|
+
const currentIndex = ref(0)
|
|
19
|
+
const requestLoading = ref(false)
|
|
20
|
+
const hasFinish = ref(false)
|
|
21
|
+
const dataList = ref<LinkageOption[]>([])
|
|
22
|
+
const textList = ref<LinkageOption[]>([{ adcode: '', name: '请选择' }])
|
|
23
|
+
const listMap = new Map<string, LinkageOption[]>()
|
|
24
|
+
|
|
25
|
+
const displayText = computed(() => {
|
|
26
|
+
const val = props.field?.value
|
|
27
|
+
if (Array.isArray(val) && val.length) return val.map((v: any) => v.name).join('')
|
|
28
|
+
if (props.field?.showValue) return props.field.showValue
|
|
29
|
+
// fallback: construct from value parts
|
|
30
|
+
if (val && typeof val === 'object') {
|
|
31
|
+
const parts = [val.province, val.city, val.country].filter(Boolean)
|
|
32
|
+
if (parts.length) return parts.join('')
|
|
33
|
+
}
|
|
34
|
+
if (props.field?.province) {
|
|
35
|
+
return [props.field.province, props.field.city, props.field.country].filter(Boolean).join('')
|
|
36
|
+
}
|
|
37
|
+
// ultimate fallback: plain string value
|
|
38
|
+
if (typeof val === 'string' && val) return val
|
|
39
|
+
return ''
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const crumbItems = computed(() => textList.value.slice(0, mapLevel.value))
|
|
43
|
+
|
|
44
|
+
function getFetcher(): FetchLinkageFn {
|
|
45
|
+
if (props.onFetchLinkage) return props.onFetchLinkage
|
|
46
|
+
if ((props.formCore as any)?._linkageFetcher) return (props.formCore as any)._linkageFetcher
|
|
47
|
+
return async () => ({ data: [] })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function linkageSearch(parentCode?: string) {
|
|
51
|
+
requestLoading.value = true
|
|
52
|
+
const fetcher = getFetcher()
|
|
53
|
+
const selected = textList.value.filter(i => i.adcode)
|
|
54
|
+
const params = {
|
|
55
|
+
province_code: selected[0]?.adcode || '',
|
|
56
|
+
city_code: selected[1]?.adcode || '',
|
|
57
|
+
district_code: selected[2]?.adcode || '',
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const res = await fetcher(params, url.value)
|
|
61
|
+
if (res.data === null) {
|
|
62
|
+
textList.value = textList.value.filter(i => i.adcode)
|
|
63
|
+
hasFinish.value = true
|
|
64
|
+
requestLoading.value = false
|
|
65
|
+
confirmSelection()
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
dataList.value = res.data || []
|
|
69
|
+
const cacheKey = parentCode || params.district_code || params.city_code || params.province_code || 'root'
|
|
70
|
+
if (dataList.value.length > 0) listMap.set(cacheKey, dataList.value)
|
|
71
|
+
} catch { /* ignore */ }
|
|
72
|
+
finally { requestLoading.value = false }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function open() {
|
|
76
|
+
if (props.field?.disabled) return
|
|
77
|
+
currentIndex.value = 0
|
|
78
|
+
const val = props.field?.value
|
|
79
|
+
if (Array.isArray(val) && val.length && val[0].code) {
|
|
80
|
+
textList.value = val.map((v: any) => ({ adcode: v.code, name: v.name }))
|
|
81
|
+
hasFinish.value = textList.value.length >= 2
|
|
82
|
+
} else {
|
|
83
|
+
textList.value = [{ adcode: '', name: '请选择' }]
|
|
84
|
+
hasFinish.value = false
|
|
85
|
+
}
|
|
86
|
+
showPanel.value = true
|
|
87
|
+
const cached = listMap.get('root')
|
|
88
|
+
if (cached) dataList.value = cached
|
|
89
|
+
else linkageSearch('root')
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function closePanel() { showPanel.value = false }
|
|
93
|
+
|
|
94
|
+
function selectItem(item: LinkageOption) {
|
|
95
|
+
if (requestLoading.value || !item.adcode) return
|
|
96
|
+
const SPEC: Record<string, number> = { '710000': 1, '810000': 2, '820000': 2 }
|
|
97
|
+
const ntl = [...textList.value]
|
|
98
|
+
item.brother = dataList.value
|
|
99
|
+
ntl[currentIndex.value] = item
|
|
100
|
+
|
|
101
|
+
const max = SPEC[item.adcode]
|
|
102
|
+
if (max !== undefined) {
|
|
103
|
+
ntl.splice(max, ntl.length - max)
|
|
104
|
+
textList.value = ntl.filter(i => i.adcode)
|
|
105
|
+
hasFinish.value = true
|
|
106
|
+
confirmSelection()
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (currentIndex.value < mapLevel.value - 1) {
|
|
111
|
+
ntl[currentIndex.value + 1] = { adcode: '', name: '' }
|
|
112
|
+
ntl.splice(currentIndex.value + 2)
|
|
113
|
+
}
|
|
114
|
+
currentIndex.value += 1
|
|
115
|
+
textList.value = ntl.slice(0, mapLevel.value)
|
|
116
|
+
|
|
117
|
+
const filled = ntl.filter(i => i.adcode)
|
|
118
|
+
if (filled.length >= mapLevel.value) { hasFinish.value = true; confirmSelection(); return }
|
|
119
|
+
|
|
120
|
+
const cached = listMap.get(item.adcode)
|
|
121
|
+
if (cached) { dataList.value = cached }
|
|
122
|
+
else { linkageSearch(item.adcode) }
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function selectCrumb(index: number) {
|
|
126
|
+
currentIndex.value = index
|
|
127
|
+
hasFinish.value = false
|
|
128
|
+
const truncated = textList.value.slice(0, index + 1)
|
|
129
|
+
if (!truncated[index].adcode) truncated[index] = { adcode: '', name: '请选择' }
|
|
130
|
+
textList.value = truncated
|
|
131
|
+
const item = textList.value[index]
|
|
132
|
+
if (item.adcode && item.brother) {
|
|
133
|
+
dataList.value = item.brother
|
|
134
|
+
} else {
|
|
135
|
+
const pc = index > 0 ? textList.value[index - 1]?.adcode : 'root'
|
|
136
|
+
const cached = listMap.get(pc)
|
|
137
|
+
if (cached) { dataList.value = cached }
|
|
138
|
+
else { linkageSearch(pc) }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function confirmSelection() {
|
|
143
|
+
const selected = textList.value.filter(i => i.adcode)
|
|
144
|
+
if (selected.length === 0) return
|
|
145
|
+
const result = selected.map(i => ({ code: i.adcode, name: i.name }))
|
|
146
|
+
const addr: Record<string, any> = { showValue: '' }
|
|
147
|
+
result.forEach((item, idx) => {
|
|
148
|
+
addr.showValue += item.name
|
|
149
|
+
if (idx === 0) { addr.province_code = item.code; addr.province = item.name }
|
|
150
|
+
if (idx === 1) { addr.city_code = item.code; addr.city = item.name }
|
|
151
|
+
if (idx === 2) { addr.country_code = item.code; addr.country = item.name }
|
|
152
|
+
})
|
|
153
|
+
emit('change', { value: result, eventType: 'pickChange', ...addr })
|
|
154
|
+
showPanel.value = false
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
watch(() => props.field?.value, (val) => {
|
|
158
|
+
if (!showPanel.value && Array.isArray(val) && val.length) {
|
|
159
|
+
textList.value = val.map((v: any) => ({ adcode: v.code, name: v.name }))
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
</script>
|
|
163
|
+
|
|
164
|
+
<template>
|
|
165
|
+
<div class="ctrl-address">
|
|
166
|
+
<div class="address-trigger" :class="{ disabled: field?.disabled, placeholder: !displayText }" @click="open">
|
|
167
|
+
<span>{{ displayText || item.placeholder || '请选择省市区' }}</span>
|
|
168
|
+
</div>
|
|
169
|
+
|
|
170
|
+
<Transition name="addr-fade">
|
|
171
|
+
<div v-if="showPanel" class="addr-mask" @click="closePanel">
|
|
172
|
+
<Transition name="addr-slide">
|
|
173
|
+
<div v-if="showPanel" class="addr-panel" @click.stop>
|
|
174
|
+
<div class="addr-hd">
|
|
175
|
+
<span class="addr-hd-cancel" @click="closePanel">取消</span>
|
|
176
|
+
<span class="addr-hd-title">选择地址</span>
|
|
177
|
+
<span class="addr-hd-ok" :class="{ on: hasFinish }" @click="hasFinish ? confirmSelection() : null">确定</span>
|
|
178
|
+
</div>
|
|
179
|
+
|
|
180
|
+
<div class="addr-crumbs">
|
|
181
|
+
<template v-for="(t, idx) in crumbItems" :key="idx">
|
|
182
|
+
<span class="addr-dot" :class="{ cur: idx === currentIndex, done: !!t.adcode && idx < currentIndex }" />
|
|
183
|
+
<span class="addr-label" :class="{ cur: idx === currentIndex, done: !!t.adcode }" @click="t.adcode ? selectCrumb(idx) : null">
|
|
184
|
+
{{ t.adcode ? t.name : '请选择' }}
|
|
185
|
+
</span>
|
|
186
|
+
<span v-if="idx < crumbItems.length - 1" class="addr-line" :class="{ done: !!t.adcode && idx < currentIndex }" />
|
|
187
|
+
</template>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<div class="addr-body">
|
|
191
|
+
<div v-if="requestLoading" class="addr-loading"><span class="addr-spinner" />加载中...</div>
|
|
192
|
+
<div v-for="opt in dataList" :key="opt.adcode" class="addr-item" :class="{ sel: textList[currentIndex]?.adcode === opt.adcode }" @click="selectItem(opt)">
|
|
193
|
+
<span>{{ opt.name }}</span>
|
|
194
|
+
<span v-if="textList[currentIndex]?.adcode === opt.adcode" class="addr-check">✓</span>
|
|
195
|
+
</div>
|
|
196
|
+
<div v-if="!requestLoading && dataList.length === 0" class="addr-empty">暂无数据</div>
|
|
197
|
+
</div>
|
|
198
|
+
|
|
199
|
+
<div class="addr-safe" />
|
|
200
|
+
</div>
|
|
201
|
+
</Transition>
|
|
202
|
+
</div>
|
|
203
|
+
</Transition>
|
|
204
|
+
</div>
|
|
205
|
+
</template>
|
|
206
|
+
|
|
207
|
+
<style scoped>
|
|
208
|
+
.ctrl-address { position: relative; }
|
|
209
|
+
.address-trigger { display: flex; align-items: center; font-size: 13px; cursor: pointer; color: #333; line-height: 20px; }
|
|
210
|
+
.address-trigger.disabled { color: #999; cursor: not-allowed; }
|
|
211
|
+
.address-trigger.placeholder { color: #bfbfbf; }
|
|
212
|
+
|
|
213
|
+
.addr-mask { position: fixed; inset: 0; z-index: 9000; background: rgba(0,0,0,0.5); }
|
|
214
|
+
.addr-panel { position: absolute; bottom: 0; left: 0; right: 0; background: #fff; border-radius: 16px 16px 0 0; max-height: 70vh; display: flex; flex-direction: column; overflow: hidden; }
|
|
215
|
+
|
|
216
|
+
.addr-hd { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; height: 44px; flex-shrink: 0; }
|
|
217
|
+
.addr-hd-cancel { font-size: 15px; color: rgba(0,0,0,0.65); cursor: pointer; }
|
|
218
|
+
.addr-hd-title { font-size: 16px; font-weight: 500; }
|
|
219
|
+
.addr-hd-ok { font-size: 15px; color: #1677FF; cursor: pointer; visibility: hidden; }
|
|
220
|
+
.addr-hd-ok.on { visibility: visible; }
|
|
221
|
+
|
|
222
|
+
.addr-crumbs { display: flex; align-items: center; padding: 6px 16px; min-height: 40px; border-bottom: 1px solid #f1f1f1; overflow-x: auto; white-space: nowrap; flex-shrink: 0; }
|
|
223
|
+
.addr-dot { width: 6px; height: 6px; border-radius: 50%; background: #1677FF; flex-shrink: 0; }
|
|
224
|
+
.addr-dot.cur, .addr-dot:not(.done) { background: #fff; border: 1px solid #1677FF; width: 5px; height: 5px; }
|
|
225
|
+
.addr-label { font-size: 13px; font-weight: 500; margin: 0 4px; color: rgba(0,0,0,0.35); flex-shrink: 0; max-width: 70px; overflow: hidden; text-overflow: ellipsis; }
|
|
226
|
+
.addr-label.done { color: rgba(0,0,0,0.85); cursor: pointer; }
|
|
227
|
+
.addr-label.cur { color: #1677FF; }
|
|
228
|
+
.addr-line { width: 14px; height: 1px; background: #e8e8e8; flex-shrink: 0; }
|
|
229
|
+
.addr-line.done { background: #1677FF; }
|
|
230
|
+
|
|
231
|
+
.addr-body { overflow-y: auto; flex: 1; position: relative; min-height: 120px; }
|
|
232
|
+
.addr-loading {
|
|
233
|
+
position: absolute; inset: 0; z-index: 2;
|
|
234
|
+
display: flex; align-items: center; justify-content: center; gap: 8px;
|
|
235
|
+
background: rgba(255,255,255,0.7); color: #1677FF; font-size: 13px;
|
|
236
|
+
}
|
|
237
|
+
.addr-spinner {
|
|
238
|
+
width: 16px; height: 16px; border: 2px solid #e8e8e8;
|
|
239
|
+
border-top-color: #1677FF; border-radius: 50%;
|
|
240
|
+
animation: addr-spin 0.6s linear infinite;
|
|
241
|
+
}
|
|
242
|
+
@keyframes addr-spin { to { transform: rotate(360deg); } }
|
|
243
|
+
.addr-empty { padding: 30px 0; text-align: center; color: rgba(0,0,0,0.25); font-size: 14px; }
|
|
244
|
+
.addr-item { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; font-size: 14px; line-height: 20px; cursor: pointer; color: rgba(0,0,0,0.85); }
|
|
245
|
+
.addr-item:active { background: #f5f5f5; }
|
|
246
|
+
.addr-item.sel { color: #1677FF; font-weight: 500; }
|
|
247
|
+
.addr-check { font-size: 14px; color: #1677FF; }
|
|
248
|
+
.addr-safe { height: env(safe-area-inset-bottom, 0px); flex-shrink: 0; }
|
|
249
|
+
|
|
250
|
+
.addr-fade-enter-active, .addr-fade-leave-active { transition: opacity .25s; }
|
|
251
|
+
.addr-fade-enter-from, .addr-fade-leave-to { opacity: 0; }
|
|
252
|
+
.addr-slide-enter-active { transition: transform .25s ease-out; }
|
|
253
|
+
.addr-slide-leave-active { transition: transform .2s ease-in; }
|
|
254
|
+
.addr-slide-enter-from, .addr-slide-leave-to { transform: translateY(100%); }
|
|
255
|
+
</style>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import type { FormItem } from '@agentprismform/core'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{ item: FormItem; field: any; formCore: any }>()
|
|
6
|
+
const emit = defineEmits(['change'])
|
|
7
|
+
|
|
8
|
+
const trueValue = computed(() => props.item.props?.trueValue ?? 'true')
|
|
9
|
+
const falseValue = computed(() => props.item.props?.falseValue ?? '')
|
|
10
|
+
const checked = computed(() => {
|
|
11
|
+
const v = props.field?.value
|
|
12
|
+
return v === trueValue.value || v === true || v === 1 || v === '1'
|
|
13
|
+
})
|
|
14
|
+
const labelText = computed(
|
|
15
|
+
() => props.item.label || props.item.props?.guideText || '本人已阅读并同意相关协议',
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
function onToggle() {
|
|
19
|
+
if (props.field?.disabled) return
|
|
20
|
+
const next = checked.value ? falseValue.value : trueValue.value
|
|
21
|
+
emit('change', { value: next, eventType: 'pickChange' })
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div class="ctrl-agreement">
|
|
27
|
+
<label class="agreement-row" @click.prevent="onToggle">
|
|
28
|
+
<span class="checkbox" :class="{ checked, disabled: field?.disabled }">
|
|
29
|
+
<span v-if="checked" class="check-mark">✓</span>
|
|
30
|
+
</span>
|
|
31
|
+
<span class="agreement-text">{{ labelText }}</span>
|
|
32
|
+
</label>
|
|
33
|
+
</div>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<style scoped>
|
|
37
|
+
.ctrl-agreement { padding: 4px 0; }
|
|
38
|
+
.agreement-row {
|
|
39
|
+
display: flex; align-items: flex-start; gap: 8px; cursor: pointer;
|
|
40
|
+
}
|
|
41
|
+
.checkbox {
|
|
42
|
+
width: 20px; height: 20px; border: 2px solid #d9d9d9; border-radius: 4px;
|
|
43
|
+
display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 1px;
|
|
44
|
+
}
|
|
45
|
+
.checkbox.checked { background: #1890ff; border-color: #1890ff; }
|
|
46
|
+
.checkbox.disabled { opacity: 0.5; }
|
|
47
|
+
.check-mark { color: #fff; font-size: 14px; }
|
|
48
|
+
.agreement-text { font-size: 13px; color: #666; line-height: 1.5; }
|
|
49
|
+
</style>
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import type { FormItem } from '@agentprismform/core'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{ item: FormItem; field: any; formCore: any }>()
|
|
6
|
+
const emit = defineEmits(['change'])
|
|
7
|
+
|
|
8
|
+
type Opt = { code: string; name: string; child?: Opt[] }
|
|
9
|
+
|
|
10
|
+
const showPanel = ref(false)
|
|
11
|
+
const path = ref<Opt[]>([])
|
|
12
|
+
|
|
13
|
+
const roots = computed<Opt[]>(() => (props.item?.initOptions || []) as Opt[])
|
|
14
|
+
|
|
15
|
+
const currentOptions = computed(() => {
|
|
16
|
+
if (path.value.length === 0) return roots.value
|
|
17
|
+
return path.value[path.value.length - 1]?.child || []
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const displayText = computed(() => {
|
|
21
|
+
const val = props.field?.value
|
|
22
|
+
if (!val) return ''
|
|
23
|
+
if (typeof val === 'object' && val !== null) {
|
|
24
|
+
if (Array.isArray((val as any).pathNames)) return (val as any).pathNames.join(' / ')
|
|
25
|
+
if ((val as any).name) return String((val as any).name)
|
|
26
|
+
if ((val as any).showValue) return String((val as any).showValue)
|
|
27
|
+
}
|
|
28
|
+
if (props.field?.showValue) return String(props.field.showValue)
|
|
29
|
+
return String(val)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const panelTitle = computed(() => props.item.props?.dialogTitle || props.item.label || '请选择')
|
|
33
|
+
|
|
34
|
+
function openPanel() {
|
|
35
|
+
if (props.field?.disabled) return
|
|
36
|
+
path.value = []
|
|
37
|
+
showPanel.value = true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function closePanel() {
|
|
41
|
+
showPanel.value = false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function selectOption(opt: Opt) {
|
|
45
|
+
const next = [...path.value, opt]
|
|
46
|
+
if (opt.child && opt.child.length > 0) {
|
|
47
|
+
path.value = next
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
emit('change', {
|
|
51
|
+
value: {
|
|
52
|
+
code: opt.code,
|
|
53
|
+
name: opt.name,
|
|
54
|
+
pathCodes: next.map((n) => n.code),
|
|
55
|
+
pathNames: next.map((n) => n.name),
|
|
56
|
+
},
|
|
57
|
+
eventType: 'pickChange',
|
|
58
|
+
})
|
|
59
|
+
showPanel.value = false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function goBack() {
|
|
63
|
+
path.value = path.value.slice(0, -1)
|
|
64
|
+
}
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<template>
|
|
68
|
+
<div class="ctrl-cascader">
|
|
69
|
+
<div
|
|
70
|
+
class="cascader-trigger"
|
|
71
|
+
:class="{ disabled: field?.disabled, placeholder: !displayText }"
|
|
72
|
+
@click="openPanel"
|
|
73
|
+
>
|
|
74
|
+
<span>{{ displayText || item.placeholder || '请选择' }}</span>
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<Transition name="panel">
|
|
78
|
+
<div v-if="showPanel" class="cascader-overlay" @click="closePanel">
|
|
79
|
+
<div class="cascader-panel" role="dialog" :aria-label="panelTitle" @click.stop>
|
|
80
|
+
<div class="panel-header">
|
|
81
|
+
<button
|
|
82
|
+
v-if="path.length"
|
|
83
|
+
type="button"
|
|
84
|
+
class="panel-back"
|
|
85
|
+
aria-label="返回上一级"
|
|
86
|
+
@click="goBack"
|
|
87
|
+
>
|
|
88
|
+
‹
|
|
89
|
+
</button>
|
|
90
|
+
<span class="panel-title">{{ panelTitle }}</span>
|
|
91
|
+
<button type="button" class="panel-close" aria-label="关闭" @click="closePanel">×</button>
|
|
92
|
+
</div>
|
|
93
|
+
<div class="panel-path" v-if="path.length">
|
|
94
|
+
{{ path.map((p) => p.name).join(' / ') }}
|
|
95
|
+
</div>
|
|
96
|
+
<div class="panel-body" role="listbox">
|
|
97
|
+
<div
|
|
98
|
+
v-for="opt in currentOptions"
|
|
99
|
+
:key="opt.code"
|
|
100
|
+
class="option-card"
|
|
101
|
+
role="option"
|
|
102
|
+
@click="selectOption(opt)"
|
|
103
|
+
>
|
|
104
|
+
<span class="option-text">{{ opt.name }}</span>
|
|
105
|
+
<span class="option-arrow" v-if="opt.child?.length">›</span>
|
|
106
|
+
</div>
|
|
107
|
+
<div v-if="!currentOptions.length" class="option-empty">暂无选项</div>
|
|
108
|
+
</div>
|
|
109
|
+
<div class="safe-area-bottom" />
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</Transition>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|
|
115
|
+
|
|
116
|
+
<style scoped>
|
|
117
|
+
.ctrl-cascader { position: relative; }
|
|
118
|
+
.cascader-trigger {
|
|
119
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
120
|
+
font-size: 13px; cursor: pointer; color: #333; line-height: 20px;
|
|
121
|
+
}
|
|
122
|
+
.cascader-trigger.disabled { color: #999; cursor: not-allowed; }
|
|
123
|
+
.cascader-trigger.placeholder { color: #bfbfbf; }
|
|
124
|
+
.cascader-overlay {
|
|
125
|
+
position: fixed; inset: 0; z-index: 999;
|
|
126
|
+
display: flex; align-items: flex-end; justify-content: center;
|
|
127
|
+
background: rgba(0, 0, 0, 0.3);
|
|
128
|
+
}
|
|
129
|
+
.cascader-panel {
|
|
130
|
+
width: 100%; max-width: 500px; max-height: 60vh;
|
|
131
|
+
display: flex; flex-direction: column; background: #F7F8FA;
|
|
132
|
+
border-radius: 20px 20px 0 0; overflow: hidden;
|
|
133
|
+
}
|
|
134
|
+
.panel-header {
|
|
135
|
+
display: flex; align-items: center; gap: 8px; padding: 14px 16px; background: #fff;
|
|
136
|
+
}
|
|
137
|
+
.panel-title { flex: 1; text-align: center; font-size: 15px; font-weight: 600; color: #333; }
|
|
138
|
+
.panel-back, .panel-close {
|
|
139
|
+
width: 28px; height: 28px; border: none; background: transparent; font-size: 22px;
|
|
140
|
+
color: #666; cursor: pointer; line-height: 1;
|
|
141
|
+
}
|
|
142
|
+
.panel-path {
|
|
143
|
+
padding: 0 16px 8px; font-size: 12px; color: #1989fa; background: #fff;
|
|
144
|
+
}
|
|
145
|
+
.panel-body { overflow: auto; padding: 8px 12px 16px; }
|
|
146
|
+
.option-card {
|
|
147
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
148
|
+
background: #fff; border-radius: 10px; padding: 14px 12px; margin-bottom: 8px; cursor: pointer;
|
|
149
|
+
}
|
|
150
|
+
.option-text { font-size: 14px; color: #333; }
|
|
151
|
+
.option-arrow { color: #bbb; font-size: 18px; }
|
|
152
|
+
.option-empty { text-align: center; color: #999; font-size: 13px; padding: 24px 0; }
|
|
153
|
+
.safe-area-bottom { height: env(safe-area-inset-bottom, 0); }
|
|
154
|
+
.panel-enter-active, .panel-leave-active { transition: opacity .2s ease; }
|
|
155
|
+
.panel-enter-active .cascader-panel,
|
|
156
|
+
.panel-leave-active .cascader-panel { transition: transform .2s ease; }
|
|
157
|
+
.panel-enter-from, .panel-leave-to { opacity: 0; }
|
|
158
|
+
.panel-enter-from .cascader-panel, .panel-leave-to .cascader-panel { transform: translateY(40px); }
|
|
159
|
+
</style>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
3
|
+
import type { FormItem } from '@agentprismform/core'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{ item: FormItem; field: any; formCore: any }>()
|
|
6
|
+
const emit = defineEmits(['change'])
|
|
7
|
+
|
|
8
|
+
const isRange = computed(() => props.item.type === 'dateRange')
|
|
9
|
+
|
|
10
|
+
const singleValue = ref(normalizeSingle(props.field?.value))
|
|
11
|
+
const rangeStart = ref(normalizeRange(props.field?.value)[0])
|
|
12
|
+
const rangeEnd = ref(normalizeRange(props.field?.value)[1])
|
|
13
|
+
|
|
14
|
+
watch(
|
|
15
|
+
() => props.field?.value,
|
|
16
|
+
(v) => {
|
|
17
|
+
if (isRange.value) {
|
|
18
|
+
const [start, end] = normalizeRange(v)
|
|
19
|
+
rangeStart.value = start
|
|
20
|
+
rangeEnd.value = end
|
|
21
|
+
} else {
|
|
22
|
+
singleValue.value = normalizeSingle(v)
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
function normalizeSingle(v: unknown): string {
|
|
28
|
+
if (v == null || v === '') return ''
|
|
29
|
+
return String(v)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizeRange(v: unknown): [string, string] {
|
|
33
|
+
if (Array.isArray(v)) return [String(v[0] || ''), String(v[1] || '')]
|
|
34
|
+
if (v && typeof v === 'object') {
|
|
35
|
+
const obj = v as { start?: string; end?: string }
|
|
36
|
+
return [String(obj.start || ''), String(obj.end || '')]
|
|
37
|
+
}
|
|
38
|
+
return ['', '']
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function commitSingle(e: Event) {
|
|
42
|
+
const val = (e.target as HTMLInputElement).value || ''
|
|
43
|
+
singleValue.value = val
|
|
44
|
+
emit('change', { value: val, eventType: 'pickChange' })
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function commitRange() {
|
|
48
|
+
const start = rangeStart.value
|
|
49
|
+
const end = rangeEnd.value
|
|
50
|
+
const value = start || end ? [start, end] : ''
|
|
51
|
+
emit('change', { value, eventType: 'pickChange' })
|
|
52
|
+
}
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div class="ctrl-date">
|
|
57
|
+
<template v-if="isRange">
|
|
58
|
+
<input
|
|
59
|
+
class="ctrl-date-input"
|
|
60
|
+
type="date"
|
|
61
|
+
:value="rangeStart"
|
|
62
|
+
:disabled="field?.disabled"
|
|
63
|
+
:aria-label="(item.label || '日期') + '开始'"
|
|
64
|
+
@change="(e) => { rangeStart = (e.target as HTMLInputElement).value; commitRange() }"
|
|
65
|
+
/>
|
|
66
|
+
<span class="ctrl-date-sep">至</span>
|
|
67
|
+
<input
|
|
68
|
+
class="ctrl-date-input"
|
|
69
|
+
type="date"
|
|
70
|
+
:value="rangeEnd"
|
|
71
|
+
:disabled="field?.disabled"
|
|
72
|
+
:aria-label="(item.label || '日期') + '结束'"
|
|
73
|
+
@change="(e) => { rangeEnd = (e.target as HTMLInputElement).value; commitRange() }"
|
|
74
|
+
/>
|
|
75
|
+
</template>
|
|
76
|
+
<input
|
|
77
|
+
v-else
|
|
78
|
+
class="ctrl-date-input"
|
|
79
|
+
type="date"
|
|
80
|
+
:value="singleValue"
|
|
81
|
+
:disabled="field?.disabled"
|
|
82
|
+
:aria-label="item.label || '日期'"
|
|
83
|
+
@change="commitSingle"
|
|
84
|
+
/>
|
|
85
|
+
</div>
|
|
86
|
+
</template>
|
|
87
|
+
|
|
88
|
+
<style scoped>
|
|
89
|
+
.ctrl-date { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
90
|
+
.ctrl-date-input {
|
|
91
|
+
flex: 1; min-width: 120px; border: none; outline: none; background: transparent;
|
|
92
|
+
font-size: 13px; color: #333; line-height: 20px;
|
|
93
|
+
}
|
|
94
|
+
.ctrl-date-input:disabled { color: #999; }
|
|
95
|
+
.ctrl-date-sep { font-size: 12px; color: #999; }
|
|
96
|
+
</style>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, inject, ref, unref, watch } from 'vue'
|
|
3
|
+
import type { FormItem } from '@agentprismform/core'
|
|
4
|
+
import {
|
|
5
|
+
FORM_UI_HOST_HANDLERS_KEY,
|
|
6
|
+
type FormUiHostHandlers,
|
|
7
|
+
} from '@agentprismform/render-ui'
|
|
8
|
+
|
|
9
|
+
const props = defineProps<{ item: FormItem; field: any; formCore: any }>()
|
|
10
|
+
const emit = defineEmits(['change'])
|
|
11
|
+
|
|
12
|
+
const hostHandlersInjected = inject<
|
|
13
|
+
FormUiHostHandlers | null | { value: FormUiHostHandlers | null }
|
|
14
|
+
>(FORM_UI_HOST_HANDLERS_KEY, null)
|
|
15
|
+
|
|
16
|
+
const urls = ref<string[]>(normalizeUrls(props.field?.value))
|
|
17
|
+
const busy = ref(false)
|
|
18
|
+
const hostError = ref('')
|
|
19
|
+
|
|
20
|
+
watch(
|
|
21
|
+
() => props.field?.value,
|
|
22
|
+
(v) => {
|
|
23
|
+
urls.value = normalizeUrls(v)
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const maxCount = computed(() => Number(props.item.props?.maxCount) || 1)
|
|
28
|
+
const canAdd = computed(
|
|
29
|
+
() => urls.value.length < maxCount.value && !props.field?.disabled && !busy.value,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
function normalizeUrls(v: unknown): string[] {
|
|
33
|
+
if (Array.isArray(v)) return v.map(String).filter(Boolean)
|
|
34
|
+
if (typeof v === 'string' && v) return [v]
|
|
35
|
+
return []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function onPick(e: Event) {
|
|
39
|
+
const input = e.target as HTMLInputElement
|
|
40
|
+
const files = Array.from(input.files || [])
|
|
41
|
+
input.value = ''
|
|
42
|
+
if (!files.length || props.field?.disabled) return
|
|
43
|
+
const room = maxCount.value - urls.value.length
|
|
44
|
+
const slice = files.slice(0, Math.max(0, room))
|
|
45
|
+
if (!slice.length) return
|
|
46
|
+
|
|
47
|
+
hostError.value = ''
|
|
48
|
+
busy.value = true
|
|
49
|
+
try {
|
|
50
|
+
const host = unref(hostHandlersInjected)
|
|
51
|
+
let next: string[]
|
|
52
|
+
if (host?.uploadFile) {
|
|
53
|
+
const uploaded: string[] = []
|
|
54
|
+
for (const file of slice) {
|
|
55
|
+
const res = await host.uploadFile(
|
|
56
|
+
{ name: file.name, size: file.size, raw: file },
|
|
57
|
+
{ item: props.item },
|
|
58
|
+
)
|
|
59
|
+
if (!res?.url) throw new Error('上传未返回 url')
|
|
60
|
+
uploaded.push(res.url)
|
|
61
|
+
}
|
|
62
|
+
next = [...urls.value, ...uploaded]
|
|
63
|
+
} else {
|
|
64
|
+
// 未注入宿主:仅本地预览,不伪造成功调用 uploadApi
|
|
65
|
+
next = [...urls.value, ...slice.map((file) => URL.createObjectURL(file))]
|
|
66
|
+
}
|
|
67
|
+
urls.value = next
|
|
68
|
+
emit('change', { value: next, eventType: 'pickChange' })
|
|
69
|
+
} catch (err: any) {
|
|
70
|
+
hostError.value = err?.message || '上传失败'
|
|
71
|
+
} finally {
|
|
72
|
+
busy.value = false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function removeAt(index: number) {
|
|
77
|
+
if (props.field?.disabled) return
|
|
78
|
+
const merged = urls.value.filter((_, i) => i !== index)
|
|
79
|
+
urls.value = merged
|
|
80
|
+
emit('change', { value: merged, eventType: 'pickChange' })
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<div class="ctrl-upload-wrap">
|
|
86
|
+
<div class="ctrl-upload">
|
|
87
|
+
<div v-for="(url, index) in urls" :key="url + index" class="ctrl-upload-thumb">
|
|
88
|
+
<img :src="url" alt="" />
|
|
89
|
+
<button
|
|
90
|
+
v-if="!field?.disabled"
|
|
91
|
+
type="button"
|
|
92
|
+
class="ctrl-upload-remove"
|
|
93
|
+
aria-label="删除图片"
|
|
94
|
+
@click="removeAt(index)"
|
|
95
|
+
>
|
|
96
|
+
×
|
|
97
|
+
</button>
|
|
98
|
+
</div>
|
|
99
|
+
<label v-if="canAdd" class="ctrl-upload-add">
|
|
100
|
+
<span>+</span>
|
|
101
|
+
<span class="ctrl-upload-hint">{{ busy ? '…' : item.placeholder || '上传' }}</span>
|
|
102
|
+
<input
|
|
103
|
+
type="file"
|
|
104
|
+
accept="image/*"
|
|
105
|
+
:multiple="maxCount > 1"
|
|
106
|
+
hidden
|
|
107
|
+
@change="onPick"
|
|
108
|
+
/>
|
|
109
|
+
</label>
|
|
110
|
+
</div>
|
|
111
|
+
<div v-if="hostError" class="ctrl-upload-error">{{ hostError }}</div>
|
|
112
|
+
</div>
|
|
113
|
+
</template>
|
|
114
|
+
|
|
115
|
+
<style scoped>
|
|
116
|
+
.ctrl-upload-wrap { width: 100%; }
|
|
117
|
+
.ctrl-upload { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
118
|
+
.ctrl-upload-thumb {
|
|
119
|
+
position: relative; width: 64px; height: 64px; border-radius: 6px; overflow: hidden;
|
|
120
|
+
background: #f5f5f5;
|
|
121
|
+
}
|
|
122
|
+
.ctrl-upload-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
|
123
|
+
.ctrl-upload-remove {
|
|
124
|
+
position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: none;
|
|
125
|
+
border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 12px;
|
|
126
|
+
line-height: 18px; cursor: pointer; padding: 0;
|
|
127
|
+
}
|
|
128
|
+
.ctrl-upload-add {
|
|
129
|
+
width: 64px; height: 64px; border: 1px dashed #d9d9d9; border-radius: 6px;
|
|
130
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
131
|
+
color: #999; font-size: 20px; cursor: pointer; gap: 2px;
|
|
132
|
+
}
|
|
133
|
+
.ctrl-upload-hint { font-size: 11px; line-height: 1; }
|
|
134
|
+
.ctrl-upload-error { font-size: 11px; color: #e74c3c; margin-top: 4px; }
|
|
135
|
+
</style>
|