@agentprismform/render-vue 0.0.0-stage → 1.2.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 +17 -0
- package/dist/index.mjs +2632 -0
- package/dist/style.css +1 -0
- package/package.json +38 -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/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 +5 -0
- package/src/taskHandlers.ts +4 -0
- package/README.md +0 -3
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, watch, 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
|
+
// 本地显示状态(对标原 custom-input 的 local display)
|
|
9
|
+
const localValue = ref(props.field?.value || '')
|
|
10
|
+
|
|
11
|
+
// 外部值变化时同步
|
|
12
|
+
watch(() => props.field?.value, (v) => {
|
|
13
|
+
localValue.value = v || ''
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const isTextarea = computed(() => props.item.type === 'textarea')
|
|
17
|
+
|
|
18
|
+
function onInput(e: Event) {
|
|
19
|
+
const target = e.target as HTMLInputElement
|
|
20
|
+
localValue.value = target.value
|
|
21
|
+
// inputChange → 仅埋点,不调 setControlData(对标 parser IGNORED)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function onBlur(e: Event) {
|
|
25
|
+
const target = e.target as HTMLInputElement
|
|
26
|
+
const val = target.value?.trim() || ''
|
|
27
|
+
localValue.value = val
|
|
28
|
+
// inputBlur → 触发完整 pipeline(value + verify + store + relations)
|
|
29
|
+
emit('change', { value: val, eventType: 'inputBlur' })
|
|
30
|
+
}
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<div class="ctrl-input-wrapper">
|
|
35
|
+
<textarea
|
|
36
|
+
v-if="isTextarea"
|
|
37
|
+
class="ctrl-input ctrl-textarea"
|
|
38
|
+
:value="localValue"
|
|
39
|
+
:placeholder="item.placeholder || '请输入'"
|
|
40
|
+
:disabled="field?.disabled"
|
|
41
|
+
:maxlength="item.props?.maxlength"
|
|
42
|
+
rows="3"
|
|
43
|
+
@input="onInput"
|
|
44
|
+
@blur="onBlur"
|
|
45
|
+
/>
|
|
46
|
+
<input
|
|
47
|
+
v-else
|
|
48
|
+
class="ctrl-input"
|
|
49
|
+
:type="item.type === 'number' ? 'number' : item.type === 'phone' ? 'tel' : 'text'"
|
|
50
|
+
:value="localValue"
|
|
51
|
+
:placeholder="item.placeholder || '请输入'"
|
|
52
|
+
:disabled="field?.disabled"
|
|
53
|
+
:maxlength="item.props?.maxlength"
|
|
54
|
+
@input="onInput"
|
|
55
|
+
@blur="onBlur"
|
|
56
|
+
/>
|
|
57
|
+
<span
|
|
58
|
+
v-if="item.props?.guideText"
|
|
59
|
+
class="ctrl-guide"
|
|
60
|
+
@click="emit('change', { eventType: 'guideClick' })"
|
|
61
|
+
>查看示例</span>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<style scoped>
|
|
66
|
+
.ctrl-input-wrapper {
|
|
67
|
+
display: flex; align-items: flex-start; gap: 6px;
|
|
68
|
+
}
|
|
69
|
+
.ctrl-input {
|
|
70
|
+
flex: 1; min-width: 0; padding: 0; font-size: 13px; border: none; outline: none;
|
|
71
|
+
background: transparent; color: #333; line-height: 20px;
|
|
72
|
+
word-break: break-all; white-space: normal; overflow-wrap: break-word;
|
|
73
|
+
}
|
|
74
|
+
.ctrl-input::placeholder { color: #bfbfbf; }
|
|
75
|
+
.ctrl-input:disabled { color: #999; }
|
|
76
|
+
.ctrl-textarea { resize: vertical; min-height: 60px; padding: 4px 0; }
|
|
77
|
+
.ctrl-guide {
|
|
78
|
+
flex-shrink: 0; font-size: 13px; color: #1989fa; line-height: 20px; cursor: pointer;
|
|
79
|
+
}
|
|
80
|
+
</style>
|
|
@@ -0,0 +1,149 @@
|
|
|
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 rows = computed<Record<string, any>[]>(() =>
|
|
9
|
+
Array.isArray(props.field?.value) ? props.field.value : [],
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
const subItems = computed(() => props.item.subItems ?? [])
|
|
13
|
+
const minItems = computed(() => props.item.listMeta?.minItems ?? 1)
|
|
14
|
+
const maxItems = computed(() => props.item.listMeta?.maxItems)
|
|
15
|
+
const canAdd = computed(() => maxItems.value === undefined || rows.value.length < maxItems.value)
|
|
16
|
+
const canRemove = computed(() => props.item.listMeta?.removable !== false && rows.value.length > minItems.value)
|
|
17
|
+
const collectionErrors = computed<Record<string, string>>(
|
|
18
|
+
() => props.field?.collectionErrors ?? {},
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
function rowValue(index: number, subItem: FormItem): any {
|
|
22
|
+
return rows.value[index]?.[subItem.key] ?? ''
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function optionCode(value: any): string {
|
|
26
|
+
if (value && typeof value === 'object') return value.code || ''
|
|
27
|
+
return value == null ? '' : String(value)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function updateRow(index: number, subItem: FormItem, value: any): void {
|
|
31
|
+
const next = rows.value.map((row) => ({ ...row }))
|
|
32
|
+
next[index] = { ...(next[index] ?? {}), [subItem.key]: value }
|
|
33
|
+
emit('change', { value: next, eventType: 'inputBlur' })
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function updateText(index: number, subItem: FormItem, event: Event): void {
|
|
37
|
+
const target = event.target as HTMLInputElement
|
|
38
|
+
updateRow(index, subItem, target.value.trim())
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updateSelect(index: number, subItem: FormItem, event: Event): void {
|
|
42
|
+
const target = event.target as HTMLSelectElement
|
|
43
|
+
const option = (subItem.initOptions ?? []).find((candidate) => candidate.code === target.value)
|
|
44
|
+
updateRow(index, subItem, option ? { code: option.code, name: option.name } : '')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function addRow(): void {
|
|
48
|
+
if (!canAdd.value || props.field?.disabled) return
|
|
49
|
+
emit('change', { value: [...rows.value, {}], eventType: 'inputChange' })
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function removeRow(index: number): void {
|
|
53
|
+
if (!canRemove.value || props.field?.disabled) return
|
|
54
|
+
emit('change', {
|
|
55
|
+
value: rows.value.filter((_row, rowIndex) => rowIndex !== index),
|
|
56
|
+
eventType: 'inputChange',
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function errorFor(index: number, key: string): string | undefined {
|
|
61
|
+
return collectionErrors.value[`${props.item.key}[${index}].${key}`]
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<template>
|
|
66
|
+
<div class="ctrl-list" :class="{ disabled: field?.disabled }">
|
|
67
|
+
<article v-for="(row, index) in rows" :key="index" class="list-row">
|
|
68
|
+
<div class="list-row-head">
|
|
69
|
+
<strong>联系人 {{ index + 1 }}</strong>
|
|
70
|
+
<button
|
|
71
|
+
v-if="item.listMeta?.removable !== false"
|
|
72
|
+
type="button"
|
|
73
|
+
class="remove-button"
|
|
74
|
+
:disabled="!canRemove || field?.disabled"
|
|
75
|
+
@click="removeRow(index)"
|
|
76
|
+
>
|
|
77
|
+
删除
|
|
78
|
+
</button>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<label v-for="subItem in subItems" :key="subItem.key" class="list-field">
|
|
82
|
+
<span class="list-field-label" :class="{ required: subItem.required }">
|
|
83
|
+
{{ subItem.label || subItem.key }}
|
|
84
|
+
</span>
|
|
85
|
+
<select
|
|
86
|
+
v-if="subItem.type === 'select' || subItem.type === 'cascader'"
|
|
87
|
+
class="list-input"
|
|
88
|
+
:value="optionCode(rowValue(index, subItem))"
|
|
89
|
+
:disabled="field?.disabled || subItem.disabled"
|
|
90
|
+
@change="updateSelect(index, subItem, $event)"
|
|
91
|
+
>
|
|
92
|
+
<option value="">{{ subItem.placeholder || '请选择' }}</option>
|
|
93
|
+
<option v-for="option in subItem.initOptions || []" :key="option.code" :value="option.code">
|
|
94
|
+
{{ option.name }}
|
|
95
|
+
</option>
|
|
96
|
+
</select>
|
|
97
|
+
<input
|
|
98
|
+
v-else
|
|
99
|
+
class="list-input"
|
|
100
|
+
:type="subItem.type === 'number' ? 'number' : subItem.type === 'phone' ? 'tel' : 'text'"
|
|
101
|
+
:value="rowValue(index, subItem)"
|
|
102
|
+
:placeholder="subItem.placeholder || '请输入'"
|
|
103
|
+
:disabled="field?.disabled || subItem.disabled"
|
|
104
|
+
@blur="updateText(index, subItem, $event)"
|
|
105
|
+
/>
|
|
106
|
+
<span v-if="errorFor(index, subItem.key)" class="list-error">
|
|
107
|
+
{{ errorFor(index, subItem.key) }}
|
|
108
|
+
</span>
|
|
109
|
+
</label>
|
|
110
|
+
</article>
|
|
111
|
+
|
|
112
|
+
<p v-if="Object.keys(collectionErrors).length" class="list-summary-error">
|
|
113
|
+
请修改重复或冲突的联系人手机号。
|
|
114
|
+
</p>
|
|
115
|
+
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
class="add-button"
|
|
119
|
+
:disabled="!canAdd || field?.disabled"
|
|
120
|
+
@click="addRow"
|
|
121
|
+
>
|
|
122
|
+
{{ item.listMeta?.addButtonText || '+ 添加联系人' }}
|
|
123
|
+
</button>
|
|
124
|
+
<p class="list-hint">{{ minItems }}–{{ maxItems ?? '∞' }} 项,当前 {{ rows.length }} 项</p>
|
|
125
|
+
</div>
|
|
126
|
+
</template>
|
|
127
|
+
|
|
128
|
+
<style scoped>
|
|
129
|
+
.ctrl-list { display: grid; gap: 10px; }
|
|
130
|
+
.ctrl-list.disabled { opacity: .65; }
|
|
131
|
+
.list-row {
|
|
132
|
+
padding: 12px; border: 1px solid #dbe4ec; border-radius: 12px;
|
|
133
|
+
background: #fbfdff;
|
|
134
|
+
}
|
|
135
|
+
.list-row-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; color: #29465d; font-size: 13px; }
|
|
136
|
+
.list-field { display: grid; gap: 4px; margin-top: 9px; }
|
|
137
|
+
.list-field-label { color: #687887; font-size: 12px; }
|
|
138
|
+
.list-field-label.required::before { content: '* '; color: #e74c3c; }
|
|
139
|
+
.list-input { width: 100%; padding: 8px 9px; color: #17212b; background: #fff; border: 1px solid #cfdbe5; border-radius: 7px; font: inherit; font-size: 13px; }
|
|
140
|
+
.list-input:focus { outline: 2px solid #b9d8ef; border-color: #6eaed8; }
|
|
141
|
+
.list-input:disabled { color: #8996a2; background: #f2f5f7; }
|
|
142
|
+
.remove-button, .add-button { border: 0; border-radius: 7px; cursor: pointer; font-size: 12px; }
|
|
143
|
+
.remove-button { padding: 5px 8px; color: #9f2d20; background: #fee4df; }
|
|
144
|
+
.add-button { padding: 9px 12px; color: #155e4a; background: #e5f5ef; }
|
|
145
|
+
.remove-button:disabled, .add-button:disabled { cursor: not-allowed; opacity: .45; }
|
|
146
|
+
.list-error, .list-summary-error { color: #b42318; font-size: 12px; line-height: 1.45; }
|
|
147
|
+
.list-summary-error { margin: 0; padding: 8px 10px; background: #fff0ee; border-radius: 7px; }
|
|
148
|
+
.list-hint { margin: 0; color: #718090; font-size: 11px; }
|
|
149
|
+
</style>
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, 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 inputValue = ref('')
|
|
9
|
+
const results = ref<any[]>([])
|
|
10
|
+
const showDropdown = ref(false)
|
|
11
|
+
const loading = ref(false)
|
|
12
|
+
// 标记用户是否正在主动输入
|
|
13
|
+
const isEditing = ref(false)
|
|
14
|
+
const searchApiId = computed(() => props.item.props?.searchApi || '')
|
|
15
|
+
|
|
16
|
+
// 下拉定位信息
|
|
17
|
+
const wrapRef = ref<HTMLElement | null>(null)
|
|
18
|
+
const dropdownStyle = ref<Record<string, string>>({})
|
|
19
|
+
|
|
20
|
+
// 外部值变化时同步输入框(仅当非编辑状态)
|
|
21
|
+
watch(() => props.field?.value, (v) => {
|
|
22
|
+
if (isEditing.value) return
|
|
23
|
+
if (v && typeof v === 'object' && v.name) {
|
|
24
|
+
inputValue.value = v.name
|
|
25
|
+
} else if (typeof v === 'string' && v) {
|
|
26
|
+
inputValue.value = v
|
|
27
|
+
} else {
|
|
28
|
+
inputValue.value = ''
|
|
29
|
+
}
|
|
30
|
+
}, { immediate: true })
|
|
31
|
+
|
|
32
|
+
const displayText = computed(() => {
|
|
33
|
+
const val = props.field?.value
|
|
34
|
+
if (!val) return ''
|
|
35
|
+
if (typeof val === 'object' && val.name) return val.name
|
|
36
|
+
if (props.field?.showValue) return props.field.showValue
|
|
37
|
+
return String(val)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
function updateDropdownPosition() {
|
|
41
|
+
if (!wrapRef.value) return
|
|
42
|
+
const rect = wrapRef.value.getBoundingClientRect()
|
|
43
|
+
dropdownStyle.value = {
|
|
44
|
+
position: 'fixed',
|
|
45
|
+
top: `${rect.bottom + 2}px`,
|
|
46
|
+
left: `${rect.left}px`,
|
|
47
|
+
width: `${rect.width}px`,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let debounceTimer: any = null
|
|
52
|
+
function onInput(e: Event) {
|
|
53
|
+
const target = e.target as HTMLInputElement
|
|
54
|
+
inputValue.value = target.value
|
|
55
|
+
isEditing.value = true
|
|
56
|
+
|
|
57
|
+
if (debounceTimer) clearTimeout(debounceTimer)
|
|
58
|
+
debounceTimer = setTimeout(() => {
|
|
59
|
+
if (inputValue.value.trim()) {
|
|
60
|
+
doSearch(inputValue.value.trim())
|
|
61
|
+
} else {
|
|
62
|
+
results.value = []
|
|
63
|
+
showDropdown.value = false
|
|
64
|
+
}
|
|
65
|
+
}, 200)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function doSearch(keyword: string) {
|
|
69
|
+
if (!searchApiId.value) return
|
|
70
|
+
|
|
71
|
+
loading.value = true
|
|
72
|
+
try {
|
|
73
|
+
// additionParams 模板引用 keywords → 传入 { keywords: ... }
|
|
74
|
+
const res = await props.formCore.fetchApi(searchApiId.value, { keywords: keyword })
|
|
75
|
+
// 搜索结果通常在 res.data 中,也可能是数组
|
|
76
|
+
const data = Array.isArray(res) ? res : (res?.data || res?.list || [])
|
|
77
|
+
results.value = data
|
|
78
|
+
if (data.length > 0) {
|
|
79
|
+
updateDropdownPosition()
|
|
80
|
+
showDropdown.value = true
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
results.value = []
|
|
84
|
+
showDropdown.value = false
|
|
85
|
+
} finally {
|
|
86
|
+
loading.value = false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function selectResult(opt: any) {
|
|
91
|
+
emit('change', { value: opt.name, eventType: 'searchChange' })
|
|
92
|
+
inputValue.value = opt.name
|
|
93
|
+
isEditing.value = false
|
|
94
|
+
showDropdown.value = false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function onFocus() {
|
|
98
|
+
// 仅当有结果且非失焦后短时间内才恢复展示
|
|
99
|
+
if (results.value.length > 0 && inputValue.value) {
|
|
100
|
+
updateDropdownPosition()
|
|
101
|
+
showDropdown.value = true
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function onBlur() {
|
|
106
|
+
showDropdown.value = false
|
|
107
|
+
results.value = []
|
|
108
|
+
if (isEditing.value) {
|
|
109
|
+
emit('change', { value: inputValue.value.trim(), eventType: 'inputBlur' })
|
|
110
|
+
}
|
|
111
|
+
isEditing.value = false
|
|
112
|
+
}
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<template>
|
|
116
|
+
<div class="ctrl-search">
|
|
117
|
+
<div ref="wrapRef" class="search-input-wrap">
|
|
118
|
+
<input
|
|
119
|
+
class="search-input"
|
|
120
|
+
type="text"
|
|
121
|
+
:value="inputValue"
|
|
122
|
+
:placeholder="item.placeholder || '请输入关键词搜索'"
|
|
123
|
+
:disabled="field?.disabled"
|
|
124
|
+
@input="onInput"
|
|
125
|
+
@focus="onFocus"
|
|
126
|
+
@blur="onBlur"
|
|
127
|
+
/>
|
|
128
|
+
<span v-if="loading" class="search-icon loading">⏳</span>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<!-- 下拉结果列表 — Teleport 到 body,fixed 定位避免被父容器裁剪 -->
|
|
132
|
+
<Teleport to="body">
|
|
133
|
+
<div
|
|
134
|
+
v-if="showDropdown && results.length > 0"
|
|
135
|
+
class="search-dropdown"
|
|
136
|
+
:style="dropdownStyle"
|
|
137
|
+
>
|
|
138
|
+
<div
|
|
139
|
+
v-for="opt in results"
|
|
140
|
+
:key="opt.code"
|
|
141
|
+
class="search-result-item"
|
|
142
|
+
@mousedown.prevent
|
|
143
|
+
@click="selectResult(opt)"
|
|
144
|
+
>
|
|
145
|
+
<span class="result-name">{{ opt.name }}</span>
|
|
146
|
+
<span v-if="opt.code" class="result-code">{{ opt.code }}</span>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</Teleport>
|
|
150
|
+
|
|
151
|
+
<div v-if="!searchApiId" class="search-hint">
|
|
152
|
+
⚠ 未配置 searchApi
|
|
153
|
+
</div>
|
|
154
|
+
</div>
|
|
155
|
+
</template>
|
|
156
|
+
|
|
157
|
+
<style scoped>
|
|
158
|
+
.ctrl-search { position: relative; }
|
|
159
|
+
.search-input-wrap { position: relative; display: flex; align-items: center; }
|
|
160
|
+
.search-input {
|
|
161
|
+
width: 100%; padding: 0;
|
|
162
|
+
border: none; font-size: 13px; outline: none; background: transparent; color: #333; line-height: 20px;
|
|
163
|
+
}
|
|
164
|
+
.search-input::placeholder { color: #bfbfbf; }
|
|
165
|
+
.search-input:focus { border-color: #1890ff; }
|
|
166
|
+
.search-input:disabled { background: #f5f5f5; color: #999; }
|
|
167
|
+
.search-icon {
|
|
168
|
+
position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
|
|
169
|
+
font-size: 14px; cursor: pointer;
|
|
170
|
+
}
|
|
171
|
+
.search-icon.loading { animation: spin 1s linear infinite; }
|
|
172
|
+
@keyframes spin { from { transform: translateY(-50%) rotate(0deg); } to { transform: translateY(-50%) rotate(360deg); } }
|
|
173
|
+
|
|
174
|
+
/* 下拉样式通过 Teleport 渲染到 body,使用非 scoped 样式 */
|
|
175
|
+
</style>
|
|
176
|
+
|
|
177
|
+
<style>
|
|
178
|
+
.search-dropdown {
|
|
179
|
+
z-index: 9999;
|
|
180
|
+
background: #fff; border: 1px solid #e8e8e8;
|
|
181
|
+
border-radius: 0 0 8px 8px; max-height: 200px; overflow-y: auto;
|
|
182
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
|
183
|
+
}
|
|
184
|
+
.search-result-item {
|
|
185
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
186
|
+
padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f5f5f5;
|
|
187
|
+
}
|
|
188
|
+
.search-result-item:last-child { border-bottom: none; }
|
|
189
|
+
.search-result-item:active { background: #e6f7ff; }
|
|
190
|
+
.result-name { font-size: 14px; color: #333; }
|
|
191
|
+
.result-code { font-size: 12px; color: #999; }
|
|
192
|
+
.search-hint { font-size: 11px; color: #faad14; margin-top: 4px; }
|
|
193
|
+
</style>
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, 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 showPanel = ref(false)
|
|
9
|
+
|
|
10
|
+
const options = computed(() => {
|
|
11
|
+
const opts = props.item?.initOptions || []
|
|
12
|
+
const val = props.field?.value
|
|
13
|
+
if (!val) return opts
|
|
14
|
+
return opts.map((o: any) => ({
|
|
15
|
+
...o,
|
|
16
|
+
_selected: props.item.props?.isSingle !== false
|
|
17
|
+
? val?.code === o.code
|
|
18
|
+
: Array.isArray(val) ? val.some((v: any) => v.code === o.code) : val === o.code,
|
|
19
|
+
}))
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const displayText = computed(() => {
|
|
23
|
+
const val = props.field?.value
|
|
24
|
+
if (!val) return ''
|
|
25
|
+
if (typeof val === 'object' && val.name) return val.name
|
|
26
|
+
if (props.field?.showValue) return props.field.showValue
|
|
27
|
+
return String(val)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const panelTitle = computed(() => props.item.props?.dialogTitle || '请选择')
|
|
31
|
+
|
|
32
|
+
function openPanel() {
|
|
33
|
+
if (props.field?.disabled) return
|
|
34
|
+
showPanel.value = true
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function closePanel() {
|
|
38
|
+
showPanel.value = false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function selectOption(opt: any) {
|
|
42
|
+
const isSingle = props.item.props?.isSingle !== false
|
|
43
|
+
if (isSingle) {
|
|
44
|
+
emit('change', { value: { code: opt.code, name: opt.name }, eventType: 'pickChange' })
|
|
45
|
+
showPanel.value = false
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div class="ctrl-select">
|
|
52
|
+
<!-- 触发器 -->
|
|
53
|
+
<div
|
|
54
|
+
class="select-trigger"
|
|
55
|
+
:class="{ disabled: field?.disabled, placeholder: !displayText }"
|
|
56
|
+
@click="openPanel"
|
|
57
|
+
>
|
|
58
|
+
<span>{{ displayText || item.placeholder || '请选择' }}</span>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<!-- 遮罩 + 底部弹窗 -->
|
|
62
|
+
<Transition name="panel">
|
|
63
|
+
<div v-if="showPanel" class="select-overlay" @click="closePanel">
|
|
64
|
+
<div class="select-panel" role="dialog" aria-label="选择选项" @click.stop>
|
|
65
|
+
<!-- 头部 -->
|
|
66
|
+
<div class="panel-header">
|
|
67
|
+
<span class="panel-title">{{ panelTitle }}</span>
|
|
68
|
+
<button class="panel-close" @click="closePanel" aria-label="关闭">×</button>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<!-- 选项列表 -->
|
|
72
|
+
<div class="panel-body" role="listbox">
|
|
73
|
+
<div
|
|
74
|
+
v-for="opt in options"
|
|
75
|
+
:key="opt.code"
|
|
76
|
+
class="option-card"
|
|
77
|
+
:class="{ 'option-selected': opt._selected }"
|
|
78
|
+
role="option"
|
|
79
|
+
:aria-selected="opt._selected"
|
|
80
|
+
@click="selectOption(opt)"
|
|
81
|
+
>
|
|
82
|
+
<span class="option-text">{{ opt.name }}</span>
|
|
83
|
+
<span class="option-btn" :class="{ 'option-btn-selected': opt._selected }">
|
|
84
|
+
{{ opt._selected ? '✓ 已选' : '选择' }}
|
|
85
|
+
</span>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
|
|
89
|
+
<!-- iOS 安全区占位 -->
|
|
90
|
+
<div class="safe-area-bottom" />
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
</Transition>
|
|
94
|
+
</div>
|
|
95
|
+
</template>
|
|
96
|
+
|
|
97
|
+
<style scoped>
|
|
98
|
+
/* ===== 触发器 ===== */
|
|
99
|
+
.ctrl-select { position: relative; }
|
|
100
|
+
.select-trigger {
|
|
101
|
+
display: flex; align-items: center; justify-content: space-between;
|
|
102
|
+
font-size: 13px; cursor: pointer; color: #333; line-height: 20px;
|
|
103
|
+
}
|
|
104
|
+
.select-trigger.disabled { background: #f5f5f5; color: #999; cursor: not-allowed; }
|
|
105
|
+
.select-trigger.placeholder { color: #bfbfbf; }
|
|
106
|
+
|
|
107
|
+
/* ===== 遮罩 ===== */
|
|
108
|
+
.select-overlay {
|
|
109
|
+
position: fixed; inset: 0; z-index: 999;
|
|
110
|
+
display: flex; align-items: flex-end; justify-content: center;
|
|
111
|
+
background: rgba(0, 0, 0, 0.3);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* ===== 底部弹窗面板 ===== */
|
|
115
|
+
.select-panel {
|
|
116
|
+
width: 100%; max-width: 500px; max-height: 60vh;
|
|
117
|
+
display: flex; flex-direction: column;
|
|
118
|
+
background: #F7F8FA;
|
|
119
|
+
border-radius: 20px 20px 0 0;
|
|
120
|
+
overflow: hidden;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* ===== 头部 ===== */
|
|
124
|
+
.panel-header {
|
|
125
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
126
|
+
padding: 14px 20px 10px;
|
|
127
|
+
flex-shrink: 0;
|
|
128
|
+
}
|
|
129
|
+
.panel-title {
|
|
130
|
+
font-size: 16px; font-weight: 500; color: #1A1A1A;
|
|
131
|
+
}
|
|
132
|
+
.panel-close {
|
|
133
|
+
width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
|
|
134
|
+
font-size: 24px; color: #999; background: none; border: none; cursor: pointer;
|
|
135
|
+
border-radius: 50%; line-height: 1;
|
|
136
|
+
}
|
|
137
|
+
.panel-close:active { background: rgba(0, 0, 0, 0.05); }
|
|
138
|
+
|
|
139
|
+
/* ===== 选项列表 ===== */
|
|
140
|
+
.panel-body {
|
|
141
|
+
flex: 1; overflow-y: auto;
|
|
142
|
+
box-sizing: border-box;
|
|
143
|
+
padding: 0 16px 8px;
|
|
144
|
+
display: flex; flex-direction: column; gap: 8px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* ===== 选项卡片 ===== */
|
|
148
|
+
.option-card {
|
|
149
|
+
display: flex; justify-content: space-between; align-items: center;
|
|
150
|
+
flex-shrink: 0;
|
|
151
|
+
padding: 12px;
|
|
152
|
+
background: #FFFFFF;
|
|
153
|
+
border-radius: 12px;
|
|
154
|
+
border: 2px solid transparent;
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
transition: border-color 0.2s ease, background 0.2s ease;
|
|
157
|
+
min-height: 44px;
|
|
158
|
+
}
|
|
159
|
+
.option-card:active { background: #F5F5F5; }
|
|
160
|
+
.option-card.option-selected {
|
|
161
|
+
border-color: #1677FF;
|
|
162
|
+
background: #E6F4FF;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.option-text {
|
|
166
|
+
font-size: 15px; font-weight: 400; color: #1A1A1A;
|
|
167
|
+
flex: 1; min-width: 0;
|
|
168
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* ===== 选择按钮 ===== */
|
|
172
|
+
.option-btn {
|
|
173
|
+
flex-shrink: 0; margin-left: 12px;
|
|
174
|
+
padding: 6px 12px;
|
|
175
|
+
font-size: 13px; color: #666666;
|
|
176
|
+
background: #F2F3F5;
|
|
177
|
+
border-radius: 8px;
|
|
178
|
+
transition: background 0.2s ease, color 0.2s ease;
|
|
179
|
+
}
|
|
180
|
+
.option-btn.option-btn-selected {
|
|
181
|
+
background: #1677FF;
|
|
182
|
+
color: #FFFFFF;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/* ===== iOS 安全区 ===== */
|
|
186
|
+
.safe-area-bottom {
|
|
187
|
+
height: env(safe-area-inset-bottom, 0px);
|
|
188
|
+
flex-shrink: 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* ===== 入场/离场动画 ===== */
|
|
192
|
+
.panel-enter-active,
|
|
193
|
+
.panel-leave-active {
|
|
194
|
+
transition: opacity 0.25s ease;
|
|
195
|
+
}
|
|
196
|
+
.panel-enter-active .select-panel,
|
|
197
|
+
.panel-leave-active .select-panel {
|
|
198
|
+
transition: transform 0.25s ease;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.panel-enter-from { opacity: 0; }
|
|
202
|
+
.panel-enter-from .select-panel { transform: translateY(20px); }
|
|
203
|
+
|
|
204
|
+
.panel-leave-to { opacity: 0; }
|
|
205
|
+
.panel-leave-to .select-panel { transform: translateY(20px); }
|
|
206
|
+
</style>
|
|
@@ -0,0 +1,61 @@
|
|
|
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 min = computed(() => Number(props.item.props?.min ?? 0))
|
|
9
|
+
const max = computed(() => Number(props.item.props?.max ?? 100))
|
|
10
|
+
const step = computed(() => Number(props.item.props?.step ?? 1))
|
|
11
|
+
|
|
12
|
+
const localValue = ref(toNumber(props.field?.value, min.value))
|
|
13
|
+
|
|
14
|
+
watch(
|
|
15
|
+
() => props.field?.value,
|
|
16
|
+
(v) => {
|
|
17
|
+
localValue.value = toNumber(v, min.value)
|
|
18
|
+
},
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
function toNumber(v: unknown, fallback: number): number {
|
|
22
|
+
const n = Number(v)
|
|
23
|
+
return Number.isFinite(n) ? n : fallback
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function onInput(e: Event) {
|
|
27
|
+
localValue.value = Number((e.target as HTMLInputElement).value)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function onChange(e: Event) {
|
|
31
|
+
const val = Number((e.target as HTMLInputElement).value)
|
|
32
|
+
localValue.value = val
|
|
33
|
+
emit('change', { value: val, eventType: 'pickChange' })
|
|
34
|
+
}
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<div class="ctrl-slider">
|
|
39
|
+
<input
|
|
40
|
+
class="ctrl-slider-input"
|
|
41
|
+
type="range"
|
|
42
|
+
:min="min"
|
|
43
|
+
:max="max"
|
|
44
|
+
:step="step"
|
|
45
|
+
:value="localValue"
|
|
46
|
+
:disabled="field?.disabled"
|
|
47
|
+
:aria-label="item.label || '滑块'"
|
|
48
|
+
@input="onInput"
|
|
49
|
+
@change="onChange"
|
|
50
|
+
/>
|
|
51
|
+
<span class="ctrl-slider-value">{{ localValue }}</span>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<style scoped>
|
|
56
|
+
.ctrl-slider { display: flex; align-items: center; gap: 10px; width: 100%; }
|
|
57
|
+
.ctrl-slider-input { flex: 1; min-width: 0; }
|
|
58
|
+
.ctrl-slider-value {
|
|
59
|
+
flex-shrink: 0; min-width: 28px; text-align: right; font-size: 13px; color: #333;
|
|
60
|
+
}
|
|
61
|
+
</style>
|