diff --git a/src/components/GxUpload/index.vue b/src/components/GxUpload/index.vue new file mode 100644 index 0000000..5802c81 --- /dev/null +++ b/src/components/GxUpload/index.vue @@ -0,0 +1,192 @@ + + + + diff --git a/src/components/Upload/UploadVideo.vue b/src/components/Upload/UploadVideo.vue index 5ece24d..67f4f3c 100644 --- a/src/components/Upload/UploadVideo.vue +++ b/src/components/Upload/UploadVideo.vue @@ -164,8 +164,9 @@ function customRequest(file) { } else { fileList.value = [record] } - + console.log(loading.value) if (!loading.value) { + console.log(1111) doUpload() } } @@ -210,24 +211,31 @@ async function doUpload() { const record = fileList.value[index] record.status = STATUS_ENUM.getValue('uploading') - // 模拟进度 - await simulateProgress(record) + try { + await simulateProgress(record) - // 模拟上传请求 - const formData = new FormData() - formData.append('file', record.file) - const { success, data } = await apis.common.uploadFile(formData) + const formData = new FormData() + formData.append('file', record.file) - if (config('http.code.success') === success) { - record.status = STATUS_ENUM.getValue('done') - record.src = data.url || record.src // 替换为真实地址 - emitValue() - await doUpload() - } else { + const { success, data } = await apis.common.uploadFile(formData) + + if (config('http.code.success') === success) { + record.percent = 100 + record.status = STATUS_ENUM.getValue('done') + record.src = data.url || record.src + emitValue() + await doUpload() // 上传下一个 + } else { + record.status = STATUS_ENUM.getValue('error') + message.error('上传失败,请重试') + } + } catch (err) { record.status = STATUS_ENUM.getValue('error') + message.error('上传异常,请检查网络或稍后再试') } } + async function simulateProgress(record) { return new Promise((resolve) => { let percent = 0 diff --git a/src/utils/util.js b/src/utils/util.js index 4a22a24..fcd56f0 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -328,3 +328,9 @@ export const myTrim = (str, char, type = 'right') => { } return str.replace(/^\s+|\s+$/g, '') } +/**截取图片路径域名部分 */ +export const spliceUrl=(fullUrl)=>{ + if(!fullUrl) return null + const pathOnly = fullUrl.replace(/^https?:\/\/[^\/]+/, ''); + return pathOnly +} diff --git a/src/views/dynamic/videoCenter/components/EditDialog.vue b/src/views/dynamic/videoCenter/components/EditDialog.vue index d45d2cb..cde3ee2 100644 --- a/src/views/dynamic/videoCenter/components/EditDialog.vue +++ b/src/views/dynamic/videoCenter/components/EditDialog.vue @@ -46,7 +46,8 @@ - + + @@ -86,6 +87,8 @@ import { useForm, useModal } from '@/hooks' import { message } from 'ant-design-vue' import { useI18n } from 'vue-i18n' import dayjs from 'dayjs' +import GxUpload from '@/components/GxUpload/index.vue' +import { spliceUrl } from '@/utils/util' const emit = defineEmits(['ok']) const { t } = useI18n() // 解构出t方法 const { modal, showModal, hideModal, showLoading, hideLoading } = useModal() @@ -96,7 +99,7 @@ const rolesValue = ref([]) const roles = ref([]) const fullImg = ref('') const smallImg = ref('') -const videoUrl = ref('') +const videoUrl = ref(['']) formRules.value = { title: { required: true, message: '请输入标题' }, subheading: { required: false, message: '请输入内容' }, @@ -145,7 +148,7 @@ async function handleEdit(record = {}) { console.log(formData.value) fullImg.value = config('http.apiBasic') + data.fullImg smallImg.value = config('http.apiBasic') + data.smallImg - videoUrl.value = config('http.apiBasic') + data.videoUrl + videoUrl.value = [config('http.apiBasic') + data.videoUrl] } /** * 确定 @@ -156,13 +159,15 @@ function handleOk() { console.log(values) try { showLoading() + //console.log(videoUrl.value) const params = { ...values, fullImg: formData.value.fullImg, smallImg: formData.value.smallImg, - videoUrl: formData.value.videoUrl, + videoUrl:videoUrl.value&&spliceUrl(videoUrl.value[0]), pushAt:dayjs(formData.value.pushAt).format("YYYY-MM-DD"), } + let result = null console.log(modal.value.type) switch (modal.value.type) { @@ -226,7 +231,7 @@ function formatArr(data, type = '') { function handleCancel() { fullImg.value = '' smallImg.value = '' - videoUrl.value = '' + videoUrl.value = [''] hideModal() } diff --git a/src/views/dynamic/videoCenter/index.vue b/src/views/dynamic/videoCenter/index.vue index 8cf3986..1df2d0a 100644 --- a/src/views/dynamic/videoCenter/index.vue +++ b/src/views/dynamic/videoCenter/index.vue @@ -51,8 +51,11 @@ + + +