diff --git a/src/hooks/useSessionMenu.js b/src/hooks/useSessionMenu.js index 1963d13..d7bff50 100644 --- a/src/hooks/useSessionMenu.js +++ b/src/hooks/useSessionMenu.js @@ -11,7 +11,12 @@ import { reactive, nextTick, computed, h, inject } from 'vue' // EditTwo, // IdCard // } from '@icon-park/vue-next' -import { ServeTopTalkList, ServeDeleteTalkList, ServeSetNotDisturb } from '@/api/chat' +import { + ServeTopTalkList, + ServeDeleteTalkList, + ServeSetNotDisturb, + ServeClearTalkUnreadNum, +} from '@/api/chat' import { useDialogueStore, useTalkStore, useDialogueListStore } from '@/store' import { ServeSecedeGroup } from '@/api/group' // import { ServeDeleteContact, ServeEditContactRemark } from '@/api/contact' @@ -23,7 +28,7 @@ export function useSessionMenu() { show: false, x: 0, y: 0, - item: {} + item: {}, }) const dialogueStore = useDialogueStore() @@ -118,10 +123,22 @@ export function useSessionMenu() { // 移除会话 const onRemoveTalk = (item) => { ServeDeleteTalkList({ - list_id: item.id + list_id: item.id, }).then(({ code }) => { if (code == 200) { onDeleteTalk(item.index_name) + console.error(item, 'item') + if (item.unread_num > 0) { + //同时已读 + ServeClearTalkUnreadNum( + { + talk_type: item.talk_type, + receiver_id: item.receiver_id, + }, + item.unread_num, + ).then(() => { + }) + } } }) } @@ -131,13 +148,13 @@ export function useSessionMenu() { ServeSetNotDisturb({ talk_type: item.talk_type, receiver_id: item.receiver_id, - is_disturb: item.is_disturb == 0 ? 1 : 0 + is_disturb: item.is_disturb == 0 ? 1 : 0, }).then(({ code, message }) => { if (code == 200) { message.success('设置成功!') talkStore.updateItem({ index_name: item.index_name, - is_disturb: item.is_disturb == 0 ? 1 : 0 + is_disturb: item.is_disturb == 0 ? 1 : 0, }) } else { message.error(message) @@ -153,12 +170,12 @@ export function useSessionMenu() { ServeTopTalkList({ list_id: item.id, - type: item.is_top == 0 ? 1 : 2 + type: item.is_top == 0 ? 1 : 2, }).then(({ code, message }) => { if (code == 200) { talkStore.updateItem({ index_name: item.index_name, - is_top: item.is_top == 0 ? 1 : 0 + is_top: item.is_top == 0 ? 1 : 0, }) } else { message.error(message) @@ -201,7 +218,7 @@ export function useSessionMenu() { negativeText: '取消', onPositiveClick: () => { ServeSecedeGroup({ - group_id: item.receiver_id + group_id: item.receiver_id, }).then(({ code, message }) => { if (code == 200) { message.success('已退出群聊') @@ -210,7 +227,7 @@ export function useSessionMenu() { message.error(message) } }) - } + }, }) } @@ -259,12 +276,18 @@ export function useSessionMenu() { disturb: onSetDisturb, signout_group: onSignOutGroup, delete_contact: onDeleteContact, - remark: onChangeRemark + remark: onChangeRemark, } dropdown.show = false evnets[key] && evnets[key](dropdown.item) } - return { dropdown, onCloseContextMenu, onContextMenuTalkHandle, onToTopTalk, onRemoveTalk } + return { + dropdown, + onCloseContextMenu, + onContextMenuTalkHandle, + onToTopTalk, + onRemoveTalk, + } } diff --git a/src/pages/dialog/components/filePanel.vue b/src/pages/dialog/components/filePanel.vue index 27470ad..33df9ad 100644 --- a/src/pages/dialog/components/filePanel.vue +++ b/src/pages/dialog/components/filePanel.vue @@ -101,6 +101,11 @@ const photoActionsSelect = (index) => { success: async (res) => { console.log(res, 'res') res.tempFiles.forEach(async (file) => { + const fileSizeInMB = (file.size / (1024 * 1024)).toFixed(2) + if (fileSizeInMB > 100) { + plus.nativeUI.toast('图片大小不能超过100MB') + return + } let data = await onUploadImageVideo(file, 'image') emit('selectImg', data, data.file_num) }) @@ -121,6 +126,13 @@ const photoActionsSelect = (index) => { fileReader.onloadend = async (e) => { const base64Url = e.target.result const fileObj = base64ToFile(base64Url) + const fileSizeInMB = (fileObj.size / (1024 * 1024)).toFixed( + 2, + ) + if (fileSizeInMB > 100) { + plus.nativeUI.toast('图片大小不能超过100MB') + return + } let data = await onUploadImageVideo(fileObj, 'image') emit('selectImg', data, data.file_num) } @@ -152,6 +164,11 @@ const photoActionsSelect = (index) => { maxDuration: 60, success: async (res) => { console.log(res, 'res') + const fileSizeInMB = (res.tempFile.size / (1024 * 1024)).toFixed(2) + if (fileSizeInMB > 100) { + plus.nativeUI.toast('视频大小不能超过100MB') + return + } let data = await onUploadImageVideo( res.tempFile, 'video', @@ -207,7 +224,9 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => { ({ status, data, msg }) => { if (status == 0) { // 更新上传状态为成功 - const index = virtualList.value.findIndex(item => item.file_num === randomId) + const index = virtualList.value.findIndex( + (item) => item.file_num === randomId, + ) if (index !== -1) { virtualList.value[index].uploadStatus = 2 virtualList.value[index].uploadCurrent = 100 @@ -222,7 +241,9 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => { }) } else { // 更新上传状态为失败 - const index = virtualList.value.findIndex(item => item.file_num === randomId) + const index = virtualList.value.findIndex( + (item) => item.file_num === randomId, + ) if (index !== -1) { virtualList.value[index].uploadStatus = 3 } @@ -273,7 +294,9 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => { ({ status, data, msg }) => { if (status == 0) { // 更新上传状态为成功 - const index = virtualList.value.findIndex(item => item.file_num === randomId) + const index = virtualList.value.findIndex( + (item) => item.file_num === randomId, + ) if (index !== -1) { virtualList.value[index].uploadStatus = 2 virtualList.value[index].uploadCurrent = 100 @@ -289,7 +312,9 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => { }) } else { // 更新上传状态为失败 - const index = virtualList.value.findIndex(item => item.file_num === randomId) + const index = virtualList.value.findIndex( + (item) => item.file_num === randomId, + ) if (index !== -1) { virtualList.value[index].uploadStatus = 3 } @@ -451,6 +476,11 @@ const chooseFile = () => { count: 1, extension: [''], success: (res) => { + const fileSizeInMB = (res.tempFiles[0].size / (1024 * 1024)).toFixed(2) + if (fileSizeInMB > 100) { + plus.nativeUI.toast('文件大小不能超过100MB') + return + } let randomId = uniqueId() let newItem = { avatar: userStore.avatar, @@ -478,23 +508,32 @@ const chooseFile = () => { uploadStatus: 1, // 1 上传中 2 上传成功 3 上传失败 } virtualList.value.unshift(newItem) - uploadsStore.initUploadFile(res.tempFiles[0], props.talkParams, randomId, (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 + uploadsStore.initUploadFile( + res.tempFiles[0], + props.talkParams, + randomId, + (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 + } + } else { + // 更新上传状态为失败 + const index = virtualList.value.findIndex( + (item) => item.file_num === randomId, + ) + if (index !== -1) { + virtualList.value[index].uploadStatus = 3 + } + message.error(msg) } - } else { - // 更新上传状态为失败 - const index = virtualList.value.findIndex(item => item.file_num === randomId) - if (index !== -1) { - virtualList.value[index].uploadStatus = 3 - } - message.error(msg) - } - }) + }, + ) }, }) } diff --git a/src/pages/dialog/index.vue b/src/pages/dialog/index.vue index f26604a..c656d95 100644 --- a/src/pages/dialog/index.vue +++ b/src/pages/dialog/index.vue @@ -22,7 +22,12 @@ :hideBack="dialogueStore.isOpenMultiSelect" >