Skip to content

Commit b1cd726

Browse files
authored
fix(#459): @kuaitu/core中移除viewui的使用,消息提示移交至业务层 (#460)
1 parent c4b778a commit b1cd726

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

packages/core/ServersPlugin.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,12 @@ class ServersPlugin {
209209

210210
clipboard() {
211211
const jsonStr = this.getJson();
212-
clipboardText(JSON.stringify(jsonStr, null, '\t'));
212+
return clipboardText(JSON.stringify(jsonStr, null, '\t'));
213213
}
214214

215-
clipboardBase64() {
216-
this.preview().then((dataUrl: any) => {
217-
clipboardText(dataUrl);
218-
});
215+
async clipboardBase64() {
216+
const dataUrl = await this.preview();
217+
return clipboardText(dataUrl);
219218
}
220219

221220
async saveJson() {
@@ -251,7 +250,7 @@ class ServersPlugin {
251250
}
252251

253252
preview() {
254-
return new Promise((resolve) => {
253+
return new Promise<string>((resolve) => {
255254
this.editor.hooksEntity.hookSaveBefore.callAsync('', () => {
256255
const option = this._getSaveOption();
257256
this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);

packages/core/utils/utils.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
import { v4 as uuid } from 'uuid';
99
import { useClipboard, useFileDialog, useBase64 } from '@vueuse/core';
10-
import { Message } from 'view-ui-plus';
1110

1211
/**
1312
* @description: 图片文件转字符串
@@ -60,17 +59,8 @@ export function insertImgFile(str: string) {
6059
* @param options Copy options
6160
* @returns Promise that resolves when the text is copied successfully, or rejects when the copy fails.
6261
*/
63-
export const clipboardText = async (
64-
source: string,
65-
options?: Parameters<typeof useClipboard>[0]
66-
) => {
67-
try {
68-
await useClipboard({ source, ...options }).copy();
69-
Message.success('复制成功');
70-
} catch (error) {
71-
Message.error('复制失败');
72-
throw error;
73-
}
62+
export const clipboardText = (source: string, options?: Parameters<typeof useClipboard>[0]) => {
63+
return useClipboard({ source, ...options }).copy();
7464
};
7565

7666
export function downFile(fileStr: string, fileType: string) {

src/components/save.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ const { t } = useI18n();
5050
const { canvasEditor } = useSelect();
5151
const cbMap = {
5252
clipboard() {
53-
canvasEditor.clipboard();
53+
try {
54+
canvasEditor.clipboard();
55+
Message.success('复制成功');
56+
} catch (error) {
57+
Message.error('复制失败');
58+
}
5459
},
5560
saveJson() {
5661
canvasEditor.saveJson();
@@ -62,7 +67,12 @@ const cbMap = {
6267
canvasEditor.saveImg();
6368
},
6469
clipboardBase64() {
65-
canvasEditor.clipboardBase64();
70+
try {
71+
canvasEditor.clipboardBase64();
72+
Message.success('复制成功');
73+
} catch (error) {
74+
Message.error('复制失败');
75+
}
6676
},
6777
async saveMyClould() {
6878
try {

0 commit comments

Comments
 (0)