useToast.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. function useToast() {
  4. const tipTitle = common_vendor.ref("");
  5. const tipIcon = common_vendor.ref("none");
  6. const tipEndtime = common_vendor.ref(2e3);
  7. function Toast(opt, to_url) {
  8. common_vendor.index.__f__("log", "at hooks/useToast.js:31", "Toast", opt, to_url);
  9. if (typeof opt == "string") {
  10. to_url = opt;
  11. opt = {};
  12. }
  13. tipTitle.value = opt.title || "";
  14. tipIcon.value = opt.icon || "none";
  15. tipEndtime.value = opt.endtime || 1e3;
  16. let success = opt.success;
  17. if (tipTitle.value)
  18. common_vendor.index.showToast({
  19. title: tipTitle.value,
  20. icon: tipIcon.value,
  21. duration: tipEndtime.value,
  22. success
  23. });
  24. if (to_url != void 0) {
  25. if (typeof to_url == "object") {
  26. let tab = to_url.tab || 1, url = to_url.url || "";
  27. common_vendor.index.__f__("log", "at hooks/useToast.js:59", "tab", tab);
  28. switch (tab) {
  29. case 1:
  30. setTimeout(() => common_vendor.index.switchTab({ url }), tipEndtime.value);
  31. break;
  32. case 2:
  33. setTimeout(() => common_vendor.index.navigateTo({ url }), tipEndtime.value);
  34. break;
  35. case 3:
  36. setTimeout(() => {
  37. common_vendor.index.navigateBack({ delta: 1 });
  38. }, tipEndtime.value);
  39. break;
  40. case 4:
  41. setTimeout(() => common_vendor.index.reLaunch({ url }), tipEndtime.value);
  42. break;
  43. case 5:
  44. setTimeout(() => common_vendor.index.redirectTo({ url }), tipEndtime.value);
  45. break;
  46. }
  47. } else if (typeof to_url == "function") {
  48. setTimeout(() => to_url && to_url(), tipEndtime.value);
  49. } else {
  50. setTimeout(
  51. () => common_vendor.index.navigateTo({ url: to_url }),
  52. tipTitle.value ? tipEndtime.value : 0
  53. );
  54. }
  55. }
  56. }
  57. return {
  58. tipTitle,
  59. tipIcon,
  60. tipEndtime,
  61. Toast
  62. };
  63. }
  64. exports.useToast = useToast;
  65. //# sourceMappingURL=../../.sourcemap/mp-weixin/hooks/useToast.js.map