Skip to content

Commit

Permalink
Merge pull request #11 from lhxcccccccccc/master
Browse files Browse the repository at this point in the history
[Serverless官网]: 组件页面支持v3
  • Loading branch information
lhxcccccccccc authored Jun 7, 2024
2 parents a6a1c95 + 136ea57 commit b36bd60
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 161 deletions.
419 changes: 270 additions & 149 deletions component.html

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion details.html
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,14 @@ <h4 id="usename">
if (!tempData) {
return ;
}
if (tempData.body) {
tempData = tempData.body
console.log('tempData')
console.log(tempData)
if (typeof tempData === 'string') {
document.getElementById("mddata").innerHTML = tempData;
return
}
renderTpl('titleTpl',
{
name: tempData.name,
Expand Down Expand Up @@ -809,8 +817,9 @@ <h4 id="usename">
},
'#quick'
)
}
return ;
})
}, 'isAllData')
}

// V3: 获取Package所有版本接口
Expand Down
8 changes: 3 additions & 5 deletions search.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ <h4 class="lasthead">微信公众号</h4>
<script src="utils/_Get.js"></script>
<script src="utils/_Post.js"></script>
<script src="utils/renderTpl.js"></script>
<script src="utils/splitMaxLenth.js"></script>
<script src="services/downloadV3Plugin.js"></script>
<script src="services/getPackagesSearchForV3.js"></script>
<!-- 注入搜索模板 -->
Expand Down Expand Up @@ -392,11 +393,6 @@ <h5><a href="details.html?name={{$value.name}}&package_type={{$value.package_typ
{{/each}}
</script>
<script>

function splitMaxLenth (dataStr) {
return dataStr.length > 25 ? dataStr.slice(0, 25) + "...": dataStr;
}

// 列表存储数据
var dataList = [];
function downloadPlugin(name) {
Expand Down Expand Up @@ -485,6 +481,8 @@ <h5><a href="details.html?name={{$value.name}}&package_type={{$value.package_typ

if(dataList && dataList.length > 0){
renderTpl('searchTpl', { data: dataList }, '#itemlist')
}else{
renderTpl('searchTpl', { data: [] }, '#itemlist')
}
}

Expand Down
4 changes: 4 additions & 0 deletions services/downloadV3Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ function downloadV3Plugin(name) {
var base_url = BASE_V3_URL
var url = base_url + '/packages/'+name+'/release/latest'
_Get(url, function (res) {
if (res.body==="未找到指定资源") {
console.log('未找到指定资源')
return;
}
var result = res.body||res.Response;
if (result && result.zipball_url) {
const link = document.createElement('a');
Expand Down
7 changes: 6 additions & 1 deletion services/getPackagesSearchForV3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// 调用V3版本 搜索接口
function getPackagesSearchForV3(dataString, callback) {
var base_url = BASE_V3_URL
var url = base_url + '/packages/releases?'+ dataString + `&platform=3`
if (dataString) {
dataString = dataString + '&platform=3'
} else {
dataString = 'platform=3'
}
var url = base_url + '/packages/releases?'+ dataString
_Get(url, function (result) {
callback && callback(result)
return ;
Expand Down
16 changes: 15 additions & 1 deletion static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,18 @@
new WOW().init();
});

})(jQuery);
})(jQuery);



var objectSerialize = function (obj) {
var params = { ...obj } // wd=111&cb=222

var arrs = [] // 数组序列化
for (var key in params) {
if (params[key]) {
arrs.push(`${key}=${params[key]}`)
}
}
return `?${arrs.join('&')}`
}
11 changes: 7 additions & 4 deletions utils/_Get.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ function _Get(url, callback, type) {
);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
var result = {};
if (type === 'isAllData') {// get方法返回所有接口数据
var result = JSON.parse(xmlhttp.responseText)
result = JSON.parse(xmlhttp.responseText)
callback&&callback(result)
return ;
}

if (type === 'response') { // get方法返回Response
var result = JSON.parse(xmlhttp.responseText).Response;
result = JSON.parse(xmlhttp.responseText).Response;
callback&&callback(result)
return ;
}

// get方法返回Body
if (type === 'body') {
var result = JSON.parse(xmlhttp.responseText).body;
result = JSON.parse(xmlhttp.responseText).body;
callback&&callback(result)
return ;
}
}else{
callback&&callback(JSON.parse(xmlhttp.responseText))
}
};
xmlhttp.setRequestHeader(
Expand All @@ -42,7 +45,7 @@ function _Get(url, callback, type) {

// _GetJSON: 方法传递json参数,默认返回接口所有数据
function _GetJSON(url, callback){
const xmlhttp = window.XMLHttpRequest
var xmlhttp = window.XMLHttpRequest
? new XMLHttpRequest()
: new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", url, false);
Expand Down
4 changes: 4 additions & 0 deletions utils/splitMaxLenth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function splitMaxLenth (dataStr, length) {
length = length || 25;
return dataStr.length > length ? dataStr.slice(0, length) + "...": dataStr;
}

0 comments on commit b36bd60

Please sign in to comment.