@wot-ui/ui 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +2 -0
- package/package.json +1 -1
- package/web-types.json +1 -1
- package/common/AbortablePromise.ts +0 -28
- package/common/canvasHelper.ts +0 -49
- package/common/clickoutside.ts +0 -25
- package/common/event.ts +0 -8
- package/common/formatDate.ts +0 -68
- package/common/interceptor.ts +0 -43
- package/common/props.ts +0 -53
- package/common/util.ts +0 -836
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export class AbortablePromise<T> {
|
|
2
|
-
promise: Promise<T>
|
|
3
|
-
private _reject: ((res?: any) => void) | null = null
|
|
4
|
-
|
|
5
|
-
constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {
|
|
6
|
-
this.promise = new Promise<T>((resolve, reject) => {
|
|
7
|
-
executor(resolve, reject)
|
|
8
|
-
this._reject = reject // 保存reject方法的引用,以便在abort时调用
|
|
9
|
-
})
|
|
10
|
-
}
|
|
11
|
-
// 提供abort方法来中止Promise
|
|
12
|
-
abort(error?: any) {
|
|
13
|
-
if (this._reject) {
|
|
14
|
-
this._reject(error) // 调用reject方法来中止Promise
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
then<TResult1 = T, TResult2 = never>(
|
|
19
|
-
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
|
|
20
|
-
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
|
|
21
|
-
): Promise<TResult1 | TResult2> {
|
|
22
|
-
return this.promise.then(onfulfilled, onrejected)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null): Promise<T | TResult> {
|
|
26
|
-
return this.promise.catch(onrejected)
|
|
27
|
-
}
|
|
28
|
-
}
|
package/common/canvasHelper.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 适配 canvas 2d 上下文
|
|
3
|
-
* @param ctx canvas 2d 上下文
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
|
-
export function canvas2dAdapter(ctx: CanvasRenderingContext2D): UniApp.CanvasContext {
|
|
7
|
-
return Object.assign(ctx, {
|
|
8
|
-
setFillStyle(color: string | CanvasGradient) {
|
|
9
|
-
ctx.fillStyle = color
|
|
10
|
-
},
|
|
11
|
-
setStrokeStyle(color: string | CanvasGradient | CanvasPattern) {
|
|
12
|
-
ctx.strokeStyle = color
|
|
13
|
-
},
|
|
14
|
-
setLineWidth(lineWidth: number) {
|
|
15
|
-
ctx.lineWidth = lineWidth
|
|
16
|
-
},
|
|
17
|
-
setLineCap(lineCap: 'butt' | 'round' | 'square') {
|
|
18
|
-
ctx.lineCap = lineCap
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
setFontSize(font: string) {
|
|
22
|
-
ctx.font = font
|
|
23
|
-
},
|
|
24
|
-
setGlobalAlpha(alpha: number) {
|
|
25
|
-
ctx.globalAlpha = alpha
|
|
26
|
-
},
|
|
27
|
-
setLineJoin(lineJoin: 'bevel' | 'round' | 'miter') {
|
|
28
|
-
ctx.lineJoin = lineJoin
|
|
29
|
-
},
|
|
30
|
-
setTextAlign(align: 'left' | 'center' | 'right') {
|
|
31
|
-
ctx.textAlign = align
|
|
32
|
-
},
|
|
33
|
-
setMiterLimit(miterLimit: number) {
|
|
34
|
-
ctx.miterLimit = miterLimit
|
|
35
|
-
},
|
|
36
|
-
setShadow(offsetX: number, offsetY: number, blur: number, color: string) {
|
|
37
|
-
ctx.shadowOffsetX = offsetX
|
|
38
|
-
ctx.shadowOffsetY = offsetY
|
|
39
|
-
ctx.shadowBlur = blur
|
|
40
|
-
ctx.shadowColor = color
|
|
41
|
-
},
|
|
42
|
-
setTextBaseline(textBaseline: 'top' | 'bottom' | 'middle') {
|
|
43
|
-
ctx.textBaseline = textBaseline
|
|
44
|
-
},
|
|
45
|
-
createCircularGradient() {},
|
|
46
|
-
draw() {},
|
|
47
|
-
addColorStop() {}
|
|
48
|
-
}) as unknown as UniApp.CanvasContext
|
|
49
|
-
}
|
package/common/clickoutside.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
let queue: any[] = []
|
|
2
|
-
|
|
3
|
-
export function pushToQueue(comp: any) {
|
|
4
|
-
queue.push(comp)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function removeFromQueue(comp: any) {
|
|
8
|
-
queue = queue.filter((item) => {
|
|
9
|
-
return item.$.uid !== comp.$.uid
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function closeOther(comp: any) {
|
|
14
|
-
queue.forEach((item) => {
|
|
15
|
-
if (item.$.uid !== comp.$.uid) {
|
|
16
|
-
item.$.exposed.close()
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function closeOutside() {
|
|
22
|
-
queue.forEach((item) => {
|
|
23
|
-
item.$.exposed.close()
|
|
24
|
-
})
|
|
25
|
-
}
|
package/common/event.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const UPDATE_MODEL_EVENT = 'update:modelValue'
|
|
2
|
-
export const CHANGE_EVENT = 'change'
|
|
3
|
-
export const INPUT_EVENT = 'input'
|
|
4
|
-
export const CLICK_EVENT = 'click'
|
|
5
|
-
export const CLOSE_EVENT = 'close'
|
|
6
|
-
export const OPEN_EVENT = 'open'
|
|
7
|
-
export const CONFIRM_EVENT = 'confirm'
|
|
8
|
-
export const CANCEL_EVENT = 'cancel'
|
package/common/formatDate.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 轻量级日期格式化工具,用于替代 dayjs
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 日期格式化函数,替代 dayjs.format()
|
|
7
|
-
* @description 将日期格式化为指定格式的字符串
|
|
8
|
-
* @param date 日期(时间戳或 Date 对象)
|
|
9
|
-
* @param format 格式模板,如 'YYYY-MM-DD HH:mm:ss'
|
|
10
|
-
* @returns 格式化后的字符串
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* formatDate(Date.now(), 'YYYY-MM-DD') // '2026-02-02'
|
|
14
|
-
* formatDate(1706860800000, 'YYYY年MM月DD日') // '2026年02月02日'
|
|
15
|
-
* formatDate(new Date(), 'HH:mm:ss') // '14:30:00'
|
|
16
|
-
*
|
|
17
|
-
* 支持的 tokens:
|
|
18
|
-
* - YYYY: 4位年份
|
|
19
|
-
* - YY: 2位年份
|
|
20
|
-
* - MM: 2位月份(补零)
|
|
21
|
-
* - M: 月份
|
|
22
|
-
* - DD: 2位日期(补零)
|
|
23
|
-
* - D: 日期
|
|
24
|
-
* - HH: 2位小时(补零,24小时制)
|
|
25
|
-
* - H: 小时(24小时制)
|
|
26
|
-
* - mm: 2位分钟(补零)
|
|
27
|
-
* - m: 分钟
|
|
28
|
-
* - ss: 2位秒数(补零)
|
|
29
|
-
* - s: 秒数
|
|
30
|
-
*/
|
|
31
|
-
export function formatDate(date: number | Date, format: string): string {
|
|
32
|
-
const d = date instanceof Date ? date : new Date(date)
|
|
33
|
-
|
|
34
|
-
// 检查日期是否有效
|
|
35
|
-
if (isNaN(d.getTime())) {
|
|
36
|
-
return 'Invalid Date'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const year = d.getFullYear()
|
|
40
|
-
const month = d.getMonth() + 1
|
|
41
|
-
const day = d.getDate()
|
|
42
|
-
const hours = d.getHours()
|
|
43
|
-
const minutes = d.getMinutes()
|
|
44
|
-
const seconds = d.getSeconds()
|
|
45
|
-
|
|
46
|
-
// 定义 token 到值的映射(按长度降序排列以确保正确匹配)
|
|
47
|
-
const tokens: Record<string, string> = {
|
|
48
|
-
YYYY: String(year),
|
|
49
|
-
YY: String(year).slice(-2),
|
|
50
|
-
MM: String(month).padStart(2, '0'),
|
|
51
|
-
M: String(month),
|
|
52
|
-
DD: String(day).padStart(2, '0'),
|
|
53
|
-
D: String(day),
|
|
54
|
-
HH: String(hours).padStart(2, '0'),
|
|
55
|
-
H: String(hours),
|
|
56
|
-
mm: String(minutes).padStart(2, '0'),
|
|
57
|
-
m: String(minutes),
|
|
58
|
-
ss: String(seconds).padStart(2, '0'),
|
|
59
|
-
s: String(seconds)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 按 token 长度降序排列,确保先匹配长 token(如 YYYY 优先于 YY)
|
|
63
|
-
const pattern = Object.keys(tokens)
|
|
64
|
-
.sort((a, b) => b.length - a.length)
|
|
65
|
-
.join('|')
|
|
66
|
-
|
|
67
|
-
return format.replace(new RegExp(pattern, 'g'), (match) => tokens[match] || match)
|
|
68
|
-
}
|
package/common/interceptor.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { isPromise } from './util'
|
|
2
|
-
|
|
3
|
-
function noop() {}
|
|
4
|
-
|
|
5
|
-
export type Interceptor = (...args: any[]) => Promise<boolean> | boolean | undefined | void
|
|
6
|
-
|
|
7
|
-
export function callInterceptor(
|
|
8
|
-
interceptor: Interceptor | undefined,
|
|
9
|
-
{
|
|
10
|
-
args = [],
|
|
11
|
-
done,
|
|
12
|
-
canceled,
|
|
13
|
-
error
|
|
14
|
-
}: {
|
|
15
|
-
args?: unknown[]
|
|
16
|
-
done: () => void
|
|
17
|
-
canceled?: () => void
|
|
18
|
-
error?: () => void
|
|
19
|
-
}
|
|
20
|
-
) {
|
|
21
|
-
if (interceptor) {
|
|
22
|
-
// eslint-disable-next-line prefer-spread
|
|
23
|
-
const returnVal = interceptor.apply(null, args)
|
|
24
|
-
|
|
25
|
-
if (isPromise(returnVal)) {
|
|
26
|
-
returnVal
|
|
27
|
-
.then((value) => {
|
|
28
|
-
if (value) {
|
|
29
|
-
done()
|
|
30
|
-
} else if (canceled) {
|
|
31
|
-
canceled()
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
.catch(error || noop)
|
|
35
|
-
} else if (returnVal) {
|
|
36
|
-
done()
|
|
37
|
-
} else if (canceled) {
|
|
38
|
-
canceled()
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
done()
|
|
42
|
-
}
|
|
43
|
-
}
|
package/common/props.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { PropType } from 'vue'
|
|
2
|
-
|
|
3
|
-
export type Numeric = number | string
|
|
4
|
-
|
|
5
|
-
export const unknownProp = null as unknown as PropType<unknown>
|
|
6
|
-
|
|
7
|
-
export const numericProp = [Number, String]
|
|
8
|
-
|
|
9
|
-
export const truthProp = {
|
|
10
|
-
type: Boolean,
|
|
11
|
-
default: true as const
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const makeRequiredProp = <T>(type: T) => ({
|
|
15
|
-
type,
|
|
16
|
-
required: true as const
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
export const makeArrayProp = <T>() => ({
|
|
20
|
-
type: Array as PropType<T[]>,
|
|
21
|
-
default: () => []
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
export const makeBooleanProp = <T>(defaultVal: T) => ({
|
|
25
|
-
type: Boolean,
|
|
26
|
-
default: defaultVal
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
export const makeNumberProp = <T>(defaultVal: T) => ({
|
|
30
|
-
type: Number,
|
|
31
|
-
default: defaultVal
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
export const makeNumericProp = <T>(defaultVal: T) => ({
|
|
35
|
-
type: numericProp,
|
|
36
|
-
default: defaultVal
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
export const makeStringProp = <T>(defaultVal: T) => ({
|
|
40
|
-
type: String as unknown as PropType<T>,
|
|
41
|
-
default: defaultVal
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
export const baseProps = {
|
|
45
|
-
/**
|
|
46
|
-
* 自定义根节点样式
|
|
47
|
-
*/
|
|
48
|
-
customStyle: makeStringProp(''),
|
|
49
|
-
/**
|
|
50
|
-
* 自定义根节点样式类
|
|
51
|
-
*/
|
|
52
|
-
customClass: makeStringProp('')
|
|
53
|
-
}
|