+
@@ -140,6 +172,9 @@ onMounted(() => {
:width="70"
:percent="props.data.uploadCurrent">
-->
+
+
+
@@ -162,7 +197,7 @@ onMounted(() => {
.im-message-video {
overflow: hidden;
padding: 20rpx 18rpx;
- background: #46299D;
+ background: #46299d;
min-width: 30rpx;
min-height: 30rpx;
display: inline-flex;
@@ -220,7 +255,6 @@ onMounted(() => {
:deep(.uni-video-bar) {
display: none;
}
-
}
.circleProgress {
width: 80rpx !important;
@@ -245,4 +279,19 @@ onMounted(() => {
height: 100%;
object-fit: contain;
}
+
+.upload-failed {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ z-index: 1;
+ width: 40rpx;
+ height: 40rpx;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: #ff4d4f;
+ border-radius: 50%;
+}
diff --git a/src/main.js b/src/main.js
index a5d29b0..94ae8fe 100644
--- a/src/main.js
+++ b/src/main.js
@@ -10,6 +10,8 @@ import tmui from '@/uni_modules/tmui'
import { config } from '@/config/tmui/index.js'
import 'dayjs/locale/zh-cn'
import xLoaderror from '@/components/x-loaderror/index.vue'
+import asyncLoading from '@/components/async-loading/index.vue'
+import asyncError from '@/components/async-error/index.vue'
import { vLoading } from '@/components/x-loading/index.js'
import messagePopup from '@/components/x-message/useMessagePopup'
import pageAnimation from '@/components/page-animation/index.vue'
@@ -29,6 +31,8 @@ export function createApp() {
app.mixin(pageAnimation)
app.component('customNavbar', customNavbar)
app.component('x-loaderror', xLoaderror)
+ app.component('AsyncLoading', asyncLoading)
+ app.component('AsyncError', asyncError)
app.directive('no-space', {
mounted(el) {
el.addEventListener('input', (e) => {
diff --git a/src/pages/dialog/components/filePanel.vue b/src/pages/dialog/components/filePanel.vue
index 33df9ad..f2550c6 100644
--- a/src/pages/dialog/components/filePanel.vue
+++ b/src/pages/dialog/components/filePanel.vue
@@ -181,12 +181,13 @@ const photoActionsSelect = (index) => {
}
const onUploadImageVideo = async (file, type = 'image', fileUrl) => {
- console.log(file, 'file')
+ console.log('开始上传文件:', file.name)
+ uploadsStore.updateUploadStatus(true)
return new Promise(async (resolve) => {
if (type === 'image') {
let image = new Image()
image.src = URL.createObjectURL(file)
- image.onload = () => {
+ image.onload = async () => {
const form = new FormData()
form.append('file', file)
form.append('source', 'fonchain-chat')
@@ -220,44 +221,62 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => {
}
virtualList.value.unshift(newItem)
- uploadImg(form, (e) => onProgressFn(e, randomId)).then(
- ({ status, data, msg }) => {
- if (status == 0) {
- // 更新上传状态为成功
- const index = virtualList.value.findIndex(
- (item) => item.file_num === randomId,
- )
- if (index !== -1) {
- virtualList.value[index].uploadStatus = 2
- virtualList.value[index].uploadCurrent = 100
- }
- resolve({
- type: 'image',
- url: data.ori_url,
- size: file.size,
- width: image.width,
- height: image.height,
- file_num: randomId,
- })
- } else {
- // 更新上传状态为失败
- const index = virtualList.value.findIndex(
- (item) => item.file_num === randomId,
- )
- if (index !== -1) {
- virtualList.value[index].uploadStatus = 3
- }
- resolve('')
- message.error(msg)
+
+ try {
+ const result = await uploadImg(form, (e) => onProgressFn(e, randomId))
+ console.log('上传完成,结果:', result)
+
+ if (result.status === 0) {
+ // 更新上传状态为成功
+ const index = virtualList.value.findIndex(
+ (item) => item.file_num === randomId,
+ )
+ if (index !== -1) {
+ virtualList.value[index].uploadStatus = 2
+ virtualList.value[index].uploadCurrent = 100
}
- },
- )
+
+ // 确保返回数据
+ resolve({
+ type: 'image',
+ url: result.data.ori_url,
+ size: file.size,
+ width: image.width,
+ height: image.height,
+ file_num: randomId,
+ })
+ } else {
+ uploadsStore.updateUploadStatus(false)
+ // 更新上传状态为失败
+ const index = virtualList.value.findIndex(
+ (item) => item.file_num === randomId,
+ )
+ if (index !== -1) {
+ virtualList.value[index].uploadStatus = 3
+ }
+ message.error(result.msg)
+ resolve('')
+ }
+ } catch (error) {
+ console.error('上传出错:', error)
+ uploadsStore.updateUploadStatus(false)
+ // 更新上传状态为失败
+ const index = virtualList.value.findIndex(
+ (item) => item.file_num === randomId,
+ )
+ if (index !== -1) {
+ virtualList.value[index].uploadStatus = 3
+ }
+ message.error('上传失败')
+ resolve('')
+ }
}
} else {
uni.getVideoInfo({
src: fileUrl,
- success: (resp) => {
- console.log(resp)
+ success: async (resp) => {
+ console.log('视频信息:', resp)
+ const form = new FormData()
form.append('file', file)
form.append('source', 'fonchain-chat')
form.append('type', 'video')
@@ -287,45 +306,65 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => {
talk_type: dialogueStore.talk.talk_type,
user_id: userStore.uid,
uploadCurrent: 0,
- uploadStatus: 1, // 1 上传中 2 上传成功 3 上传失败
+ uploadStatus: 1,
}
virtualList.value.unshift(newItem)
- uploadImg(form, (e) => onProgressFn(e, randomId)).then(
- ({ status, data, msg }) => {
- if (status == 0) {
- // 更新上传状态为成功
- const index = virtualList.value.findIndex(
- (item) => item.file_num === randomId,
- )
- if (index !== -1) {
- virtualList.value[index].uploadStatus = 2
- virtualList.value[index].uploadCurrent = 100
- }
- console.log(data)
- resolve({
- type: 'video',
- url: data.ori_url,
- cover: data.cover_url,
- duration: parseInt(resp.duration),
- size: file.size,
- file_num: randomId,
- })
- } else {
- // 更新上传状态为失败
- const index = virtualList.value.findIndex(
- (item) => item.file_num === randomId,
- )
- if (index !== -1) {
- virtualList.value[index].uploadStatus = 3
- }
- resolve('')
- message.error(msg)
+
+ try {
+ const result = await uploadImg(form, (e) => onProgressFn(e, randomId))
+ console.log('视频上传完成,结果:', result)
+
+ if (result.status === 0) {
+ // 更新上传状态为成功
+ const index = virtualList.value.findIndex(
+ (item) => item.file_num === randomId,
+ )
+ if (index !== -1) {
+ virtualList.value[index].uploadStatus = 2
+ virtualList.value[index].uploadCurrent = 100
}
- },
- )
+
+ resolve({
+ type: 'video',
+ url: result.data.ori_url,
+ cover: result.data.cover_url,
+ duration: parseInt(resp.duration),
+ size: file.size,
+ file_num: randomId,
+ })
+ } else {
+ uploadsStore.updateUploadStatus(false)
+ // 更新上传状态为失败
+ const index = virtualList.value.findIndex(
+ (item) => item.file_num === randomId,
+ )
+ if (index !== -1) {
+ virtualList.value[index].uploadStatus = 3
+ }
+ message.error(result.msg)
+ resolve('')
+ }
+ } catch (error) {
+ console.error('视频上传出错:', error)
+ uploadsStore.updateUploadStatus(false)
+ // 更新上传状态为失败
+ const index = virtualList.value.findIndex(
+ (item) => item.file_num === randomId,
+ )
+ if (index !== -1) {
+ virtualList.value[index].uploadStatus = 3
+ }
+ message.error('上传失败')
+ resolve('')
+ }
},
+ fail: (error) => {
+ console.error('获取视频信息失败:', error)
+ uploadsStore.updateUploadStatus(false)
+ message.error('获取视频信息失败')
+ resolve('')
+ }
})
- const form = new FormData()
}
})
}
@@ -508,6 +547,7 @@ const chooseFile = () => {
uploadStatus: 1, // 1 上传中 2 上传成功 3 上传失败
}
virtualList.value.unshift(newItem)
+ uploadsStore.updateUploadStatus(true)
uploadsStore.initUploadFile(
res.tempFiles[0],
props.talkParams,
@@ -523,6 +563,7 @@ const chooseFile = () => {
virtualList.value[index].uploadCurrent = 100
}
} else {
+ uploadsStore.updateUploadStatus(false)
// 更新上传状态为失败
const index = virtualList.value.findIndex(
(item) => item.file_num === randomId,
diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue
index 5a74812..f506d15 100644
--- a/src/pages/dialog/index.vue
+++ b/src/pages/dialog/index.vue
@@ -216,6 +216,17 @@