refactor: add prettier and format
This commit is contained in:
@@ -2,36 +2,39 @@ import { EditorComponent, EDITOR_COMPONENT } from '../../editor'
|
||||
import './dialog.css'
|
||||
|
||||
export interface IDialogData {
|
||||
type: string;
|
||||
label?: string;
|
||||
name: string;
|
||||
value?: string;
|
||||
options?: { label: string; value: string; }[];
|
||||
placeholder?: string;
|
||||
width?: number;
|
||||
height?: number;
|
||||
required?: boolean;
|
||||
type: string
|
||||
label?: string
|
||||
name: string
|
||||
value?: string
|
||||
options?: { label: string; value: string }[]
|
||||
placeholder?: string
|
||||
width?: number
|
||||
height?: number
|
||||
required?: boolean
|
||||
}
|
||||
|
||||
export interface IDialogConfirm {
|
||||
name: string;
|
||||
value: string;
|
||||
name: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface IDialogOptions {
|
||||
onClose?: () => void;
|
||||
onCancel?: () => void;
|
||||
onConfirm?: (payload: IDialogConfirm[]) => void;
|
||||
title: string;
|
||||
data: IDialogData[];
|
||||
onClose?: () => void
|
||||
onCancel?: () => void
|
||||
onConfirm?: (payload: IDialogConfirm[]) => void
|
||||
title: string
|
||||
data: IDialogData[]
|
||||
}
|
||||
|
||||
export class Dialog {
|
||||
|
||||
private options: IDialogOptions
|
||||
private mask: HTMLDivElement | null
|
||||
private container: HTMLDivElement | null
|
||||
private inputList: (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[]
|
||||
private inputList: (
|
||||
| HTMLInputElement
|
||||
| HTMLTextAreaElement
|
||||
| HTMLSelectElement
|
||||
)[]
|
||||
|
||||
constructor(options: IDialogOptions) {
|
||||
this.options = options
|
||||
@@ -90,7 +93,10 @@ export class Dialog {
|
||||
}
|
||||
}
|
||||
// 选项输入框
|
||||
let optionInput: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
|
||||
let optionInput:
|
||||
| HTMLInputElement
|
||||
| HTMLTextAreaElement
|
||||
| HTMLSelectElement
|
||||
if (option.type === 'select') {
|
||||
optionInput = document.createElement('select')
|
||||
option.options?.forEach(item => {
|
||||
@@ -162,5 +168,4 @@ export class Dialog {
|
||||
this.mask?.remove()
|
||||
this.container?.remove()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,17 +2,17 @@ import { EditorComponent, EDITOR_COMPONENT } from '../../editor'
|
||||
import './signature.css'
|
||||
|
||||
export interface ISignatureResult {
|
||||
value: string;
|
||||
width: number;
|
||||
height: number;
|
||||
value: string
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
export interface ISignatureOptions {
|
||||
width?: number;
|
||||
height?: number;
|
||||
onClose?: () => void;
|
||||
onCancel?: () => void;
|
||||
onConfirm?: (payload: ISignatureResult | null) => void;
|
||||
width?: number
|
||||
height?: number
|
||||
onClose?: () => void
|
||||
onCancel?: () => void
|
||||
onConfirm?: (payload: ISignatureResult | null) => void
|
||||
}
|
||||
|
||||
export class Signature {
|
||||
@@ -43,7 +43,8 @@ export class Signature {
|
||||
this.dpr = window.devicePixelRatio
|
||||
this.canvasWidth = (options.width || this.DEFAULT_WIDTH) * this.dpr
|
||||
this.canvasHeight = (options.height || this.DEFAULT_HEIGHT) * this.dpr
|
||||
const { mask, container, trashContainer, undoContainer, canvas } = this._render()
|
||||
const { mask, container, trashContainer, undoContainer, canvas } =
|
||||
this._render()
|
||||
this.mask = mask
|
||||
this.container = container
|
||||
this.trashContainer = trashContainer
|
||||
@@ -213,7 +214,8 @@ export class Signature {
|
||||
const targetLineWidth = Math.min(5, Math.max(1, 5 - speed * SPEED_FACTOR))
|
||||
// 平滑过渡算法(20%的变化比例)调整线条粗细:系数0.2
|
||||
const SMOOTH_FACTOR = 0.2
|
||||
this.ctx.lineWidth = this.ctx.lineWidth * (1 - SMOOTH_FACTOR) + targetLineWidth * SMOOTH_FACTOR
|
||||
this.ctx.lineWidth =
|
||||
this.ctx.lineWidth * (1 - SMOOTH_FACTOR) + targetLineWidth * SMOOTH_FACTOR
|
||||
// 绘制
|
||||
const { offsetX, offsetY } = evt
|
||||
this.ctx.beginPath()
|
||||
@@ -231,7 +233,12 @@ export class Signature {
|
||||
private _stopDraw() {
|
||||
this.isDrawing = false
|
||||
if (this.isDrawn) {
|
||||
const imageData = this.ctx.getImageData(0, 0, this.canvasWidth, this.canvasHeight)
|
||||
const imageData = this.ctx.getImageData(
|
||||
0,
|
||||
0,
|
||||
this.canvasWidth,
|
||||
this.canvasHeight
|
||||
)
|
||||
const self = this
|
||||
this._saveUndoFn(function () {
|
||||
self.ctx.clearRect(0, 0, self.canvasWidth, self.canvasHeight)
|
||||
@@ -299,5 +306,4 @@ export class Signature {
|
||||
this.mask.remove()
|
||||
this.container.remove()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user