|
@@ -6,9 +6,9 @@ var requestUrlConfig = {
|
|
|
|
|
|
var articleList = new Vue({
|
|
|
el: '#articleList',
|
|
|
- filters:{
|
|
|
- keywordSlice: function(keyword){
|
|
|
- return keyword.length > 6 ? keyword.slice(0,6) + '…' : keyword;
|
|
|
+ filters: {
|
|
|
+ keywordSlice: function (keyword) {
|
|
|
+ return keyword.length > 6 ? keyword.slice(0, 6) + '…' : keyword;
|
|
|
}
|
|
|
},
|
|
|
data: {
|
|
@@ -63,9 +63,29 @@ var articleList = new Vue({
|
|
|
this.$nextTick(function () {
|
|
|
self.initQueryParam();
|
|
|
self.initBase();
|
|
|
+ self.initAuthInputComplete();
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
methods: {
|
|
|
+ // init auto-input complete
|
|
|
+ initAuthInputComplete(){
|
|
|
+ new AutoComplete({
|
|
|
+ el: '.auto-input',
|
|
|
+ callback: async function(keyword){
|
|
|
+ try {
|
|
|
+ const res = await PublicApi.fetchQueryKeywordList({keyword: keyword});
|
|
|
+ if(!res.data) return [];
|
|
|
+ return res.data.map(item => item.keyword);
|
|
|
+ } catch (e) {
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ itemClick: function (keyword) {
|
|
|
+ window.location.href = '/info/search-1.html?keyword='+keyword;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
// 初始化链接参数
|
|
|
initQueryParam() {
|
|
|
if (isPC) {
|
|
@@ -143,8 +163,8 @@ var articleList = new Vue({
|
|
|
},
|
|
|
|
|
|
// 高亮关键词
|
|
|
- highlightKeyword: function(str){
|
|
|
- return str.replace(new RegExp(this.keyword, 'g'), '<span style="color: #E15616">'+ this.keyword +'</span>')
|
|
|
+ highlightKeyword: function (str) {
|
|
|
+ return str.replace(new RegExp(this.keyword, 'g'), '<span style="color: #E15616">' + this.keyword + '</span>')
|
|
|
},
|
|
|
|
|
|
// 获取文章列表
|
|
@@ -171,7 +191,7 @@ var articleList = new Vue({
|
|
|
});
|
|
|
});
|
|
|
// 处理标题和描述
|
|
|
- resultData = resultData.map(function (item){
|
|
|
+ resultData = resultData.map(function (item) {
|
|
|
item.title = self.highlightKeyword(item.title);
|
|
|
item.intro = self.highlightKeyword(item.intro);
|
|
|
return item
|
|
@@ -281,53 +301,56 @@ var articleList = new Vue({
|
|
|
})
|
|
|
},
|
|
|
|
|
|
+ onPageScroll: debounce(function () {
|
|
|
+ var scrollTop = $('body').scrollTop();
|
|
|
+ var documentHeight = $(document).height();
|
|
|
+ var windowHeight = $('body').height();
|
|
|
+ // alert(scrollTop + windowHeight == documentHeight)
|
|
|
+ if (scrollTop > 600) {
|
|
|
+ $('#scrollTop').show();
|
|
|
+ } else {
|
|
|
+ $('#scrollTop').hide();
|
|
|
+ }
|
|
|
+ if (scrollTop + windowHeight + 100 > documentHeight) {
|
|
|
+ //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
|
|
|
+ if (this.params.num < this.pageTotal) { // 获取列表数据
|
|
|
+ if (this.requestFlag) {
|
|
|
+ this.params.num = this.params.num + 1;
|
|
|
+ this.requestAction(this.requestType);
|
|
|
+ }
|
|
|
+ } else { //到底了
|
|
|
+ this.noMore = true;
|
|
|
+ $('footer').removeClass("noneImportant");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }),
|
|
|
+
|
|
|
// 页面样式初始化
|
|
|
initPageReset: function () {
|
|
|
- var self = this;
|
|
|
if (!isPC) {
|
|
|
$('footer').addClass("noneImportant");
|
|
|
//移动端上垃加载更多
|
|
|
- $('body').on('scroll', function () {
|
|
|
- var scrollTop = $(this).scrollTop();
|
|
|
- var documentHeight = $(document).height();
|
|
|
- var windowHeight = $(this).height();
|
|
|
- // alert(scrollTop + windowHeight == documentHeight)
|
|
|
- if (scrollTop + windowHeight + 100 > documentHeight) {
|
|
|
- //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
|
|
|
- var totalPage = Math.ceil(self.listRecord / self.params.size) ? Math.ceil(self.listRecord / self.params.size) : 1;
|
|
|
- self.params.num = self.params.num + 1;
|
|
|
- if (next <= totalPage) { // 获取列表数据
|
|
|
- if (self.requestFlag) {
|
|
|
- self.requestAction(self.requestType);
|
|
|
- }
|
|
|
- self.requestFlag = false;
|
|
|
- } else { //到底了
|
|
|
- self.noMore = false;
|
|
|
- $('footer').removeClass("noneImportant");
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ $('body').on('scroll', this.onPageScroll);
|
|
|
}
|
|
|
},
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-function initFilterSort(option = {}){
|
|
|
+function initFilterSort(option = {}) {
|
|
|
var sortControl = $(option.el);
|
|
|
var sortItem = sortControl.find('.search__sort_select li');
|
|
|
var sotrCurrent = sortControl.find('.search__sort_current');
|
|
|
|
|
|
- $(window).on('click', function(el){
|
|
|
- console.log(el);
|
|
|
+ $(window).on('click', function (el) {
|
|
|
if (sortControl.has(el.target).length > 0) return;
|
|
|
sortControl.removeClass('active');
|
|
|
})
|
|
|
|
|
|
- sortControl.on('click', function(){
|
|
|
+ sortControl.on('click', function () {
|
|
|
$(this).toggleClass('active');
|
|
|
})
|
|
|
|
|
|
- sortItem.on('click', function(el){
|
|
|
+ sortItem.on('click', function (el) {
|
|
|
$(this).addClass('selected').siblings('li').removeClass('selected');
|
|
|
var status = parseInt($(this).attr('data-type'));
|
|
|
console.log(status)
|