@tuya-miniapp/smart-ui 2.13.4-beta-0 → 2.13.4-beta-2
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/dist/cell/README.md +2 -0
- package/dist/cell/index.css +1 -1
- package/dist/cell/index.wxss +1 -1
- package/dist/toast/index.js +4 -5
- package/dist/toast/toast.d.ts +19 -1
- package/dist/toast/toast.js +56 -4
- package/lib/cell/README.md +2 -0
- package/lib/cell/index.css +1 -1
- package/lib/cell/index.wxss +1 -1
- package/lib/toast/index.js +3 -4
- package/lib/toast/toast.d.ts +19 -1
- package/lib/toast/toast.js +59 -5
- package/package.json +1 -1
package/dist/cell/README.md
CHANGED
|
@@ -225,6 +225,8 @@ category: 展示
|
|
|
225
225
|
| --cell-label-line-height | _18px_ | 单元格标签行高 |
|
|
226
226
|
| --cell-label-margin-top | _3px_ | 单元格标签上边距 |
|
|
227
227
|
| --cell-value-color | _var(--app-B6-N3, rgba(0, 0, 0, 0.5))_ | 单元格值文字颜色 |
|
|
228
|
+
| --cell-value-max-width `v2.13.4` | _none_ | 单元格值区域最大宽度,超出部分隐藏;默认不限制 |
|
|
229
|
+
| --cell-value-margin-left `v2.13.4` | _8px_ | 单元格值区域与标题的间距 |
|
|
228
230
|
| --cell-icon-size | _24px_ | 单元格图标大小 |
|
|
229
231
|
| --cell-right-icon-color | _var(--app-B6-N6, rgba(0, 0, 0, 0.2))_ | 单元格右侧图标颜色 |
|
|
230
232
|
| --cell-border-color `v2.1.4` | _var(--app-B6-N7, rgba(0, 0, 0, 0.1))_ | 单元格边框颜色 |
|
package/dist/cell/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex-direction:column;justify-content:center}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;justify-content:flex-end;overflow:hidden;text-align:right;vertical-align:middle}.smart-
|
|
1
|
+
@import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex:1;flex-direction:column;justify-content:center}.smart-cell__title:empty{display:none}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;flex:none;justify-content:flex-end;margin-left:var(--cell-value-margin-left,8px);max-width:var(--cell-value-max-width,none);overflow:hidden;text-align:right;vertical-align:middle}.smart-cell__value:empty{display:none}.smart-cell__left-icon-wrap,.smart-cell__right-icon-wrap{align-items:center;display:flex;font-size:var(--cell-icon-size,24px);height:var(--cell-line-height,24px)}.smart-cell__left-icon-wrap{margin-right:var(--padding-base,4px)}.smart-cell__right-icon-wrap{color:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)));margin-left:var(--padding-base,4px)}.smart-cell__left-icon{vertical-align:middle}.smart-cell__left-icon,.smart-cell__right-icon{line-height:var(--cell-line-height,24px)}.smart-cell__right-icon>view{background:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)))}.smart-cell--clickable.smart-cell--hover{background-color:var(--cell-active-color,var(--app-B1,#f6f7fb))}.smart-cell--required{overflow:visible}.smart-cell--required:before{color:var(--cell-required-color,var(--app-M2,#f04c4c));content:"*";font-size:var(--cell-font-size,16px);left:var(--padding-xs,8px);position:absolute}
|
package/dist/cell/index.wxss
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import '../common/index.wxss';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex-direction:column;justify-content:center}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;justify-content:flex-end;overflow:hidden;text-align:right;vertical-align:middle}.smart-
|
|
1
|
+
@import '../common/index.wxss';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex:1;flex-direction:column;justify-content:center}.smart-cell__title:empty{display:none}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;flex:none;justify-content:flex-end;margin-left:var(--cell-value-margin-left,8px);max-width:var(--cell-value-max-width,none);overflow:hidden;text-align:right;vertical-align:middle}.smart-cell__value:empty{display:none}.smart-cell__left-icon-wrap,.smart-cell__right-icon-wrap{align-items:center;display:flex;font-size:var(--cell-icon-size,24px);height:var(--cell-line-height,24px)}.smart-cell__left-icon-wrap{margin-right:var(--padding-base,4px)}.smart-cell__right-icon-wrap{color:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)));margin-left:var(--padding-base,4px)}.smart-cell__left-icon{vertical-align:middle}.smart-cell__left-icon,.smart-cell__right-icon{line-height:var(--cell-line-height,24px)}.smart-cell__right-icon>view{background:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)))}.smart-cell--clickable.smart-cell--hover{background-color:var(--cell-active-color,var(--app-B1,#f6f7fb))}.smart-cell--required{overflow:visible}.smart-cell--required:before{color:var(--cell-required-color,var(--app-M2,#f04c4c));content:"*";font-size:var(--cell-font-size,16px);left:var(--padding-xs,8px);position:absolute}
|
package/dist/toast/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Success, Alarm, Error } from './icons';
|
|
2
2
|
import { SmartComponent } from '../common/component';
|
|
3
|
-
import {
|
|
4
|
-
import { getCurrentPage } from '../common/utils';
|
|
3
|
+
import { registerToastContext, unregisterToastContext } from './toast';
|
|
5
4
|
import appLog from '../common/appLog';
|
|
6
5
|
SmartComponent({
|
|
7
6
|
props: {
|
|
@@ -43,17 +42,17 @@ SmartComponent({
|
|
|
43
42
|
mounted: function () {
|
|
44
43
|
if (!this.id)
|
|
45
44
|
return;
|
|
46
|
-
|
|
45
|
+
const repeated = registerToastContext(`#${this.id}`, this);
|
|
46
|
+
if (repeated) {
|
|
47
47
|
console.error(`Toast component #${this.id} repeated!`);
|
|
48
48
|
appLog.info(`Toast component #${this.id} repeated!`);
|
|
49
49
|
}
|
|
50
|
-
contextRef.value[`#${this.id}`] = getCurrentPage();
|
|
51
50
|
appLog.info(`Toast #${this.id} mounted`);
|
|
52
51
|
},
|
|
53
52
|
destroyed: function () {
|
|
54
53
|
if (!this.id)
|
|
55
54
|
return;
|
|
56
|
-
|
|
55
|
+
unregisterToastContext(`#${this.id}`, this);
|
|
57
56
|
appLog.info(`Toast #${this.id} destroyed`);
|
|
58
57
|
},
|
|
59
58
|
methods: {
|
package/dist/toast/toast.d.ts
CHANGED
|
@@ -21,9 +21,27 @@ interface ToastOptions {
|
|
|
21
21
|
width?: number;
|
|
22
22
|
onClose?: () => void;
|
|
23
23
|
}
|
|
24
|
+
interface ToastContextEntry {
|
|
25
|
+
page: ToastContext;
|
|
26
|
+
instance: WechatMiniprogram.Component.TrivialInstance | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* selector -> 该 selector 下所有存活的 toast 实例。
|
|
30
|
+
* 一个 selector(id)可以同时挂在多个页面(多 webview)上,因此用数组记录,
|
|
31
|
+
* 而不再是「一个 selector 只对应一个 page」的单槽结构。
|
|
32
|
+
* 为向后兼容,仍容忍外部直接赋值为单个 page(非数组)的旧写法。
|
|
33
|
+
*/
|
|
24
34
|
export declare const contextRef: {
|
|
25
|
-
value: Record<string, ToastContext | null>;
|
|
35
|
+
value: Record<string, ToastContext | ToastContextEntry[] | null>;
|
|
26
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* 组件挂载时登记自身。同一 selector 在「同一个页面」上重复挂载才算冲突,
|
|
39
|
+
* 不同页面共用同一 selector 是被允许的(这正是「每页挂一个默认 toast」的场景)。
|
|
40
|
+
* @returns 是否与同页已有实例冲突(供组件层打印 repeated 提示)。
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerToastContext(selector: string, instance: WechatMiniprogram.Component.TrivialInstance): boolean;
|
|
43
|
+
/** 组件卸载时精确移除自身,不影响其它页面上同 selector 的实例。 */
|
|
44
|
+
export declare function unregisterToastContext(selector: string, instance: WechatMiniprogram.Component.TrivialInstance): void;
|
|
27
45
|
declare function Toast(toastOptions: ToastOptions | ToastMessage): WechatMiniprogram.Component.TrivialInstance | undefined;
|
|
28
46
|
declare namespace Toast {
|
|
29
47
|
var loading: (options: ToastMessage | ToastOptions) => WechatMiniprogram.Component.TrivialInstance | undefined;
|
package/dist/toast/toast.js
CHANGED
|
@@ -30,16 +30,68 @@ let currentOptions = Object.assign({}, defaultOptions);
|
|
|
30
30
|
function parseOptions(message) {
|
|
31
31
|
return isObj(message) ? message : { message };
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* selector -> 该 selector 下所有存活的 toast 实例。
|
|
35
|
+
* 一个 selector(id)可以同时挂在多个页面(多 webview)上,因此用数组记录,
|
|
36
|
+
* 而不再是「一个 selector 只对应一个 page」的单槽结构。
|
|
37
|
+
* 为向后兼容,仍容忍外部直接赋值为单个 page(非数组)的旧写法。
|
|
38
|
+
*/
|
|
33
39
|
export const contextRef = {
|
|
34
40
|
value: {},
|
|
35
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* 组件挂载时登记自身。同一 selector 在「同一个页面」上重复挂载才算冲突,
|
|
44
|
+
* 不同页面共用同一 selector 是被允许的(这正是「每页挂一个默认 toast」的场景)。
|
|
45
|
+
* @returns 是否与同页已有实例冲突(供组件层打印 repeated 提示)。
|
|
46
|
+
*/
|
|
47
|
+
export function registerToastContext(selector, instance) {
|
|
48
|
+
const existing = contextRef.value[selector];
|
|
49
|
+
const list = Array.isArray(existing) ? existing : [];
|
|
50
|
+
contextRef.value[selector] = list;
|
|
51
|
+
const page = getCurrentPage();
|
|
52
|
+
const samePage = list.find(entry => entry.page === page);
|
|
53
|
+
if (samePage) {
|
|
54
|
+
samePage.instance = instance;
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
list.push({ page, instance });
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/** 组件卸载时精确移除自身,不影响其它页面上同 selector 的实例。 */
|
|
61
|
+
export function unregisterToastContext(selector, instance) {
|
|
62
|
+
const existing = contextRef.value[selector];
|
|
63
|
+
if (!Array.isArray(existing)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
contextRef.value[selector] = existing.filter(entry => entry.instance !== instance);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 解析目标实例所在的上下文:优先命中「当前页面」上的实例,
|
|
70
|
+
* 其次退回最后挂载的实例(栈顶,覆盖跨页/非当前页场景),
|
|
71
|
+
* 同时兼容外部直接赋值单个 page 的旧写法。
|
|
72
|
+
*/
|
|
73
|
+
function resolveContextEntry(selector) {
|
|
74
|
+
const existing = contextRef.value[selector];
|
|
75
|
+
if (!existing) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (!Array.isArray(existing)) {
|
|
79
|
+
// 兼容旧结构:value[selector] 直接是一个 page
|
|
80
|
+
return { page: existing, instance: null };
|
|
81
|
+
}
|
|
82
|
+
if (!existing.length) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const currentPage = getCurrentPage();
|
|
86
|
+
return existing.find(entry => entry.page === currentPage) || existing[existing.length - 1];
|
|
87
|
+
}
|
|
36
88
|
function Toast(toastOptions) {
|
|
37
89
|
const options = Object.assign(Object.assign({}, currentOptions), parseOptions(toastOptions));
|
|
38
90
|
appLog.info('start open Toast');
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const toast = context.selectComponent(options.selector);
|
|
91
|
+
const explicitContext = typeof options.context === 'function' ? options.context() : options.context;
|
|
92
|
+
const entry = explicitContext ? null : resolveContextEntry(options.selector);
|
|
93
|
+
const context = explicitContext || (entry === null || entry === void 0 ? void 0 : entry.page) || getCurrentPage();
|
|
94
|
+
const toast = context.selectComponent(options.selector) || (entry === null || entry === void 0 ? void 0 : entry.instance) || null;
|
|
43
95
|
appLog.info(`toast selector: ${options.selector}`);
|
|
44
96
|
appLog.info(`toast component ${toast ? 'success' : 'fail'}`);
|
|
45
97
|
if (!toast) {
|
package/lib/cell/README.md
CHANGED
|
@@ -225,6 +225,8 @@ category: 展示
|
|
|
225
225
|
| --cell-label-line-height | _18px_ | 单元格标签行高 |
|
|
226
226
|
| --cell-label-margin-top | _3px_ | 单元格标签上边距 |
|
|
227
227
|
| --cell-value-color | _var(--app-B6-N3, rgba(0, 0, 0, 0.5))_ | 单元格值文字颜色 |
|
|
228
|
+
| --cell-value-max-width `v2.13.4` | _none_ | 单元格值区域最大宽度,超出部分隐藏;默认不限制 |
|
|
229
|
+
| --cell-value-margin-left `v2.13.4` | _8px_ | 单元格值区域与标题的间距 |
|
|
228
230
|
| --cell-icon-size | _24px_ | 单元格图标大小 |
|
|
229
231
|
| --cell-right-icon-color | _var(--app-B6-N6, rgba(0, 0, 0, 0.2))_ | 单元格右侧图标颜色 |
|
|
230
232
|
| --cell-border-color `v2.1.4` | _var(--app-B6-N7, rgba(0, 0, 0, 0.1))_ | 单元格边框颜色 |
|
package/lib/cell/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex-direction:column;justify-content:center}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;justify-content:flex-end;overflow:hidden;text-align:right;vertical-align:middle}.smart-
|
|
1
|
+
@import '../common/index.css';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex:1;flex-direction:column;justify-content:center}.smart-cell__title:empty{display:none}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;flex:none;justify-content:flex-end;margin-left:var(--cell-value-margin-left,8px);max-width:var(--cell-value-max-width,none);overflow:hidden;text-align:right;vertical-align:middle}.smart-cell__value:empty{display:none}.smart-cell__left-icon-wrap,.smart-cell__right-icon-wrap{align-items:center;display:flex;font-size:var(--cell-icon-size,24px);height:var(--cell-line-height,24px)}.smart-cell__left-icon-wrap{margin-right:var(--padding-base,4px)}.smart-cell__right-icon-wrap{color:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)));margin-left:var(--padding-base,4px)}.smart-cell__left-icon{vertical-align:middle}.smart-cell__left-icon,.smart-cell__right-icon{line-height:var(--cell-line-height,24px)}.smart-cell__right-icon>view{background:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)))}.smart-cell--clickable.smart-cell--hover{background-color:var(--cell-active-color,var(--app-B1,#f6f7fb))}.smart-cell--required{overflow:visible}.smart-cell--required:before{color:var(--cell-required-color,var(--app-M2,#f04c4c));content:"*";font-size:var(--cell-font-size,16px);left:var(--padding-xs,8px);position:absolute}
|
package/lib/cell/index.wxss
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
@import '../common/index.wxss';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex-direction:column;justify-content:center}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;justify-content:flex-end;overflow:hidden;text-align:right;vertical-align:middle}.smart-
|
|
1
|
+
@import '../common/index.wxss';:root{--smart-ui-overlay:rgba(0,0,0,.4);--smart-ui-bottom-sheet-dragger-node-background:rgba(0,0,0,.3);--smart-ui-dialog-background:var(--app-B4,#fff);--smart-ui-border-image:linear-gradient(90deg,transparent,rgba(0,0,0,.3),transparent);--smart-ui-battery-body-base-background:rgba(0,0,0,.25);--smart-ui-battery-text-color:rgba(0,0,0,.6);--smart-ui-battery-slash-border-color:#fff;--smart-ui-toast-background:#5c5c5c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 4px 12px rgba(0,0,0,.1),0 16px 32px rgba(0,0,0,.12);--smart-ui-overlay-blur-background:rgba(40,44,53,.22)}:root[theme=dark]{--smart-ui-overlay:rgba(0,0,0,.7);--smart-ui-bottom-sheet-dragger-node-background:hsla(0,0%,100%,.3);--smart-ui-dialog-background:linear-gradient(0deg,var(--app-B4-N6),var(--app-B4-N6)),var(--app-B1);--smart-ui-border-image:linear-gradient(90deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.3),hsla(0,0%,100%,0));--smart-ui-battery-body-base-background:hsla(0,0%,100%,.4);--smart-ui-battery-text-color:#fff;--smart-ui-battery-slash-border-color:#000;--smart-ui-toast-background:#3c3c3c;--smart-ui-toast-border:1px solid hsla(0,0%,100%,.05);--smart-ui-toast-box-shadow:0 8px 24px 0 rgba(0,0,0,.15);--smart-ui-overlay-blur-background:rgba(0,0,0,.6)}.smart-manrope{font-family:Manrope,sans-serif}.smart-cell{align-items:center;background-color:var(--cell-background-color,var(--app-B6,#fff));box-sizing:border-box;color:var(--cell-text-color,var(--app-B6-N1,#000));display:flex;font-size:var(--cell-font-size,16px);line-height:var(--cell-line-height,24px);padding:var(--cell-vertical-padding,16px) var(--cell-horizontal-padding,16px);position:relative;width:100%}.smart-cell:after{border-bottom:1px solid var(--cell-border-color,var(--app-B6-N7,rgba(0,0,0,.1)));bottom:0;box-sizing:border-box;content:" ";left:var(--cell-border-left-position,16px);pointer-events:none;position:absolute;right:var(--cell-border-right-position,16px);transform:scaleY(.5);transform-origin:center}.smart-cell--borderless:after{display:none}.smart-cell-group{background-color:var(--cell-background-color,var(--app-B6,#fff))}.smart-cell__label{color:var(--cell-label-color,var(--app-B6-N3,rgba(0,0,0,.5)));font-size:var(--cell-label-font-size,14px);line-height:var(--cell-label-line-height,18px);margin-top:var(--cell-label-margin-top,3px)}.smart-cell__title{align-items:flex-start;display:flex;flex:1;flex-direction:column;justify-content:center}.smart-cell__title:empty{display:none}.smart-cell__value{align-items:center;color:var(--cell-value-color,var(--app-B6-N3,rgba(0,0,0,.5)));display:flex;flex:none;justify-content:flex-end;margin-left:var(--cell-value-margin-left,8px);max-width:var(--cell-value-max-width,none);overflow:hidden;text-align:right;vertical-align:middle}.smart-cell__value:empty{display:none}.smart-cell__left-icon-wrap,.smart-cell__right-icon-wrap{align-items:center;display:flex;font-size:var(--cell-icon-size,24px);height:var(--cell-line-height,24px)}.smart-cell__left-icon-wrap{margin-right:var(--padding-base,4px)}.smart-cell__right-icon-wrap{color:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)));margin-left:var(--padding-base,4px)}.smart-cell__left-icon{vertical-align:middle}.smart-cell__left-icon,.smart-cell__right-icon{line-height:var(--cell-line-height,24px)}.smart-cell__right-icon>view{background:var(--cell-right-icon-color,var(--app-B6-N6,rgba(0,0,0,.2)))}.smart-cell--clickable.smart-cell--hover{background-color:var(--cell-active-color,var(--app-B1,#f6f7fb))}.smart-cell--required{overflow:visible}.smart-cell--required:before{color:var(--cell-required-color,var(--app-M2,#f04c4c));content:"*";font-size:var(--cell-font-size,16px);left:var(--padding-xs,8px);position:absolute}
|
package/lib/toast/index.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
var icons_1 = require("./icons");
|
|
7
7
|
var component_1 = require("../common/component");
|
|
8
8
|
var toast_1 = require("./toast");
|
|
9
|
-
var utils_1 = require("../common/utils");
|
|
10
9
|
var appLog_1 = __importDefault(require("../common/appLog"));
|
|
11
10
|
(0, component_1.SmartComponent)({
|
|
12
11
|
props: {
|
|
@@ -48,17 +47,17 @@ var appLog_1 = __importDefault(require("../common/appLog"));
|
|
|
48
47
|
mounted: function () {
|
|
49
48
|
if (!this.id)
|
|
50
49
|
return;
|
|
51
|
-
|
|
50
|
+
var repeated = (0, toast_1.registerToastContext)("#".concat(this.id), this);
|
|
51
|
+
if (repeated) {
|
|
52
52
|
console.error("Toast component #".concat(this.id, " repeated!"));
|
|
53
53
|
appLog_1.default.info("Toast component #".concat(this.id, " repeated!"));
|
|
54
54
|
}
|
|
55
|
-
toast_1.contextRef.value["#".concat(this.id)] = (0, utils_1.getCurrentPage)();
|
|
56
55
|
appLog_1.default.info("Toast #".concat(this.id, " mounted"));
|
|
57
56
|
},
|
|
58
57
|
destroyed: function () {
|
|
59
58
|
if (!this.id)
|
|
60
59
|
return;
|
|
61
|
-
toast_1.
|
|
60
|
+
(0, toast_1.unregisterToastContext)("#".concat(this.id), this);
|
|
62
61
|
appLog_1.default.info("Toast #".concat(this.id, " destroyed"));
|
|
63
62
|
},
|
|
64
63
|
methods: {
|
package/lib/toast/toast.d.ts
CHANGED
|
@@ -21,9 +21,27 @@ interface ToastOptions {
|
|
|
21
21
|
width?: number;
|
|
22
22
|
onClose?: () => void;
|
|
23
23
|
}
|
|
24
|
+
interface ToastContextEntry {
|
|
25
|
+
page: ToastContext;
|
|
26
|
+
instance: WechatMiniprogram.Component.TrivialInstance | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* selector -> 该 selector 下所有存活的 toast 实例。
|
|
30
|
+
* 一个 selector(id)可以同时挂在多个页面(多 webview)上,因此用数组记录,
|
|
31
|
+
* 而不再是「一个 selector 只对应一个 page」的单槽结构。
|
|
32
|
+
* 为向后兼容,仍容忍外部直接赋值为单个 page(非数组)的旧写法。
|
|
33
|
+
*/
|
|
24
34
|
export declare const contextRef: {
|
|
25
|
-
value: Record<string, ToastContext | null>;
|
|
35
|
+
value: Record<string, ToastContext | ToastContextEntry[] | null>;
|
|
26
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* 组件挂载时登记自身。同一 selector 在「同一个页面」上重复挂载才算冲突,
|
|
39
|
+
* 不同页面共用同一 selector 是被允许的(这正是「每页挂一个默认 toast」的场景)。
|
|
40
|
+
* @returns 是否与同页已有实例冲突(供组件层打印 repeated 提示)。
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerToastContext(selector: string, instance: WechatMiniprogram.Component.TrivialInstance): boolean;
|
|
43
|
+
/** 组件卸载时精确移除自身,不影响其它页面上同 selector 的实例。 */
|
|
44
|
+
export declare function unregisterToastContext(selector: string, instance: WechatMiniprogram.Component.TrivialInstance): void;
|
|
27
45
|
declare function Toast(toastOptions: ToastOptions | ToastMessage): WechatMiniprogram.Component.TrivialInstance | undefined;
|
|
28
46
|
declare namespace Toast {
|
|
29
47
|
var loading: (options: ToastMessage | ToastOptions) => WechatMiniprogram.Component.TrivialInstance | undefined;
|
package/lib/toast/toast.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.contextRef = void 0;
|
|
17
|
+
exports.unregisterToastContext = exports.registerToastContext = exports.contextRef = void 0;
|
|
18
18
|
var appLog_1 = __importDefault(require("../common/appLog"));
|
|
19
19
|
var utils_1 = require("../common/utils");
|
|
20
20
|
var validator_1 = require("../common/validator");
|
|
@@ -47,16 +47,70 @@ var currentOptions = __assign({}, defaultOptions);
|
|
|
47
47
|
function parseOptions(message) {
|
|
48
48
|
return (0, validator_1.isObj)(message) ? message : { message: message };
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* selector -> 该 selector 下所有存活的 toast 实例。
|
|
52
|
+
* 一个 selector(id)可以同时挂在多个页面(多 webview)上,因此用数组记录,
|
|
53
|
+
* 而不再是「一个 selector 只对应一个 page」的单槽结构。
|
|
54
|
+
* 为向后兼容,仍容忍外部直接赋值为单个 page(非数组)的旧写法。
|
|
55
|
+
*/
|
|
50
56
|
exports.contextRef = {
|
|
51
57
|
value: {},
|
|
52
58
|
};
|
|
59
|
+
/**
|
|
60
|
+
* 组件挂载时登记自身。同一 selector 在「同一个页面」上重复挂载才算冲突,
|
|
61
|
+
* 不同页面共用同一 selector 是被允许的(这正是「每页挂一个默认 toast」的场景)。
|
|
62
|
+
* @returns 是否与同页已有实例冲突(供组件层打印 repeated 提示)。
|
|
63
|
+
*/
|
|
64
|
+
function registerToastContext(selector, instance) {
|
|
65
|
+
var existing = exports.contextRef.value[selector];
|
|
66
|
+
var list = Array.isArray(existing) ? existing : [];
|
|
67
|
+
exports.contextRef.value[selector] = list;
|
|
68
|
+
var page = (0, utils_1.getCurrentPage)();
|
|
69
|
+
var samePage = list.find(function (entry) { return entry.page === page; });
|
|
70
|
+
if (samePage) {
|
|
71
|
+
samePage.instance = instance;
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
list.push({ page: page, instance: instance });
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
exports.registerToastContext = registerToastContext;
|
|
78
|
+
/** 组件卸载时精确移除自身,不影响其它页面上同 selector 的实例。 */
|
|
79
|
+
function unregisterToastContext(selector, instance) {
|
|
80
|
+
var existing = exports.contextRef.value[selector];
|
|
81
|
+
if (!Array.isArray(existing)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
exports.contextRef.value[selector] = existing.filter(function (entry) { return entry.instance !== instance; });
|
|
85
|
+
}
|
|
86
|
+
exports.unregisterToastContext = unregisterToastContext;
|
|
87
|
+
/**
|
|
88
|
+
* 解析目标实例所在的上下文:优先命中「当前页面」上的实例,
|
|
89
|
+
* 其次退回最后挂载的实例(栈顶,覆盖跨页/非当前页场景),
|
|
90
|
+
* 同时兼容外部直接赋值单个 page 的旧写法。
|
|
91
|
+
*/
|
|
92
|
+
function resolveContextEntry(selector) {
|
|
93
|
+
var existing = exports.contextRef.value[selector];
|
|
94
|
+
if (!existing) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
if (!Array.isArray(existing)) {
|
|
98
|
+
// 兼容旧结构:value[selector] 直接是一个 page
|
|
99
|
+
return { page: existing, instance: null };
|
|
100
|
+
}
|
|
101
|
+
if (!existing.length) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
var currentPage = (0, utils_1.getCurrentPage)();
|
|
105
|
+
return existing.find(function (entry) { return entry.page === currentPage; }) || existing[existing.length - 1];
|
|
106
|
+
}
|
|
53
107
|
function Toast(toastOptions) {
|
|
54
108
|
var options = __assign(__assign({}, currentOptions), parseOptions(toastOptions));
|
|
55
109
|
appLog_1.default.info('start open Toast');
|
|
56
|
-
var
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var toast = context.selectComponent(options.selector);
|
|
110
|
+
var explicitContext = typeof options.context === 'function' ? options.context() : options.context;
|
|
111
|
+
var entry = explicitContext ? null : resolveContextEntry(options.selector);
|
|
112
|
+
var context = explicitContext || (entry === null || entry === void 0 ? void 0 : entry.page) || (0, utils_1.getCurrentPage)();
|
|
113
|
+
var toast = context.selectComponent(options.selector) || (entry === null || entry === void 0 ? void 0 : entry.instance) || null;
|
|
60
114
|
appLog_1.default.info("toast selector: ".concat(options.selector));
|
|
61
115
|
appLog_1.default.info("toast component ".concat(toast ? 'success' : 'fail'));
|
|
62
116
|
if (!toast) {
|