mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-26 15:23:04 +00:00
perf: 消息菜单新增复制图片、链接功能
This commit is contained in:
parent
108c82b353
commit
51763d7857
13
electron/electron.js
vendored
13
electron/electron.js
vendored
@ -413,6 +413,19 @@ ipcMain.on('setDockBadge', (event, args) => {
|
|||||||
event.returnValue = "ok"
|
event.returnValue = "ok"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制Base64图片
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
ipcMain.on('copyBase64Image', (event, args) => {
|
||||||
|
const { base64 } = args;
|
||||||
|
if (base64) {
|
||||||
|
const img = nativeImage.createFromDataURL(base64)
|
||||||
|
clipboard.writeImage(img)
|
||||||
|
}
|
||||||
|
event.returnValue = "ok"
|
||||||
|
})
|
||||||
|
|
||||||
//================================================================
|
//================================================================
|
||||||
// Update
|
// Update
|
||||||
//================================================================
|
//================================================================
|
||||||
|
|||||||
@ -175,9 +175,9 @@
|
|||||||
<i class="taskfont"></i>
|
<i class="taskfont"></i>
|
||||||
<span>{{ $L('编辑') }}</span>
|
<span>{{ $L('编辑') }}</span>
|
||||||
</li>
|
</li>
|
||||||
<li v-if="operateHasText" @click="onOperate('copy')">
|
<li v-for="item in operateCopys" @click="onOperate('copy', item)">
|
||||||
<i class="taskfont"></i>
|
<i class="taskfont" v-html="item.icon"></i>
|
||||||
<span>{{ $L('复制') }}</span>
|
<span>{{ $L(item.label) }}</span>
|
||||||
</li>
|
</li>
|
||||||
<li @click="onOperate('forward')">
|
<li @click="onOperate('forward')">
|
||||||
<i class="taskfont"></i>
|
<i class="taskfont"></i>
|
||||||
@ -472,7 +472,7 @@ export default {
|
|||||||
navStyle: {},
|
navStyle: {},
|
||||||
|
|
||||||
operateVisible: false,
|
operateVisible: false,
|
||||||
operateHasText: false,
|
operateCopys: [],
|
||||||
operateStyles: {},
|
operateStyles: {},
|
||||||
operateItem: {},
|
operateItem: {},
|
||||||
operateEmojis: ['👌', '🤝', '🎉', '❤️', '👍', '🥰', '🥳️', '✅', '❌', '⭕️', '❓', '🚀', '👀'],
|
operateEmojis: ['👌', '🤝', '🎉', '❤️', '👍', '🥰', '🥳️', '✅', '❌', '⭕️', '❓', '🚀', '👀'],
|
||||||
@ -1601,7 +1601,30 @@ export default {
|
|||||||
onLongpress({event, el, msgData}) {
|
onLongpress({event, el, msgData}) {
|
||||||
this.operateVisible = this.operateItem.id === msgData.id;
|
this.operateVisible = this.operateItem.id === msgData.id;
|
||||||
this.operateItem = $A.isJson(msgData) ? msgData : {};
|
this.operateItem = $A.isJson(msgData) ? msgData : {};
|
||||||
this.operateHasText = msgData.type === 'text' && msgData.msg.text.replace(/<[^>]+>/g,"").length > 0
|
this.operateCopys = []
|
||||||
|
if (event.target.nodeName === 'IMG' && this.$Electron) {
|
||||||
|
this.operateCopys.push({
|
||||||
|
type: 'image',
|
||||||
|
icon: '',
|
||||||
|
label: '复制图片',
|
||||||
|
value: $A.rightDelete(event.target.currentSrc, '_thumb.jpg'),
|
||||||
|
})
|
||||||
|
} else if (event.target.nodeName === 'A') {
|
||||||
|
this.operateCopys.push({
|
||||||
|
type: 'link',
|
||||||
|
icon: '',
|
||||||
|
label: '复制链接',
|
||||||
|
value: event.target.href,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (msgData.type === 'text' && msgData.msg.text.replace(/<[^>]+>/g,"").length > 0) {
|
||||||
|
this.operateCopys.push({
|
||||||
|
type: 'text',
|
||||||
|
icon: '',
|
||||||
|
label: this.operateCopys.length > 0 ? '复制文本' : '复制',
|
||||||
|
value: '',
|
||||||
|
})
|
||||||
|
}
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const projectRect = el.getBoundingClientRect();
|
const projectRect = el.getBoundingClientRect();
|
||||||
const wrapRect = this.$el.getBoundingClientRect();
|
const wrapRect = this.$el.getBoundingClientRect();
|
||||||
@ -1627,7 +1650,7 @@ export default {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "copy":
|
case "copy":
|
||||||
this.onCopy()
|
this.onCopy(value)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "forward":
|
case "forward":
|
||||||
@ -1693,18 +1716,34 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onCopy() {
|
onCopy(data) {
|
||||||
if (this.operateHasText) {
|
if (!$A.isJson(data)) {
|
||||||
try {
|
return
|
||||||
|
}
|
||||||
|
const {type, value} = data
|
||||||
|
switch (type) {
|
||||||
|
case 'image':
|
||||||
|
if (this.$Electron) {
|
||||||
|
this.getBase64Image(value).then(base64 => {
|
||||||
|
this.$Electron.sendMessage('copyBase64Image', {base64});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'link':
|
||||||
|
this.$copyText(value).then(_ => $A.messageSuccess('复制成功')).catch(_ => $A.messageError('复制失败'))
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'text':
|
||||||
const copyEl = $A(this.$refs.scroller.$el).find(`[data-id="${this.operateItem.id}"]`).find('.dialog-content')
|
const copyEl = $A(this.$refs.scroller.$el).find(`[data-id="${this.operateItem.id}"]`).find('.dialog-content')
|
||||||
if (copyEl.length > 0) {
|
if (copyEl.length > 0) {
|
||||||
const text = copyEl[0].innerText.replace(/\n\n/g, "\n")
|
const text = copyEl[0].innerText.replace(/\n\n/g, "\n")
|
||||||
this.$copyText(text).then(_ => $A.messageSuccess('复制成功')).catch(_ => $A.messageError('复制失败'));
|
this.$copyText(text).then(_ => $A.messageSuccess('复制成功')).catch(_ => $A.messageError('复制失败'))
|
||||||
return
|
} else {
|
||||||
|
$A.messageWarning('不可复制的内容');
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
break;
|
||||||
}
|
}
|
||||||
$A.messageWarning('不可复制的内容');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onCancelReply() {
|
onCancelReply() {
|
||||||
@ -1994,6 +2033,29 @@ export default {
|
|||||||
this.$store.dispatch("updateDialogLastMsg", data.add);
|
this.$store.dispatch("updateDialogLastMsg", data.add);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getBase64Image(url) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
let canvas = document.createElement('CANVAS'),
|
||||||
|
ctx = canvas.getContext('2d'),
|
||||||
|
img = new Image;
|
||||||
|
img.crossOrigin = 'Anonymous';
|
||||||
|
img.onload = () => {
|
||||||
|
canvas.height = img.height;
|
||||||
|
canvas.width = img.width;
|
||||||
|
ctx.drawImage(img, 0, 0);
|
||||||
|
let format = "png";
|
||||||
|
if ($A.rightExists(url, "jpg") || $A.rightExists(url, "jpeg")) {
|
||||||
|
format = "jpeg"
|
||||||
|
} else if ($A.rightExists(url, "git")) {
|
||||||
|
format = "git"
|
||||||
|
}
|
||||||
|
resolve(canvas.toDataURL(`image/${format}`));
|
||||||
|
canvas = null;
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -41,6 +41,7 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: 18px 24px;
|
margin: 18px 24px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
> button {
|
> button {
|
||||||
margin: 0 8px;
|
margin: 0 8px;
|
||||||
}
|
}
|
||||||
@ -63,6 +64,7 @@
|
|||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: rgba($primary-desc-color, 0.1);
|
background-color: rgba($primary-desc-color, 0.1);
|
||||||
|
|
||||||
.user-exit {
|
.user-exit {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: translateX(0);
|
transform: translateX(0);
|
||||||
@ -79,8 +81,10 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: #999;
|
color: #999;
|
||||||
|
|
||||||
.common-loading {
|
.common-loading {
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
@ -90,6 +94,7 @@
|
|||||||
.common-avatar {
|
.common-avatar {
|
||||||
width: 0;
|
width: 0;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
||||||
.avatar-name {
|
.avatar-name {
|
||||||
padding-left: 8px;
|
padding-left: 8px;
|
||||||
}
|
}
|
||||||
@ -117,11 +122,18 @@
|
|||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateX(50%);
|
transform: translateX(50%);
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateX(0);
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
> i {
|
> i {
|
||||||
color: $primary-text-color;
|
color: $primary-text-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
> i {
|
> i {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@ -1320,18 +1320,18 @@
|
|||||||
margin-bottom: -8px;
|
margin-bottom: -8px;
|
||||||
display: grid;
|
display: grid;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
grid-template-columns: repeat(auto-fill, 50px);
|
grid-template-columns: repeat(auto-fill, 60px);
|
||||||
> li {
|
> li {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
width: 50px;
|
width: 60px;
|
||||||
height: 48px;
|
height: 52px;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 14px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
.taskfont {
|
.taskfont {
|
||||||
font-size: 20px;
|
font-size: 22px;
|
||||||
}
|
}
|
||||||
> span {
|
> span {
|
||||||
padding: 0 1px;
|
padding: 0 1px;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user