chore:跳转文章列表链接可以分类
This commit is contained in:
@@ -40,20 +40,39 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
list: []
|
list: [],
|
||||||
|
// 从跳转 URL 上携带的参数
|
||||||
|
categoryId: '',
|
||||||
|
title: '',
|
||||||
|
pageKey: '',
|
||||||
|
pageParams: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
onLoad(options) {
|
||||||
|
// 还原跳转时携带的过滤/展示参数,避免请求 API 时丢失
|
||||||
|
if (options.category_id) this.categoryId = options.category_id;
|
||||||
|
if (options.title) {
|
||||||
|
this.title = decodeURIComponent(options.title);
|
||||||
|
if (this.title) uni.setNavigationBarTitle({ title: this.title });
|
||||||
|
}
|
||||||
|
if (options.page_key) this.pageKey = options.page_key;
|
||||||
|
this.pageParams = this.$util.parsePageParams(options.page_params) || {};
|
||||||
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.setPublicShare();
|
this.setPublicShare();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getData(mescroll) {
|
getData(mescroll) {
|
||||||
|
// 合并 page_params 与显式参数,保证后端拿到完整过滤条件
|
||||||
|
let data = Object.assign({}, this.pageParams, {
|
||||||
|
page_size: mescroll.size,
|
||||||
|
page: mescroll.num
|
||||||
|
});
|
||||||
|
if (this.categoryId) data.category_id = this.categoryId;
|
||||||
|
|
||||||
this.$api.sendRequest({
|
this.$api.sendRequest({
|
||||||
url: '/api/article/page',
|
url: '/api/article/page',
|
||||||
data: {
|
data: data,
|
||||||
page_size: mescroll.size,
|
|
||||||
page: mescroll.num
|
|
||||||
},
|
|
||||||
success: res => {
|
success: res => {
|
||||||
let newArr = [];
|
let newArr = [];
|
||||||
let msg = res.message;
|
let msg = res.message;
|
||||||
@@ -87,17 +106,32 @@ export default {
|
|||||||
// 设置公众号分享
|
// 设置公众号分享
|
||||||
setPublicShare() {
|
setPublicShare() {
|
||||||
let shareUrl = this.$config.h5Domain + '/pages_tool/article/list';
|
let shareUrl = this.$config.h5Domain + '/pages_tool/article/list';
|
||||||
|
let query = this.shareQuery();
|
||||||
|
if (query) shareUrl += '?' + query;
|
||||||
this.$util.setPublicShare({
|
this.$util.setPublicShare({
|
||||||
title: this.$lang('article.list.title'),
|
title: this.title || this.$lang('article.list.title'),
|
||||||
desc: '',
|
desc: '',
|
||||||
link: shareUrl,
|
link: shareUrl,
|
||||||
imgUrl: this.siteInfo ? this.$util.img(this.siteInfo.logo_square) : ''
|
imgUrl: this.siteInfo ? this.$util.img(this.siteInfo.logo_square) : ''
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
// 组装带回过滤参数的 query 串,保证分享/跳转后参数不丢失
|
||||||
|
shareQuery() {
|
||||||
|
let params = {};
|
||||||
|
if (this.categoryId) params.category_id = this.categoryId;
|
||||||
|
if (this.title) params.title = encodeURIComponent(this.title);
|
||||||
|
if (this.pageKey) params.page_key = this.pageKey;
|
||||||
|
if (Object.keys(this.pageParams).length) params.page_params = encodeURIComponent(JSON.stringify(this.pageParams));
|
||||||
|
return Object.keys(params)
|
||||||
|
.map(k => k + '=' + params[k])
|
||||||
|
.join('&');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onShareAppMessage(res) {
|
onShareAppMessage(res) {
|
||||||
var title = this.$lang('article.list.title');
|
var title = this.title || this.$lang('article.list.title');
|
||||||
var path = '/pages_tool/article/list';
|
var path = '/pages_tool/article/list';
|
||||||
|
var query = this.shareQuery();
|
||||||
|
if (query) path += '?' + query;
|
||||||
return {
|
return {
|
||||||
title: title,
|
title: title,
|
||||||
path: path,
|
path: path,
|
||||||
@@ -107,8 +141,10 @@ export default {
|
|||||||
},
|
},
|
||||||
//分享到朋友圈
|
//分享到朋友圈
|
||||||
onShareTimeline() {
|
onShareTimeline() {
|
||||||
var title = this.$lang('article.list.title');
|
var title = this.title || this.$lang('article.list.title');
|
||||||
var query = '/pages_tool/article/list';
|
var query = '/pages_tool/article/list';
|
||||||
|
var q = this.shareQuery();
|
||||||
|
if (q) query += '?' + q;
|
||||||
return {
|
return {
|
||||||
title: title,
|
title: title,
|
||||||
query: query,
|
query: query,
|
||||||
|
|||||||
Reference in New Issue
Block a user