H5微信分享,fontSize自适应

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui"/>
  <meta name="format-detection" content="telephone=no, email=no"/>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="renderer" content="webkit">
  <meta name="HandheldFriendly" content="true">
  <meta name="MobileOptimized" content="320">
  <meta name="screen-orientation" content="portrait">
  <meta name="x5-orientation" content="portrait">
  <meta name="full-screen" content="yes">
  <meta name="x5-fullscreen" content="true">
  <meta name="browsermode" content="application">
  <meta name="x5-page-mode" content="app">
  <meta name="msapplication-tap-highlight" content="no">
  <title></title>
  <link rel="stylesheet" href="../js/lib/mint_ui/style.min.css">
  <script src="../js/lib/jquery-3.1.1.min.js"></script>
  <script type="text/javascript" src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  <script src="../js/lib/vue.min.js"></script>
<!--	<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.4.1/vconsole.min.js"></script>-->
  <script src="../js/lib/mint_ui/index.js"></script>
  <script src="../js/request.js"></script>
  <style>
  font {
  font-size: 16px;
}
  font[size="6"] {
  font-size: 17px
  }
  font[size="7"] {
    font-size: 18px
  }
  font[size="5"] {
    font-size: 16px
  }
  font[size="4"] {
    font-size: 15px
  }
  font[size="3"] {
    font-size: 14px
  }
  font[size="2"] {
    font-size: 13px
  }
  font[size="1"] {
    font-size: 12px
  }
  .vhtml{
    font-size: 17px!important;
  }
  .vhtml p{
    margin: 20px 0 20px 0!important;
    line-height: 1.6;
  }
  .vhtml p span{
    font-size: 16px!important;
  }
  </style>

</head>
<body>
  <div id="app" style="height: 100%;">
    <div v-if="offline" style="padding: 10px 10px 0;;height: 100%;">
      <p style="font-size: 24px;margin: 0;font-weight: 700;">{{title}}</p>
      <p style="margin: 8px 0;font-size: 13px;color: #666;">{{publish_time}}</p>
      <p v-if="abstract" style="margin: 8px 0;
      padding: 9.375px 11.25px;
      font-size: 14px;
      text-align: justify;
      word-break: break-all;
      word-wrap: break-word;
      background: #f5f5f5;
      color: #666;">{{abstract}}</p>
      <div v-html="content" class="vhtml"></div>
    </div>
    <div v-if="offline" style="background: #d7d7d7;height: 74.5313px;
    padding: 9.9994px;
    font-size: 14.0006px;">注:投资有风险,入市需谨慎</div>
    <div v-if="!offline" style="
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-top: 8vh;
    ">
      <img src="../images/offline.png" style="width: 255px;">
      <span style="margin-top: 30px;font-size: 14px;">内容已下线</span>
    </div>
  </div>
</body>
<script>
  var protocol = window.location.protocol;//获取http头
  // var vConsole = new VConsole();
  var app = new Vue({
    el:"#app",
    name:"MarketingShare",
    data:{
      unique_id: '',
      code: '',
      abstract:'',
      content:'',
      next: 1,
      publish_time:'',
      cover_img:'',
      offline: true,
      title:'',
      id:'',
    },
    created:function() {
      this.next = sessionStorage.getItem('next')  * 1 || 1
      this.unique_id = tool.getStringNew("unique_id");
      this.code = tool.getStringNew("code");
    },
    mounted:function() {
      this.getData()
      this.is_weixn()
      /* 适配 */
      this.windowChange()
      window.addEventListener('resize', this.windowChange)
    },
    destroyed() {
    document.getElementsByTagName('html')[0].style.fontSize = ''
    window.removeEventListener('resize', this.windowChange)
    },
    methods:{
      is_weixn(){
        var ua = navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i)=="micromessenger") {
          var APPID = 'appid'
          var url = window.location.origin+ '地址?unique_id=' + this.unique_id
          if (this.code) {
            this.browsingHistory()
          }
          console.log('!this.code',!this.code);
          console.log(' this.offline', this.offline);
          console.log('url',url);

          if (!this.code  && this.offline) {

            console.log('!this.code  && this.offline',!this.code  && this.offline);
            this.next = this.next + 1
            sessionStorage.setItem('next', this.next)
            console.log('this.next',this.next);
            if (this.next <= 2) {
              console.log('this.next66',this.next);
              window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + APPID +
              '&redirect_uri=' + encodeURIComponent(url) +
              '&response_type=code&' +
              'scope=snsapi_userinfo&' +
              'state=STATE&' +
              '#wechat_redirect'
            }
          }

        } else {
          this.browsingHistory()
          console.log('微信外请求记录');
        }
      },
      share() {
        var _this = this;
        tool.shareimg({
            platform: ['weixin','qicq'],//品台
            link: window.location.href, //分享详情连接
            title: _this.title, //分享详情标题
            dsec: _this.abstract,//分享详情简介
            imgUrl: _this.cover_img,//分享图片
          });
      },
      windowChange() {
      const dom = document.querySelector('html');
      const fontSize = (dom.clientWidth / 30.4375).toFixed(4)
      document.getElementsByTagName('html')[0].style.fontSize = fontSize + 'px'
      },
      browsingHistory() {
        var _this = this;
        var url = protocol + '//'+window.CONFIG.SERVICE_URL+'接口';
        tool.ajaxFix({
            type: 'get',
            dataType: 'jsonp',
            url: url,
            data: {
              unique_id:_this.unique_id,
              wx_code: _this.code,
            },
            success: function(res){
              if (res.code ==1) {
              }
              if(res.code != 1){
                _this.$toast(res.message);
              }
            }
        })   
      },

      getData() {
        var _this = this;
        var url = protocol + '//'+window.CONFIG.SERVICE_URL+'接口';

        tool.ajaxFix({
            type: 'get',
            dataType: 'jsonp',
            url: url,
            data: {
              unique_id:_this.unique_id,
            },
            success: function(res){
              if (res.code ==1) {
                let {abstract,content,cover_img,id,publish_time,title} = res.data
                _this.title = title
                _this.id = id
                _this.cover_img = cover_img
                _this.publish_time = publish_time
                _this.content = content
                _this.abstract = abstract
                //微信浏览器无封面问题
                _this.$nextTick(()=>{
                  var u = navigator.userAgent;
                  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;     //android终端
                  var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
                  var ua = navigator.userAgent.toLowerCase();
                  if(ua.match(/MicroMessenger/i)=="micromessenger") {
                    console.log('微信内')

                    if(isAndroid){ //安卓
                      console.log('安卓');
                      let videos = document.getElementsByTagName('video');
                      for(var i= 0; i<videos.length; i++){
                        videos[i].currentTime = 0.01
                      };
                    }
                    if (isiOS) {
                      console.log('是IOS');
                      document.addEventListener('WeixinJSBridgeReady', function() {
                      let videos = document.getElementsByTagName('video');
                      for(var i= 0; i<videos.length; i++){
    
                          videos[i].setAttribute('webkit-playsinline', "true");
                          videos[i].setAttribute('playsinline', "true");
                          videos[i].setAttribute('x5-playsinline', "true");
                          videos[i].play()
                          // videos[i].currentTime = 0.01
                          videos[i].pause()
                        };
                      })   
                    }
                  }else{
                    console.log('微信外')
                      let videos = document.getElementsByTagName('video');
                      for(var i= 0; i<videos.length; i++){
                        videos[i].setAttribute('webkit-playsinline', "true");
                        videos[i].setAttribute('playsinline', "true");
                        videos[i].setAttribute('x5-playsinline', "true");
                        videos[i].play()
                        videos[i].pause()
                      };
                  }

                })    

                _this.share()
              }
              if(res.code != 1){
                _this.offline = false
                _this.$toast(res.message);
              }
            }
        }) 
      },
    }
  })
</script>
</html>
getString:function(_name){
    var obj = this.getUrlQueryArgs();
   if (obj && obj.hasOwnProperty(_name)) {
   return obj[_name];
       } else {
         return '';
         }
},

// 解析url query参数
var getUrlQueryArgs = (function() {
    var obj = null;
    return function(){
        if (obj) return obj;
        obj = {};
        var searchStr = window.location.search;
        if (!searchStr) return null;
        var _search = searchStr.slice(1).split("&");
        for(var i = 0, len = _search.length; i < len; i++){
            var _item = _search[i].split("=");
            obj[_item[0]] = _item[1];
        }
        if (i) {
            return obj;
        } else {
            return null;
        }
    }
})();

is_weixn:function(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
},

shareimg: (function() {
    //自定义分享图片
    var platformShareMethods = {
        weixin: function(options){
            tool.ajaxFix({
                url: protocol + "//"+ window.CONFIG.SERVICE_URL + "接口" + tool.getString("appcode"),
                // url: 'https://h5.jjzqtz.com/sample.php',
                data:{
                    url: window.location.href
                },
                type: "get",
                dataType: "json",
                success: function (res) {
                    wx.config({
                        debug: false,// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。移动端会通过弹窗来提示相关信息。如果分享信息配置不正确的话,可以开了看对应报错信息
                        appId: res.data.appId,
                        timestamp: res.data.timestamp,
                        nonceStr: res.data.nonceStr,
                        rawString: res.data.rawString,
                        signature: res.data.signature,
                        jsApiList: ['updateAppMessageShareData','onMenuShareAppMessage',
]
                    });
                    wx.ready(function(){
                        if (wx.updateAppMessageShareData) {
                            wx.updateAppMessageShareData({
                                title: options.title, // 分享标题
                                desc: options.dsec, // 分享描述
                                link: options.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                                imgUrl: options.imgUrl, // 分享图标
                                success: function() {
                                    // 设置成功
                                    console.log('分享成功')
                                    }
                            })
                        } else {
                            wx.onMenuShareAppMessage({
                                title: options.title, // 分享标题
                                desc: options.dsec, // 分享描述
                                link: options.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                                imgUrl: options.imgUrl, // 分享图标
                                success: function() {
                                    // 设置成功
                                    console.log('分享成功')
                                    }
                            })
                        }

                    });
                    // wx.error(function(err){
                    //     alert(err)
                    // })
                },
                error: function(err){
                    // alert(JSON.stringify(err))
                }
            })
        }
        /*qicq: function(options){
            setShareInfo({
                title: options.title, // 分享标题
                summary: options.desc, // 分享内容
                pic: options.imgUrl, // 分享图片
                url: options.link, // 分享链接
            });
        }*/
    }
    return function(options){
        for(var i = 0; i < options.platform.length; i++){
            // platformShareMethods[options.platform[i]](options);

            // this[options.platform[i]] = options.isJsApiList[i]

            if (typeof (platformShareMethods[options.platform[i]]) == 'function') {

                platformShareMethods[options.platform[i]].call(this, options)
            }
        }
    }
})(),

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值