123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /**
- * 获取动态广告栏属性
- * @param type
- * @returns {Object|*}
- */
- // url转base64 方法
- // base64 编码
- function getBase64Image(img) {
- var canvas = document.createElement('canvas')
- canvas.width = img.width
- canvas.height = img.height
- var ctx = canvas.getContext('2d')
- ctx.drawImage(img, 0, 0, img.width, img.height)
- var dataURL = canvas.toDataURL('image/png')
- return dataURL
- }
- function getImage64Url(url, ref) {
- // var that = this
- var image = document.createElement('img')
- image.setAttribute('crossorigin', 'anonymous')
- image.src = url + '?v=' + Math.random() // 处理缓存
- image.crossOrigin = 'anonymous'
- image.onload = function () {
- var base64 = getBase64Image(image)
- console.log(base64);
- }
- }
- // var ua = window.navigator.userAgent
- // let _isIOS = -1;
- // function isIOS() {
- // if (_isIOS === -1) {
- // _isIOS = /iPhone|iPod|iPad/i.test(ua) ? 1 : 0;
- // }
- // return _isIOS === 1;
- // }
- var getActive = {
- // 版本号
- version: '0.0.1',
- drawBase64Image: function (img) {
- var canvas = document.createElement('canvas')
- canvas.width = img.width
- canvas.height = img.height
- var ctx = canvas.getContext('2d')
- ctx.drawImage(img, 0, 0, img.width, img.height)
- var dataURL = canvas.toDataURL('image/png')
- return dataURL
- },
- /**
- * 获取后台广告方法
- * @param {Array|String} active_codes_map 广告id标识符--数组集合["jy-wx-course-pay-success"]
- * @param {String} active_tip_group 展示广告的容器demo节点
- * @param {String} isAppsion 请求环境、app、weixin、pc
- * @returns {Object|Array}
- */
- getActiveInfo: function (active_codes_map,isAppsion) {
- // 如果执行环境是app
- var isAppsionApp = isAppsion === 'App'
- $.ajax({
- url: '/publicapply/free/getJyAdList',
- type: 'POST',
- dataType: "json",
- traditional: true,
- //强制请求头数据格式 'application/json'
- headers: {'Content-Type': 'application/json'},
- data:active_codes_map,
- // JSON.stringify({codes:["jy-wx-course-pay-success","jy-pc-dataPackage-pay-success"] })
- // JSON.stringify()
- }).done(function (res) {
- // res.error_code =1
- // Object.value 兼容处理
- Object.values = function (obj) {
- return Object.keys(obj).map(function(e) {
- return obj[e]
- })
- }
- if (res.error_code === 0 && res.data && Object.values(res.data)[0] && Object.values(res.data)[0] !=null && Object.values(res.data)[0][0]) {
- // weixin、pc环境
- var img = new Image()
- var imgsrcArr = Object.values(res.data)[0][0]
- img.src = imgsrcArr.s_pic
- img.onload= function() {
- $(".active-tip-group").show()
- }
- $(".active-tip-group img").attr('src', imgsrcArr.s_pic + '?v=' + Math.random())
- // 如果是app环境 ,调用原生方法、执行保存
- // var isAppsionType = isAppsionApp || utils.isIos || utils.isAndroid
- var that = this
- var isAppsionType = isAppsionApp
- if (isAppsionType) {
- // APP 保存图片
- $('.active-tip-group').off('click').on('click', function () {
- if(!window.picImgUrl) {
- html2canvas(document.querySelector('.active-tip-group'), {
- // allowTaint: true,
- useCORS: true,
- backgroundColor: null,
- scale: 3,
- imageTimeout: 30000,
- allowTaint: true, // 允许跨域图片
- }).then(function(canvas) {
- var imgUrl = imgsrcArr.base64 || canvas.toDataURL('image/png')
- console.log(imgUrl)
- // $(".active-tip-group img").attr('src', imgUrl)
- imgUrl = imgUrl.replace('data:image/png;base64,', '')
- // console.log(imgUrl)
- window.picImgUrl = imgUrl
- try {
- window.JyObj.savePic(imgUrl)
- setTimeout(function() {
- weui.toast('图片已保存,快去扫码识别吧', {
- duration: 800,
- className: 'text-overflow100'
- })
- }, 2300)
- } catch (e) {
- weui.toast('保存失败', {
- duration: 800,
- className: 'j-toast'
- })
- console.log(e)
- // location.href=imgsrcArr.s_link
- }
- })
- }else {
- window.JyObj.savePic(window.picImgUrl)
- setTimeout(function() {
- weui.toast('图片已保存,快去扫码识别吧', {
- duration: 800,
- className: 'text-overflow100'
- })
- }, 2300)
- }
- })
- } // App打开新窗口等 用 @param {String} isAppsion === 'Applink'
- else if ((isAppsion === 'Applink') && imgsrcArr.o_extend && imgsrcArr.o_extend.linktype === 'abroad') {
- $(".active-tip-group").on('click', function () {
- try {
- JyObj.openExternalLink(imgsrcArr.s_link, imgsrcArr.o_extend.title || '剑鱼标讯');
- } catch (e) {
- console.log(e);
- }
- })
- if (isIOS()) {
- $('.rules').css('margin-top', '0.28rem')
- }
- } else {
- // weixin、pc环境 直接跳转
- if (imgsrcArr.s_link) {
- $(".active-tip-group").on('click', function () {
- try {
- location.href=imgsrcArr.s_link
- } catch (e) {
- console.log(e);
- }
- })
- }
- }
- } else {
- $('.rules').css('margin-top', '0.8rem')
- $('.ad_space').hide()
- $('.login-dig-box').css('left', 'calc(50vw - 181px)')
- }
- })
- }
- }
|