获取到的链接是附件下载的永久链接,没有时间限制
AI 自定义字段代码如下:
// <free_field_name>下载链接文本框</free_field_name>
// <file_name>DownloadUrlTextInput.jsx</file_name>
function DownloadUrlTextInput({ value, currentControl, formData, onChange,env }) {
const [downloadUrls, setDownloadUrls] = useState(value || ''); // 初始化为传入的值
const handleFetchUrls = () => {
const attachmentControlId = env.file; // 附件字段的 controlId
const attachmentValue = formData[attachmentControlId]?.value; // 获取附件字段的值
// 将文本格式的数组转换为 JSON 对象数组
try {
const parsedValue = JSON.parse(attachmentValue || '[]'); // 解析为数组
const newUrls = parsedValue
.map((item, index) => `${index + 1}:${item.downloadUrl}`) // 添加序号
.filter(Boolean) // 过滤掉无效的值
.join('\n'); // 用换行符连接
// 更新状态,覆盖之前的值
setDownloadUrls(newUrls); // 更新状态
onChange(newUrls); // 更新外部值
} catch (error) {
console.error("解析附件值时出错:", error);
}
};
const handleChange = (e) => {
const newValue = e.target.value;
setDownloadUrls(newValue); // 更新本地状态
onChange(newValue); // 更新外部值
};
return (
<div className="flex items-center">
<textarea
className="w-[500px] h-[50px] px-2 border rounded-md border-gray-300"
value={downloadUrls}
onChange={handleChange} // 允许用户编辑
/>
<button
className="ml-2 h-[36px] px-4 bg-blue-600 text-white rounded-md"
onClick={handleFetchUrls}
>
查询
</button>
</div>
);
}
效果: