feat: 添加移动端提示可能要发送的图片

This commit is contained in:
kuaifan 2025-03-28 15:48:14 +08:00
parent 21aa4f7b2b
commit 1f0ab02702
3 changed files with 60 additions and 8 deletions

View File

@ -289,6 +289,10 @@
if (expiration > 0 && (result.created + expiration) < $A.dayjs().unix()) { if (expiration > 0 && (result.created + expiration) < $A.dayjs().unix()) {
return reject({msg: "photo expired"}); return reject({msg: "photo expired"});
} }
if ($A.__latestPhotoCreated && $A.__latestPhotoCreated === result.created) {
return reject({msg: "photo expired"});
}
$A.__latestPhotoCreated = result.created;
resolve(result); resolve(result);
}); });
} catch (e) { } catch (e) {
@ -296,6 +300,7 @@
} }
}) })
}, },
__latestPhotoCreated: null,
// 上传照片(通过 eeuiAppGetLatestPhoto 获取到的pathparams 参数:{url,data,headers,path,fieldName} // 上传照片(通过 eeuiAppGetLatestPhoto 获取到的pathparams 参数:{url,data,headers,path,fieldName}
eeuiAppUploadPhoto(params, timeout = 30) { eeuiAppUploadPhoto(params, timeout = 30) {
@ -312,7 +317,21 @@
reject({msg: "timeout"}); reject({msg: "timeout"});
}, timeout * 1000) : null; }, timeout * 1000) : null;
// //
if (!$A.isJson(params)) {
return reject({msg: "params error"});
}
let onReady = () => {};
if (typeof params.onReady !== "undefined") {
if (typeof params.onReady === "function") {
onReady = params.onReady;
}
delete params.onReady;
}
eeui.uploadPhoto(params, result => { eeui.uploadPhoto(params, result => {
if (result.status === 'ready') {
onReady(result.id)
return
}
timer && clearTimeout(timer); timer && clearTimeout(timer);
if (result.status !== 'success') { if (result.status !== 'success') {
return reject({msg: result.error || "upload failed"}); return reject({msg: result.error || "upload failed"});
@ -326,6 +345,29 @@
reject({msg: e.message}); reject({msg: e.message});
} }
}) })
},
// 取消上传照片
eeuiAppCancelUploadPhoto(id) {
return new Promise(async (resolve, reject) => {
if (!$A.isEEUiApp) {
return reject({msg: "not eeui app"});
}
try {
const eeui = await $A.eeuiModule("eeui")
if (!eeui) {
return reject({msg: "not eeui module"});
}
eeui.cancelUploadPhoto(id, result => {
if (result.status !== 'success') {
return reject({msg: result.error || "cancel failed"});
}
resolve(result);
});
} catch (e) {
reject({msg: e.message});
}
})
} }
}); });

View File

@ -796,7 +796,7 @@ export default {
this.showEmoji = false; this.showEmoji = false;
this.emojiQuickShow = false; this.emojiQuickShow = false;
// //
$A.eeuiAppGetLatestPhoto(0).then(({thumbnail, original}) => { $A.eeuiAppGetLatestPhoto().then(({thumbnail, original}) => {
const width = 120; const width = 120;
const height = Math.min(150, thumbnail.height / (thumbnail.width / width)); const height = Math.min(150, thumbnail.height / (thumbnail.width / width));
this.maybePhotoStyle = { this.maybePhotoStyle = {

View File

@ -1736,6 +1736,7 @@ export default {
const tempMsg = { const tempMsg = {
id: $A.randNum(1000000000, 9999999999), id: $A.randNum(1000000000, 9999999999),
file_uid: 0, file_uid: 0,
file_method: 'photo',
dialog_id: this.dialogData.id, dialog_id: this.dialogData.id,
reply_id: this.quoteId, reply_id: this.quoteId,
type: 'file', type: 'file',
@ -1753,7 +1754,10 @@ export default {
token: this.userToken, token: this.userToken,
}, },
path: msg.path, path: msg.path,
fieldName: "files" fieldName: "files",
onReady: (id) => {
this.$set(tempMsg, 'file_uid', id)
},
}).then(data => { }).then(data => {
this.sendSuccess(data, tempMsg.id) this.sendSuccess(data, tempMsg.id)
}).catch(({msg}) => { }).catch(({msg}) => {
@ -2317,6 +2321,7 @@ export default {
const tempMsg = { const tempMsg = {
id: file.tempId, id: file.tempId,
file_uid: file.uid, file_uid: file.uid,
file_method: 'uplaod',
dialog_id: this.dialogData.id, dialog_id: this.dialogData.id,
reply_id: this.quoteId, reply_id: this.quoteId,
type: 'file', type: 'file',
@ -3260,19 +3265,24 @@ export default {
content: '你确定要取消发送吗?', content: '你确定要取消发送吗?',
loading: true, loading: true,
onOk: () => { onOk: () => {
return new Promise((resolve, reject) => { return new Promise(async (resolve, reject) => {
if (this.operateItem.created_at) { if (this.operateItem.created_at) {
reject("消息已发送,不可取消"); reject("消息已发送,不可取消");
return return
} }
if (this.operateItem.type === 'file') { if (this.operateItem.type === "file") {
// //
if (this.$refs.chatUpload.cancel(this.operateItem.file_uid)) { const {file_uid, file_method} = this.operateItem
if (file_method === "photo") {
await $A.eeuiAppCancelUploadPhoto(file_uid)
this.forgetTempMsg(this.operateItem.id) this.forgetTempMsg(this.operateItem.id)
resolve(); return resolve();
} else {
reject("取消发送失败");
} }
if (this.$refs.chatUpload.cancel(file_uid)) {
this.forgetTempMsg(this.operateItem.id)
return resolve();
}
reject("取消发送失败");
} else { } else {
// //
this.$store.dispatch('callCancel', this.operateItem.id).then(() => { this.$store.dispatch('callCancel', this.operateItem.id).then(() => {