Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(group): method to download template file #294

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/composables/config/useGroupList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type { GroupData } from '@/types/config'
import { OmitArrayFields } from '@/utils/utils'
import useUploadTagList from '@/composables/config/useUploadTagList'
import useExportTagTable from '@/composables/config/useExportTagTable'
import { useDownload } from '@/composables/useDownload'
import http from '@/utils/http'

interface GroupDataInTable extends GroupData {
checked: boolean
Expand Down Expand Up @@ -74,8 +76,17 @@ export default () => {
}

// download template file
const downloadTemplate = () => {
window.open('/template/upload-tag-template.xlsx', '_blank')
const { downloadFile } = useDownload()
const fileName = 'upload-tag-template.xlsx'
const downloadTemplate = async () => {
try {
const { pathname } = window.location
const fileURL = `${pathname.slice(-1) === '/' ? pathname.slice(0, -1) : pathname}/template/${fileName}`
const { data } = await http.get(fileURL, { responseType: 'blob', baseURL: '' })
downloadFile({ 'content-type': 'application/octet-stream', 'content-disposition': `filename=${fileName}` }, data)
} catch (error) {
//
}
}

// import file
Expand Down