瀏覽代碼

fix: export workflow image

tags/2.0.0-beta.1
zxhlyh 1 月之前
父節點
當前提交
1bf04b7b74

+ 1
- 1
web/app/components/workflow-app/hooks/use-workflow-init.ts 查看文件

const [data, setData] = useState<FetchWorkflowDraftResponse>() const [data, setData] = useState<FetchWorkflowDraftResponse>()
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
useEffect(() => { useEffect(() => {
workflowStore.setState({ appId: appDetail.id })
workflowStore.setState({ appId: appDetail.id, appName: appDetail.name })
}, [appDetail.id, workflowStore]) }, [appDetail.id, workflowStore])


const handleUpdateWorkflowConfig = useCallback((config: Record<string, any>) => { const handleUpdateWorkflowConfig = useCallback((config: Record<string, any>) => {

+ 2
- 0
web/app/components/workflow-app/store/workflow/workflow-slice.ts 查看文件



export type WorkflowSliceShape = { export type WorkflowSliceShape = {
appId: string appId: string
appName: string
notInitialWorkflow: boolean notInitialWorkflow: boolean
setNotInitialWorkflow: (notInitialWorkflow: boolean) => void setNotInitialWorkflow: (notInitialWorkflow: boolean) => void
nodesDefaultConfigs: Record<string, any> nodesDefaultConfigs: Record<string, any>
export type CreateWorkflowSlice = StateCreator<WorkflowSliceShape> export type CreateWorkflowSlice = StateCreator<WorkflowSliceShape>
export const createWorkflowSlice: StateCreator<WorkflowSliceShape> = set => ({ export const createWorkflowSlice: StateCreator<WorkflowSliceShape> = set => ({
appId: '', appId: '',
appName: '',
notInitialWorkflow: false, notInitialWorkflow: false,
setNotInitialWorkflow: notInitialWorkflow => set(() => ({ notInitialWorkflow })), setNotInitialWorkflow: notInitialWorkflow => set(() => ({ notInitialWorkflow })),
nodesDefaultConfigs: {}, nodesDefaultConfigs: {},

+ 5
- 6
web/app/components/workflow/operator/export-image.tsx 查看文件

import TipPopup from './tip-popup' import TipPopup from './tip-popup'
import { RiExportLine } from '@remixicon/react' import { RiExportLine } from '@remixicon/react'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useStore as useAppStore } from '@/app/components/app/store'
import { import {
PortalToFollowElem, PortalToFollowElem,
PortalToFollowElemContent, PortalToFollowElemContent,
const { getNodesReadOnly } = useNodesReadOnly() const { getNodesReadOnly } = useNodesReadOnly()
const reactFlow = useReactFlow() const reactFlow = useReactFlow()


const appDetail = useAppStore(s => s.appDetail)
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [previewUrl, setPreviewUrl] = useState('') const [previewUrl, setPreviewUrl] = useState('')
const [previewTitle, setPreviewTitle] = useState('') const [previewTitle, setPreviewTitle] = useState('')
const knowledgeName = useStore(s => s.knowledgeName) const knowledgeName = useStore(s => s.knowledgeName)
const appName = useStore(s => s.appName)


const handleExportImage = useCallback(async (type: 'png' | 'jpeg' | 'svg', currentWorkflow = false) => { const handleExportImage = useCallback(async (type: 'png' | 'jpeg' | 'svg', currentWorkflow = false) => {
if (!appDetail && !knowledgeName)
if (!appName && !knowledgeName)
return return


if (getNodesReadOnly()) if (getNodesReadOnly())
if (!flowElement) return if (!flowElement) return


try { try {
let filename = appName || knowledgeName
const filter = (node: HTMLElement) => { const filter = (node: HTMLElement) => {
if (node instanceof HTMLImageElement) if (node instanceof HTMLImageElement)
return node.complete && node.naturalHeight !== 0 return node.complete && node.naturalHeight !== 0
} }


let dataUrl let dataUrl
let filename = `${appDetail.name}`


if (currentWorkflow) { if (currentWorkflow) {
// Get all nodes and their bounds // Get all nodes and their bounds
// For current view, just download // For current view, just download
const link = document.createElement('a') const link = document.createElement('a')
link.href = dataUrl link.href = dataUrl
link.download = `${appDetail ? filename : knowledgeName}.${type}`
link.download = `${filename}.${type}`
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
document.body.removeChild(link) document.body.removeChild(link)
catch (error) { catch (error) {
console.error('Export image failed:', error) console.error('Export image failed:', error)
} }
}, [getNodesReadOnly, appDetail, reactFlow, knowledgeName])
}, [getNodesReadOnly, appName, reactFlow, knowledgeName])


const handleTrigger = useCallback(() => { const handleTrigger = useCallback(() => {
if (getNodesReadOnly()) if (getNodesReadOnly())

Loading…
取消
儲存