Browse Source

chore(gui-v2): create file data in page

pull/3211/head
braks 2 years ago
parent
commit
f9d8182ee5
  1. 16
      packages/nc-gui-v2/components/dlg/QuickImport.vue
  2. 11
      packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index/index.vue

16
packages/nc-gui-v2/components/dlg/QuickImport.vue

@ -53,7 +53,7 @@ const templateEditorModal = ref(false)
const useForm = Form.useForm const useForm = Form.useForm
const importState = reactive({ const importState = reactive({
fileList: [] as (UploadFile & { data: any })[], fileList: [] as (UploadFile & { data: string | ArrayBuffer })[],
url: '', url: '',
jsonEditor: {}, jsonEditor: {},
parserConfig: { parserConfig: {
@ -163,7 +163,7 @@ async function handleImport() {
dialogShow.value = false dialogShow.value = false
} }
async function parseAndExtractData(val: any, name: string) { async function parseAndExtractData(val: string | ArrayBuffer, name: string) {
try { try {
templateData.value = null templateData.value = null
importData.value = null importData.value = null
@ -206,18 +206,14 @@ function handleChange(info: UploadChangeParam) {
reader.onload = (e: ProgressEvent<FileReader>) => { reader.onload = (e: ProgressEvent<FileReader>) => {
const target = importState.fileList.find((f) => f.uid === info.file.uid) const target = importState.fileList.find((f) => f.uid === info.file.uid)
if (e.target) { if (e.target && e.target.result) {
/** if the file was pushed into the list by `<a-upload-dragger>` we just add the data to the file */
if (target) { if (target) {
target.data = e.target.result target.data = e.target.result
} else if (!target) { } else if (!target) {
// push new file to fileList /** if the file was added programmatically and not with d&d, we create file infos and push it into the list */
importState.fileList.push({ importState.fileList.push({
...info.file.originFileObj!, ...info.file,
name: info.file.originFileObj!.name,
fileName: info.file.originFileObj!.name,
originFileObj: info.file.originFileObj!,
type: info.file.originFileObj!.type,
uid: Math.random().toString(36).substring(2),
status: 'done', status: 'done',
data: e.target.result, data: e.target.result,
}) })

11
packages/nc-gui-v2/pages/[projectType]/[projectId]/index/index/index.vue

@ -70,7 +70,16 @@ function openQuickImportDialog(type: QuickImportTypes, file: File) {
}) })
vNode.value?.component?.exposed?.handleChange({ vNode.value?.component?.exposed?.handleChange({
file: { originFileObj: file }, file: {
uid: `${type}-${file.name}-${Math.random().toString(36).substring(2)}`,
name: file.name,
type: file.type,
status: 'done',
fileName: file.name,
lastModified: file.lastModified,
size: file.size,
originFileObj: file,
},
event: { percent: 100 }, event: { percent: 100 },
} as UploadChangeParam<UploadFile<File>>) } as UploadChangeParam<UploadFile<File>>)

Loading…
Cancel
Save