index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_store_index = require("../store/index.js");
  4. const sheep_hooks_useModal = require("../hooks/useModal.js");
  5. const sheep_helper_throttle = require("../helper/throttle.js");
  6. const _go = (path, params = {}, options = {
  7. redirect: false
  8. }) => {
  9. var _a;
  10. let page = "";
  11. let query = "";
  12. let url = "";
  13. if (common_vendor.lodashExports.isString(path)) {
  14. if (common_vendor.lodashExports.startsWith(path, "http")) {
  15. page = `/pages/public/webview`;
  16. query = `url=${encodeURIComponent(path)}`;
  17. } else if (common_vendor.lodashExports.startsWith(path, "action:")) {
  18. handleAction(path);
  19. return;
  20. } else {
  21. [page, query] = path.split("?");
  22. }
  23. if (!common_vendor.lodashExports.isEmpty(params)) {
  24. let query2 = paramsToQuery(params);
  25. if (common_vendor.lodashExports.isEmpty(query)) {
  26. query = query2;
  27. } else {
  28. query += "&" + query2;
  29. }
  30. }
  31. }
  32. if (common_vendor.lodashExports.isObject(path)) {
  33. page = path.url;
  34. if (!common_vendor.lodashExports.isNil(path.params)) {
  35. query = paramsToQuery(path.params);
  36. }
  37. }
  38. const nextRoute = { "/pages/index/index": { "path": "/pages/index/index", "aliasPath": "/", "meta": { "auth": false, "sync": true, "title": "首页", "group": "商城" } }, "/pages/index/user": { "path": "/pages/index/user", "meta": { "sync": true, "title": "个人中心", "group": "商城" } }, "/pages/index/category": { "path": "/pages/index/category", "meta": { "sync": true, "title": "商品分类", "group": "商城" } }, "/pages/index/cart": { "path": "/pages/index/cart", "meta": { "sync": true, "title": "购物车", "group": "商城" } }, "/pages/index/login": { "path": "/pages/index/login" }, "/pages/index/search": { "path": "/pages/index/search", "meta": { "sync": true, "title": "搜索", "group": "商城" } }, "/pages/index/page": { "path": "/pages/index/page", "meta": { "auth": false, "sync": true, "title": "自定义页面", "group": "商城" } }, "/pages/goods/index": { "path": "/pages/goods/index", "meta": { "sync": true, "title": "普通商品", "group": "商品" } }, "/pages/goods/groupon": { "path": "/pages/goods/groupon", "meta": { "sync": true, "title": "拼团商品", "group": "商品" } }, "/pages/goods/seckill": { "path": "/pages/goods/seckill", "meta": { "sync": true, "title": "秒杀商品", "group": "商品" } }, "/pages/goods/list": { "path": "/pages/goods/list", "meta": { "sync": true, "title": "商品列表", "group": "商品" } }, "/pages/goods/comment/add": { "path": "/pages/goods/comment/add", "meta": { "auth": true } }, "/pages/goods/comment/list": { "path": "/pages/goods/comment/list" }, "/pages/order/detail": { "path": "/pages/order/detail", "meta": { "auth": true, "title": "订单详情" } }, "/pages/order/confirm": { "path": "/pages/order/confirm", "meta": { "auth": true, "title": "确认订单" } }, "/pages/order/list": { "path": "/pages/order/list", "meta": { "auth": true, "sync": true, "title": "用户订单", "group": "订单中心" } }, "/pages/order/aftersale/apply": { "path": "/pages/order/aftersale/apply", "meta": { "auth": true, "title": "申请售后" } }, "/pages/order/aftersale/return-delivery": { "path": "/pages/order/aftersale/return-delivery", "meta": { "auth": true, "title": "退货物流" } }, "/pages/order/aftersale/list": { "path": "/pages/order/aftersale/list", "meta": { "auth": true, "sync": true, "title": "售后订单", "group": "订单中心" } }, "/pages/order/aftersale/detail": { "path": "/pages/order/aftersale/detail", "meta": { "auth": true, "title": "售后详情" } }, "/pages/order/aftersale/log": { "path": "/pages/order/aftersale/log", "meta": { "auth": true, "title": "售后进度" } }, "/pages/order/express/log": { "path": "/pages/order/express/log", "meta": { "auth": true, "title": "物流轨迹" } }, "/pages/order/otherlist": { "path": "/pages/order/otherlist" }, "/pages/user/info": { "path": "/pages/user/info", "meta": { "auth": true, "sync": true, "title": "用户信息", "group": "用户中心" } }, "/pages/user/setting": { "path": "/pages/user/setting", "meta": { "auth": true, "sync": true, "title": "用户设置", "group": "用户中心" } }, "/pages/user/qrcode-share": { "path": "/pages/user/qrcode-share", "meta": { "auth": true, "sync": true, "title": "我的二维码/分享页", "group": "用户中心" } }, "/pages/user/goods-collect": { "path": "/pages/user/goods-collect", "meta": { "auth": true, "sync": true, "title": "商品收藏", "group": "用户中心" } }, "/pages/user/goods-log": { "path": "/pages/user/goods-log", "meta": { "auth": true, "sync": true, "title": "浏览记录", "group": "用户中心" } }, "/pages/user/address/list": { "path": "/pages/user/address/list", "meta": { "auth": true, "sync": true, "title": "地址管理", "group": "用户中心" } }, "/pages/user/dummyAddress/list": { "path": "/pages/user/dummyAddress/list", "meta": { "auth": true, "sync": true, "title": "虚拟商品收货地址", "group": "用户中心" } }, "/pages/user/invoice/edit": { "path": "/pages/user/invoice/edit", "meta": { "auth": true, "title": "发票抬头" } }, "/pages/user/invoice/list": { "path": "/pages/user/invoice/list", "meta": { "auth": true, "sync": true, "title": "发票抬头管理", "group": "用户中心" } }, "/pages/user/address/edit": { "path": "/pages/user/address/edit", "meta": { "auth": true, "title": "编辑地址" } }, "/pages/user/dummyAddress/edit": { "path": "/pages/user/dummyAddress/edit", "meta": { "auth": true, "title": "编辑地址" } }, "/pages/user/wallet/money": { "path": "/pages/user/wallet/money", "meta": { "auth": true, "sync": true, "title": "用户余额", "group": "用户中心" } }, "/pages/user/wallet/score": { "path": "/pages/user/wallet/score", "meta": { "auth": true, "sync": true, "title": "用户积分", "group": "用户中心" } }, "/pages/user/wallet/scoreToMoney": { "path": "/pages/user/wallet/scoreToMoney", "meta": { "auth": true, "sync": true, "title": "积分兑换", "group": "用户中心" } }, "/pages/user/wallet/ScoreLog": { "path": "/pages/user/wallet/ScoreLog" }, "/pages/user/wallet/maxScoreLog": { "path": "/pages/user/wallet/maxScoreLog" }, "/pages/user/wallet/team": { "path": "/pages/user/wallet/team", "meta": { "auth": true, "sync": true, "title": "团队", "group": "用户中心" } }, "/pages/commission/index": { "path": "/pages/commission/index", "meta": { "auth": true, "sync": true, "title": "分销中心", "group": "分销商城" } }, "/pages/commission/wallet": { "path": "/pages/commission/wallet", "meta": { "auth": true, "sync": true, "title": "用户佣金", "group": "分销中心" } }, "/pages/commission/goods": { "path": "/pages/commission/goods", "meta": { "auth": true, "sync": true, "title": "推广商品", "group": "分销商城" } }, "/pages/commission/order": { "path": "/pages/commission/order", "meta": { "auth": true, "sync": true, "title": "分销订单", "group": "分销商城" } }, "/pages/commission/team": { "path": "/pages/commission/team", "meta": { "auth": true, "sync": true, "title": "我的团队", "group": "分销商城" } }, "/pages/commission/promoter": { "path": "/pages/commission/promoter", "meta": { "auth": true, "sync": true, "title": "推广人排行榜", "group": "分销商城" } }, "/pages/commission/commission-ranking": { "path": "/pages/commission/commission-ranking", "meta": { "auth": true, "sync": true, "title": "佣金排行榜", "group": "分销商城" } }, "/pages/commission/withdraw": { "path": "/pages/commission/withdraw", "meta": { "auth": true, "sync": true, "title": "申请提现", "group": "分销商城" } }, "/pages/app/sign": { "path": "/pages/app/sign", "meta": { "auth": true, "sync": true, "title": "签到中心", "group": "应用" } }, "/pages/shop/index": { "path": "/pages/shop/index", "meta": { "auth": true, "sync": true, "title": "店铺首页", "group": "应用" } }, "/pages/public/setting": { "path": "/pages/public/setting", "meta": { "sync": true, "title": "系统设置", "group": "通用" } }, "/pages/public/richtext": { "path": "/pages/public/richtext", "meta": { "sync": true, "title": "富文本", "group": "通用" } }, "/pages/public/faq": { "path": "/pages/public/faq", "meta": { "sync": true, "title": "常见问题", "group": "通用" } }, "/pages/public/error": { "path": "/pages/public/error" }, "/pages/public/webview": { "path": "/pages/public/webview" }, "/pages/coupon/list": { "path": "/pages/coupon/list", "meta": { "sync": true, "title": "领券中心", "group": "优惠券" } }, "/pages/coupon/detail": { "path": "/pages/coupon/detail", "meta": { "auth": false, "sync": true, "title": "优惠券详情", "group": "优惠券" } }, "/pages/chat/index": { "path": "/pages/chat/index", "meta": { "auth": true, "sync": true, "title": "客服", "group": "客服" } }, "/pages/chat/speechtotext": { "path": "/pages/chat/speechtotext", "meta": { "auth": true, "sync": true, "title": "语音转文字", "group": "语音转文字" } }, "/pages/pay/index": { "path": "/pages/pay/index" }, "/pages/pay/result": { "path": "/pages/pay/result" }, "/pages/pay/recharge": { "path": "/pages/pay/recharge", "meta": { "auth": true, "sync": true, "title": "充值余额", "group": "支付" } }, "/pages/pay/recharge-log": { "path": "/pages/pay/recharge-log", "meta": { "auth": true, "sync": true, "title": "充值记录", "group": "支付" } }, "/pages/activity/groupon/detail": { "path": "/pages/activity/groupon/detail" }, "/pages/activity/groupon/order": { "path": "/pages/activity/groupon/order", "meta": { "auth": true, "sync": true, "title": "拼团订单", "group": "营销活动" } }, "/pages/activity/index": { "path": "/pages/activity/index", "meta": { "sync": true, "title": "营销商品", "group": "营销活动" } }, "/pages/activity/groupon/list": { "path": "/pages/activity/groupon/list", "meta": { "sync": true, "title": "拼团活动", "group": "营销活动" } }, "/pages/activity/seckill/list": { "path": "/pages/activity/seckill/list", "meta": { "sync": true, "title": "秒杀活动", "group": "营销活动" } }, "/pages/activity/bargain/list": { "path": "/pages/activity/bargain/list", "meta": { "sync": true, "title": "砍价列表", "group": "营销活动" } }, "/pages/activity/bargain/detail": { "path": "/pages/activity/bargain/detail", "meta": { "sync": true, "title": "砍价详情", "group": "营销活动" } } }[page];
  39. if (!nextRoute) {
  40. console.log(`%c跳转路径参数错误<${page || "EMPTY"}>`, "color:red;background:yellow");
  41. return;
  42. }
  43. if (((_a = nextRoute.meta) == null ? void 0 : _a.auth) && !sheep_store_index.$store("user").isLogin) {
  44. sheep_hooks_useModal.showAuthModal();
  45. return;
  46. }
  47. url = page;
  48. if (!common_vendor.lodashExports.isEmpty(query)) {
  49. url += `?${query}`;
  50. }
  51. if (["/pages/index/index", "/pages/index/cart", "/pages/index/user"].includes(page)) {
  52. common_vendor.index.switchTab({
  53. url
  54. });
  55. return;
  56. }
  57. if (options.redirect) {
  58. common_vendor.index.redirectTo({
  59. url
  60. });
  61. return;
  62. }
  63. common_vendor.index.navigateTo({
  64. url
  65. });
  66. };
  67. function go(...args) {
  68. sheep_helper_throttle.throttle(() => {
  69. _go(...args);
  70. });
  71. }
  72. function paramsToQuery(params) {
  73. if (common_vendor.lodashExports.isEmpty(params)) {
  74. return "";
  75. }
  76. let query = [];
  77. for (let key in params) {
  78. query.push(key + "=" + params[key]);
  79. }
  80. return query.join("&");
  81. }
  82. function back() {
  83. common_vendor.index.navigateBack();
  84. }
  85. function redirect(path, params = {}) {
  86. go(path, params, {
  87. redirect: true
  88. });
  89. }
  90. function hasHistory() {
  91. const pages = getCurrentPages();
  92. if (pages.length > 1) {
  93. return true;
  94. }
  95. return false;
  96. }
  97. function getCurrentRoute(field = "") {
  98. let currentPage = getCurrentPage();
  99. currentPage.$page["route"] = currentPage.route;
  100. currentPage.$page["options"] = currentPage.options;
  101. if (field !== "") {
  102. return currentPage.$page[field];
  103. } else {
  104. return currentPage.$page;
  105. }
  106. }
  107. function getCurrentPage() {
  108. let pages = getCurrentPages();
  109. return pages[pages.length - 1];
  110. }
  111. function handleAction(path) {
  112. const action = path.split(":");
  113. switch (action[1]) {
  114. case "showShareModal":
  115. sheep_hooks_useModal.showShareModal();
  116. break;
  117. }
  118. }
  119. function error(errCode, errMsg = "") {
  120. redirect("/pages/public/error", {
  121. errCode,
  122. errMsg
  123. });
  124. }
  125. const $router = {
  126. go,
  127. back,
  128. hasHistory,
  129. redirect,
  130. getCurrentPage,
  131. getCurrentRoute,
  132. error
  133. };
  134. exports.$router = $router;