lyb-pixi-js 1.12.46 → 1.12.48
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.
|
@@ -27,10 +27,6 @@ interface Params {
|
|
|
27
27
|
integer?: boolean;
|
|
28
28
|
/** 是否允许输入负数 */
|
|
29
29
|
isNegative?: boolean;
|
|
30
|
-
/** 最小值 */
|
|
31
|
-
min?: number;
|
|
32
|
-
/** 最大值 */
|
|
33
|
-
max?: number;
|
|
34
30
|
/** 最大长度 */
|
|
35
31
|
maxLength?: number;
|
|
36
32
|
/** 对齐方式 */
|
|
@@ -59,19 +55,23 @@ export declare class LibPixiInput extends LibPixiContainer {
|
|
|
59
55
|
constructor(params: Params);
|
|
60
56
|
/** @description 设置值 */
|
|
61
57
|
setValue(v: string): void;
|
|
58
|
+
/** @description 更改输入框描述 */
|
|
59
|
+
setPlaceholder(v: string): void;
|
|
60
|
+
/** @description 聚焦 */
|
|
61
|
+
focus(): void;
|
|
62
|
+
/** @description 设置输入框类型 */
|
|
63
|
+
toggleType(type: "text" | "password"): void;
|
|
64
|
+
/** @description 清空输入框 */
|
|
65
|
+
clear(): void;
|
|
62
66
|
/** @description 创建输入框 */
|
|
63
67
|
private _createInput;
|
|
64
68
|
/** @description 创建只读输入框 */
|
|
65
69
|
private _createReadOnlyInput;
|
|
66
|
-
/** @description 聚焦 */
|
|
67
|
-
private _focus;
|
|
68
70
|
/** @description 失焦 */
|
|
69
71
|
private _blur;
|
|
70
72
|
/** @description 失去焦点处理 */
|
|
71
73
|
private _onBlurHandler;
|
|
72
74
|
/** @description 实时更新输入框位置 */
|
|
73
75
|
private _updateInputPosition;
|
|
74
|
-
/** @description 设置输入框类型 */
|
|
75
|
-
toggleType(type: "text" | "password"): void;
|
|
76
76
|
}
|
|
77
77
|
export {};
|
|
@@ -13,20 +13,15 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
13
13
|
this._value = "";
|
|
14
14
|
/** @description 失去焦点处理 */
|
|
15
15
|
this._onBlurHandler = () => {
|
|
16
|
-
const { type = "text", integer = false
|
|
16
|
+
const { type = "text", integer = false } = this._params;
|
|
17
17
|
let text = this._input.value.trim();
|
|
18
18
|
//如果类型为字符串,则不参与校验
|
|
19
19
|
if (["text", "password"].includes(type))
|
|
20
20
|
return text;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (Number(text) < min)
|
|
26
|
-
text = min.toString();
|
|
27
|
-
//如果存在最大值,且输入值大于最大值,则使用最大值
|
|
28
|
-
if (max && Number(text) > max)
|
|
29
|
-
text = max.toString();
|
|
21
|
+
const num = Number(text);
|
|
22
|
+
//如果小于0,则返回空
|
|
23
|
+
if (num <= 0)
|
|
24
|
+
return "";
|
|
30
25
|
//如果要求整数,则取整
|
|
31
26
|
if (integer)
|
|
32
27
|
text = parseInt(text).toString();
|
|
@@ -41,7 +36,7 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
41
36
|
this._createInput();
|
|
42
37
|
this._createReadOnlyInput();
|
|
43
38
|
//聚焦
|
|
44
|
-
libPixiEvent(this, "pointertap", this.
|
|
39
|
+
libPixiEvent(this, "pointertap", this.focus.bind(this));
|
|
45
40
|
const ticker = new Ticker();
|
|
46
41
|
ticker.add(() => {
|
|
47
42
|
if (this.destroyed) {
|
|
@@ -65,6 +60,37 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
65
60
|
this._readonlyInput.text = (onFormatValue === null || onFormatValue === void 0 ? void 0 : onFormatValue(value)) || value;
|
|
66
61
|
}
|
|
67
62
|
}
|
|
63
|
+
/** @description 更改输入框描述 */
|
|
64
|
+
setPlaceholder(v) {
|
|
65
|
+
this._placeholder.text = v;
|
|
66
|
+
}
|
|
67
|
+
/** @description 聚焦 */
|
|
68
|
+
focus() {
|
|
69
|
+
const { type } = this._params;
|
|
70
|
+
this._input.style.display = "block";
|
|
71
|
+
this._input.focus();
|
|
72
|
+
this._readonlyInput.visible = false;
|
|
73
|
+
this._placeholder.visible = false;
|
|
74
|
+
if (type === "number") {
|
|
75
|
+
this._input.value = this._value && Number(this._value).toString();
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this._input.value = this._value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** @description 设置输入框类型 */
|
|
82
|
+
toggleType(type) {
|
|
83
|
+
this._input.type = type;
|
|
84
|
+
this._params.type = type;
|
|
85
|
+
this.setValue(this._value);
|
|
86
|
+
}
|
|
87
|
+
/** @description 清空输入框 */
|
|
88
|
+
clear() {
|
|
89
|
+
this._input.value = "";
|
|
90
|
+
this._placeholder.visible = true;
|
|
91
|
+
this._readonlyInput.visible = false;
|
|
92
|
+
this._blur();
|
|
93
|
+
}
|
|
68
94
|
/** @description 创建输入框 */
|
|
69
95
|
_createInput() {
|
|
70
96
|
const { color = "#fff", maxLength = 999999, align = "left", type = "text", onInput = () => { }, fontFamily = "", bold = false, } = this._params;
|
|
@@ -127,20 +153,6 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
127
153
|
this._readonlyInput.anchor.set(align === "left" ? 0 : 0.5, 0.5);
|
|
128
154
|
this._readonlyInput.position.set(align === "left" ? 0 : width / 2, height / 2);
|
|
129
155
|
}
|
|
130
|
-
/** @description 聚焦 */
|
|
131
|
-
_focus() {
|
|
132
|
-
const { type } = this._params;
|
|
133
|
-
this._input.style.display = "block";
|
|
134
|
-
this._input.focus();
|
|
135
|
-
this._readonlyInput.visible = false;
|
|
136
|
-
this._placeholder.visible = false;
|
|
137
|
-
if (type === "number") {
|
|
138
|
-
this._input.value = this._value && Number(this._value).toString();
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
this._input.value = this._value;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
156
|
/** @description 失焦 */
|
|
145
157
|
_blur() {
|
|
146
158
|
const { onValue, width } = this._params;
|
|
@@ -148,7 +160,7 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
148
160
|
this.setValue(value);
|
|
149
161
|
this._input.style.display = "none";
|
|
150
162
|
libPixiScaleContainer(this._readonlyInput, width);
|
|
151
|
-
if (this._params.type === "number") {
|
|
163
|
+
if (this._params.type === "number" && value !== "") {
|
|
152
164
|
this._readonlyInput.visible = true;
|
|
153
165
|
onValue === null || onValue === void 0 ? void 0 : onValue(Number(value));
|
|
154
166
|
}
|
|
@@ -189,10 +201,4 @@ export class LibPixiInput extends LibPixiContainer {
|
|
|
189
201
|
this._input.style.transform = `rotate(90deg)`;
|
|
190
202
|
}
|
|
191
203
|
}
|
|
192
|
-
/** @description 设置输入框类型 */
|
|
193
|
-
toggleType(type) {
|
|
194
|
-
this._input.type = type;
|
|
195
|
-
this._params.type = type;
|
|
196
|
-
this.setValue(this._value);
|
|
197
|
-
}
|
|
198
204
|
}
|
|
@@ -8,7 +8,9 @@ interface IViewCtor {
|
|
|
8
8
|
/** @description 弹窗管理器 */
|
|
9
9
|
export declare class LibPixiDialogManager {
|
|
10
10
|
/** 视图表 */
|
|
11
|
-
private
|
|
11
|
+
private _views;
|
|
12
|
+
/** 弹窗关闭监听器表 */
|
|
13
|
+
private _closeListeners;
|
|
12
14
|
/** open时显示的元素的父容器 */
|
|
13
15
|
private _openContainer;
|
|
14
16
|
constructor(parent: Container);
|
|
@@ -18,6 +20,11 @@ export declare class LibPixiDialogManager {
|
|
|
18
20
|
* @param args 实例参数
|
|
19
21
|
*/
|
|
20
22
|
open<T extends IViewCtor>(View: T, id: string, ...args: ConstructorParameters<T>): InstanceType<T>;
|
|
23
|
+
/** 监听弹窗关闭
|
|
24
|
+
* @param id 弹窗id
|
|
25
|
+
* @param callback 关闭回调
|
|
26
|
+
*/
|
|
27
|
+
onClose(id: string, callback: () => void): void;
|
|
21
28
|
/** @description 关闭页面,会调用页面的 onBeforeUnmount 事件,里面会做关闭动画,动画结束后会自动销毁
|
|
22
29
|
* @param id 页面名称
|
|
23
30
|
*/
|
|
@@ -13,7 +13,9 @@ export { LibPixiDialog } from "./ui/LibPixiDialog";
|
|
|
13
13
|
export class LibPixiDialogManager {
|
|
14
14
|
constructor(parent) {
|
|
15
15
|
/** 视图表 */
|
|
16
|
-
this.
|
|
16
|
+
this._views = {};
|
|
17
|
+
/** 弹窗关闭监听器表 */
|
|
18
|
+
this._closeListeners = new Map();
|
|
17
19
|
this._openContainer = parent;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
@@ -24,26 +26,41 @@ export class LibPixiDialogManager {
|
|
|
24
26
|
open(View, id, ...args) {
|
|
25
27
|
const view = new View(...args);
|
|
26
28
|
this._openContainer.addChild(view);
|
|
27
|
-
this.
|
|
29
|
+
this._views[id] = view;
|
|
28
30
|
return view;
|
|
29
31
|
}
|
|
32
|
+
/** 监听弹窗关闭
|
|
33
|
+
* @param id 弹窗id
|
|
34
|
+
* @param callback 关闭回调
|
|
35
|
+
*/
|
|
36
|
+
onClose(id, callback) {
|
|
37
|
+
if (!this._closeListeners.has(id))
|
|
38
|
+
this._closeListeners.set(id, new Set());
|
|
39
|
+
this._closeListeners.get(id).add(callback);
|
|
40
|
+
}
|
|
30
41
|
/** @description 关闭页面,会调用页面的 onBeforeUnmount 事件,里面会做关闭动画,动画结束后会自动销毁
|
|
31
42
|
* @param id 页面名称
|
|
32
43
|
*/
|
|
33
44
|
close(id) {
|
|
34
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
46
|
var _a;
|
|
36
|
-
const view = this.
|
|
47
|
+
const view = this._views[id];
|
|
37
48
|
if (view) {
|
|
38
49
|
yield ((_a = view.destroy) === null || _a === void 0 ? void 0 : _a.call(view));
|
|
39
|
-
delete this.
|
|
50
|
+
delete this._views[id];
|
|
51
|
+
const set = this._closeListeners.get(id);
|
|
52
|
+
if (!set)
|
|
53
|
+
return;
|
|
54
|
+
for (const cb of set)
|
|
55
|
+
cb();
|
|
56
|
+
this._closeListeners.delete(id);
|
|
40
57
|
}
|
|
41
58
|
});
|
|
42
59
|
}
|
|
43
60
|
/** @description 关闭并销毁所有弹窗 */
|
|
44
61
|
closeAll() {
|
|
45
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const ids = Object.keys(this.
|
|
63
|
+
const ids = Object.keys(this._views);
|
|
47
64
|
for (const id of ids) {
|
|
48
65
|
yield this.close(id);
|
|
49
66
|
}
|