|
@@ -40,39 +40,27 @@
|
|
|
transform: scale(1.1);
|
|
|
padding-bottom: 2px;
|
|
|
box-sizing: border-box;
|
|
|
- "
|
|
|
- src="../../../assets/shuax.svg"
|
|
|
- alt=""
|
|
|
- />
|
|
|
- {{ lang.flushed }}</el-button
|
|
|
- >
|
|
|
- <el-button
|
|
|
- v-if="userid == data.userid"
|
|
|
- type="primary"
|
|
|
- icon="el-icon-plus"
|
|
|
- size="small"
|
|
|
- @click="addImg($event)"
|
|
|
- >{{ lang.uploadFile }}
|
|
|
- <input
|
|
|
- type="file"
|
|
|
- accept="*"
|
|
|
- style="display: none"
|
|
|
- multiple="multiple"
|
|
|
- @change="beforeUpload($event)"
|
|
|
- /></el-button>
|
|
|
- <el-button
|
|
|
- type="primary"
|
|
|
- size="small"
|
|
|
- @click="openG"
|
|
|
- v-if="userid == data.userid && data.isMo == '2'"
|
|
|
- >
|
|
|
- <img
|
|
|
- style="vertical-align: middle"
|
|
|
- src="../../../assets/ETL.svg"
|
|
|
- alt=""
|
|
|
- />
|
|
|
- {{ lang.associatedFiles }}</el-button
|
|
|
- >
|
|
|
+ " src="../../../assets/shuax.svg" alt=""/>
|
|
|
+ {{ lang.flushed }}
|
|
|
+ </el-button>
|
|
|
+ <el-button v-if="userid == data.userid" type="primary" icon="el-icon-plus" size="small"
|
|
|
+ @click="addImg($event)">{{ lang.uploadFile }}
|
|
|
+ <input type="file" accept="*" style="display: none" multiple="multiple"
|
|
|
+ @change="beforeUpload($event)"/></el-button>
|
|
|
+ <el-button v-if="userid == data.userid" type="primary" icon="el-icon-plus" size="small"
|
|
|
+ @click="importFromWebpage($event)">{{ lang.importFromWebpage }}
|
|
|
+ <!-- <input-->
|
|
|
+ <!-- type="file"-->
|
|
|
+ <!-- accept="*"-->
|
|
|
+ <!-- style="display: none"-->
|
|
|
+ <!-- multiple="multiple"-->
|
|
|
+ <!-- @change="importFromWebpage($event)"-->
|
|
|
+ <!-- />-->
|
|
|
+ </el-button>
|
|
|
+ <el-button type="primary" size="small" @click="openG" v-if="userid == data.userid && data.isMo == '2'">
|
|
|
+ <img style="vertical-align: middle" src="../../../assets/ETL.svg" alt=""/>
|
|
|
+ {{ lang.associatedFiles }}
|
|
|
+ </el-button>
|
|
|
|
|
|
<el-button
|
|
|
type="primary"
|
|
@@ -406,6 +394,7 @@
|
|
|
></wOffice>
|
|
|
<relateFiles ref="relateFiles"></relateFiles>
|
|
|
<checkDialog ref="checkDialog"></checkDialog>
|
|
|
+ <WebCrawlDialog :visible.sync="webUrlDialogVisible" @confirm="handleWebUrlConfirm"/>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -434,6 +423,8 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
import relateFiles from "./components/relateFiles";
|
|
|
import checkDialog from "./components/checkDialog";
|
|
|
import testBox from "./components/testBox";
|
|
|
+import WebCrawlDialog from "./WebCrawlDialog.vue";
|
|
|
+
|
|
|
export default {
|
|
|
components: {
|
|
|
wVideo,
|
|
@@ -442,6 +433,7 @@ export default {
|
|
|
relateFiles,
|
|
|
checkDialog,
|
|
|
testBox,
|
|
|
+ WebCrawlDialog,
|
|
|
},
|
|
|
props: {
|
|
|
userid: {
|
|
@@ -519,6 +511,8 @@ export default {
|
|
|
pcount: 0,
|
|
|
ptotal: 0,
|
|
|
fileType: 1,
|
|
|
+ webUrlDialogVisible: false,
|
|
|
+
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -700,6 +694,133 @@ export default {
|
|
|
|
|
|
await uploadFiles(event.target.files);
|
|
|
},
|
|
|
+ async importFromWebpage(event) {
|
|
|
+ console.log('importFromWebpage');
|
|
|
+ this.webUrlDialogVisible = true;
|
|
|
+ },
|
|
|
+ handleWebUrlConfirm(dataFromForm) {
|
|
|
+ if (!dataFromForm) return;
|
|
|
+ // 直接 decode,不用判断前缀
|
|
|
+ // let url = decodeURIComponent(dataFromForm.url);
|
|
|
+
|
|
|
+ // const fileExtension = file.name.split(".").pop().toLowerCase();
|
|
|
+
|
|
|
+ // if (!allowedExtensions.includes(fileExtension)) {
|
|
|
+ // this.$message.error(`${this.lang.unsupFileformats}: ${file.name}`);
|
|
|
+ // await new Promise((resolve) => setTimeout(resolve, 1000)); // 延迟1秒再跳过
|
|
|
+ // continue; // 跳过不支持的文件
|
|
|
+ // }
|
|
|
+ let uuid = uuidv4();
|
|
|
+ let formData = new FormData();
|
|
|
+ // const timestamp = Date.now();
|
|
|
+ // const baseName = file.name.slice(0, -(fileExtension.length + 1));
|
|
|
+ let string = [this.folderid, this.moFolderid].filter((id) => id);
|
|
|
+ formData.append("url", dataFromForm.url)
|
|
|
+ // formData.append(
|
|
|
+ // "file",
|
|
|
+ // new File([file], `${baseName}${timestamp}.${fileExtension}`)
|
|
|
+ // );
|
|
|
+ formData.append("collection_ids", JSON.stringify(string));
|
|
|
+ formData.append("id", uuid);
|
|
|
+ formData.append(
|
|
|
+ "metadata",
|
|
|
+ JSON.stringify({url: dataFromForm.url, collection_ids: string})
|
|
|
+ );
|
|
|
+ formData.append("ingestion_mode", "fast");
|
|
|
+ formData.append("run_with_orchestration", "false");
|
|
|
+
|
|
|
+ // 获取html2md服务地址,优先从store取,没有则默认
|
|
|
+ const html2mdApi = process.env.VUE_APP_HTML2MD_API || 'http://localhost:7004';
|
|
|
+ const url = html2mdApi + '/file/knowledge-base/html-to-markdown';
|
|
|
+ const headers = {'Content-Type': 'multipart/form-data'};
|
|
|
+ this.ajax.post(url, formData, {headers})
|
|
|
+ .then(async (response) => {
|
|
|
+ // if (this.loadingInstance) {
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // this.loadingInstance.close();
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ console.log(response);
|
|
|
+ if (response && response.data && response.data.results) {
|
|
|
+ this.$message.success('文件上传成功');
|
|
|
+ // 获取文件名和id
|
|
|
+ // const fileName = response.data.results && response.data.results.filename ? response.data.results.filename : url;
|
|
|
+ const fileName = response.data.title;
|
|
|
+ const documentId = response.data.results && response.data.results.documentId;
|
|
|
+
|
|
|
+ const status =
|
|
|
+ response && response.status === 200
|
|
|
+ ? "success"
|
|
|
+ : "failed";
|
|
|
+ const msg =
|
|
|
+ response && response.status === 200
|
|
|
+ ? "切片成功"
|
|
|
+ : "切片失败";
|
|
|
+ this.$message({
|
|
|
+ message: msg,
|
|
|
+ type: status == "success" ? status : "error",
|
|
|
+ });
|
|
|
+ // setTimeout(() => {
|
|
|
+ this.getData();
|
|
|
+ // }, 1000)
|
|
|
+ setTimeout(() => {
|
|
|
+ this.fileArray.forEach((e) => {
|
|
|
+ if (e.documentid === uuid) {
|
|
|
+ e.ingestionStatus = status;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }, 1000);
|
|
|
+
|
|
|
+ // 调用 bindFileAndFolder
|
|
|
+ if (documentId) {
|
|
|
+ await this.bindFileAndFolder(
|
|
|
+ fileName,
|
|
|
+ documentId,
|
|
|
+ this.userid,
|
|
|
+ this.folderid,
|
|
|
+ this.moFolderid
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$message.error(response && response.data && response.data.msg ? response.data.msg : '文件上传失败');
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ this.$message.error('服务器繁忙');
|
|
|
+ if (this.fileNames) this.fileNames.pop && this.fileNames.pop();
|
|
|
+ if (this.fileUrls) this.fileUrls.pop && this.fileUrls.pop();
|
|
|
+ console.log(error);
|
|
|
+ if (this.loadingInstance) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.loadingInstance.close();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ async bindFileAndFolder(name, docid, uid, folder_id, mofid = '') {
|
|
|
+ try {
|
|
|
+ let params = {
|
|
|
+ n: name,
|
|
|
+ did: docid,
|
|
|
+ uid: this.userid,
|
|
|
+ fid: this.folderid,
|
|
|
+ mofid: this.moFolderid != this.folderid ? this.moFolderid : "",
|
|
|
+ };
|
|
|
+ const res2 = await this.ajax.post(this.$store.state.api + "addFile", [
|
|
|
+ params,
|
|
|
+ ]);
|
|
|
+ // 如果成功,关闭对话框
|
|
|
+ if (res2 && res2.status === 200) {
|
|
|
+ // this.handleClose && this.handleClose();
|
|
|
+ this.webUrlDialogVisible = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(res2);
|
|
|
+ } catch (err) {
|
|
|
+ console.error(err);
|
|
|
+ this.$message.error(this.lang.uploadFail);
|
|
|
+ }
|
|
|
+ },
|
|
|
async uploadFile(formData, name, uuid) {
|
|
|
try {
|
|
|
this.ajax
|
|
@@ -1064,6 +1185,7 @@ export default {
|
|
|
padding: 0 24px;
|
|
|
min-height: fit-content;
|
|
|
}
|
|
|
+
|
|
|
.f_box_top_right > .input {
|
|
|
position: relative;
|
|
|
/* height: 40px; */
|