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

feat: Add import document view #2578

Merged
merged 1 commit into from
Mar 17, 2025
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
19 changes: 8 additions & 11 deletions ui/src/components/generate-related-dialog/index.vue
Original file line number Diff line number Diff line change
@@ -48,14 +48,16 @@
type="textarea"
/>
</el-form-item>
<el-form-item v-if="apiType === 'document'" :label="$t('components.selectParagraph.title')" prop="state">
<el-form-item
v-if="apiType === 'document'"
:label="$t('components.selectParagraph.title')"
prop="state"
>
<el-radio-group v-model="state" class="radio-block">
<el-radio value="error" size="large">{{
$t('components.selectParagraph.error')
}}</el-radio>
<el-radio value="all" size="large">{{
$t('components.selectParagraph.all')
}}</el-radio>
<el-radio value="all" size="large">{{ $t('components.selectParagraph.all') }}</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
@@ -147,7 +149,7 @@ const submitHandle = async (formEl: FormInstance) => {
if (apiType.value === 'paragraph') {
const data = {
...form.value,
paragraph_id_list: idList.value,
paragraph_id_list: idList.value
}
paragraphApi.batchGenerateRelated(id, documentId, data, loading).then(() => {
MsgSuccess(t('views.document.generateQuestion.successMessage'))
@@ -185,9 +187,4 @@ function getModel() {

defineExpose({ open })
</script>
<style lang="scss" scope>
.update-info {
background: #d6e2ff;
line-height: 25px;
}
</style>
<style lang="scss" scope></style>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No significant irregularities, potential issues, or optimization suggestions were found in the provided code. The only minor change is that the closing comment tag </style> was moved to after the final style block definition, which follows standard SCSS syntax rules.

6 changes: 6 additions & 0 deletions ui/src/locales/lang/en-US/views/document.ts
Original file line number Diff line number Diff line change
@@ -168,5 +168,11 @@ export default {
prompt1:
'Content: {data}\n \n Please summarize the above and generate 5 questions based on the summary. \nAnswer requirements: \n - Please output only questions; \n - Please place each question in',
prompt2: 'tag.'
},
feishu: {
selectDocument: 'Select Document',
tip1: 'Only documents and tables are supported. Documents will be segmented based on titles, and tables will be converted to Markdown format before segmentation.',
tip2: 'The system does not store the original document. Before importing the document, it is recommended to standardize the document segmentation markers.',
allCheck: 'Select All'
}
}
14 changes: 10 additions & 4 deletions ui/src/locales/lang/zh-CN/views/document.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ export default {
cancelGenerateQuestion: '取消生成问题',
cancelVectorization: '取消向量化',
cancelGenerate: '取消生成',
export: '导出',
export: '导出'
},
tip: {
saveMessage: '当前的更改尚未保存,确认退出吗?',
@@ -108,7 +108,7 @@ export default {
GENERATE: '生成中',
SYNC: '同步中',
REVOKE: '取消中',
finish:'完成'
finish: '完成'
},
enableStatus: {
label: '启用状态',
@@ -149,7 +149,7 @@ export default {
label: '相似度高于',
placeholder: '直接返回分段内容',
requiredMessage: '请输入相似度'
},
}
},
hitHandlingMethod: {
optimization: '模型优化',
@@ -163,6 +163,12 @@ export default {
tip3: '标签中,系统会自动关联标签中的问题;',
tip4: '生成效果依赖于所选模型和提示词,用户可自行调整至最佳效果。',
prompt1: `内容:{data}\n\n请总结上面的内容,并根据内容总结生成 5 个问题。\n回答要求:\n- 请只输出问题;\n- 请将每个问题放置`,
prompt2: `标签中。`,
prompt2: `标签中。`
},
feishu: {
selectDocument: '选择文档',
tip1: '仅支持文档和表格类型,文档会根据标题分段,表格会转为Markdown格式后再分段。',
tip2: '系统不存储原始文档,导入文档前,建议规范文档的分段标识。',
allCheck: '全选'
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code seems to be missing some closing braces and properly formatted syntax throughout. Specifically, there are issues with the JSON structure of the file:

  1. There's an extra comma after "tip" in "enableStatus".
"enableStatus": {
  1. This line is missing its end curly brace:
placeholder: '直接返回分段内容',
requiredMessage: '请输入相似度'
  1. The opening brace for "feishu" is not closed:
{
}
  1. The object under "label" isn't enclosed in quotes:
"label": "相似度高于",
  1. There're two empty objects without content at the end.

After fixing these issues, here's how the corrected version should look like:

export default {
  common: {
    cancelGenerateQuestion: '取消生成问题',
    cancelVectorization: '取消向量化',
    cancelGenerate: '取消生成',
    export: '导出'
  },
  tip: {
    saveMessage: '当前的更改尚未保存,确认退出吗? '
  },
  generateResult: {
    GENERATE: '生成中',
    SYNC: '同步中',
    REVOKE: '取消中',
    finish: '完成'
  },
  enableStatus: {
    label: '启用状态'
  },
  hitHandlingMethod: {
    optimization: '模型优化'
  },
  queryConfig: {},
  feishu: {
    selectDocument: '选择文档',
    tip1: '仅支持文档和表格类型,文档会根据标题分段,表格会转为Markdown格式后再分段。',
    tip2: '系统不存储原始文档,导入文档前,建议规范文档的分段标识。',
    allCheck: '全选'
  }
}

6 changes: 6 additions & 0 deletions ui/src/locales/lang/zh-Hant/views/document.ts
Original file line number Diff line number Diff line change
@@ -164,5 +164,11 @@ export default {
tip4: '生成效果取決於所選模型和提示詞,用戶可自行調整至最佳效果。',
prompt1: `內容:{data}\n\n請總結上面的內容,並根據內容總結生成 5 個問題。\n回答要求:\n - 請只輸出問題;\n - 請將每個問題放置在`,
prompt2: `標籤中。`,
},
feishu: {
selectDocument: '選擇文檔',
tip1: '僅支持文檔和表格類型,文檔會根據標題分段,表格會轉為Markdown格式後再分段。',
tip2: '系統不存儲原始文檔,導入文檔前,建議規範文檔的分段標識。',
allCheck: '全選'
}
}
13 changes: 10 additions & 3 deletions ui/src/router/modules/dataset.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import Layout from '@/layout/layout-template/DetailLayout.vue'
const datasetRouter = {
path: '/dataset',
name: 'dataset',
meta: { title: 'views.dataset.title', permission: 'DATASET:READ' },
meta: { title: 'views.dataset.title', permission: 'DATASET:READ' },
component: () => import('@/layout/layout-template/AppLayout.vue'),
redirect: '/dataset',
children: [
@@ -13,7 +13,7 @@ const datasetRouter = {
component: () => import('@/views/dataset/index.vue')
},
{
path: '/dataset/:type', // upload
path: '/dataset/upload',
name: 'UploadDocumentDataset',
meta: { activeMenu: '/dataset' },
component: () => import('@/views/dataset/UploadDocumentDataset.vue'),
@@ -85,7 +85,14 @@ const datasetRouter = {
meta: { activeMenu: '/dataset' },
component: () => import('@/views/paragraph/index.vue'),
hidden: true
}
},
{
path: '/dataset/import',
name: 'ImportDocumentDataset',
meta: { activeMenu: '/dataset' },
component: () => import('@/views/dataset/ImportDocumentDataset.vue'),
hidden: true
},
]
}

6 changes: 6 additions & 0 deletions ui/src/styles/app.scss
Original file line number Diff line number Diff line change
@@ -765,3 +765,9 @@ h5 {
width: 90% !important;
}
}

// 蓝色提示框
.update-info {
background: #d6e2ff;
line-height: 25px;
}
149 changes: 149 additions & 0 deletions ui/src/views/dataset/ImportDocumentDataset.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<template>
<LayoutContainer :header="$t('views.document.importDocument')" class="create-dataset">
<template #backButton>
<back-button @click="back"></back-button>
</template>
<div class="create-dataset__main flex" v-loading="loading">
<div class="create-dataset__component main-calc-height">
<el-scrollbar>
<div class="upload-document p-24">
<h4 class="title-decoration-1 mb-8">
{{ $t('views.document.feishu.selectDocument') }}
</h4>
<el-form
ref="FormRef"
:model="form"
:rules="rules"
label-position="top"
require-asterisk-position="right"
>
<div class="mt-16 mb-16">
<el-radio-group v-model="form.fileType" class="app-radio-button-group">
<el-radio-button value="txt">{{
$t('views.document.fileType.txt.label')
}}</el-radio-button>
</el-radio-group>
</div>
<div class="update-info flex p-8-12 border-r-4 mb-16">
<div class="mt-4">
<AppIcon iconName="app-warning-colorful" style="font-size: 16px"></AppIcon>
</div>
<div class="ml-16 lighter">
<p>{{ $t('views.document.feishu.tip1') }}</p>
<p>{{ $t('views.document.feishu.tip2') }}</p>
</div>
</div>
<div class="card-never border-r-4 mb-16">
<el-checkbox
v-model="allCheck"
:label="$t('views.document.feishu.allCheck')"
size="large"
class="ml-24"
/>
</div>

<el-tree :props="props" :load="loadNode" lazy show-checkbox />
</el-form>
</div>
</el-scrollbar>
</div>
</div>
<div class="create-dataset__footer text-right border-t">
<el-button @click="router.go(-1)">{{ $t('common.cancel') }}</el-button>

<el-button @click="submit" type="primary">
{{ $t('views.document.buttons.import') }}
</el-button>
</div>
</LayoutContainer>
</template>
<script setup lang="ts">
import { ref, reactive, computed, onUnmounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'

import documentApi from '@/api/document'
import { MsgConfirm, MsgSuccess } from '@/utils/message'
import { t } from '@/locales'
import type Node from 'element-plus/es/components/tree/src/model/node'

interface Tree {
name: string
leaf?: boolean
}
const router = useRouter()
const route = useRoute()
const {
query: { id } // id为datasetID,有id的是上传文档
} = route

const loading = ref(false)
const disabled = ref(false)
const allCheck = ref(false)
const form = ref({
fileType: 'txt',
fileList: [] as any
})

const rules = reactive({
fileList: [
{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }
]
})

const props = {
label: 'name',
children: 'zones',
isLeaf: 'leaf'
}

const loadNode = (node: Node, resolve: (data: Tree[]) => void) => {
if (node.level === 0) {
return resolve([{ name: 'region' }])
}
if (node.level > 1) return resolve([])

setTimeout(() => {
const data: Tree[] = [
{
name: 'leaf',
leaf: true
},
{
name: 'zone'
}
]

resolve(data)
}, 500)
}

function submit() {
loading.value = true
}
function back() {
router.go(-1)
}
</script>
<style lang="scss" scoped>
.create-dataset {
&__component {
width: 100%;
margin: 0 auto;
overflow: hidden;
}
&__footer {
padding: 16px 24px;
position: fixed;
bottom: 0;
left: 0;
background: #ffffff;
width: 100%;
box-sizing: border-box;
}
.upload-document {
width: 70%;
margin: 0 auto;
margin-bottom: 20px;
}
}
</style>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this Vue component template, there are several potential improvements and issues:

Improvements

  1. Vue 3 Composition API: You're using Vue 2 syntax (<template>, @click directives), which should be updated to Vue 3's composition API syntax.
<script setup lang="ts">
// Use Vue 3 imports
import { ref, reactive, computed, onUnmounted } from 'vue';
// Import necessary modules/routes/...
  1. Computed Property for query Parameter: This can make the code cleaner if you want to access the id parameter more frequently.
const datasetId = computed(() => route.query.id);
// Usage:
if (datasetId.value) {
  // Do something with datasetID.value
}
  1. Dynamic Class Usage: In CSS classes like .border-r-4, it would be better to define these globally or use a less utility-like approach if they aren't dynamically changing based on conditions.

  2. Tree Node Label Handling: Since prop.children is set to "zones", ensure that your backend returns appropriate tree structure reflecting these names.

  3. Loading Handling: Consider showing a spinner or overlay when loading data instead of directly disabling buttons unless absolutely necessary as it might confuse users waiting too long without a response.

  4. Error Handling: Add basic error handling logic for API calls and user actions to manage unexpected situations gracefully.

Optimizations

  1. Avoid Inline Template Styles: For styles, consider importing them into SCSS files rather than embedding them within <style> tags. This makes managing styles easier across components and reduces file sizes.

  2. **Consistent Naming Conventions): Ensure consistency in variable and function naming, especially those related to API data models/interfaces/classes/typescript definitions.

  3. Optimize Data Fetching: If multiple parts rely on async data fetching, ensure proper cancellation strategies to avoid resource leakage during page transitions.

  4. Consider State Management Libraries: While not strictly relevant here since state management isn't explicitly used beyond simple refs, introducing a store could improve maintainability and scale as application grows.

Here’s a refined version implementing some of these points:

Script Section

Update to composition-api:

<script setup lang="ts">
import { ref, reactive, computed, onUnmounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';

import documentApi from '@/api/document'; 
import { MsgConfirm, MsgSuccess } from '@/utils/message';
import { t } from '@/locales';

interface TreeNode {
  name: string;
  leaf?: boolean;
}

const router = useRouter();
const route = useRoute();

const datasetId = computed(() => Number(route.query.id)); // Convert to number for numeric comparisons

const loading = ref(false);
const allCheck = ref(false);

const form = ref({
  fileType: 'txt',
  fileList: []
});

const rules = reactive({
  fileList: [{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }]
});

const props = {
  label: 'name',
  children: () => ['zones'],
  isLeaf: 'leaf'
};

async function fetchNodes(nodeId: number | null) {
  try {
    const nodesData = await documentApi.fetchNodesById(nodeId ?? undefined); // Adjust based on API call params
    console.log(nodesData);
  } catch (error) {
    console.error(error);
  }
}

onMounted(async () => {
  await fetchNodes(datasetId.value || -1); // Initial fetch
});

// ...rest of the functions remain unchanged but now use new methods and variables properly
</script>

Stylus/Css Sections

Move styles to global/styles or scoped styles appropriately:

/* app.scss */
.create-dataset {
  &__component {
    @include no-scrollbar; // Example mixin
  }
}

By addressing these improvements and optimizations, you'll have a more robust and efficient Vue component that adheres closer to best practices while still being functional.

5 changes: 1 addition & 4 deletions ui/src/views/dataset/component/UploadComponent.vue
Original file line number Diff line number Diff line change
@@ -323,8 +323,5 @@ defineExpose({
color: var(--el-color-primary-light-5);
}
}
.update-info {
background: #d6e2ff;
line-height: 25px;
}

</style>