https节点表单更改
This commit is contained in:
@@ -106,22 +106,13 @@
|
||||
:show-file-list="false"
|
||||
class="field-upload"
|
||||
>
|
||||
<el-button size="small" type="primary" :disabled="getFieldFileList(fieldItem.field).length >= 1">
|
||||
选择文件
|
||||
</el-button>
|
||||
<el-button size="small" type="primary" :disabled="getFieldFileList(fieldItem.field).length >= 1"> 选择文件 </el-button>
|
||||
</el-upload>
|
||||
<!-- 手动显示已上传成功的文件列表 -->
|
||||
<div v-if="getFieldFileList(fieldItem.field).length > 0" class="uploaded-files-list">
|
||||
<div v-for="(uploadedFile, fileIdx) in getFieldFileList(fieldItem.field)" :key="fileIdx" class="uploaded-file-item">
|
||||
<span class="file-name">{{ uploadedFile.name }}</span>
|
||||
<el-button
|
||||
type="danger"
|
||||
link
|
||||
size="small"
|
||||
@click="removeFieldFile(fieldItem.field, fileIdx, 'upload')"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
<el-button type="danger" link size="small" @click="removeFieldFile(fieldItem.field, fileIdx, 'upload')"> 删除 </el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -142,12 +133,7 @@
|
||||
<div v-if="getFieldFileList(fieldItem.field).length > 0" class="uploaded-files-list">
|
||||
<div v-for="(uploadedFile, fileIdx) in getFieldFileList(fieldItem.field)" :key="fileIdx" class="uploaded-file-item">
|
||||
<span class="file-name">{{ uploadedFile.name }}</span>
|
||||
<el-button
|
||||
type="danger"
|
||||
link
|
||||
size="small"
|
||||
@click="removeFieldFile(fieldItem.field, fileIdx, 'uploadMultiple')"
|
||||
>
|
||||
<el-button type="danger" link size="small" @click="removeFieldFile(fieldItem.field, fileIdx, 'uploadMultiple')">
|
||||
删除
|
||||
</el-button>
|
||||
</div>
|
||||
@@ -155,38 +141,12 @@
|
||||
</div>
|
||||
<!-- 键值对输入(HTTP节点的headers和body) -->
|
||||
<div v-else-if="fieldItem.type === 'keyValue'" class="key-value-input-wrapper">
|
||||
<div
|
||||
v-for="(pair, pairIndex) in getKeyValuePairs(fieldItem.field)"
|
||||
:key="pairIndex"
|
||||
class="key-value-pair"
|
||||
>
|
||||
<el-input
|
||||
v-model="pair.key"
|
||||
placeholder="键"
|
||||
class="key-input"
|
||||
@input="updateKeyValueField(fieldItem.field)"
|
||||
/>
|
||||
<el-input
|
||||
v-model="pair.value"
|
||||
placeholder="值"
|
||||
class="value-input"
|
||||
@input="updateKeyValueField(fieldItem.field)"
|
||||
/>
|
||||
<el-button
|
||||
type="danger"
|
||||
:icon="Delete"
|
||||
circle
|
||||
size="small"
|
||||
@click="removeKeyValuePair(fieldItem.field, pairIndex)"
|
||||
/>
|
||||
<div v-for="(pair, pairIndex) in getKeyValuePairs(fieldItem.field)" :key="pairIndex" class="key-value-pair">
|
||||
<el-input v-model="pair.key" placeholder="键" class="key-input" @input="updateKeyValueField(fieldItem.field)" />
|
||||
<el-input v-model="pair.value" placeholder="值" class="value-input" @input="updateKeyValueField(fieldItem.field)" />
|
||||
<el-button type="danger" :icon="Delete" circle size="small" @click="removeKeyValuePair(fieldItem.field, pairIndex)" />
|
||||
</div>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:icon="Plus"
|
||||
@click="addKeyValuePair(fieldItem.field)"
|
||||
class="add-pair-btn"
|
||||
>
|
||||
<el-button type="primary" link :icon="Plus" @click="addKeyValuePair(fieldItem.field)" class="add-pair-btn">
|
||||
添加键值对
|
||||
</el-button>
|
||||
</div>
|
||||
@@ -275,7 +235,11 @@
|
||||
:show-file-list="false"
|
||||
class="custom-field-upload"
|
||||
>
|
||||
<el-button size="small" type="primary" :disabled="customField.type === 'upload' && getCustomFieldFileList(index).length >= 1">
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
:disabled="customField.type === 'upload' && getCustomFieldFileList(index).length >= 1"
|
||||
>
|
||||
选择文件
|
||||
</el-button>
|
||||
</el-upload>
|
||||
@@ -283,24 +247,14 @@
|
||||
<div v-if="getCustomFieldFileList(index).length > 0" class="uploaded-files-list">
|
||||
<div v-for="(uploadedFile, fileIdx) in getCustomFieldFileList(index)" :key="fileIdx" class="uploaded-file-item">
|
||||
<span class="file-name">{{ uploadedFile.name }}</span>
|
||||
<el-button
|
||||
type="danger"
|
||||
link
|
||||
size="small"
|
||||
@click="removeCustomFieldFile(index, fileIdx, customField.type)"
|
||||
>
|
||||
<el-button type="danger" link size="small" @click="removeCustomFieldFile(index, fileIdx, customField.type)">
|
||||
删除
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 非文件上传类型显示默认值输入框 -->
|
||||
<el-input
|
||||
v-else
|
||||
v-model="customField.value"
|
||||
placeholder="默认值"
|
||||
class="custom-field-value-full"
|
||||
/>
|
||||
<el-input v-else v-model="customField.value" placeholder="默认值" class="custom-field-value-full" />
|
||||
</div>
|
||||
<el-button type="primary" link class="w100" @click="addCustomField">+ 添加自定义字段</el-button>
|
||||
</template>
|
||||
@@ -1841,9 +1795,7 @@ const handleCustomFieldUpload = async (index: number, file: any, type: string) =
|
||||
throw new Error('上传失败:未返回文件URL');
|
||||
}
|
||||
|
||||
const fileUrl = uploadRes.data.fileAddressPrefix
|
||||
? `${uploadRes.data.fileAddressPrefix}${uploadRes.data.fileURL}`
|
||||
: uploadRes.data.fileURL;
|
||||
const fileUrl = uploadRes.data.fileAddressPrefix ? `${uploadRes.data.fileAddressPrefix}${uploadRes.data.fileURL}` : uploadRes.data.fileURL;
|
||||
|
||||
// 初始化 fileList
|
||||
if (!field.fileList) {
|
||||
@@ -1917,39 +1869,40 @@ const removeCustomFieldFile = (index: number, fileIdx: number, type: string) =>
|
||||
// 递增 uploadKey 来重置上传组件
|
||||
field.uploadKey = (field.uploadKey || 0) + 1;
|
||||
};
|
||||
// 获取键值对数组
|
||||
// 获取键值对数组(使用响应式存储)
|
||||
const getKeyValuePairs = (field: string) => {
|
||||
const value = dynamicFormValues[field];
|
||||
if (!value) {
|
||||
return [{ key: '', value: '' }];
|
||||
}
|
||||
// 如果还没有初始化,从 dynamicFormValues 中加载
|
||||
if (!fieldKeyValuePairs[field]) {
|
||||
const value = dynamicFormValues[field];
|
||||
|
||||
// 如果是字符串,尝试解析为JSON对象
|
||||
if (typeof value === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
||||
return Object.entries(parsed).map(([k, v]) => ({ key: k, value: String(v) }));
|
||||
if (!value) {
|
||||
fieldKeyValuePairs[field] = [{ key: '', value: '' }];
|
||||
} else if (typeof value === 'string') {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
||||
fieldKeyValuePairs[field] = Object.entries(parsed).map(([k, v]) => ({ key: k, value: String(v) }));
|
||||
} else {
|
||||
fieldKeyValuePairs[field] = [{ key: '', value: '' }];
|
||||
}
|
||||
} catch (e) {
|
||||
fieldKeyValuePairs[field] = [{ key: '', value: '' }];
|
||||
}
|
||||
} catch (e) {
|
||||
// 解析失败,返回空数组
|
||||
} else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||
const pairs = Object.entries(value).map(([k, v]) => ({ key: k, value: String(v) }));
|
||||
fieldKeyValuePairs[field] = pairs.length > 0 ? pairs : [{ key: '', value: '' }];
|
||||
} else {
|
||||
fieldKeyValuePairs[field] = [{ key: '', value: '' }];
|
||||
}
|
||||
return [{ key: '', value: '' }];
|
||||
}
|
||||
|
||||
// 如果是对象,转换为键值对数组
|
||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||
const pairs = Object.entries(value).map(([k, v]) => ({ key: k, value: String(v) }));
|
||||
return pairs.length > 0 ? pairs : [{ key: '', value: '' }];
|
||||
}
|
||||
|
||||
return [{ key: '', value: '' }];
|
||||
return fieldKeyValuePairs[field];
|
||||
};
|
||||
// 添加键值对
|
||||
const addKeyValuePair = (field: string) => {
|
||||
const pairs = getKeyValuePairs(field);
|
||||
pairs.push({ key: '', value: '' });
|
||||
updateKeyValueFieldFromPairs(field, pairs);
|
||||
updateKeyValueFieldFromPairs(field);
|
||||
};
|
||||
// 删除键值对
|
||||
const removeKeyValuePair = (field: string, index: number) => {
|
||||
@@ -1959,21 +1912,23 @@ const removeKeyValuePair = (field: string, index: number) => {
|
||||
if (pairs.length === 0) {
|
||||
pairs.push({ key: '', value: '' });
|
||||
}
|
||||
updateKeyValueFieldFromPairs(field, pairs);
|
||||
updateKeyValueFieldFromPairs(field);
|
||||
};
|
||||
// 更新键值对字段
|
||||
const updateKeyValueField = (field: string) => {
|
||||
const pairs = getKeyValuePairs(field);
|
||||
updateKeyValueFieldFromPairs(field, pairs);
|
||||
updateKeyValueFieldFromPairs(field);
|
||||
};
|
||||
// 从键值对数组更新字段值
|
||||
const updateKeyValueFieldFromPairs = (field: string, pairs: Array<{ key: string; value: string }>) => {
|
||||
const updateKeyValueFieldFromPairs = (field: string) => {
|
||||
const pairs = fieldKeyValuePairs[field];
|
||||
if (!pairs) return;
|
||||
|
||||
// 过滤掉空的键值对
|
||||
const validPairs = pairs.filter(p => p.key.trim() !== '');
|
||||
const validPairs = pairs.filter((p) => p.key.trim() !== '');
|
||||
|
||||
// 转换为对象
|
||||
const obj: Record<string, string> = {};
|
||||
validPairs.forEach(p => {
|
||||
validPairs.forEach((p) => {
|
||||
if (p.key.trim()) {
|
||||
obj[p.key.trim()] = p.value;
|
||||
}
|
||||
@@ -1986,6 +1941,8 @@ const updateKeyValueFieldFromPairs = (field: string, pairs: Array<{ key: string;
|
||||
const fieldFileLists = reactive<Record<string, any[]>>({});
|
||||
// 存储字段的上传key(用于重置上传组件)
|
||||
const fieldUploadKeys = reactive<Record<string, number>>({});
|
||||
// 存储字段的键值对(用于响应式更新)
|
||||
const fieldKeyValuePairs = reactive<Record<string, Array<{ key: string; value: string }>>>({});
|
||||
// 获取字段的文件列表
|
||||
const getFieldFileList = (field: string) => {
|
||||
return fieldFileLists[field] || [];
|
||||
@@ -2005,9 +1962,7 @@ const handleFieldUpload = async (field: string, file: any, type: string) => {
|
||||
throw new Error('上传失败:未返回文件URL');
|
||||
}
|
||||
|
||||
const fileUrl = uploadRes.data.fileAddressPrefix
|
||||
? `${uploadRes.data.fileAddressPrefix}${uploadRes.data.fileURL}`
|
||||
: uploadRes.data.fileURL;
|
||||
const fileUrl = uploadRes.data.fileAddressPrefix ? `${uploadRes.data.fileAddressPrefix}${uploadRes.data.fileURL}` : uploadRes.data.fileURL;
|
||||
|
||||
// 初始化文件列表
|
||||
if (!fieldFileLists[field]) {
|
||||
@@ -3007,7 +2962,7 @@ onBeforeUnmount(() => {
|
||||
.creation-page {
|
||||
height: calc(100vh - 100px);
|
||||
display: grid;
|
||||
grid-template-columns: 320px minmax(0, 1fr) 340px;
|
||||
grid-template-columns: 360px minmax(0, 1fr) 360px;
|
||||
gap: 14px;
|
||||
padding: 14px;
|
||||
background: #f6f8fb;
|
||||
|
||||
Reference in New Issue
Block a user