Browse Source

feat(gui-v2): add json editor & refactor import state

pull/2795/head
Wing-Kam Wong 2 years ago
parent
commit
7387da1364
  1. 41
      packages/nc-gui-v2/components/dlg/FileImport.vue

41
packages/nc-gui-v2/components/dlg/FileImport.vue

@ -20,19 +20,23 @@ const { modelValue, importType } = defineProps<Props>()
const toast = useToast() const toast = useToast()
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
const activeKey = ref('upload') const activeKey = ref('upload')
const fileList = ref([]) const jsonEditorRef = ref()
const urlValidator = ref() const loading = ref(false)
const useForm = Form.useForm const useForm = Form.useForm
const formState = reactive({
const importState = ref({
fileList: [],
url: '', url: '',
json: {},
}) })
const validators = computed(() => { const validators = computed(() => {
return { return {
url: [fieldRequiredValidator], url: [fieldRequiredValidator],
} }
}) })
const { resetFields, validate, validateInfos } = useForm(formState, validators) const { resetFields, validate, validateInfos } = useForm(importState, validators)
const handleDrop = (e: DragEvent) => { const handleDrop = (e: DragEvent) => {
console.log(e) console.log(e)
@ -80,6 +84,10 @@ const handleChange = (info: UploadChangeParam) => {
} }
} }
const formatJson = () => {
jsonEditorRef.value.format()
}
const handleSubmit = () => { const handleSubmit = () => {
if (activeKey.value === 'upload') { if (activeKey.value === 'upload') {
// TODO // TODO
@ -97,13 +105,12 @@ const handleSubmit = () => {
</script> </script>
<template> <template>
<a-modal <a-modal v-model:visible="dialogShow" width="max(90vw, 600px)" @keydown.esc="dialogShow = false">
v-model:visible="dialogShow" <template #footer>
width="max(90vw, 600px)" <a-button key="back" @click="dialogShow = false">Cancel</a-button>
@keydown.esc="dialogShow = false" <a-button v-if="activeKey === 'json'" key="format" :loading="loading" @click="formatJson">Format JSON</a-button>
@ok="handleSubmit" <a-button key="submit" type="primary" :loading="loading" @click="handleSubmit">Import</a-button>
okText="Import" </template>
>
<a-tabs v-model:activeKey="activeKey" hide-add type="editable-card" :tab-position="top"> <a-tabs v-model:activeKey="activeKey" hide-add type="editable-card" :tab-position="top">
<a-tab-pane key="upload" :closable="false"> <a-tab-pane key="upload" :closable="false">
<template #tab> <template #tab>
@ -114,7 +121,7 @@ const handleSubmit = () => {
</template> </template>
<div class="pl-10 pr-10 pb-10 pt-5"> <div class="pl-10 pr-10 pb-10 pt-5">
<a-upload-dragger <a-upload-dragger
v-model:fileList="fileList" v-model:fileList="importState.fileList"
name="file" name="file"
:multiple="true" :multiple="true"
@change="handleChange" @change="handleChange"
@ -133,10 +140,12 @@ const handleSubmit = () => {
<template #tab> <template #tab>
<span class="flex items-center gap-2"> <span class="flex items-center gap-2">
<MdiCodeJSONIcon /> <MdiCodeJSONIcon />
Json String Json Editor
</span> </span>
</template> </template>
<!-- TODO --> <div class="pl-10 pr-10 pb-10 pt-5">
<MonacoEditor v-model="importState.json" class="h-[400px]" ref="jsonEditorRef" />
</div>
</a-tab-pane> </a-tab-pane>
<a-tab-pane v-else key="url" :closable="false"> <a-tab-pane v-else key="url" :closable="false">
<template #tab> <template #tab>
@ -147,9 +156,9 @@ const handleSubmit = () => {
</template> </template>
<div class="pl-10 pr-10 pb-10 pt-5"> <div class="pl-10 pr-10 pb-10 pt-5">
<a-form ref="formValidator" layout="vertical" :model="form"> <a-form ref="formValidator" layout="vertical" :model="form">
<a-form-item ref="form" :model="formState" name="quick-import-url-form" layout="horizontal" class="mb-0"> <a-form-item ref="form" :model="importState" name="quick-import-url-form" layout="horizontal" class="mb-0">
<a-form-item :label="importMeta.urlInputLabel" v-bind="validateInfos.url"> <a-form-item :label="importMeta.urlInputLabel" v-bind="validateInfos.url">
<a-input v-model:value="formState.url" size="large" /> <a-input v-model:value="importState.url" size="large" />
</a-form-item> </a-form-item>
</a-form-item> </a-form-item>
</a-form> </a-form>

Loading…
Cancel
Save