Skip to content

Commit

Permalink
Merge branch 'nihaojob:main' into types_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ByeWord authored Jun 17, 2024
2 parents 2dd2c7d + d03f83b commit 5b83dda
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 38 deletions.
4 changes: 4 additions & 0 deletions packages/core/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import ContextMenu from './ContextMenu.js';
import ServersPlugin from './ServersPlugin';
import { AsyncSeriesHook } from 'tapable';

import Utils from './utils/utils';

class Editor extends EventEmitter {
private canvas: fabric.Canvas | null = null;
contextMenu: ContextMenu | null = null;
Expand Down Expand Up @@ -33,6 +35,8 @@ class Editor extends EventEmitter {
this._bindContextMenu();
this._initActionHooks();
this._initServersPlugin();

this.Utils = Utils;
}

get fabricCanvas() {
Expand Down
16 changes: 3 additions & 13 deletions packages/core/plugin/QrCodePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* @Author: 秦少卫
* @Date: 2024-06-06 19:58:26
* @LastEditors: 秦少卫
* @LastEditTime: 2024-06-07 21:25:16
* @LastEditTime: 2024-06-15 09:34:36
* @Description: 二维码生成工具
*/

import { fabric } from 'fabric';
import Editor from '../Editor';
import QRCodeStyling from 'qr-code-styling';
import { blobToBase64 } from '../utils/utils';

type IEditor = Editor;

Expand Down Expand Up @@ -58,7 +59,7 @@ class QrCodePlugin implements IPluginTempl {
const qrCode = new QRCodeStyling(options);
const blob = await qrCode.getRawData('png');
if (!blob) return '';
const base64Str = await this._blobToBase64(blob);
const base64Str = await blobToBase64(blob);
return base64Str || '';
}

Expand Down Expand Up @@ -110,17 +111,6 @@ class QrCodePlugin implements IPluginTempl {
};
}

_blobToBase64(blob: Blob) {
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
//读取后,result属性中将包含一个data:URL格式的Base64字符串用来表示所读取的文件
reader.onload = function (e) {
resolve(e.target.result);
};
});
}

async addQrCode() {
const option = this._defaultBarcodeOption();
const paramsOption = this._paramsToOption(option);
Expand Down
29 changes: 28 additions & 1 deletion packages/core/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 秦少卫
* @Date: 2022-09-05 22:21:55
* @LastEditors: 秦少卫
* @LastEditTime: 2024-04-22 00:43:01
* @LastEditTime: 2024-06-15 10:34:55
* @Description: 工具文件
*/
import { v4 as uuid } from 'uuid';
Expand Down Expand Up @@ -136,6 +136,31 @@ export const isActiveSelection = (thing: unknown): thing is fabric.ActiveSelecti
return thing instanceof fabric.ActiveSelection;
};

export function blobToBase64(blob: Blob) {
return new Promise((resolve) => {
const reader = new FileReader();
reader.addEventListener('load', () => {
resolve(reader.result);
});
reader.readAsDataURL(blob);
});
}

export function base64ToBlob(base64Data: string) {
if (!base64Data) {
return null;
}
const dataArr = base64Data.split(',');
const imageType = dataArr[0].match(/:(.*?);/)[1];
const textData = window.atob(dataArr[1]);
const arrayBuffer = new ArrayBuffer(textData.length);
const uint8Array = new Uint8Array(arrayBuffer);
for (let i = 0; i < textData.length; i++) {
uint8Array[i] = textData.charCodeAt(i);
}
return [new Blob([arrayBuffer], { type: imageType }), imageType.slice(6)];
}

export default {
getImgStr,
downFile,
Expand All @@ -147,4 +172,6 @@ export default {
isGroup,
isIText,
isActiveSelection,
blobToBase64,
base64ToBlob,
};
14 changes: 0 additions & 14 deletions src/App.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion src/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 秦少卫
* @Date: 2024-04-24 14:07:06
* @LastEditors: 秦少卫
* @LastEditTime: 2024-05-31 15:52:01
* @LastEditTime: 2024-06-14 16:17:41
* @Description: 用户接口登录
*/

Expand Down Expand Up @@ -78,3 +78,6 @@ export const getFileTypeTree = (data: any) =>
instance.get(`/api/custom/getUerFileTypeTree`, {
params: data,
});

// 获取用户树菜单
export const getUerFileTree = () => instance.get(`/api/user-templ/getUerFileTree`);
2 changes: 1 addition & 1 deletion src/components/lang.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @LastEditTime: 2023-07-29 22:24:03
-->
<template>
<Dropdown @on-click="setLang">
<Dropdown placement="bottom-end" @on-click="setLang">
<Button type="text">
{{ lang }}
<Icon type="ios-arrow-down"></Icon>
Expand Down
5 changes: 3 additions & 2 deletions src/language/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,6 @@
"addTemplPlaceholder": "请输入模板名称",
"addTemplCheckTip": "模板名称不能为空"
},
"mine": "我的"
}
"mine": "我的",
"batch": "批量"
}
18 changes: 12 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createApp } from 'vue';
import App from './App';
import App from './App.vue';
import router from './router';
import ViewUiPlus from 'view-ui-plus';
import 'view-ui-plus/dist/styles/viewuiplus.css';
Expand All @@ -12,8 +12,14 @@ import { VueMasonryPlugin } from 'vue-masonry';

import i18n from './language/index';

const app = createApp(App);

app.use(VueMasonryPlugin);

app.use(router).use(i18n).use(VueLazyLoad, {}).use(ViewUiPlus).mount('#app');
async function bootstrap() {
const app = createApp(App);
app.use(VueMasonryPlugin);
app.use(router);
app.use(i18n);
app.use(VueLazyLoad, {});
app.use(ViewUiPlus);
await router.isReady();
app.mount('#app');
}
bootstrap();
2 changes: 2 additions & 0 deletions src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ const rulerSwitch = (val) => {
} else {
canvasEditor.rulerDisable();
}
// 使标尺开关组件失焦,避免响应键盘的空格事件
document.activeElement.blur();
};
// 隐藏工具条
Expand Down

0 comments on commit 5b83dda

Please sign in to comment.