Authored by 郭成尧

link-handle

  1 +require('./link-handle');
  1 +/* global wx */
  2 +import $ from 'yoho-jquery';
  3 +
  4 +class LinkHandle {
  5 + constructor() {
  6 + $('a').map((index, elem) => {
  7 + $(elem).on('click', event => {
  8 + let $currentTarget = $(event.currentTarget);
  9 + let href = $currentTarget.attr('href');
  10 +
  11 + if (!href) {
  12 + return;
  13 + }
  14 +
  15 + let path = this.transToPath(href);
  16 +
  17 + this.goMiniProgram(path);
  18 +
  19 + event.preventDefault();
  20 + });
  21 +
  22 + return false;
  23 + });
  24 + }
  25 +
  26 + /**
  27 + * 跳小程序原生页面
  28 + */
  29 + goMiniProgram(path) {
  30 + if (wx) {
  31 + wx.miniProgram.navigateTo({
  32 + url: path
  33 + });
  34 + } else {
  35 + // TODO
  36 + }
  37 + }
  38 +
  39 + /**
  40 + * 转换为小程序页面地址
  41 + */
  42 + transToPath(href) {
  43 + let path = href;
  44 +
  45 + return path;
  46 + }
  47 +}
  48 +
  49 +export default new LinkHandle();