diff --git a/resources/assets/js/functions/eeui.js b/resources/assets/js/functions/eeui.js index 3470d6cfe..6ac5cbb5a 100755 --- a/resources/assets/js/functions/eeui.js +++ b/resources/assets/js/functions/eeui.js @@ -263,18 +263,68 @@ }, // 获取最新一张照片 - eeuiAppGetLatestPhoto(callback) { - if (!$A.isEEUiApp) return; - $A.eeuiModule("eeui").then(obj => { - obj.getLatestPhoto(callback); + eeuiAppGetLatestPhoto(expiration = 60, timeout = 10) { + 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"}); + } + const timer = timeout > 0 ? setTimeout(() => { + reject({msg: "timeout"}); + }, timeout * 1000) : null; + // + eeui.getLatestPhoto(result => { + timer && clearTimeout(timer); + if ( + result.status !== 'success' || + result.thumbnail.width < 10 || !result.thumbnail.base64 || + result.original.width < 10 || !result.original.path + ) { + return reject({msg: result.error || "no photo"}); + } + if (expiration > 0 && (result.created + expiration) < $A.dayjs().unix()) { + return reject({msg: "photo expired"}); + } + resolve(result); + }); + } catch (e) { + reject({msg: e.message}); + } }) }, // 上传照片(通过 eeuiAppGetLatestPhoto 获取到的path,params 参数:{url,data,headers,path,fieldName}) - eeuiAppUploadPhoto(params, callback) { - if (!$A.isEEUiApp) return; - $A.eeuiModule("eeui").then(obj => { - obj.uploadPhoto(params, callback); + eeuiAppUploadPhoto(params, timeout = 30) { + 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"}); + } + const timer = timeout > 0 ? setTimeout(() => { + reject({msg: "timeout"}); + }, timeout * 1000) : null; + // + eeui.uploadPhoto(params, result => { + timer && clearTimeout(timer); + if (result.status !== 'success') { + return reject({msg: result.error || "upload failed"}); + } + if (result.data.ret !== 1) { + return reject({msg: result.data.msg || "upload failed"}); + } + resolve(result.data.data); + }); + } catch (e) { + reject({msg: e.message}); + } }) } }); diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 353f567a7..0aead23fd 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -796,13 +796,7 @@ export default { this.showEmoji = false; this.emojiQuickShow = false; // - $A.eeuiAppGetLatestPhoto(({status, created, thumbnail, original}) => { - if (status !== 'success' - // || created + 60 < $A.dayjs().unix() - || !thumbnail.base64 - || !original.path) { - return - } + $A.eeuiAppGetLatestPhoto(0).then(({thumbnail, original}) => { const width = 120; const height = Math.min(150, thumbnail.height / (thumbnail.width / width)); this.maybePhotoStyle = { @@ -810,7 +804,7 @@ export default { height: height + 'px', backgroundImage: `url(${thumbnail.base64})`, } - this.maybePhotoData = original + this.maybePhotoData = {thumbnail, original} this.maybePhotoShow = true this.$nextTick(() => { this.$refs.more?.updatePopper() @@ -1643,29 +1637,15 @@ export default { break; case 'maybe-photo': - $A.eeuiAppUploadPhoto({ - url: $A.apiUrl('dialog/msg/sendfile'), - data: { - dialog_id: this.dialogId, - }, - headers: { - token: this.userToken, - }, - path: this.maybePhotoData.path, - fieldName: "files" - }, ({status, data}) => { - /*switch (status) { - case "uploading": - break; - case "success": - if (data.ret !== 1) { - $A.messageError(data.msg || "上传失败") - } - break; - case "error": - $A - break; - }*/ + this.$emit('on-file', { + type: 'photo', + msg: { + type: 'img', + path: this.maybePhotoData.original.path, + width: this.maybePhotoData.original.width, + height: this.maybePhotoData.original.height, + thumb: this.maybePhotoData.thumbnail.base64, + } }) break; diff --git a/resources/assets/js/pages/manage/components/DialogWrapper.vue b/resources/assets/js/pages/manage/components/DialogWrapper.vue index d14a5e2c6..98ca7de09 100644 --- a/resources/assets/js/pages/manage/components/DialogWrapper.vue +++ b/resources/assets/js/pages/manage/components/DialogWrapper.vue @@ -1700,6 +1700,10 @@ export default { this.pasteFile = []; this.pasteItem = []; files.some(file => { + if (file.type === 'photo') { + this.sendPhoto(file.msg) + return false; + } const item = { type: $A.getMiddle(file.type, null, '/'), name: file.name, @@ -1724,6 +1728,40 @@ export default { } }, + /** + * 发送照片 + * @param msg + */ + sendPhoto(msg) { + const tempMsg = { + id: $A.randNum(1000000000, 9999999999), + file_uid: 0, + dialog_id: this.dialogData.id, + reply_id: this.quoteId, + type: 'file', + userid: this.userId, + msg, + } + this.tempMsgs.push(tempMsg) + // + $A.eeuiAppUploadPhoto({ + url: $A.apiUrl('dialog/msg/sendfile'), + data: { + dialog_id: tempMsg.dialog_id, + }, + headers: { + token: this.userToken, + }, + path: msg.path, + fieldName: "files" + }).then(data => { + this.sendSuccess(data, tempMsg.id) + }).catch(({msg}) => { + this.forgetTempMsg(tempMsg.id) + $A.messageError(msg || "上传失败") + }) + }, + /** * 发送位置消息 * @param data