{"id":13654363,"url":"https://github.com/kiinlam/wetoast","last_synced_at":"2025-04-23T09:33:24.068Z","repository":{"id":207521571,"uuid":"75173443","full_name":"kiinlam/wetoast","owner":"kiinlam","description":"微信小程序toast增强插件","archived":true,"fork":false,"pushed_at":"2019-03-02T09:40:32.000Z","size":34,"stargazers_count":232,"open_issues_count":5,"forks_count":71,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-02-13T16:11:25.252Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kiinlam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-11-30T09:48:54.000Z","updated_at":"2023-11-01T15:15:31.000Z","dependencies_parsed_at":"2023-11-16T08:48:27.236Z","dependency_job_id":null,"html_url":"https://github.com/kiinlam/wetoast","commit_stats":null,"previous_names":["kiinlam/wetoast"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiinlam%2Fwetoast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiinlam%2Fwetoast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiinlam%2Fwetoast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiinlam%2Fwetoast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiinlam","download_url":"https://codeload.github.com/kiinlam/wetoast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250407696,"owners_count":21425544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T03:00:30.592Z","updated_at":"2025-04-23T09:33:23.831Z","avatar_url":"https://github.com/kiinlam.png","language":"JavaScript","funding_links":[],"categories":["组件","UI组件","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"## 公告\n\n微信小程序现已在框架升级了`showToast`API，增加了更多自定义功能，推荐使用。本仓库停止更新。需要交流可提Issue，不便之处请海涵。\n\n`wx.showToast` API地址：https://developers.weixin.qq.com/miniprogram/dev/api/wx.showToast.html\n\n===\n\nWeToast for 微信小程序 toast增强插件\n===\n\n## 概述\n\n[WeToast](https://github.com/kiinlam/wetoast) 是仿照微信小程序提供的 `showToast` 功能，提供视觉一致的增强插件，弥补小程序`showToast`功能上的不足（如只能显示`success`、`loading`两种icon，且icon不可去除，持续时间最大10秒等）。\n\n## 预览\n\n[下载WeToast项目](https://github.com/kiinlam/wetoast/archive/master.zip)，用[微信web开发者工具](https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html)打开项目根目录\n\n\u003cimg src=\"https://raw.githubusercontent.com/kiinlam/wetoast/master/images/demo.png\" alt=\"demo capture\" /\u003e\n\n## 如何使用\n\nWeTaost插件源码位于`src`目录下，包含3个文件。\n\n- wetoast.js: 脚本代码\n- wetoast.wxml: 模板结构\n- wetoast.wxss: 样式\n\n使用时只需要加入以上3个文件即可，使用方法可参考本项目示范。\n\n#### 推荐方案\n\n##### Step1、在项目的`app.js`中引入`wetoast.js`，并注册到小程序上，小程序所有Page页面均可使用，无需再次引入\n\n```javascript\nlet {WeToast} = require('src/wetoast.js')    // 返回构造函数，变量名可自定义\nApp({\n\tWeToast    // 后面可以通过app.WeToast访问\n})\n```\n\n##### Step2、在项目的`app.wxss`中引入`wetoast.wxss`\n\n```css\n@import \"src/wetoast.wxss\";\n```\n\n##### Step3、引入WeToast模板结构，\n\n*方式一，在单独页面使用*\n\n```html\n\u003c!-- 文件 index.wxml 中 --\u003e\n\u003cimport src=\"../../src/wetoast.wxml\"/\u003e\n\u003ctemplate is=\"wetoast\" data=\"{{...__wetoast__}}\"/\u003e\n```\n\n*方式二，创建公用包含文件，将所有公用模板放在一起*\n\n```html\n\u003c!-- 文件 footer.wxml 中 --\u003e\n\u003cimport src=\"src/wetoast.wxml\"/\u003e\n\u003ctemplate is=\"wetoast\" data=\"{{...__wetoast__}}\"/\u003e\n\u003c!-- 其他xxoo模板 --\u003e\n\u003ctemplate is=\"wexxoo\" data=\"{{...wexxoo}}\"/\u003e\n```\n\n*然后通过`include`引入*\n\n```html\n\u003c!-- Page文件 index.wxml 底部 --\u003e\n\u003cinclude src=\"footer.wxml\"/\u003e\n```\n\n## API\n\n#### WeToast()\n\n构造函数，返回WeToast实例对象，该操作会在当前Page上创建一个名为`wetoast`的引用，在Page中可通过`this.wetoast`访问。通常在Page的`onLoad`中调用，可重复使用。\n\n###### 示例\n\n```javascript\n// 创建可重复使用的WeToast实例，并附加到Page上，通过this.wetoast访问\nnew app.WeToast()\n// 也可创建变量来保存\nlet mytoast = new app.WeToast()\n```\n\n#### WeToast.prototype.toast(Object)\n\n控制toast的显示、隐藏，接收一个可选的对象作为配置参数。不提供参数时，表示隐藏toast。\n\n###### Object参数说明：\n\n| 参数          | 类型          | 必填  | 说明                         |\n| ------------- | ------------- | ----- | ---------------------------- |\n| img           | String\t\t| 可选* | 提示的图片，网络地址或base64 |\n| imgClassName  | String\t\t| 否    | 自定义图片样式时使用的class  |\n| imgMode       | String\t\t| 否    | 参考小程序image组件mode属性  |\n| title \t\t| String\t\t| 可选* | 提示的内容                   |\n| titleClassName| String\t\t| 否    | 自定义内容样式时使用的class  |\n| duration \t\t| Number\t\t| 否    | 提示的持续时间，默认1500毫秒 |\n| success \t\t| Function\t\t| 否    | 提示即将隐藏时的回调函数     |\n| fail \t\t\t| Function\t\t| 否    | 调用过程抛出错误时的回调函数 |\n| complete \t\t| Function\t\t| 否    | 调用结束时的回调函数         |\n\n*可选表示至少设置 `img` 或 `title` 中的一个*\n\n###### img参数补充说明\n\n提示的图片设置尺寸为55px * 55px，建议使用原始大小为110px * 110px的图片。使用图片时，优先选择base64形式，保证实时显示。\n\n###### title参数补充说明\n\n提示框的宽度设置了最小宽度为8.4em，最大宽度为屏幕的70%，超过时会换行。\n\n###### duration参数补充说明\n\n当`duration`设置为`0`时，将不自动隐藏提示层，直到下次再次调用`wetoast.toast()`，不传入配置项表示隐藏提示。\n\n###### 回调函数参数补充说明：\n\n`success`、`fail`、`complete`执行时均会回传配置参数`Object`。无论成功或失败，`complete`都会执行。\n\n###### 示例\n\n```javascript\n// 只显示图标，不显示文字\nwetoast.toast({\n    img: 'https://raw.githubusercontent.com/kiinlam/wetoast/master/images/cross.png'\n})\n```\n\n```javascript\n// 只显示文字，不显示图标\nwetoast.toast({\n    title: 'WeToast'\n})\n```\n\n```javascript\n// 显示文字、图标，执行回调函数\nwetoast.toast({\n    img: 'https://raw.githubusercontent.com/kiinlam/wetoast/master/images/star.png',\n    title: 'WeToast',\n    success (data) {\n        console.log(Date.now() + ': success')\n    },\n    fail (data) {\n        console.log(Date.now() + ': fail')\n    },\n    complete (data) {\n        console.log(Date.now() + ': complete')\n    }\n})\n```\n\n```javascript\n// 自定义显示持续时间\nwetoast.toast({\n    title: 'WeToast',\n    duration: 5000\n})\n```\n\n## 问答\n\n##### 问：个人开发者怎么体验小程序？\n\n答：可参考此文[个人开发者体验小程序的方法](https://sso.ifanr.com/trochili/thread/11856/)。原理很简单，只要能扫码进入微信web开发者工具，就能创建小程序项目，所以问题变为如何成为开发者。\n\n个人成为开发者最简单的方式就是申请微信订阅号，完成后即可进入开发者工具。\n\n##### 问：为什么做这个插件？\n\n答：微信小程序提供的`showToast`API目前仅支持显示`success`、`loading`两种图标，不够用，且在某些场景下，最大值10秒也不够用。\n\n在官方未提供更丰富配置的情况下，有必要在官方UI规范的框架下提供一套功能更实用的备选方案。\n\n同时我也希望各开发者能够达成共识，在实现自身需求时，尽量以官方UI规范为指导，避免出现各种花样的弹层效果。\n\n##### 问：是否会出现“串页”问题？\n\n答：此处“串页”是指上一页的代码在当前页执行。在navigate跳转的情况下，由于页面不是被关闭，因此代码还在执行，一些涉及全局的操作会被带入当前页。\n\n在开发本插件的时候，充分考虑了这一点，采用实例化toast对象并附加到当前的Page对象上，在切换Page后仍然指向上一页的Page对象，不会出现“串页”问题。\n\n## TODO\n\n- 增加预定义ICON\n- 增加可自定义动画功能\n\n## License\nThe MIT License(http://opensource.org/licenses/MIT)\n\n请自由地享受和参与开源\n\n## 贡献\n\n如果你有好的意见或建议，欢迎给我提issue或pull request。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiinlam%2Fwetoast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiinlam%2Fwetoast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiinlam%2Fwetoast/lists"}