Blog/themes/freemind/source/js/foxsay.js
2022-03-16 22:24:24 +08:00

60 lines
No EOL
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var {
Query
} = AV;
AV.init({
appId: "hINvYWepO1gnhcNIPEycw7o5-MdYXbMMI", //你的 leancloud 应用 id (设置-应用keys-AppID
appKey: "9PFMoeAb7yW62fAyNYdVDHAQ", //你的 leancloud 应用 AppKey (设置-应用keys-AppKey
});
var query = new AV.Query('content');
var app = new Vue({
el: '#app',
data: {
page: 0,
count: 0,
contents: []
},
methods: {
loadMore: function(event) {
getData(++this.page);
}
}
})
function urlToLink(str) {
var re = /(http|ftp|https):\/\/[\w-]+(.[\w-]+)+([\w-.,@?^=%&:/~+#]*[\w-\@?^=%&/~+#])?/g;;
str = str.replace(re, function(website) {
if (str.indexOf("cf-ipfs") != -1 ) {
return "<img src='" + website + "' alt='图片'></img>"
} else {
return "<a href='" + website + "' target='_blank'> <i class='iconfont icon-lianjie-copy'></i>链接 </a>";
}
});
return str;
}
function getData(page = 0) {
query.descending('createdAt').skip(page * 20).limit(20).find().then(function(results) {
if (results.length == 0) {
alert('无了。')
} else {
let resC = results;
reqData = false;
resC.forEach((i) => {
let dateTmp = new Date(i.createdAt);
i.attributes.content = "<p>" + urlToLink(i.attributes.content) + "</p>";
i.attributes.time = `${dateTmp.getFullYear()}-${(dateTmp.getMonth() + 1) < 10 ? ('0' + (dateTmp.getMonth()+1)) : dateTmp.getMonth()+1}-${(dateTmp.getDate() + 1) < 10 ? ('0' + dateTmp.getDate()) : dateTmp.getDate()} ${(dateTmp.getHours() + 1) <= 10 ? ('0' + dateTmp.getHours()) : dateTmp.getHours()}:${(dateTmp.getMinutes() + 1) <= 10 ? ('0' + dateTmp.getMinutes()) : dateTmp.getMinutes()}`;
app.contents.push(i);
})
}
}, function(error) {});
}
getData(0);
query.count().then(function(count) {
app.count = count;
}, function(error) {});