allinssl/frontend/apps/vue-flow/components/configs/ApplyNodeConfig.tsx

97 lines
2.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { defineComponent, ref } from 'vue'
import { useWorkflowStore } from '../../store/workflow'
import { ApplyNodeData } from '../../types'
import configStyles from './Config.module.css'
export default defineComponent({
name: 'ApplyNodeConfig',
props: {
nodeId: {
type: String,
required: true,
},
nodeData: {
type: Object as () => ApplyNodeData,
required: true,
},
},
setup(props) {
const workflowStore = useWorkflowStore()
const applicationContent = ref(props.nodeData.applicationContent || '')
const applyStatus = ref<'idle' | 'applying' | 'success' | 'error'>('idle')
const errorMessage = ref('')
// 更新节点标签
const updateNodeLabel = (value: string) => {
workflowStore.updateNodeData(props.nodeId, { label: value })
}
// 更新申请内容
const updateApplicationContent = (value: string) => {
applicationContent.value = value
}
// 提交申请
const submitApplication = () => {
if (!applicationContent.value.trim()) {
errorMessage.value = '请输入申请内容'
return
}
// 模拟申请过程
applyStatus.value = 'applying'
errorMessage.value = ''
setTimeout(() => {
applyStatus.value = 'success'
workflowStore.updateNodeData(props.nodeId, {
applicationContent: applicationContent.value,
})
}, 1000)
}
return () => (
<div class={configStyles.configContainer}>
<div class={configStyles.configField}>
<div class={configStyles.configLabel}></div>
<input
type="text"
value={props.nodeData.label}
onInput={(e) => updateNodeLabel((e.target as HTMLInputElement).value)}
class={configStyles.configInput}
/>
</div>
<div class={configStyles.configField}>
<div class={configStyles.configLabel}></div>
<textarea
value={applicationContent.value}
onInput={(e) => updateApplicationContent((e.target as HTMLTextAreaElement).value)}
class={configStyles.configTextarea}
placeholder="请输入申请内容"
></textarea>
</div>
{errorMessage.value && <div class={configStyles.configError}>{errorMessage.value}</div>}
<div class={configStyles.configActions}>
<button
class={configStyles.configButton}
onClick={submitApplication}
disabled={applyStatus.value === 'applying'}
>
{applyStatus.value === 'applying' ? '申请中...' : '提交申请'}
</button>
{applyStatus.value === 'success' && <div class={configStyles.configSuccess}></div>}
</div>
<div class={configStyles.configInfo}>
<div class={configStyles.configInfoTitle}></div>
<div class={configStyles.configInfoContent}></div>
</div>
</div>
)
},
})