Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

utils.ts 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import wx from 'weixin-js-sdk';
  2. // 判断当前环境
  3. export const handleToTypes = () => {
  4. let userAgent = navigator.userAgent.toLowerCase();
  5. let type = '';
  6. if (userAgent.indexOf('miniprogram') > -1) {
  7. if (userAgent.indexOf('alipay') > -1) {
  8. // 支付宝小程序环境
  9. console.log('支付宝小程序');
  10. type = 'alipaymini';
  11. } else if (
  12. userAgent.indexOf('wechat') > -1 ||
  13. userAgent.indexOf('wx') > -1
  14. ) {
  15. // 微信小程序
  16. console.log('微信小程序');
  17. type = 'wechatmini';
  18. }
  19. //else{
  20. // // this.juti = '其他小程序'
  21. // }
  22. } else if (
  23. userAgent.indexOf('android') > -1 ||
  24. userAgent.indexOf('linux') > -1 ||
  25. userAgent.indexOf('adr') > -1
  26. ) {
  27. type = 'android';
  28. console.log('android');
  29. } else {
  30. if (userAgent.indexOf('wechat') > -1 || userAgent.indexOf('wx') > -1) {
  31. // this.juti = '微信公众号'
  32. console.log('微信内部打开未内嵌');
  33. type = 'wechat';
  34. } else {
  35. // 其他页面暂时未实现
  36. type = 'other';
  37. }
  38. }
  39. return type;
  40. };
  41. // 判断是否为网页还是其他
  42. export const isWeb = (str) => {
  43. const reg =
  44. /(https?:\/\/)?(([0-9a-z.]+\.[a-z]+)|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:[0-9]+)?(\/[0-9a-z%/.\-_]*)?(\?[0-9a-z=&%_\-]*)?(\#[0-9a-z=&%_\-]*)?/gi;
  45. return reg.test(str);
  46. };
  47. export const handleToZhifubao = (path) => {
  48. my.navigateTo({
  49. url: path
  50. });
  51. };
  52. // 跳转微信小程序内部
  53. export const handleTonei = (path) => {
  54. wx.miniProgram.navigateTo({
  55. url: path, // 可选,小程序的页面路径,可以不填
  56. extraData: {
  57. // 可选,传递给小程序的数据,如分享信息等
  58. },
  59. success(res) {
  60. // 打开小程序成功的回调
  61. // console.log(res);
  62. // alert(JSON.stringify(res) + '123')
  63. },
  64. fail(err) {
  65. // 打开小程序失败的回调
  66. // console.error(err);
  67. // alert(JSON.stringify(err) + '456')
  68. }
  69. });
  70. };