From 84b17eb26ab668aff916c5ccaa7bcdd92a3fbaf0 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 27 Dec 2024 17:58:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=87=E8=AE=B0=E9=83=A8=E5=88=86=20c?= =?UTF-8?q?lass=20=E6=97=A0=E5=89=AF=E4=BD=9C=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/x/components/button/model.ts | 15 +-- .../src/x/components/checkbox-group/model.ts | 86 ++++++++++-------- .../src/x/components/checkbox/model.ts | 35 +++---- .../src/x/components/form/form.tsx | 75 ++++++++------- .../src/x/components/navigator/model.ts | 36 ++++---- .../src/x/components/picker-view/model.ts | 91 +++++++++++-------- .../src/x/components/progress/model.ts | 56 +++++++----- .../src/x/components/radio-group/model.ts | 84 +++++++++-------- .../src/x/components/radio/model.ts | 35 +++---- .../src/x/components/slider/slider.tsx | 69 ++++++++------ 10 files changed, 329 insertions(+), 253 deletions(-) diff --git a/packages/uni-app-plus/src/x/components/button/model.ts b/packages/uni-app-plus/src/x/components/button/model.ts index bd2cd24bd8b..ca5bf44ae67 100644 --- a/packages/uni-app-plus/src/x/components/button/model.ts +++ b/packages/uni-app-plus/src/x/components/button/model.ts @@ -47,12 +47,15 @@ export const buttonProps = { } // 这里是从 x-dom 的 global 里读取的 -export class UniButtonElement extends UniTextElementImpl { - // constructor(data: INodeData) { - // super() - // // super(data) - // } -} +export const UniButtonElement = /* @__PURE__ */ (() => + class extends UniTextElementImpl { + // constructor(data: INodeData) { + // super() + // // super(data) + // } + })() + +export type UniButtonElement = InstanceType export const hoverStyles = new Map>([ [ diff --git a/packages/uni-app-plus/src/x/components/checkbox-group/model.ts b/packages/uni-app-plus/src/x/components/checkbox-group/model.ts index 250aed1688a..de56b64edb1 100644 --- a/packages/uni-app-plus/src/x/components/checkbox-group/model.ts +++ b/packages/uni-app-plus/src/x/components/checkbox-group/model.ts @@ -16,46 +16,51 @@ export interface CheckboxInfo { setCheckboxChecked: (checked: boolean) => void } -export class UniCheckboxGroupElement extends UniFormControlElement { - _initialValue: string[] = [] +export const UniCheckboxGroupElement = /* @__PURE__ */ (() => + class extends UniFormControlElement { + _initialValue: string[] = [] - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override tagName = 'CHECKBOX-GROUP' - override nodeName = this.tagName + override tagName = 'CHECKBOX-GROUP' + override nodeName = this.tagName - override get value(): string[] { - return this._getValue() - } + override get value(): string[] { + return this._getValue() + } - override set value(value: string[]) { - this._setValue(value) - } + override set value(value: string[]) { + this._setValue(value) + } - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - // 这个会被重写 - _getAttribute = (key: string): string | null => { - return null - } + // 这个会被重写 + _getAttribute = (key: string): string | null => { + return null + } - override reset() { - this.value = this._initialValue.slice(0) - } + override reset() { + this.value = this._initialValue.slice(0) + } - _getValue = (): string[] => { - return this._initialValue - } - _setValue = (value: string[]) => {} -} + _getValue = (): string[] => { + return this._initialValue + } + _setValue = (value: string[]) => {} + })() + +export type UniCheckboxGroupElement = InstanceType< + typeof UniCheckboxGroupElement +> // export const checkboxGroupProps = {} class UniCheckboxGroupChangeEventDetail { @@ -64,10 +69,15 @@ class UniCheckboxGroupChangeEventDetail { this.value = value } } -export class UniCheckboxGroupChangeEvent extends UniCustomEvent { - constructor(value: string[]) { - super('change', { - detail: new UniCheckboxGroupChangeEventDetail(value), - }) - } -} +export const UniCheckboxGroupChangeEvent = /* @__PURE__ */ (() => + class extends UniCustomEvent { + constructor(value: string[]) { + super('change', { + detail: new UniCheckboxGroupChangeEventDetail(value), + }) + } + })() + +export type UniCheckboxGroupChangeEvent = InstanceType< + typeof UniCheckboxGroupChangeEvent +> diff --git a/packages/uni-app-plus/src/x/components/checkbox/model.ts b/packages/uni-app-plus/src/x/components/checkbox/model.ts index d40382ea1d5..b47d31ac09d 100644 --- a/packages/uni-app-plus/src/x/components/checkbox/model.ts +++ b/packages/uni-app-plus/src/x/components/checkbox/model.ts @@ -3,26 +3,29 @@ export const CHECKBOX_NAME = 'Checkbox' export const CHECKBOX_ROOT_ELEMENT = 'uni-checkbox-element' -export class UniCheckboxElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export const UniCheckboxElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override tagName = 'CHECKBOX' - override nodeName = this.tagName + override tagName = 'CHECKBOX' + override nodeName = this.tagName - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - _getAttribute = (key: string): string | null => { - return null - } -} + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniCheckboxElement = InstanceType // UniElementImpl diff --git a/packages/uni-app-plus/src/x/components/form/form.tsx b/packages/uni-app-plus/src/x/components/form/form.tsx index b9e23896229..8ef4f258540 100644 --- a/packages/uni-app-plus/src/x/components/form/form.tsx +++ b/packages/uni-app-plus/src/x/components/form/form.tsx @@ -1,31 +1,34 @@ /// import { defineBuiltInComponent } from '@dcloudio/uni-components' import { - onMounted, - ComponentInternalInstance, + type ComponentInternalInstance, + type Ref, + type VNode, getCurrentInstance, + onMounted, ref, - Ref, - VNode, } from 'vue' -export class UniFormElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export const UniFormElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - // override getAttribute(key: string): string | null { - // const value = this._getAttribute(key) - // if (value != null) { - // return value - // } - // return super.getAttribute(key) - // } + // override getAttribute(key: string): string | null { + // const value = this._getAttribute(key) + // if (value != null) { + // return value + // } + // return super.getAttribute(key) + // } - _getAttribute = (key: string): string | null => { - return null - } -} + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniFormElement = InstanceType class UniFormSubmitEventDetail { value = {} @@ -36,21 +39,27 @@ class UniFormSubmitEventDetail { class UniFormResetEventDetail {} -export class UniFormSubmitEvent extends CustomEvent { - constructor(value: any) { - super('change', { - detail: new UniFormSubmitEventDetail(value), - } as CustomEventOptions) - } -} +export const UniFormSubmitEvent = /* @__PURE__ */ (() => + class extends CustomEvent { + constructor(value: any) { + super('change', { + detail: new UniFormSubmitEventDetail(value), + } as CustomEventOptions) + } + })() -export class UniFormResetEvent extends CustomEvent { - constructor() { - super('change', { - detail: new UniFormResetEventDetail(), - } as CustomEventOptions) - } -} +export type UniFormSubmitEvent = InstanceType + +export const UniFormResetEvent = /* @__PURE__ */ (() => + class extends CustomEvent { + constructor() { + super('change', { + detail: new UniFormResetEventDetail(), + } as CustomEventOptions) + } + })() + +export type UniFormResetEvent = InstanceType export default /*#__PURE__*/ defineBuiltInComponent({ name: 'Form', diff --git a/packages/uni-app-plus/src/x/components/navigator/model.ts b/packages/uni-app-plus/src/x/components/navigator/model.ts index dfed4bdd4af..13a5ae18b02 100644 --- a/packages/uni-app-plus/src/x/components/navigator/model.ts +++ b/packages/uni-app-plus/src/x/components/navigator/model.ts @@ -1,23 +1,27 @@ -export class UniNavigatorElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export const UniNavigatorElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - override tagName = 'NAVIGATOR' - override nodeName = this.tagName + override tagName = 'NAVIGATOR' + override nodeName = this.tagName + + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniNavigatorElement = InstanceType - _getAttribute = (key: string): string | null => { - return null - } -} export const navigatorProps = { url: { type: String, diff --git a/packages/uni-app-plus/src/x/components/picker-view/model.ts b/packages/uni-app-plus/src/x/components/picker-view/model.ts index 7367a34d2d6..38c004ac92a 100644 --- a/packages/uni-app-plus/src/x/components/picker-view/model.ts +++ b/packages/uni-app-plus/src/x/components/picker-view/model.ts @@ -1,23 +1,28 @@ -export class UniPickerViewColumnElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export const UniPickerViewColumnElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override tagName = 'PICKER-VIEW-COLUMN' - override nodeName = this.tagName + override tagName = 'PICKER-VIEW-COLUMN' + override nodeName = this.tagName - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - _getAttribute = (key: string): string | null => { - return null - } -} + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniPickerViewColumnElement = InstanceType< + typeof UniPickerViewColumnElement +> class UniPickerViewChangeEventDetail { value: number[] @@ -26,31 +31,39 @@ class UniPickerViewChangeEventDetail { } } -export class UniPickerViewChangeEvent extends UniCustomEvent { - constructor(value: number[]) { - super('change', { - detail: new UniPickerViewChangeEventDetail(value), - } as CustomEventOptions) - } -} +export const UniPickerViewChangeEvent = /* @__PURE__ */ (() => + class extends UniCustomEvent { + constructor(value: number[]) { + super('change', { + detail: new UniPickerViewChangeEventDetail(value), + } as CustomEventOptions) + } + })() -export class UniPickerViewElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export type UniPickerViewChangeEvent = InstanceType< + typeof UniPickerViewChangeEvent +> - override tagName = 'PICKER-VIEW' - override nodeName = this.tagName +export const UniPickerViewElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override tagName = 'PICKER-VIEW' + override nodeName = this.tagName + + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - _getAttribute = (key: string): string | null => { - return null - } -} + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniPickerViewElement = InstanceType diff --git a/packages/uni-app-plus/src/x/components/progress/model.ts b/packages/uni-app-plus/src/x/components/progress/model.ts index 633e38fe844..b17e0b7b1ab 100644 --- a/packages/uni-app-plus/src/x/components/progress/model.ts +++ b/packages/uni-app-plus/src/x/components/progress/model.ts @@ -10,33 +10,43 @@ class UniProgressActiveendEventDetail { this.curPercent = value } } -export class UniProgressActiveendEvent extends UniCustomEvent { - constructor(value: number) { - super('activeend', { - detail: new UniProgressActiveendEventDetail(value), - } as CustomEventOptions) - } -} -export class UniProgressElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export const UniProgressActiveendEvent = /* @__PURE__ */ (() => + class extends UniCustomEvent { + constructor(value: number) { + super('activeend', { + detail: new UniProgressActiveendEventDetail(value), + } as CustomEventOptions) + } + })() - override tagName = 'PROGRESS' - override nodeName = this.tagName +export type UniProgressActiveendEvent = InstanceType< + typeof UniProgressActiveendEvent +> - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value +export const UniProgressElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) } - return super.getAnyAttribute(key) - } - _getAttribute = (key: string): string | null => { - return null - } -} + override tagName = 'PROGRESS' + override nodeName = this.tagName + + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) + } + + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniProgressElement = InstanceType + export const progressProps = { percent: { type: Number, diff --git a/packages/uni-app-plus/src/x/components/radio-group/model.ts b/packages/uni-app-plus/src/x/components/radio-group/model.ts index 711b31f9a7b..40ffb59ef31 100644 --- a/packages/uni-app-plus/src/x/components/radio-group/model.ts +++ b/packages/uni-app-plus/src/x/components/radio-group/model.ts @@ -16,45 +16,48 @@ export interface RadioInfo { setRadioChecked: (checked: boolean) => void } -export class UniRadioGroupElement extends UniFormControlElement { - _initialValue: string = '' +export const UniRadioGroupElement = /* @__PURE__ */ (() => + class extends UniFormControlElement { + _initialValue: string = '' - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override tagName = 'RADIO-GROUP' - override nodeName = this.tagName + override tagName = 'RADIO-GROUP' + override nodeName = this.tagName - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - override get value(): string { - return this._getValue() - } - override set value(value: string) { - this._setValue(value) - } + override get value(): string { + return this._getValue() + } + override set value(value: string) { + this._setValue(value) + } - override reset() { - this.value = this._initialValue - } + override reset() { + this.value = this._initialValue + } - // 带 _ 的方法、属性会在组件渲染之后被重写 - _getAttribute = (key: string): string | null => { - return null - } + // 带 _ 的方法、属性会在组件渲染之后被重写 + _getAttribute = (key: string): string | null => { + return null + } - _getValue = (): string => { - return this._initialValue - } - _setValue = (value: string) => {} -} + _getValue = (): string => { + return this._initialValue + } + _setValue = (value: string) => {} + })() + +export type UniRadioGroupElement = InstanceType class UniRadioGroupChangeEventDetail { value: string @@ -63,10 +66,15 @@ class UniRadioGroupChangeEventDetail { } } -export class UniRadioGroupChangeEvent extends UniCustomEvent { - constructor(value: string) { - super('change', { - detail: new UniRadioGroupChangeEventDetail(value), - } as CustomEventOptions) - } -} +export const UniRadioGroupChangeEvent = /* @__PURE__ */ (() => + class extends UniCustomEvent { + constructor(value: string) { + super('change', { + detail: new UniRadioGroupChangeEventDetail(value), + } as CustomEventOptions) + } + })() + +export type UniRadioGroupChangeEvent = InstanceType< + typeof UniRadioGroupChangeEvent +> diff --git a/packages/uni-app-plus/src/x/components/radio/model.ts b/packages/uni-app-plus/src/x/components/radio/model.ts index fe2d87112c8..c357cf0df6f 100644 --- a/packages/uni-app-plus/src/x/components/radio/model.ts +++ b/packages/uni-app-plus/src/x/components/radio/model.ts @@ -3,26 +3,29 @@ export const RADIO_NAME = 'Radio' export const RADIO_ROOT_ELEMENT = 'uni-radio-element' -export class UniRadioElement extends UniElementImpl { - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } +export const UniRadioElement = /* @__PURE__ */ (() => + class extends UniElementImpl { + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - override tagName = 'RADIO' - override nodeName = this.tagName + override tagName = 'RADIO' + override nodeName = this.tagName - override getAnyAttribute(key: string): string { - const value = this._getAttribute(key) - if (value != null) { - return value + override getAnyAttribute(key: string): string { + const value = this._getAttribute(key) + if (value != null) { + return value + } + return super.getAnyAttribute(key) } - return super.getAnyAttribute(key) - } - _getAttribute = (key: string): string | null => { - return null - } -} + _getAttribute = (key: string): string | null => { + return null + } + })() + +export type UniRadioElement = InstanceType // UniElementImpl diff --git a/packages/uni-app-plus/src/x/components/slider/slider.tsx b/packages/uni-app-plus/src/x/components/slider/slider.tsx index 11ee95bd91b..79c1c711953 100644 --- a/packages/uni-app-plus/src/x/components/slider/slider.tsx +++ b/packages/uni-app-plus/src/x/components/slider/slider.tsx @@ -1,6 +1,13 @@ /// import { defineBuiltInComponent } from '@dcloudio/uni-components' -import { onMounted, getCurrentInstance, watch, computed, ref, Ref } from 'vue' +import { + type Ref, + computed, + getCurrentInstance, + onMounted, + ref, + watch, +} from 'vue' const SLIDER_TRACK_HEIGHT = 2 const SLIDER_THUMB_SHADOW = 4 @@ -9,31 +16,34 @@ const SLIDER_VALUE_FONT_SIZE = 14 const SLIDER_BLOCK_SIZE_MIN_VALUE = 12 const SLIDER_BLOCK_SIZE_MAX_VALUE = 28 -export class UniSliderElement extends UniFormControlElement { - _initialValue: number = 0 - _value: number = 0 +export const UniSliderElement = /* @__PURE__ */ (() => + class extends UniFormControlElement { + _initialValue: number = 0 + _value: number = 0 - constructor(data: INodeData, pageNode: PageNode) { - super(data, pageNode) - } + constructor(data: INodeData, pageNode: PageNode) { + super(data, pageNode) + } - get value(): number { - return this._value - } - set value(value: number) { - if (this._value == value) { - return + get value(): number { + return this._value + } + set value(value: number) { + if (this._value == value) { + return + } + this._value = value + this.onValueChanged(value) } - this._value = value - this.onValueChanged(value) - } - reset() { - this.value = this._initialValue - } + reset() { + this.value = this._initialValue + } - onValueChanged = (value: number) => {} -} + onValueChanged = (value: number) => {} + })() + +export type UniSliderElement = InstanceType class SliderChangeEventDetail { value: number = 0 @@ -42,13 +52,16 @@ class SliderChangeEventDetail { } } -export class SliderChangeEvent extends CustomEvent { - constructor(value: number) { - super('change', { - detail: new SliderChangeEventDetail(value), - } as CustomEventOptions) - } -} +export const SliderChangeEvent = /* @__PURE__ */ (() => + class extends CustomEvent { + constructor(value: number) { + super('change', { + detail: new SliderChangeEventDetail(value), + } as CustomEventOptions) + } + })() + +export type SliderChangeEvent = InstanceType export default /*#__PURE__*/ defineBuiltInComponent({ name: 'Slider',