feat: update utils type

This commit is contained in:
IchliebedichZhu 2024-03-05 12:09:09 +00:00
parent bb4e0e66a5
commit ed5885caf1
7 changed files with 41 additions and 29 deletions

View File

@ -38,7 +38,7 @@
"vuex": "^4.0.0-0" "vuex": "^4.0.0-0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^16.3.1", "@types/node": "^20.11.24",
"@types/throttle-debounce": "^2.1.0", "@types/throttle-debounce": "^2.1.0",
"@typescript-eslint/eslint-plugin": "^7.1.0", "@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0", "@typescript-eslint/parser": "^7.1.0",

View File

@ -1,3 +1,5 @@
import { RouteRecordRaw } from 'vue-router';
/* /*
* @Author: ShawnPhang * @Author: ShawnPhang
* @Date: 2021-08-19 18:43:22 * @Date: 2021-08-19 18:43:22
@ -40,4 +42,4 @@ export default [
name: 'Psd', name: 'Psd',
component: () => import(/* webpackChunkName: 'psd' */ '@/views/Psd.vue'), component: () => import(/* webpackChunkName: 'psd' */ '@/views/Psd.vue'),
}, },
] ] as RouteRecordRaw[]

View File

@ -1,8 +1,10 @@
// import store from '@/store' // import store from '@/store'
export default (router: Type.Object) => { import { NavigationGuardNext, RouteLocationNormalized, Router } from "vue-router"
export default (router: Router) => {
router.beforeEach((to: Type.Object, from: Type.Object, next: () => void) => { router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
// if (to.meta.requireAuth) { } // if (to.meta.requireAuth) { }
// 有必要时清除残余的loading框 // 有必要时清除残余的loading框

View File

@ -7,8 +7,9 @@
*/ */
// import { Button, Field, Divider, NavBar, Toast, Popup } from 'vant' // import { Button, Field, Divider, NavBar, Toast, Popup } from 'vant'
import coms from '@/components/modules' import coms from '@/components/modules'
import { App } from 'vue'
export default (Vue: any) => { export default (Vue: App) => {
coms(Vue) coms(Vue)
// Vue.component(Button.name, Button) // Vue.component(Button.name, Button)
// Vue.use(Field).use(Divider).use(NavBar).use(Toast).use(Popup) // Vue.use(Field).use(Divider).use(NavBar).use(Toast).use(Popup)

View File

@ -6,8 +6,9 @@
* @LastEditTime: 2023-09-19 17:32:40 * @LastEditTime: 2023-09-19 17:32:40
*/ */
export default class PointImg { export default class PointImg {
private canvas: any private canvas: HTMLCanvasElement | undefined
private cvs: any private cvs: CanvasRenderingContext2D | null | undefined
constructor(img: any) { constructor(img: any) {
if (img.src) { if (img.src) {
try { try {
@ -16,6 +17,8 @@ export default class PointImg {
this.canvas.height = img.height this.canvas.height = img.height
img.crossOrigin = 'Anonymous' img.crossOrigin = 'Anonymous'
this.cvs = this.canvas.getContext('2d') this.cvs = this.canvas.getContext('2d')
if (!this.cvs) return
this.cvs.drawImage(img, 0, 0, img.width, img.height) this.cvs.drawImage(img, 0, 0, img.width, img.height)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
@ -28,8 +31,9 @@ export default class PointImg {
* @param y Number y坐标起点 * @param y Number y坐标起点
* @return color Object rgba #16 * @return color Object rgba #16
*/ */
const color: any = {} const color: Record<string, string> = {}
try { try {
if (!this.cvs) return
const obj = this.cvs.getImageData(x, y, 1, 1) const obj = this.cvs.getImageData(x, y, 1, 1)
const arr = obj.data.toString().split(',') const arr = obj.data.toString().split(',')
@ -42,7 +46,7 @@ export default class PointImg {
let third = parseInt(arr[2], 10).toString(16) let third = parseInt(arr[2], 10).toString(16)
third = third.length === 2 ? third : third + third third = third.length === 2 ? third : third + third
let last = parseInt(arr.pop(), 10) / 255 let last = parseInt(arr.pop() || '0', 10) / 255
last = Number(last.toFixed(0)) last = Number(last.toFixed(0))
color['rgba'] = 'rgba(' + arr.join(',') + ',' + last + ')' color['rgba'] = 'rgba(' + arr.join(',') + ',' + last + ')'

View File

@ -2,27 +2,27 @@
* @Author: ShawnPhang * @Author: ShawnPhang
* @Date: 2021-12-24 15:13:58 * @Date: 2021-12-24 15:13:58
* @Description: * @Description:
* @LastEditors: ShawnPhang <https://m.palxp.cn> * @LastEditors: ShawnPhang <https://m.palxp.cn>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2023-09-19 17:19:07 * @LastEditTime: 2024-03-05 12:00:00
*/ */
export default class PreLoad { export default class PreLoad {
private i: number private i: number
private arr: any[] private arr: (string | HTMLImageElement | ChildNode[])[]
constructor(arr: string[]) { constructor(arr: (string | HTMLImageElement | ChildNode[])[]) {
this.i = 0 this.i = 0
this.arr = arr this.arr = arr
} }
public imgs() { public imgs() {
return new Promise((resolve: any) => { return new Promise<void>((resolve) => {
const work = (src: string) => { const work = (src: string) => {
if (this.i < this.arr.length) { if (this.i < this.arr.length) {
const img = new Image() const img = new Image()
img.src = src img.src = src
if (img.complete) { if (img.complete) {
work(this.arr[this.i++]) work(this.arr[this.i++] as string)
} else { } else {
img.onload = () => { img.onload = () => {
work(this.arr[this.i++]) work(this.arr[this.i++] as string)
img.onload = null img.onload = null
} }
} }
@ -31,14 +31,14 @@ export default class PreLoad {
resolve() resolve()
} }
} }
work(this.arr[this.i]) work(this.arr[this.i] as string)
}) })
} }
public doms() { public doms() {
return new Promise((resolve: Function) => { return new Promise<void>((resolve) => {
const work = () => { const work = () => {
if (this.i < this.arr.length) { if (this.i < this.arr.length) {
this.arr[this.i].complete && this.i++ (this.arr[this.i] as HTMLImageElement).complete && this.i++
setTimeout(() => { setTimeout(() => {
work() work()
}, 100) }, 100)
@ -51,10 +51,10 @@ export default class PreLoad {
} }
/** 判断是否加载svg */ /** 判断是否加载svg */
public svgs() { public svgs() {
return new Promise((resolve: Function) => { return new Promise<void>((resolve) => {
const work = () => { const work = () => {
if (this.i < this.arr.length) { if (this.i < this.arr.length) {
this.arr[this.i].length > 0 && this.i++ (this.arr[this.i] as ChildNode[]).length > 0 && this.i++
setTimeout(() => { setTimeout(() => {
work() work()
}, 100) }, 100)

View File

@ -2,11 +2,11 @@
* @Author: ShawnPhang * @Author: ShawnPhang
* @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>, Jeremy Yu <https://github.com/JeremyYu-cn>
* @LastEditTime: 2023-09-14 17:28:53 * @LastEditTime: 2024-03-05 12:00:00
*/ */
export default class WebWorker { export default class WebWorker {
private worker: any private worker: Worker | undefined
constructor(name: string) { constructor(name: string) {
if (typeof Worker === 'undefined') { if (typeof Worker === 'undefined') {
@ -21,12 +21,15 @@ export default class WebWorker {
} }
public start(data: any) { public start(data: any) {
return new Promise((resolve) => { return new Promise((resolve) => {
// 监听Web Worker的消息 if (!this.worker) resolve('')
this.worker.onmessage = (e: any) => { else {
resolve(e.data) // 监听Web Worker的消息
this.worker.onmessage = (e) => {
resolve(e.data)
}
// 发送数据给Web Worker
this.worker.postMessage(data)
} }
// 发送数据给Web Worker
this.worker.postMessage(data)
}) })
} }
} }