From 237a55b8fe130958c8218eee8bb687db06da9a2c Mon Sep 17 00:00:00 2001 From: mip-platform Date: Wed, 5 Sep 2018 17:03:30 +0800 Subject: [PATCH] update extensions --- mip-360docreward/README.md | 2 +- mip-360docreward/mip-360docreward.js | 403 +++++++++--------- mip-360docreward/package.json | 2 +- mip-fetch-comment/README.md | 64 +++ mip-fetch-comment/mip-fetch-comment.js | 105 +++++ mip-fetch-comment/package.json | 14 + .../mip-ilaw66-baidu-couponPay.js | 4 +- mip-ilaw66-baidu-couponPay/package.json | 2 +- mip-xxd-logic-form/mip-xxd-logic-form.js | 47 +- 9 files changed, 433 insertions(+), 210 deletions(-) create mode 100644 mip-fetch-comment/README.md create mode 100644 mip-fetch-comment/mip-fetch-comment.js create mode 100644 mip-fetch-comment/package.json diff --git a/mip-360docreward/README.md b/mip-360docreward/README.md index 16fd3301..bb32a1de 100644 --- a/mip-360docreward/README.md +++ b/mip-360docreward/README.md @@ -6,7 +6,7 @@ mip-360docreward 是360doc打赏组件。 ----|---- 类型|业务,广告 支持布局|N/S -所需脚本|https://c.mipcdn.com/extensions/platform/v1/mip-360docstat-script/mip-360docstat-script.js +所需脚本|https://c.mipcdn.com/extensions/platform/v1/mip-360docreward/mip-360docreward.js ## 示例 diff --git a/mip-360docreward/mip-360docreward.js b/mip-360docreward/mip-360docreward.js index 82ee5bda..2059befb 100644 --- a/mip-360docreward/mip-360docreward.js +++ b/mip-360docreward/mip-360docreward.js @@ -7,231 +7,234 @@ define(function (require) { var customElem = require('customElement').create(); // build 方法,元素插入到文档时执行,仅会执行一次 customElem.prototype.build = function () { + var element = $(this.element); try { - if ($('.yc_user').length !== 0) { - if ($('#hiddenoriginal').val() === 1) { - $('.yc_user').show(); + if ($(element.find('.yc_user')).length !== 0) { + if ($(element.find('.hiddenoriginal')).val() === 1) { + $(element.find('.yc_user')).show(); rewardlist.original = 1; - rewardlist.artid = $('#hiddenartid').val(); - rewardlist.userid = $('#hiddenuserid').val(); + rewardlist.artid = $(element.find('.hiddenartid')).val(); + rewardlist.userid = $(element.find('.hiddenuserid')).val(); rewardlist.showRewardDiv(); } } } catch (e) { } - }; - var rewardlist = { - type: 'mip', - queryStartID: 0, - lastRewarUserID: 0, - showRewardLoading: false, - rewardLoading: false, - orderid: 0, - paytype: 9, - artid: '', - userid: '', - original: '', - IntervalunQuery: null, + var rewardlist = { + type: 'mip', + queryStartID: 0, + lastRewarUserID: 0, + showRewardLoading: false, + rewardLoading: false, + orderid: 0, + paytype: 9, + artid: '', + userid: '', + original: '', + IntervalunQuery: null, + + // 显示赞赏列表div + showRewardDiv: function () { + if (!rewardlist.showRewardLoading) { + rewardlist.showRewardLoading = true; + var sign = rewardlist.xfejh({ + 'op': 'getartuserinfo', 'type': rewardlist.type, 'artuserid': + rewardlist.userid + }); + $.ajax({ + url: 'https://account.360doc.com/ajax/QueryHandler.ashx?op=getartuserinfo', + dataType: 'jsonp', + data: {artuserid: rewardlist.userid, type: rewardlist.type, sign: sign}, + success: function (result) { + rewardlist.showRewardLoading = false; + // decodeURIComponent + if (result.status === 1) { + $(element.find('.yc_user')).show(); - // 显示赞赏列表div - showRewardDiv: function () { - if (!rewardlist.showRewardLoading) { - rewardlist.showRewardLoading = true; + var user1html = '
'; + user1html += '

'; + user1html += '
'; + user1html += '

' + decodeURIComponent(result.username) + '

'; + user1html += '
' + rewardlist.getStarrank(result.degree) + + '
'; + user1html += '
'; + user1html += ''; + user1html += '
'; + user1html += '
' + decodeURIComponent(result.description) + '
'; + $(element.find('.yc_user_1')).html(user1html).show(); + $(element.find('.yc_user_2')).html('

你的赞赏是我坚持原创的动力!' + + '

' + + '赞赏
').show(); + rewardlist.getRewardUserList(); + } + } + }); + } + }, + // 获取前10个赞赏用户列表 + getRewardUserList: function () { var sign = rewardlist.xfejh({ - 'op': 'getartuserinfo', 'type': rewardlist.type, 'artuserid': - rewardlist.userid + 'op': 'gettipuserlist', + 'type': rewardlist.type, + 'aid': rewardlist.artid, + 'dn': '10', + 'id': '0' }); $.ajax({ - url: 'https://account.360doc.com/ajax/QueryHandler.ashx?op=getartuserinfo', + url: 'https://account.360doc.com/ajax/QueryHandler.ashx?op=gettipuserlist', dataType: 'jsonp', - data: {artuserid: rewardlist.userid, type: rewardlist.type, sign: sign}, + data: {aid: rewardlist.artid, dn: 10, id: 0, type: rewardlist.type, sign: sign}, success: function (result) { - rewardlist.showRewardLoading = false; - // decodeURIComponent - if (result.status === 1) { - $('.yc_user').show(); - - var user1html = '
'; - user1html += '

'; - user1html += '
'; - user1html += '

' + decodeURIComponent(result.username) + '

'; - user1html += '
' + rewardlist.getStarrank(result.degree) + '
'; - user1html += '
'; - user1html += ''; - user1html += '
'; - user1html += '
' + decodeURIComponent(result.description) + '
'; - $('.yc_user_1').html(user1html).show(); - $('.yc_user_2').html('

你的赞赏是我坚持原创的动力!' - + '

' - + '赞赏
').show(); - rewardlist.getRewardUserList(); - } - } - }); - } - }, - // 获取前10个赞赏用户列表 - getRewardUserList: function () { - var sign = rewardlist.xfejh({ - 'op': 'gettipuserlist', - 'type': rewardlist.type, - 'aid': rewardlist.artid, - 'dn': '10', - 'id': '0' - }); - $.ajax({ - url: 'https://account.360doc.com/ajax/QueryHandler.ashx?op=gettipuserlist', - dataType: 'jsonp', - data: {aid: rewardlist.artid, dn: 10, id: 0, type: rewardlist.type, sign: sign}, - success: function (result) { - // $('#rewarduserslist').remove(); //先清空 - if (result.status === 1 && result.count > 0 && result.userlist.length > 0) { - $('#rewarduserslist').html('共' - + ' ' + result.count + ' 人赞赏'); - var rewarduserhref = ''; - var rewardusername = ''; - var rewarduserphoto = ''; - for (var i = 0; i < result.userlist.length; i++) { - if (result.userlist[i].userid === -1) { - rewarduserhref = 'javascript:void(0);'; - rewardusername = '游客'; - rewarduserphoto = ''; + // $('#rewarduserslist').remove(); //先清空 + if (result.status === 1 && result.count > 0 && result.userlist.length > 0) { + $(element.find('.rewarduserslist')).html('共' + + ' ' + result.count + ' 人赞赏'); + var rewarduserhref = ''; + var rewardusername = ''; + var rewarduserphoto = ''; + for (var i = 0; i < result.userlist.length; i++) { + if (result.userlist[i].userid === -1) { + rewarduserhref = 'javascript:void(0);'; + rewardusername = '游客'; + rewarduserphoto = ''; + } + else { + rewarduserhref = 'http://www.360doc.cn/userhome.aspx?userid=' + result.userlist[i].userid; + rewardusername = rewardlist.autoAddEllipsis(result.userlist[i].nickname, 14); + rewarduserphoto = ''; + } + $(element.find('.spantotalrewardcount')).before('' + rewarduserphoto + ''); } - else { - rewarduserhref = 'http://www.360doc.cn/userhome.aspx?userid=' + result.userlist[i].userid; - rewardusername = rewardlist.autoAddEllipsis(result.userlist[i].nickname, 14); - rewarduserphoto = ''; - } - $('#spantotalrewardcount').before('' + rewarduserphoto + ''); } } + }); + }, + // 星级 + getStarrank: function (strStarrank) { + var html = ''; + var s1 = 0; + var s2 = 0; + if (strStarrank % 2 === 0) { + s1 = parseInt(strStarrank / 2, 10); + } + else { + s1 = parseInt(strStarrank / 2, 10); + s2 = 1; + } + for (var i = 0; i < s1; i++) { + html += ''; + } + for (var i = 0; i < s2; i++) { + html += ''; + } + for (var i = 0; i < (5 - s1 - s2); i++) { + html += ''; } - }); - }, - // 星级 - getStarrank: function (strStarrank) { - var html = ''; - var s1 = 0; - var s2 = 0; - if (strStarrank % 2 === 0) { - s1 = parseInt(strStarrank / 2, 10); - } - else { - s1 = parseInt(strStarrank / 2, 10); - s2 = 1; - } - for (var i = 0; i < s1; i++) { - html += ''; - } - for (var i = 0; i < s2; i++) { - html += ''; - } - for (var i = 0; i < (5 - s1 - s2); i++) { - html += ''; - } - return html; - }, - // 展示赞赏弹出层 - showRewardAlert: function () { + return html; + }, + // 展示赞赏弹出层 + showRewardAlert: function () { - var jsondata = 'url=' + encodeURIComponent(window.location.href) + '&aid=' + rewardlist.artid; - window.location.href = 'http://www.360doc.cn/weixinreward/mipreward.aspx?' + jsondata; - return; - }, - // 处理过长的字符串,截取并添加省略号 - autoAddEllipsis: function (pStr, pLen) { - var ret = rewardlist.cutString(pStr, pLen); - var cutFlag = ret.cutflag; - var cutStringn = ret.cutstring; + var jsondata = 'url=' + encodeURIComponent(window.location.href) + '&aid=' + rewardlist.artid; + window.location.href = 'http://www.360doc.cn/weixinreward/mipreward.aspx?' + jsondata; + return; + }, + // 处理过长的字符串,截取并添加省略号 + autoAddEllipsis: function (pStr, pLen) { + var ret = rewardlist.cutString(pStr, pLen); + var cutFlag = ret.cutflag; + var cutStringn = ret.cutstring; - if ('1' === cutFlag) { - return cutStringn + '...'; - } - else { - return cutStringn; - } - }, - // 取得指定长度的字符串 - cutString: function (pStr, pLen) { - // 原字符串长度 - var strLen = pStr.length; - var tmpCode; - var cutString; - // 默认情况下,返回的字符串是原字符串的一部分 - var cutFlag = '1'; - var lenCount = 0; - var ret = false; - if (strLen <= pLen / 2) { - cutString = pStr; - ret = true; - } - if (!ret) { - for (var i = 0; i < strLen; i++) { - if (rewardlist.isFull(pStr.charAt(i))) { - lenCount += 2; - } - else { - lenCount += 1; - } - if (lenCount > pLen) { - cutString = pStr.substring(0, i); - ret = true; - break; + if ('1' === cutFlag) { + return cutStringn + '...'; + } + else { + return cutStringn; + } + }, + // 取得指定长度的字符串 + cutString: function (pStr, pLen) { + // 原字符串长度 + var strLen = pStr.length; + var tmpCode; + var cutString; + // 默认情况下,返回的字符串是原字符串的一部分 + var cutFlag = '1'; + var lenCount = 0; + var ret = false; + if (strLen <= pLen / 2) { + cutString = pStr; + ret = true; + } + if (!ret) { + for (var i = 0; i < strLen; i++) { + if (rewardlist.isFull(pStr.charAt(i))) { + lenCount += 2; + } + else { + lenCount += 1; + } + if (lenCount > pLen) { + cutString = pStr.substring(0, i); + ret = true; + break; + } + else if (lenCount === pLen) { + cutString = pStr.substring(0, i + 1); + ret = true; + break; + } } - else if (lenCount === pLen) { - cutString = pStr.substring(0, i + 1); - ret = true; - break; + } + if (!ret) { + cutString = pStr; + ret = true; + } + if (cutString.length === strLen) { + cutFlag = '0'; + } + return {'cutstring': cutString, 'cutflag': cutFlag}; + }, + // 判断是否为全角 + isFull: function (pChar) { + if ((pChar.charCodeAt(0) > 128)) { + return true; + } + else { + return false; + } + }, + xfejh: function (param) { + var signStr = ''; + for (var key in param) { + if (!(typeof (param[key]) === 'string' && param[key] === '')) { + signStr += key + '=' + param[key] + '&'; } } - } - if (!ret) { - cutString = pStr; - ret = true; - } - if (cutString.length === strLen) { - cutFlag = '0'; - } - return {'cutstring': cutString, 'cutflag': cutFlag}; - }, - // 判断是否为全角 - isFull: function (pChar) { - if ((pChar.charCodeAt(0) > 128)) { - return true; - } - else { - return false; - } - }, - xfejh: function (param) { - var signStr = ''; - for (var key in param) { - if (!(typeof (param[key]) === 'string' && param[key] === '')) { - signStr += key + '=' + param[key] + '&'; + if (signStr.substr(signStr.length - 1, 1) === '&') { + signStr = signStr.substr(0, signStr.length - 1); } + var array = signStr.split('&'); + array.sort(); + var rel = ''; + for (var i = 0; i < array.length; i++) { + rel += array[i]; + } + var array = rel.split('='); + array.sort(); + var rel = ''; + for (i = 0; i < array.length; i++) { + rel += array[i]; + } + return rel + Date.parse(new Date()); } - if (signStr.substr(signStr.length - 1, 1) === '&') { - signStr = signStr.substr(0, signStr.length - 1); - } - var array = signStr.split('&'); - array.sort(); - var rel = ''; - for (var i = 0; i < array.length; i++) { - rel += array[i]; - } - var array = rel.split('='); - array.sort(); - var rel = ''; - for (i = 0; i < array.length; i++) { - rel += array[i]; - } - return rel + Date.parse(new Date()); - } + }; }; return customElem; }); diff --git a/mip-360docreward/package.json b/mip-360docreward/package.json index f9c61571..0540bbb0 100644 --- a/mip-360docreward/package.json +++ b/mip-360docreward/package.json @@ -1,6 +1,6 @@ { "name": "mip-360docreward", - "version": "1.0.0", + "version": "1.0.1", "description": "360doc打赏组件", "contributors": [ { diff --git a/mip-fetch-comment/README.md b/mip-fetch-comment/README.md new file mode 100644 index 00000000..ea435c8a --- /dev/null +++ b/mip-fetch-comment/README.md @@ -0,0 +1,64 @@ +# mip-fetch-comment + +mip-fetch-comment 根据点击的年份异步加载酒款的评价信息 + +标题|内容 +----|---- +类型|通用 +支持布局|container +所需脚本|https://mipcache.bdstatic.com/static/v1/mip-fetch-comment/mip-fetch-comment.js + +## 示例 + +```html + +
+ + +
+
+

年份

全部年份
+
+
+
+ +
+
+
+ + + + + + +
+
+
+
+
+
+
+
+
+
+
评分
+
+
+
+ +
+
获奖
+
+ +
+
+ +
+
酒评
+
    +
    +
    +
    +``` + + diff --git a/mip-fetch-comment/mip-fetch-comment.js b/mip-fetch-comment/mip-fetch-comment.js new file mode 100644 index 00000000..27cc0726 --- /dev/null +++ b/mip-fetch-comment/mip-fetch-comment.js @@ -0,0 +1,105 @@ +/** + * @file mip-fetch-comment 组件 + * @author + */ + +define(function (require) { + var customElement = require('customElement').create(); + customElement.prototype.firstInviewCallback = function () { + var element = this.element; + var wineId = element.querySelector('#wineId').value; + loadData(wineId, ''); + var arr = element.querySelectorAll('.nianfen'); + for (var i = 0; i < arr.length; i++) { + arr[i].onclick = function () { + loadData(wineId, this.dataset.vintage); + for (var j = 0; j < arr.length; j++) { + arr[j].className = 'nianfen'; + if (arr[j].dataset.yvalue === this.dataset.yvalue) { + arr[j].className = 'nianfen currVintage'; + } + }; + }; + }; + function loadData(wineid, year) { + var url = 'https://mip-test.wine-world.com/wine/GetWineInfo?wineid=' + wineid + '&vintageid=' + year; + fetch(url, { + method: 'POST', + headers: { + 'Content-type': 'application/json' + } + }).then(function (res) { + return res.json(); + }).then(function (json) { + if (json.hj.length > 0) { + var awardsContent = element.querySelector('#awardsContent'); + awardsContent.style = 'display:block'; + var awardsHtml = element.querySelector('#pjawards'); + awardsHtml.innerHTML = ''; + var hjhtml = ''; + for (var i = 0; i < json.hj.length; i++) { + hjhtml += '
    获奖时间:' + + json.hj[i].year + '
    ' + + json.hj[i].grade + + '
    葡萄酒年份:' + + json.hj[i].year + '
    颁奖组织:' + + json.hj[i].agency + '
    ?
    '; + } + awardsHtml.innerHTML += hjhtml; + } + else { + var awardsContent = element.querySelector('#awardsContent'); + awardsContent.style = 'display:none'; + } + if (json.pf.length > 0) { + var gradeContent = element.querySelector('#gradeContent'); + gradeContent.style = 'display:block'; + var gradeHtml = element.querySelector('#pjgrade'); + gradeHtml.innerHTML = ''; + var pfhtml = ''; + for (var i = 0; i < json.pf.length; i++) { + var showStr = ''; + if (json.pf[i].score.indexOf('/100') > -1) { + showStr = '' + json.pf[i].score.replace('/100', '') + + '/100
    '; + } else if (json.pf[i].score.indexOf('/20') > -1) { + showStr = '' + json.pf[i].score.replace('/20', '') + + '/20
    '; + } else if (json.pf[i].score.indexOf('/5') > -1) { + showStr = '' + json.pf[i].score.replace('/5', '') + + '/5
    '; + } else { + showStr = '' + json.pf[i].score + '
    '; + } + pfhtml += '
    适饮时间:' + + json.pf[i].date == null ? '' : json.pf[i].date + + '
    ' + + showStr + '
    葡萄酒年份:' + + json.pf[i].year + '
    评分者:' + + json.pf[i].critic + '
    ?
    '; + } + gradeHtml.innerHTML += pfhtml; + } else { + var gradeContent = element.querySelector('#gradeContent'); + gradeContent.style = 'display:none'; + } + if (json.taste.length > 0) { + var wineContent = element.querySelector('#wineContent'); + wineContent.style = 'display:block'; + var jiupingHtml = element.querySelector('#pjjiuping'); + jiupingHtml.innerHTML = ''; + var jphtml = ''; + for (var i = 0; i < json.taste.length; i++) { + jphtml += '
  • ' + json.taste[i].tastenote + '—— ' + + json.taste[i].critic + '
  • '; + } + jiupingHtml.innerHTML += jphtml; + } else { + var wineContent = element.querySelector('#wineContent'); + wineContent.style = 'display:none'; + } + }); + } + }; + return customElement; +}); diff --git a/mip-fetch-comment/package.json b/mip-fetch-comment/package.json new file mode 100644 index 00000000..f024bfbc --- /dev/null +++ b/mip-fetch-comment/package.json @@ -0,0 +1,14 @@ +{ + "name": "mip-fetch-comment", + "version": "1.0.1", + "description": "根据点击的年份异步加载酒款的相关评价信息", + "contributors": [ + { + "name": "chenwenkai", + "email": "1084072318@qq.com" + } + ], + "engines": { + "mip": ">=1.1.0" + } +} \ No newline at end of file diff --git a/mip-ilaw66-baidu-couponPay/mip-ilaw66-baidu-couponPay.js b/mip-ilaw66-baidu-couponPay/mip-ilaw66-baidu-couponPay.js index 32e3e9ed..8a14a398 100644 --- a/mip-ilaw66-baidu-couponPay/mip-ilaw66-baidu-couponPay.js +++ b/mip-ilaw66-baidu-couponPay/mip-ilaw66-baidu-couponPay.js @@ -178,8 +178,8 @@ define(function (require) { data: data, success: function (data) { if (data && data.cashier_url) { - // window.top.location.href = data.cashier_url; - locahost(data.cashier_url, '电话咨询'); + window.top.location.href = data.cashier_url; +// locahost(data.cashier_url, '电话咨询'); } else { $el.find('.popUp_sysErr').fadeIn(); diff --git a/mip-ilaw66-baidu-couponPay/package.json b/mip-ilaw66-baidu-couponPay/package.json index 68455f6c..5b6b77df 100644 --- a/mip-ilaw66-baidu-couponPay/package.json +++ b/mip-ilaw66-baidu-couponPay/package.json @@ -1,6 +1,6 @@ { "name": "mip-ilaw66-baidu-couponPay", - "version": "1.0.9", + "version": "1.1.0", "description": "百度支付页", "contributors": [ { diff --git a/mip-xxd-logic-form/mip-xxd-logic-form.js b/mip-xxd-logic-form/mip-xxd-logic-form.js index dabef3d0..eb7c3b49 100644 --- a/mip-xxd-logic-form/mip-xxd-logic-form.js +++ b/mip-xxd-logic-form/mip-xxd-logic-form.js @@ -8,6 +8,7 @@ define(function (require) { var customElement = require('customElement').create(); var fetchJsonp = require('fetch-jsonp'); + var viewer = require('viewer'); /** * 创建tip元素 @@ -88,6 +89,7 @@ define(function (require) { }).then(function (data) { if (data.status === 0) { submitData.response = data.data; + submitData = Object.assign({}, submitData, element.extraData); var token = data.token; var redirectUrl = redirect.replace(/#([^#]*)#/g, function ($0, $1) { return submitData[$1] || defaultValue; @@ -146,6 +148,7 @@ define(function (require) { } else { + submitData = Object.assign({}, submitData, element.extraData); // 直接转跳 var redirectUrl = redirect.replace(/#([^#]*)#/g, function ($0, $1) { return submitData[$1] || ''; @@ -162,8 +165,9 @@ define(function (require) { * 提交表单 * * @param {dom} element dom元素 + * @param {Event} event 事件对象 */ - function onSubmit(element) { + function onSubmit(element, event) { if (element.submitting) { return; } @@ -181,7 +185,17 @@ define(function (require) { if (!validateForm.call(element)) { return; } - onRedirect.call(element, data); + + // 判断是否需要百度授权登录 + var loginEleId = element.dataset.loginId || ''; + + if (!loginEleId || element.extraData.sessionId) { + onRedirect.call(element, data); + } + else { + var loginEle = document.getElementById(loginEleId); + viewer.eventAction.execute('login', loginEle, event); + } } /** @@ -261,6 +275,20 @@ define(function (require) { return result; } + /** + * 读取localStorage + * + * @param {string} key 要读取的key + * @return {string} 存储的值 + */ + function readStorage(key) { + var result = ''; + if (localStorage) { + result = localStorage.getItem(key); + } + return result; + } + /** * 展示tips * @@ -289,8 +317,8 @@ define(function (require) { element.id = 'mip-xxd-logic-form'; var submitElement = element.querySelector('#submit'); - submitElement.addEventListener('click', function () { - onSubmit(element); + submitElement.addEventListener('click', function (event) { + onSubmit(element, event); }); var bindRecordBtnEvent = function (recordElement) { @@ -309,7 +337,6 @@ define(function (require) { } var data = {}; - var inputs = element.querySelectorAll('mip-xxd-input-item'); Array.prototype.forEach.call(inputs, function (child) { var key = child.dataset.key; var value = child.dataset.value; @@ -348,6 +375,16 @@ define(function (require) { showTip.call(element, text); return; }); + + // 记录登录后的额外信息 + element.extraData = {}; + self.addEventAction('saveData', function () { + var info = JSON.parse(element.dataset.info || '{}'); + var sessionStorageId = element.dataset.sessionStorageId; + var extraData = Object.assign({}, info, {sessionId: readStorage(sessionStorageId)}); + element.extraData = extraData; + onSubmit(element, event); + }); }; return customElement;