From 33afc123fdbd93f09591c3b2b56a06f45dcf606a Mon Sep 17 00:00:00 2001
From: liudong <liudong>
Date: 星期一, 29 七月 2024 16:40:28 +0800
Subject: [PATCH] 知识库页面文件上传接口调用开发
---
src/api/kbList.ts | 17 ++++
src/views/dmx/knowledgeLib/index.vue | 42 +++++++---
src/views/dmx/knowledgeLib/add.vue | 158 ++++++++++++--------------------------
3 files changed, 95 insertions(+), 122 deletions(-)
diff --git a/src/api/kbList.ts b/src/api/kbList.ts
index 9f1afc9..66f72e9 100644
--- a/src/api/kbList.ts
+++ b/src/api/kbList.ts
@@ -64,10 +64,25 @@
// 鏂囨。涓婁紶鎺ュ彛
+// export function kbdocumentupload(params) {
+// return axios.post('/api/v1/document/upload', params);
+// }
+
export function kbdocumentupload(params) {
- return axios.post('/api/v1/document/upload', params);
+ const config = {
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ // token: token,
+ },
+ }
+ return axios.post(
+ '/api/v1/document/upload',
+ params,
+ config
+ )
}
+
// 鏂囨。鍚姩/鍙栨秷瑙f瀽鎺ュ彛
export function kbdocumentrun(params) {
diff --git a/src/views/dmx/knowledgeLib/add.vue b/src/views/dmx/knowledgeLib/add.vue
index b1f803a..34bc1de 100644
--- a/src/views/dmx/knowledgeLib/add.vue
+++ b/src/views/dmx/knowledgeLib/add.vue
@@ -9,27 +9,36 @@
<a-modal v-model:visible="visible" title="涓婁紶鏂囦欢" @before-open="handleOpened" @cancel="handleCancel" @before-ok="handleBeforeOk" title-align="start">
<a-tabs :default-active-key="activeKey" @change="activeKeyChange">
<a-tab-pane key="1" title="鏂囦欢">
- <div class="aUpload">
-<!-- <a-upload :file-list="uploadList" draggable accept=".word, .pdf, .ppt, .excel, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .pptx, .ppt, .pdf, .mp4, .avi, .mp3,.wav, .wma, .wmv, .rm," :custom-request="customRequest" />-->
- <a-upload :file-list="uploadList" draggable :accept="acceptNameList" :custom-request="customRequest" />
- </div>
</a-tab-pane>
<a-tab-pane key="2" title="鏂囦欢澶�">
- <div class="aUpload">
- <a-upload :file-list="uploadList" draggable accept=".word, .pdf, .ppt, .excel, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .pptx, .ppt," directory :custom-request="customRequest" />
- </div>
</a-tab-pane>
</a-tabs>
+ <div class="aUpload">
+ <!-- <a-upload :file-list="uploadList" draggable accept=".word, .pdf, .ppt, .excel, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .pptx, .ppt, .pdf, .mp4, .avi, .mp3,.wav, .wma, .wmv, .rm," :custom-request="customRequest" />-->
+ <a-upload
+ action="/"
+ :auto-upload="false"
+ ref="uploadRef"
+ :file-list="uploadList"
+ draggable
+ :directory="directory"
+ @change="onChange"
+ multiple
+ />
+ </div>
</a-modal>
</template>
<script lang="ts" setup>
import { onMounted, onBeforeMount, reactive, ref, computed } from "vue";
import axios from 'axios';
+import { kbdocumentupload } from "@/api/kbList";
+import { Message } from '@arco-design/web-vue';
let CancelToken = axios.CancelToken
let source = null
const visible = ref(false);
const loading = ref(false);
+const directory = ref(false);
const activeKey = ref('1');
const formRef = ref(null);
const uploadList = ref([]);
@@ -39,130 +48,65 @@
post: '',// 宀椾綅
txt: '',// 澶囨敞
});
+const props = defineProps(['kbobj'])
+const emit = defineEmits(['changeFetchData'])
+const uploadRef = ref();
+const files = ref([]);
+console.log(props.kbobj);
const acceptNameList = computed(
()=>{
return '.word, .pdf, .ppt, .excel, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .pptx, .ppt, .pdf, .mp4, .avi, .mp3,.wav, .wma, .wmv, .rm,'
}
)
-const customRequest = (option) => {
- const {onProgress, onError, onSuccess, fileItem, name} = option
- const xhr = new XMLHttpRequest();
- if (xhr.upload) {
- xhr.upload.onprogress = function (event) {
- let percent;
- if (event.total > 0) {
- // 0 ~ 1
- percent = event.loaded / event.total;
- }
- onProgress(percent, event);
- };
- }
- xhr.onerror = function error(e) {
- onError(e);
- };
- xhr.onload = function onload() {
- if (xhr.status < 200 || xhr.status >= 300) {
- return onError(xhr.responseText);
- }
- onSuccess(xhr.response);
- };
-
- const formData = new FormData();
- formData.append(name || 'file', fileItem.file);
- xhr.open('post', '/v1/user/login', true);
- xhr.send(formData);
-
- return {
- abort() {
- xhr.abort()
- }
- }
-};
// 涓婁紶鏂囦欢
-// async submitForm = ()=>{
-// if (this.fileList && this.fileList.length > 0) {
-// source = CancelToken.source()
-// this.fileUploadLoad = true
-// const formdata = new FormData()
-// let param = {
-// userName: this.userInfo.userName,
-// userId: this.userInfo.userID,
-// cfeId: this.currow.conferences[0].id,
-// }
-// this.fileList.map((item) => {
-// formdata.append('file', item.raw)
-// })
-// uploadCfeFile(
-// { param, formdata },
-// (progressEvent) => {
-// let total = progressEvent.total
-// let loaded = progressEvent.loaded
-// this.uploadPercent = parseInt(((loaded / total) * 100).toFixed(0))
-// },
-// source
-// )
-// .then((res) => {
-// if (res.data.code === '0') {
-// //涓婁紶鎴愬姛
-// this.$successMessage(
-// this.translateTitle(
-// 'json_fileupload.json_file_tip.json_file_tip08'
-// )
-// )
-// this.fileList = []
-// this.$refs.upload.clearFiles()
-// this.queryList()
-// } else {
-// this.$errorMessage(res.data.message)
-// }
-// this.fileUploadLoad = false
-// this.uploadPercent = 0
-// })
-// .catch((error) => {
-// this.fileUploadLoad = false
-// this.uploadPercent = 0
-// if (axios.isCancel(error)) {
-// //宸茬粓姝笂浼�
-// this.$errorMessage(
-// this.translateTitle(
-// 'json_fileupload.json_file_tip.json_file_tip09'
-// )
-// )
-// } else {
-// this.$errorMessage('鏂囦欢澶у皬瓒呰繃闄愬埗锛屼笂浼犲け璐�')
-// }
-// })
-// } else {
-// //璇烽�夋嫨瑕佷笂浼犵殑鏂囦欢
-// this.$warningMessage(
-// this.translateTitle('json_fileupload.json_file_tip.json_file_tip10')
-// )
-// }
-// }
-
-
+const submitForm = async()=>{
+ if (files.value && files.value.length > 0) {
+ files.value.map((item) => {
+ const formData = new FormData()
+ formData.append(name || 'file', item.file);
+ formData.append('kb_id', props.kbobj.id);
+ kbdocumentupload(formData).then((res) => {
+ if(res.code == 0){
+ emit('changeFetchData')
+ Message.success('涓婁紶鎴愬姛');
+ visible.value = false;
+ }
+ })
+ })
+ }
+}
const handleSubmit = ({values, errors}) => {
- console.log('values:', values, '\nerrors:', errors)
+
}
+
+
+const onChange = (fileList) => {
+ files.value = fileList;
+};
+
+
+
+
+
const handleClick = () => {
visible.value = true;
};
const handleBeforeOk = (done) => {
-
+ submitForm();
};
const handleCancel = () => {
visible.value = false;
}
const handleOpened =(el) => {
+ console.log(props.kbobj);
uploadList.value = [];
- console.log(uploadList, 'uploadList');
- console.log(activeKey.value, 'activeKey');
}
const activeKeyChange = (value)=>{
activeKey.value = value;
+ directory.value = value == '2' ? true : false;
}
onBeforeMount(()=>{
diff --git a/src/views/dmx/knowledgeLib/index.vue b/src/views/dmx/knowledgeLib/index.vue
index 12287ee..04e8c58 100644
--- a/src/views/dmx/knowledgeLib/index.vue
+++ b/src/views/dmx/knowledgeLib/index.vue
@@ -53,7 +53,7 @@
style="width: 200px;margin-right: 10px"
/>
<!-- 鏂板缓-->
- <add />
+ <add :kbobj="kbobj" @changeFetchData="changeFetchData"/>
</a-col>
</a-row>
</a-form>
@@ -292,7 +292,7 @@
queryKbDocumentList,
deleteKnow,
queryKbdetail,
- queryKbtenantInfo, kbdocumentrm, kbdocumentchangeparser
+ queryKbtenantInfo, kbdocumentrm, kbdocumentchangeparser, kbdocumentrun
} from "@/api/kbList";
import { Pagination } from '@/types/global';
import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
@@ -333,13 +333,15 @@
let visible = ref(false)
let detailsShow = ref(false)
let selectedTab = ref(0)
+ let kbobj = reactive({})
let tabs = ref([])
const selectTab = (index,item) => {
selectedTab.value= index;
console.log(item.id);
+ kbobj= item
fetchData({
- kb_id: item.id,
+ kb_id: kbobj.id,
page: 1,
page_size: 20
})
@@ -505,8 +507,9 @@
tabs.value = data;
console.log(tabs.value, 'tabs');
if(tabs.value.length>0 && tabs.value[0]){
+ kbobj = tabs.value[0]
fetchData({
- kb_id: tabs.value[0].id,
+ kb_id: kbobj.id,
page: 1,
page_size: 20
})
@@ -523,10 +526,6 @@
};
const deleteKnowledge = async (id) => {
-
-
-
-
let data = await deleteKnow({
kb_id:id
})
@@ -615,18 +614,27 @@
let data = await kbdocumentrm({doc_id: row.id})
if(data.code == 0){
Message.success('鍒犻櫎鎴愬姛');
- knowledgeData()
+ console.log(kbobj, 'kbobj');
+ fetchData({
+ kb_id: kbobj.id,
+ page: 1,
+ page_size: 20
+ })
}
}
const run = async (row)=>{
console.log(row);
row.loading = true;
- let data = await kbdocumentchangeparser({
- parser_id: row.parser_id,
- doc_id: row.id,
- parser_config: row.parser_config,
+ let data = await kbdocumentrun({
+ doc_ids: [row.id],
+ run: '1'
})
+ // let data = await kbdocumentchangeparser({
+ // parser_id: row.parser_id,
+ // doc_id: row.id,
+ // parser_config: row.parser_config,
+ // })
if(data.code == 0){
Message.success('瑙f瀽鎴愬姛');
row.run = '3';
@@ -637,7 +645,13 @@
row.loading = false;
}
-
+const changeFetchData = async (row)=>{
+ fetchData({
+ kb_id: kbobj.id,
+ page: 1,
+ page_size: 20
+ })
+}
watch(
() => columns.value,
(val) => {
--
Gitblit v1.8.0