mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-27 13:08:13 +00:00
feat: 添加移动端提示可能要发送的图片
This commit is contained in:
parent
8bdd31ae67
commit
43d0a85061
66
resources/assets/js/functions/eeui.js
vendored
66
resources/assets/js/functions/eeui.js
vendored
@ -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});
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user