chore:跳转文章列表链接可以分类
This commit is contained in:
@@ -40,20 +40,39 @@
|
||||
export default {
|
||||
data() {
|
||||
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() {
|
||||
this.setPublicShare();
|
||||
},
|
||||
methods: {
|
||||
getData(mescroll) {
|
||||
this.$api.sendRequest({
|
||||
url: '/api/article/page',
|
||||
data: {
|
||||
// 合并 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({
|
||||
url: '/api/article/page',
|
||||
data: data,
|
||||
success: res => {
|
||||
let newArr = [];
|
||||
let msg = res.message;
|
||||
@@ -87,17 +106,32 @@ export default {
|
||||
// 设置公众号分享
|
||||
setPublicShare() {
|
||||
let shareUrl = this.$config.h5Domain + '/pages_tool/article/list';
|
||||
let query = this.shareQuery();
|
||||
if (query) shareUrl += '?' + query;
|
||||
this.$util.setPublicShare({
|
||||
title: this.$lang('article.list.title'),
|
||||
title: this.title || this.$lang('article.list.title'),
|
||||
desc: '',
|
||||
link: shareUrl,
|
||||
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) {
|
||||
var title = this.$lang('article.list.title');
|
||||
var title = this.title || this.$lang('article.list.title');
|
||||
var path = '/pages_tool/article/list';
|
||||
var query = this.shareQuery();
|
||||
if (query) path += '?' + query;
|
||||
return {
|
||||
title: title,
|
||||
path: path,
|
||||
@@ -107,8 +141,10 @@ export default {
|
||||
},
|
||||
//分享到朋友圈
|
||||
onShareTimeline() {
|
||||
var title = this.$lang('article.list.title');
|
||||
var title = this.title || this.$lang('article.list.title');
|
||||
var query = '/pages_tool/article/list';
|
||||
var q = this.shareQuery();
|
||||
if (q) query += '?' + q;
|
||||
return {
|
||||
title: title,
|
||||
query: query,
|
||||
|
||||
Reference in New Issue
Block a user