1 line
6.3 KiB
Plaintext
1 line
6.3 KiB
Plaintext
{"version":3,"file":"index.js","sources":["../../../../../src/sheep/router/index.js"],"sourcesContent":["import $store from '@/sheep/store'\r\nimport { showAuthModal, showShareModal } from '@/sheep/hooks/useModal'\r\nimport { isNumber, isString, isEmpty, startsWith, isObject, isNil, clone } from 'lodash-es'\r\nimport throttle from '@/sheep/helper/throttle'\r\n\r\nconst _go = (\r\n path,\r\n params = {},\r\n options = {\r\n redirect: false,\r\n },\r\n) => {\r\n let page = '' // 跳转页面\r\n let query = '' // 页面参数\r\n let url = '' // 跳转页面完整路径\r\n\r\n if (isString(path)) {\r\n // 判断跳转类型是 path | 还是http\r\n if (startsWith(path, 'http')) {\r\n // #ifdef H5\r\n window.location = path\r\n return\r\n // #endif\r\n // #ifndef H5\r\n page = `/modules/mall/public/webview`\r\n query = `url=${encodeURIComponent(path)}`\r\n // #endif\r\n } else if (startsWith(path, 'action:')) {\r\n handleAction(path)\r\n return\r\n } else {\r\n ;[page, query] = path.split('?')\r\n }\r\n if (!isEmpty(params)) {\r\n const query2 = paramsToQuery(params)\r\n if (isEmpty(query)) {\r\n query = query2\r\n } else {\r\n query += '&' + query2\r\n }\r\n }\r\n }\r\n\r\n if (isObject(path)) {\r\n page = path.url\r\n if (!isNil(path.params)) {\r\n query = paramsToQuery(path.params)\r\n }\r\n }\r\n\r\n const nextRoute = ROUTES_MAP[page]\r\n\r\n // 未找到指定跳转页面\r\n // mark: 跳转404页\r\n if (!nextRoute) {\r\n console.log(`%c跳转路径参数错误<${page || 'EMPTY'}>`, 'color:red;background:yellow')\r\n return\r\n }\r\n\r\n // 页面登录拦截\r\n if (nextRoute.meta?.auth && !$store('user').isLogin) {\r\n showAuthModal()\r\n return\r\n }\r\n\r\n url = page\r\n if (!isEmpty(query)) {\r\n url += `?${query}`\r\n }\r\n\r\n // 跳转底部导航\r\n if (TABBAR.includes(page)) {\r\n uni.switchTab({\r\n url,\r\n })\r\n return\r\n }\r\n\r\n // 使用redirect跳转\r\n if (options.redirect) {\r\n uni.redirectTo({\r\n url,\r\n })\r\n return\r\n }\r\n\r\n uni.navigateTo({\r\n url,\r\n })\r\n}\r\n\r\n// 限流 防止重复点击跳转\r\nfunction go(...args) {\r\n throttle(() => {\r\n _go(...args)\r\n })\r\n}\r\n\r\nfunction paramsToQuery(params) {\r\n if (isEmpty(params)) {\r\n return ''\r\n }\r\n // return new URLSearchParams(Object.entries(params)).toString();\r\n const query = []\r\n for (const key in params) {\r\n query.push(key + '=' + params[key])\r\n }\r\n\r\n return query.join('&')\r\n}\r\n\r\nfunction back() {\r\n // #ifdef H5\r\n history.back()\r\n // #endif\r\n\r\n // #ifndef H5\r\n uni.navigateBack()\r\n // #endif\r\n}\r\n\r\nfunction redirect(path, params = {}) {\r\n go(path, params, {\r\n redirect: true,\r\n })\r\n}\r\n\r\n// 检测是否有浏览器历史\r\nfunction hasHistory() {\r\n // #ifndef H5\r\n const pages = getCurrentPages()\r\n if (pages.length > 1) {\r\n return true\r\n }\r\n return false\r\n // #endif\r\n\r\n // #ifdef H5\r\n return !!history.state.back\r\n // #endif\r\n}\r\n\r\nfunction getCurrentRoute(field = '') {\r\n const currentPage = getCurrentPage()\r\n // #ifdef MP\r\n currentPage.$page.route = currentPage.route\r\n currentPage.$page.options = currentPage.options\r\n // #endif\r\n if (field !== '') {\r\n return currentPage.$page[field]\r\n } else {\r\n return currentPage.$page\r\n }\r\n}\r\n\r\nfunction getCurrentPage() {\r\n const pages = getCurrentPages()\r\n return pages[pages.length - 1]\r\n}\r\n\r\nfunction handleAction(path) {\r\n const action = path.split(':')\r\n switch (action[1]) {\r\n case 'showShareModal':\r\n showShareModal()\r\n break\r\n }\r\n}\r\n\r\nfunction error(errCode, errMsg = '') {\r\n redirect('/modules/mall/public/error', {\r\n errCode,\r\n errMsg,\r\n })\r\n}\r\n\r\nexport default {\r\n go,\r\n back,\r\n hasHistory,\r\n redirect,\r\n getCurrentPage,\r\n getCurrentRoute,\r\n error,\r\n}\r\n"],"names":["isString","startsWith","isEmpty","isObject","isNil","$store","showAuthModal","uni","throttle","showShareModal"],"mappings":";;;;;;;AAKA,MAAM,MAAM,CACV,MACA,SAAS,CAAA,GACT,UAAU;AAAA,EACR,UAAU;AACZ,MACG;;AACH,MAAI,OAAO;AACX,MAAI,QAAQ;AACZ,MAAI,MAAM;AAEN,MAAAA,cAAAA,SAAS,IAAI,GAAG;AAEd,QAAAC,cAAA,WAAW,MAAM,MAAM,GAAG;AAMrB,aAAA;AACC,cAAA,OAAO,mBAAmB,IAAI,CAAC;AAAA,IAE9B,WAAAA,cAAA,WAAW,MAAM,SAAS,GAAG;AACtC,mBAAa,IAAI;AACjB;AAAA,IAAA,OACK;AACJ,OAAC,MAAM,KAAK,IAAI,KAAK,MAAM,GAAG;AAAA,IACjC;AACI,QAAA,CAACC,cAAAA,QAAQ,MAAM,GAAG;AACd,YAAA,SAAS,cAAc,MAAM;AAC/B,UAAAA,cAAAA,QAAQ,KAAK,GAAG;AACV,gBAAA;AAAA,MAAA,OACH;AACL,iBAAS,MAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAEI,MAAAC,cAAAA,SAAS,IAAI,GAAG;AAClB,WAAO,KAAK;AACZ,QAAI,CAACC,cAAA,MAAM,KAAK,MAAM,GAAG;AACf,cAAA,cAAc,KAAK,MAAM;AAAA,IACnC;AAAA,EACF;AAEM,QAAA,YAAY,0BAAW,IAAI;AAIjC,MAAI,CAAC,WAAW;AACd,YAAQ,IAAI,cAAc,QAAQ,OAAO,KAAK,6BAA6B;AAC3E;AAAA,EACF;AAGA,QAAI,eAAU,SAAV,mBAAgB,SAAQ,CAACC,kBAAAA,OAAO,MAAM,EAAE,SAAS;AACrCC,yBAAAA;AACd;AAAA,EACF;AAEM,QAAA;AACF,MAAA,CAACJ,cAAAA,QAAQ,KAAK,GAAG;AACnB,WAAO,IAAI,KAAK;AAAA,EAClB;AAGI,MAAA,sBAAO,SAAS,IAAI,GAAG;AACzBK,kBAAAA,MAA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