Skip to content

Commit

Permalink
perf: 优化复制功能
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Mar 12, 2024
1 parent 71c62a3 commit 1fdd532
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 24 deletions.
21 changes: 21 additions & 0 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,27 @@ Vue.prototype.goBack = function () {
}
};

// 复制文本
Vue.prototype.copyText = function (obj) {
if (!$A.isJson(obj)) {
obj = {
text: obj,
success: "复制成功",
error: "复制失败"
}
}
if ($A.isEEUiApp) {
$A.eeuiAppCopyText(obj.text)
obj.success && $A.messageSuccess(obj.success)
return
}
app.$copyText(text).then(_ => {
obj.success && $A.messageSuccess(obj.success)
}).catch(_ => {
obj.error && $A.messageError(obj.error)
})
};

// 全局对象/变量
$A.L = $L;
$A.Electron = null;
Expand Down
5 changes: 5 additions & 0 deletions resources/assets/js/functions/eeui.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@
if (!$A.isEEUiApp) return;
return $A.eeuiModuleSync("webview").setDisabledUserLongClickSelect(val);
},

eeuiAppCopyText(text) {
if (!$A.isEEUiApp) return;
$A.eeuiModule("eeui").copyText(text)
},
});

window.$A = $;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ export default {
if (navigator.clipboard?.writeText)
navigator.clipboard.writeText(codeBlock.textContent ?? '')
else
this.copyText({text: codeBlock.textContent ?? '', origin: true})
this.copyContent({text: codeBlock.textContent ?? '', origin: true})
})
}
})
},
copyText(options) {
copyContent(options) {
const props = {origin: true, ...options}
let input
Expand Down
6 changes: 3 additions & 3 deletions resources/assets/js/pages/manage/components/DialogWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2872,18 +2872,18 @@ export default {
break;
case 'link':
this.$copyText(value).then(_ => $A.messageSuccess('复制成功')).catch(_ => $A.messageError('复制失败'))
this.copyText(value);
break;
case 'selected':
this.$copyText(value).then(_ => $A.messageSuccess('复制成功')).catch(_ => $A.messageError('复制失败'))
this.copyText(value);
break;
case 'text':
const copyEl = $A(this.$refs.scroller.$el).find(`[data-id="${this.operateItem.id}"]`).find('.dialog-content')
if (copyEl.length > 0) {
const text = copyEl[0].innerText.replace(/\n\n/g, "\n").replace(/(^\s*)|(\s*$)/g, "")
this.$copyText(text).then(_ => $A.messageSuccess('复制成功')).catch(_ => $A.messageError('复制失败'))
this.copyText(text)
} else {
$A.messageWarning('不可复制的内容');
}
Expand Down
6 changes: 1 addition & 5 deletions resources/assets/js/pages/manage/components/FileContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,7 @@ export default {
return;
}
this.linkFocus();
this.$copyText(this.linkData.url).then(_ => {
$A.messageSuccess('复制成功');
}).catch(_ => {
$A.messageError('复制失败');
});
this.copyText(this.linkData.url);
},
linkFocus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ export default {
sharekey: this.addData.sharekey
},
}).then(({ data }) => {
this.$copyText(data).then(_ => {
$A.messageSuccess('已复制会议邀请链接');
}).catch(_ => {
$A.messageError('复制失败');
this.copyText({
text: data,
success: '已复制会议邀请链接',
error: "复制失败"
});
this.invitationShow = false;
}).catch(({ msg }) => {
Expand Down
6 changes: 1 addition & 5 deletions resources/assets/js/pages/manage/components/ProjectPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1420,11 +1420,7 @@ export default {
return;
}
this.inviteFocus();
this.$copyText(this.inviteData.url).then(_ => {
$A.messageSuccess('复制成功');
}).catch(_ => {
$A.messageError('复制失败');
});
this.copyText(this.inviteData.url);
},
inviteFocus() {
Expand Down
6 changes: 1 addition & 5 deletions resources/assets/js/pages/manage/file.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,7 @@ export default {
return;
}
this.linkFocus();
this.$copyText(this.linkData.url).then(_ => {
$A.messageSuccess('复制成功');
}).catch(_ => {
$A.messageError('复制失败');
});
this.copyText(this.linkData.url);
},
linkFocus() {
Expand Down

0 comments on commit 1fdd532

Please sign in to comment.