parse-scan-result.uts 586 B

12345678910111213141516171819202122232425262728
  1. function parseScanResult (scanText: string): void {
  2. const match = scanText.match(/^(.*?):\/\/(.*)/)
  3. if (!match || match.length < 1) {
  4. uni.showToast({
  5. icon: 'none',
  6. title: '未能识别到有效信息'
  7. })
  8. }
  9. const [, protocol, path] = match
  10. switch (protocol) {
  11. case "internallink":
  12. uni.navigateTo({
  13. url: `/${path.replace(/^\//, '')}`,
  14. fail: () => {
  15. uni.showToast({
  16. icon: "none",
  17. title: "访问的路径不存在"
  18. })
  19. }
  20. })
  21. break
  22. }
  23. }
  24. export default parseScanResult