This commit is contained in:
ShawnPhang 2024-08-20 16:15:07 +08:00
parent cba825cdbf
commit 82a68319f7
3 changed files with 13 additions and 10 deletions

View File

@ -3,20 +3,22 @@
* @Date: 2022-03-06 13:53:30 * @Date: 2022-03-06 13:53:30
* @Description: * @Description:
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-04-18 20:02:55 * @LastEditTime: 2024-08-20 16:12:54
*/ */
export default class WebWorker { export default class WebWorker {
private worker: Worker | undefined private worker: Worker | undefined
constructor(name: string) { constructor(useWorker: any) {
if (typeof Worker === 'undefined') { if (typeof Worker === 'undefined') {
console.error('Web Worker is not supported in this browser.') console.error('Web Worker is not supported in this browser.')
} else { } else {
const file = name ? `../widgets/${name}.worker.ts` : null // 动态引入无法打包,必须是静态的
file && // const file = name ? `../widgets/${name}.worker.ts` : null
(this.worker = new Worker(new URL(file, import.meta.url), { // file &&
type: 'module', // (this.worker = new Worker(new URL(file, import.meta.url), {
})) // type: 'module',
// }))
this.worker = new useWorker()
} }
} }
public start(data?: any, cb?: Function) { public start(data?: any, cb?: Function) {

View File

@ -3,7 +3,7 @@
* @Date: 2022-01-10 14:57:53 * @Date: 2022-01-10 14:57:53
* @Description: Psd文件解析 * @Description: Psd文件解析
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>
* @LastEditTime: 2024-08-18 21:06:05 * @LastEditTime: 2024-08-20 16:14:18
--> -->
<template> <template>
<div id="page-design-index" ref="pageDesignIndex"> <div id="page-design-index" ref="pageDesignIndex">
@ -58,7 +58,8 @@ import designBoard from '@/components/modules/layout/designBoard/index.vue'
import zoomControl from '@/components/modules/layout/zoomControl/index.vue' import zoomControl from '@/components/modules/layout/zoomControl/index.vue'
import HeaderOptions, { TEmitChangeData } from './components/UploadTemplate.vue' import HeaderOptions, { TEmitChangeData } from './components/UploadTemplate.vue'
import ProgressLoading from '@/components/common/ProgressLoading/index.vue' import ProgressLoading from '@/components/common/ProgressLoading/index.vue'
import MyWorker from '@/utils/plugins/webWorker' import useWorker from '@/utils/plugins/webWorker'
import psdWorker from '../utils/plugins/worker/loadPSD.worker.ts?worker'
// import { processPSD2Page } from '@/utils/plugins/psd' // import { processPSD2Page } from '@/utils/plugins/psd'
import { createBase64 } from '@/utils/plugins/psd' import { createBase64 } from '@/utils/plugins/psd'
// import { useSetupMapGetters } from '@/common/hooks/mapGetters' // import { useSetupMapGetters } from '@/common/hooks/mapGetters'
@ -97,7 +98,7 @@ const { dZoom } = storeToRefs(useCanvasStore())
const zoomControlRef = ref<typeof zoomControl | null>() const zoomControlRef = ref<typeof zoomControl | null>()
let loading: ReturnType<typeof useLoading> | null = null let loading: ReturnType<typeof useLoading> | null = null
const myWorker = new MyWorker('loadPSD') const myWorker = new useWorker(psdWorker)
onMounted(async () => { onMounted(async () => {
groupStore.initGroupJson(JSON.stringify(wGroupSetting)) groupStore.initGroupJson(JSON.stringify(wGroupSetting))