types(Toast): fix context type

This commit is contained in:
chenjiahan 2022-09-07 22:54:48 +08:00
parent 8220552f66
commit 9a708747a8
3 changed files with 16 additions and 80 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ example/dist
changelog.generated.md
package-lock.json
build/private.wx1c01b35002d3ba14.key
project.private.config.json

View File

@ -1,7 +1,8 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
"ignore": [],
"include": []
},
"setting": {
"urlCheck": false,
@ -42,355 +43,279 @@
"libVersion": "2.6.5",
"appid": "wx1c01b35002d3ba14",
"projectname": "vant-weapp",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [
{
"id": -1,
"name": "button",
"pathName": "pages/button/index",
"query": ""
},
{
"id": -1,
"name": "loading",
"pathName": "pages/loading/index",
"query": ""
},
{
"id": -1,
"name": "icon",
"pathName": "pages/icon/index",
"query": ""
},
{
"id": 3,
"name": "layout",
"pathName": "pages/col/index",
"query": ""
},
{
"id": -1,
"name": "cell",
"pathName": "pages/cell/index",
"query": ""
},
{
"id": -1,
"name": "config-provider",
"pathName": "pages/config-provider/index",
"query": ""
},
{
"id": -1,
"name": "card",
"pathName": "pages/card/index",
"query": ""
},
{
"id": -1,
"name": "stepper",
"pathName": "pages/stepper/index",
"query": ""
},
{
"id": -1,
"name": "switch",
"pathName": "pages/switch/index",
"query": ""
},
{
"id": -1,
"name": "tag",
"pathName": "pages/tag/index",
"query": ""
},
{
"id": -1,
"name": "notice-bar",
"pathName": "pages/notice-bar/index",
"query": ""
},
{
"id": -1,
"name": "tree-select",
"pathName": "pages/tree-select/index",
"query": ""
},
{
"id": -1,
"name": "select",
"pathName": "pages/select/index",
"query": ""
},
{
"id": -1,
"name": "field",
"pathName": "pages/field/index",
"query": ""
},
{
"id": 13,
"name": "sidebar",
"pathName": "pages/sidebar/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "panel",
"pathName": "pages/panel/index",
"query": ""
},
{
"id": -1,
"name": "popup",
"pathName": "pages/popup/index",
"query": ""
},
{
"id": 16,
"name": "action-sheet",
"pathName": "pages/action-sheet/index",
"query": ""
},
{
"id": -1,
"name": "steps",
"pathName": "pages/steps/index",
"query": ""
},
{
"id": -1,
"name": "search",
"pathName": "pages/search/index",
"query": ""
},
{
"id": -1,
"name": "nav-bar",
"pathName": "pages/nav-bar/index",
"query": ""
},
{
"id": -1,
"name": "notify",
"pathName": "pages/notify/index",
"query": ""
},
{
"id": -1,
"name": "toast",
"pathName": "pages/toast/index",
"query": ""
},
{
"id": -1,
"name": "tabbar",
"pathName": "pages/tabbar/index",
"query": ""
},
{
"id": -1,
"name": "transition",
"pathName": "pages/transition/index",
"query": ""
},
{
"id": -1,
"name": "slider",
"pathName": "pages/slider/index",
"query": ""
},
{
"id": -1,
"name": "progress",
"pathName": "pages/progress/index",
"query": ""
},
{
"id": -1,
"name": "area",
"pathName": "pages/area/index",
"query": ""
},
{
"id": -1,
"name": "tab",
"pathName": "pages/tab/index",
"query": ""
},
{
"id": -1,
"name": "dialog",
"pathName": "pages/dialog/index",
"query": ""
},
{
"id": -1,
"name": "submit-bar",
"pathName": "pages/submit-bar/index",
"query": ""
},
{
"id": -1,
"name": "checkbox",
"pathName": "pages/checkbox/index",
"query": ""
},
{
"id": -1,
"name": "goods-action",
"pathName": "pages/goods-action/index",
"query": ""
},
{
"id": -1,
"name": "radio",
"pathName": "pages/radio/index",
"query": ""
},
{
"id": -1,
"name": "swipe-cell",
"pathName": "pages/swipe-cell/index",
"query": ""
},
{
"id": -1,
"name": "rate",
"pathName": "pages/rate/index",
"query": ""
},
{
"id": -1,
"name": "collapse",
"pathName": "pages/collapse/index",
"query": ""
},
{
"id": -1,
"name": "datetime-picker",
"pathName": "pages/datetime-picker/index",
"query": ""
},
{
"id": -1,
"name": "sticky",
"pathName": "pages/sticky/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "picker",
"pathName": "pages/picker/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "overlay",
"pathName": "pages/overlay/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "circle",
"pathName": "pages/circle/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "grid",
"pathName": "pages/grid/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "count-down",
"pathName": "pages/count-down/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "image",
"pathName": "pages/image/index",
"query": "",
"scene": null
},
{
"id": 45,
"name": "skeleton",
"pathName": "pages/skeleton/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "uploader",
"pathName": "pages/uploader/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "dropdown-menu",
"pathName": "pages/dropdown-menu/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "calendar",
"pathName": "pages/calendar/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "index-bar",
"pathName": "pages/index-bar/index",
"query": "",
"scene": null
},
{
"id": -1,
"name": "empty",
"pathName": "pages/empty/index",
"query": "",
"scene": null
},
{
"id": 51,
"name": "share-sheet",
"pathName": "pages/share-sheet/index",
"query": "",
@ -405,9 +330,14 @@
{
"name": "divider",
"pathName": "pages/divider/index",
"query": "",
"scene": null
}
]
}
},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}

View File

@ -1,14 +1,16 @@
import { isObj } from '../common/validator';
type ToastMessage = string | number;
type ToastContext = WechatMiniprogram.Component.TrivialInstance | WechatMiniprogram.Page.TrivialInstance
type ToastContext =
| WechatMiniprogram.Component.TrivialInstance
| WechatMiniprogram.Page.TrivialInstance;
interface ToastOptions {
show?: boolean;
type?: string;
mask?: boolean;
zIndex?: number;
context?: () => ToastContext | ToastContext;
context?: (() => ToastContext) | ToastContext;
position?: string;
duration?: number;
selector?: string;
@ -49,7 +51,10 @@ function Toast(toastOptions: ToastOptions | ToastMessage) {
...parseOptions(toastOptions),
} as ToastOptions;
const context = (typeof options.context === 'function' ? options.context() : options.context) || getContext();
const context =
(typeof options.context === 'function'
? options.context()
: options.context) || getContext();
const toast = context.selectComponent(options.selector as string);
if (!toast) {