From 2f5fbb2144ca03477eb91ab36a990ea013065214 Mon Sep 17 00:00:00 2001 From: liudong <liudong> Date: 星期四, 08 八月 2024 17:47:32 +0800 Subject: [PATCH] 解析块页面修改 --- src/views/dmx/knowledgeLib/add.vue | 208 +++++++++++++++++++++++++++------------------------- 1 files changed, 108 insertions(+), 100 deletions(-) diff --git a/src/views/dmx/knowledgeLib/add.vue b/src/views/dmx/knowledgeLib/add.vue index 4fa459a..f8cca58 100644 --- a/src/views/dmx/knowledgeLib/add.vue +++ b/src/views/dmx/knowledgeLib/add.vue @@ -1,124 +1,132 @@ - <template> <a-button type="primary" @click="handleClick"> <template #icon> <icon-plus /> </template> - 鏂板缓鏂囦欢 + 鏂板鏂囦欢 </a-button> - <a-modal v-model:visible="visible" title="涓婁紶鏂囦欢" @before-open="handleOpened" @cancel="handleCancel" @before-ok="handleBeforeOk" title-align="start"> + <a-modal + v-model:visible="visible" + title="涓婁紶鏂囦欢" + @open="handleOpened" + @cancel="handleCancel" + :ok-loading="loading" + @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=".word, .pdf, .ppt, .excel, .txt, .zip, .rar, .7z, .doc, .docx, .xls, .xlsx, .pptx, .ppt," :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-tab-pane key="1" title="鏂囦欢"> </a-tab-pane> + <a-tab-pane key="2" title="鏂囦欢澶�"> </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 } from "vue"; - -const visible = ref(false); -const loading = ref(false); -const activeKey = ref('1'); -const formRef = ref(null); -const uploadList = ref([]); -const form = reactive({ - name: '',// 鐢ㄦ埛鍚� - nameJoin: '',// 鏄电О - post: '',// 宀椾綅 - txt: '',// 澶囨敞 -}); - - -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); + 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([]); + const form = reactive({ + name: '', // 鐢ㄦ埛鍚� + nameJoin: '', // 鏄电О + 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 submitForm = async (done) => { + if (files.value && files.value.length > 0) { + files.value.map((item) => { + const formData = new FormData(); + formData.append('file', item.file); + formData.append('kb_id', props.kbobj.id); + kbdocumentupload(formData).then((res) => { + if (res.code == 0) { + emit('changeFetchData'); + Message.success('涓婁紶鎴愬姛'); + handleCancel(); + } + }); + }); + done(false); + } else { + done(false); } - onSuccess(xhr.response); }; - const formData = new FormData(); - formData.append(name || 'file', fileItem.file); - xhr.open('post', '//upload-z2.qbox.me/', true); - xhr.send(formData); + const handleSubmit = ({ values, errors }) => {}; - return { - abort() { - xhr.abort() - } - } -}; + const onChange = (fileList) => { + files.value = fileList; + }; -const handleSubmit = ({values, errors}) => { - console.log('values:', values, '\nerrors:', errors) -} + const handleClick = () => { + visible.value = true; + }; + const handleBeforeOk = (done) => { + submitForm(done); + }; + const handleCancel = () => { + visible.value = false; + }; -const handleClick = () => { - visible.value = true; -}; -const handleBeforeOk = (done) => { - -}; -const handleCancel = () => { - visible.value = false; -} - -const handleOpened =(el) => { - uploadList.value = []; - console.log(uploadList, 'uploadList'); - console.log(activeKey.value, 'activeKey'); -} -const activeKeyChange = (value)=>{ - activeKey.value = value; -} -onBeforeMount(()=>{ - -}) -onMounted(()=>{ - - -}) + const handleOpened = (el) => { + // console.log(props.kbobj); + uploadList.value = []; + files.value = []; + loading.value = false; + }; + const activeKeyChange = (value) => { + activeKey.value = value; + directory.value = value == '2' ? true : false; + }; + onBeforeMount(() => {}); + onMounted(() => {}); </script> <script lang="ts"> -export default { - name: 'add', - methods: { - - } -}; + export default { + name: 'add', + methods: {}, + }; </script> <style scoped lang="less"> -.aUpload { - width: 100%; - max-height: 500px; - overflow: hidden; - overflow-y: auto; -} -</style> \ No newline at end of file + .aUpload { + width: 100%; + max-height: 500px; + overflow: hidden; + overflow-y: auto; + :deep(.arco-upload-progress) { + display: none; + } + } +</style> -- Gitblit v1.8.0