Browse Source

[Feature][UI Next]Added the method of downloading files (#9605)

3.0.0/version-upgrade
labbomb 3 years ago committed by GitHub
parent
commit
5b2a96b830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      dolphinscheduler-ui-next/src/service/modules/resources/index.ts
  2. 5
      dolphinscheduler-ui-next/src/service/modules/task-instances/index.ts
  3. 43
      dolphinscheduler-ui-next/src/service/service.ts
  4. 58
      dolphinscheduler-ui-next/src/utils/downloadFile.ts
  5. 4
      dolphinscheduler-ui-next/src/utils/index.ts
  6. 4
      dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/index.tsx

5
dolphinscheduler-ui-next/src/service/modules/resources/index.ts

@ -15,7 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { axios, downloadFile } from '@/service/service' import { axios } from '@/service/service'
import utils from '@/utils'
import { import {
ResourceTypeReq, ResourceTypeReq,
NameReq, NameReq,
@ -211,7 +212,7 @@ export function deleteResource(id: number): any {
} }
export function downloadResource(id: number): void { export function downloadResource(id: number): void {
downloadFile(`resources/${id}/download`) utils.downloadFile(`resources/${id}/download`)
} }
export function viewUIUdfFunction(id: IdReq): any { export function viewUIUdfFunction(id: IdReq): any {

5
dolphinscheduler-ui-next/src/service/modules/task-instances/index.ts

@ -15,7 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { axios, downloadFile } from '@/service/service' import { axios } from '@/service/service'
import utils from '@/utils'
import { ProjectCodeReq, IdReq, TaskListReq } from './types' import { ProjectCodeReq, IdReq, TaskListReq } from './types'
export function queryTaskListPaging( export function queryTaskListPaging(
@ -37,5 +38,5 @@ export function forceSuccess(taskId: IdReq, projectCode: ProjectCodeReq): any {
} }
export function downloadLog(id: number): void { export function downloadLog(id: number): void {
downloadFile('log/download-log', { taskInstanceId: id }) utils.downloadFile('log/download-log', { taskInstanceId: id })
} }

43
dolphinscheduler-ui-next/src/service/service.ts

@ -93,46 +93,5 @@ service.interceptors.response.use((res: AxiosResponse) => {
} }
}, err) }, err)
const apiPrefix = '/dolphinscheduler'
const reSlashPrefix = /^\/+/
const resolveURL = (url: string) => { export { service as axios }
if (url.indexOf('http') === 0) {
return url
}
if (url.charAt(0) !== '/') {
return `${apiPrefix}/${url.replace(reSlashPrefix, '')}`
}
return url
}
/**
* download file
*/
const downloadFile = (url: string, obj?: any) => {
const param: any = {
url: resolveURL(url),
obj: obj || {}
}
const form = document.createElement('form')
form.action = param.url
form.method = 'get'
form.style.display = 'none'
Object.keys(param.obj).forEach((key) => {
const input = document.createElement('input')
input.type = 'hidden'
input.name = key
input.value = param.obj[key]
form.appendChild(input)
})
const button = document.createElement('input')
button.type = 'submit'
form.appendChild(button)
document.body.appendChild(form)
form.submit()
document.body.removeChild(form)
}
export { service as axios, downloadFile }

58
dolphinscheduler-ui-next/src/utils/downloadFile.ts

@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const apiPrefix = '/dolphinscheduler'
const reSlashPrefix = /^\/+/
const resolveURL = (url: string) => {
if (url.indexOf('http') === 0) {
return url
}
if (url.charAt(0) !== '/') {
return `${apiPrefix}/${url.replace(reSlashPrefix, '')}`
}
return url
}
const downloadFile = (url: string, obj?: any) => {
const param: any = {
url: resolveURL(url),
obj: obj || {}
}
const form = document.createElement('form')
form.action = param.url
form.method = 'get'
form.style.display = 'none'
Object.keys(param.obj).forEach((key) => {
const input = document.createElement('input')
input.type = 'hidden'
input.name = key
input.value = param.obj[key]
form.appendChild(input)
})
const button = document.createElement('input')
button.type = 'submit'
form.appendChild(button)
document.body.appendChild(form)
form.submit()
document.body.removeChild(form)
}
export default downloadFile

4
dolphinscheduler-ui-next/src/utils/index.ts

@ -19,12 +19,14 @@ import mapping from './mapping'
import regex from './regex' import regex from './regex'
import truncateText from './truncate-text' import truncateText from './truncate-text'
import log from './log' import log from './log'
import downloadFile from './downloadFile'
const utils = { const utils = {
mapping, mapping,
regex, regex,
truncateText, truncateText,
log log,
downloadFile
} }
export default utils export default utils

4
dolphinscheduler-ui-next/src/views/projects/workflow/components/dag/index.tsx

@ -53,7 +53,7 @@ import LogModal from '@/components/log-modal'
import './x6-style.scss' import './x6-style.scss'
import { queryLog } from '@/service/modules/log' import { queryLog } from '@/service/modules/log'
import { useAsyncState } from '@vueuse/core' import { useAsyncState } from '@vueuse/core'
import { downloadFile } from '@/service/service' import utils from '@/utils'
const props = { const props = {
// If this prop is passed, it means from definition detail // If this prop is passed, it means from definition detail
@ -265,7 +265,7 @@ export default defineComponent({
} }
const downloadLogs = () => { const downloadLogs = () => {
downloadFile('log/download-log', { utils.downloadFile('log/download-log', {
taskInstanceId: nodeVariables.logTaskId taskInstanceId: nodeVariables.logTaskId
}) })
} }

Loading…
Cancel
Save