From 985730b42b04374a1beb25407b1bd2b688c47877 Mon Sep 17 00:00:00 2001
From: lzx_win <2602107437@qq.com>
Date: Fri, 17 Oct 2025 11:16:04 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E5=88=86=E4=BA=AB):=20=E9=87=8D=E6=9E=84?=
=?UTF-8?q?=E5=88=86=E4=BA=AB=E5=8A=9F=E8=83=BD=E5=B9=B6=E7=BB=9F=E4=B8=80?=
=?UTF-8?q?=E5=A4=84=E7=90=86=E5=88=86=E4=BA=AB=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 移除各页面独立的onShareAppMessage方法,改为统一通过share mixin处理
- 为各详情页添加分享路径和分享信息设置逻辑
- 新增getImageOne工具方法用于获取图片字符串中的第一张图片
- 优化动态列表的媒体展示布局,根据数量自动调整样式
- 在store中扩展configListMax用于存储完整配置项
---
components/list/dynamic/daynamicInfo.vue | 85 +++++++++++++++++++++++++----
mixins/share.js | 2 +
pages/index/article.vue | 2 +-
pages/index/index.vue | 13 +++--
pages_order/article/index.vue | 2 +-
pages_order/car/carListDetail.vue | 12 ++--
pages_order/gourmet/gourmetDetail.vue | 20 +++----
pages_order/group/groupDetail.vue | 7 +++
pages_order/post/postDetail.vue | 24 +++++---
pages_order/product/productDetail.vue | 14 ++---
pages_order/renting/rentingDetail.vue | 13 +++--
pages_order/scenicSpot/scenicSpotDetail.vue | 13 +++--
pages_order/work/workDetail.vue | 12 ++--
store/store.js | 6 +-
utils/utils.js | 37 ++++++++++++-
15 files changed, 188 insertions(+), 74 deletions(-)
diff --git a/components/list/dynamic/daynamicInfo.vue b/components/list/dynamic/daynamicInfo.vue
index d509b6e..110cd92 100644
--- a/components/list/dynamic/daynamicInfo.vue
+++ b/components/list/dynamic/daynamicInfo.vue
@@ -3,13 +3,13 @@
-
+
+ :style="videoStyle">
@@ -70,6 +70,35 @@
}
return mediaArray
+ },
+ // 根据媒体数量决定布局类型
+ layoutClass(){
+ const count = this.mediaList.length
+ if(count === 1){
+ return 'single-layout'
+ } else if(count === 2 || count === 4){
+ return 'grid-layout-2x2'
+ } else {
+ return 'grid-layout-3x3'
+ }
+ },
+ // 动态视频样式
+ videoStyle(){
+ const count = this.mediaList.length
+ let style = 'border-radius: 20rpx;'
+
+ if(count === 1){
+ // 单个视频占满宽度
+ style += 'width: 100%; height: 400rpx;'
+ } else if(count === 2 || count === 4){
+ // 4宫格布局
+ style += 'width: calc(50% - 10rpx); height: 200rpx;'
+ } else {
+ // 9宫格布局
+ style += 'width: calc(33.33% - 10rpx); height: 150rpx;'
+ }
+
+ return style
}
},
data() {
@@ -112,20 +141,54 @@
.Artworkimages {
display: flex;
flex-wrap: wrap;
+ margin-top: 20rpx;
- .wrokimg {
- margin: 10rpx;
- position: relative;
+ // 单图布局 - 占满宽度
+ &.single-layout {
+ .wrokimg {
+ width: 100%;
+ margin: 0;
+
+ image {
+ width: 100%;
+ height: 400rpx;
+ border-radius: 20rpx;
+ }
+ }
+ }
- image {
- height: 190rpx;
- width: 190rpx;
- border-radius: 20rpx;
+ // 4宫格布局 - 2x2
+ &.grid-layout-2x2 {
+ .wrokimg {
+ width: calc(50% - 10rpx);
+ margin: 5rpx;
+
+ image {
+ width: 100%;
+ height: 200rpx;
+ border-radius: 20rpx;
+ }
+ }
+ }
+
+ // 9宫格布局 - 3x3
+ &.grid-layout-3x3 {
+ .wrokimg {
+ width: calc(33.33% - 10rpx);
+ margin: 5rpx;
+
+ image {
+ width: 100%;
+ height: 150rpx;
+ border-radius: 20rpx;
+ }
}
+ }
+
+ .wrokimg {
+ position: relative;
video {
- height: 190rpx;
- width: 190rpx;
border-radius: 20rpx;
}
diff --git a/mixins/share.js b/mixins/share.js
index 461c81d..ab70118 100644
--- a/mixins/share.js
+++ b/mixins/share.js
@@ -18,8 +18,10 @@ export default {
// 定义全局分享
// 1.发送给朋友
onShareAppMessage(res) {
+ console.log('this.share', this.share);
let o = {
...this.share,
+ imageUrl : this.share.imageUrl || this.configList.applet_logo
}
if(this.userInfo.id){
o.path = this.share.path + '?shareId=' + this.userInfo.id
diff --git a/pages/index/article.vue b/pages/index/article.vue
index 79c5e33..4f1b340 100644
--- a/pages/index/article.vue
+++ b/pages/index/article.vue
@@ -6,7 +6,7 @@
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 92ea380..cb6f9cf 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -225,12 +225,12 @@
// this.getBannerList()
this.$store.commit('getCategory')
},
- onShareAppMessage(res) {
- return {
- title: this.headInfo.name,
- path: '/pages/index/index'
- }
- },
+ // onShareAppMessage(res) {
+ // return {
+ // title: this.headInfo.name,
+ // path: '/pages/index/index'
+ // }
+ // },
onShow() {
// this.onSubscribeMessageTap();
this.getUserInfo();
@@ -311,6 +311,7 @@
this.$api('getIndexHeaderInfo', res => {
if (res.code == 200) {
this.headInfo = res.result
+ this.share.title = this.headInfo.name
}
})
},
diff --git a/pages_order/article/index.vue b/pages_order/article/index.vue
index 0d600f3..fc3bd70 100644
--- a/pages_order/article/index.vue
+++ b/pages_order/article/index.vue
@@ -1,6 +1,6 @@
-
+
diff --git a/pages_order/car/carListDetail.vue b/pages_order/car/carListDetail.vue
index 2f43139..39524b3 100644
--- a/pages_order/car/carListDetail.vue
+++ b/pages_order/car/carListDetail.vue
@@ -76,6 +76,9 @@
this.queryParams.orderId = options.id
this.params.orderId = options.id
+
+ // 设置分享路径
+ this.share.path = '/pages_order/car/carListDetail?id=' + this.id
},
onPullDownRefresh(){
this.getDetail()
@@ -83,12 +86,6 @@
onShow() {
this.getDetail()
},
- onShareAppMessage(res) {
- return {
- title: this.detail.title,
- path: '/pages_order/scenicSpot/scenicSpotDetail?id=' + this.id
- }
- },
methods: {
getDetail() {
this.$api('getCatDetail', {
@@ -100,6 +97,9 @@
this.detail = res.result
+ // 设置分享信息
+ this.share.title = res.result.title || '拼车详情'
+ this.share.imageUrl = this.$utils.getImageOne(res.result.imageTitle)
}
})
},
diff --git a/pages_order/gourmet/gourmetDetail.vue b/pages_order/gourmet/gourmetDetail.vue
index 29099a1..f9074d0 100644
--- a/pages_order/gourmet/gourmetDetail.vue
+++ b/pages_order/gourmet/gourmetDetail.vue
@@ -170,12 +170,9 @@
this.params.orderId = options.id
this.queryParams.shopId = options.id
- },
- onShareAppMessage(res) {
- return {
- title: this.detail.title,
- path: '/pages_order/gourmet/gourmetDetail?id=' + this.id
- }
+
+ // 设置分享路径
+ this.share.path = '/pages_order/gourmet/gourmetDetail?id=' + this.id
},
onPullDownRefresh() {
this.getDetail()
@@ -183,13 +180,6 @@
onShow() {
this.getDetail()
},
- onShareAppMessage(res) {
- // return {
- // title: this.item.title,
- // desc: this.item.content && this.item.content.slice(0, 30),
- // path: '/pages/publish/postDetail?id=' + this.id
- // }
- },
methods: {
// 跳转到二维码页面
goToQrCode() {
@@ -233,6 +223,10 @@
// res.result.details.split(',') : []
this.detail = res.result
+
+ // 设置分享信息
+ this.share.title = res.result.title || '美食详情'
+ this.share.imageUrl = this.$utils.getImageOne(res.result.logoImage)
}
})
},
diff --git a/pages_order/group/groupDetail.vue b/pages_order/group/groupDetail.vue
index 5de8ee3..7e830d2 100644
--- a/pages_order/group/groupDetail.vue
+++ b/pages_order/group/groupDetail.vue
@@ -100,6 +100,9 @@
this.getGroupDetail()
}
// initRewardedVideoAd() 已在混入的mounted中处理
+
+ // 设置分享路径
+ this.share.path = '/pages_order/group/groupDetail?id=' + options.id
},
methods: {
// 广告观看完成回调
@@ -130,6 +133,10 @@
this.$api('groupDetail', { id: this.groupId }, res => {
if (res.code === 200 && res.result) {
this.groupInfo = res.result
+
+ // 设置分享信息
+ this.share.title = res.result.title || '群组详情'
+ this.share.imageUrl = this.$utils.getImageOne(res.result.image)
} else {
uni.showToast({
title: res.message || '获取群组详情失败',
diff --git a/pages_order/post/postDetail.vue b/pages_order/post/postDetail.vue
index 683af1d..4f3f136 100644
--- a/pages_order/post/postDetail.vue
+++ b/pages_order/post/postDetail.vue
@@ -98,33 +98,35 @@
onLoad(options) {
// this.$route.query的参数
- console.log(options)
this.id = options.id
this.queryParams.type = this.params.type
this.queryParams.orderId = options.id
this.queryParams.formId = options.id
this.params.orderId = options.id
+
+
+ this.share.path = '/pages_order/post/postDetail?id=' + this.id
},
- onShareAppMessage(res) {
- return {
- title: this.detail.title,
- path: '/pages_order/post/postDetail?id=' + this.id
- }
- },
+ // onShareAppMessage(res) {
+ // return {
+ // title: this.detail.title,
+ // path: '/pages_order/post/postDetail?id=' + this.id
+ // }
+ // },
onPullDownRefresh() {
this.getDetail()
},
onShow() {
this.getDetail()
},
- onShareAppMessage(res) {
+ // onShareAppMessage(res) {
// return {
// title: this.item.title,
// desc: this.item.content && this.item.content.slice(0, 30),
// path: '/pages/publish/postDetail?id=' + this.id
// }
- },
+ // },
methods: {
tabsClick({index}){
this.tagIndex = index
@@ -140,8 +142,12 @@
if (res.code == 200) {
this.params.name = res.result.userName
+
+ this.share.title = res.result.title
this.detail = res.result
+
+ this.share.imageUrl = this.$utils.getImageOne(res.result.image)
}
})
},
diff --git a/pages_order/product/productDetail.vue b/pages_order/product/productDetail.vue
index 3f58594..adb68cd 100644
--- a/pages_order/product/productDetail.vue
+++ b/pages_order/product/productDetail.vue
@@ -116,13 +116,9 @@
onLoad(args) {
this.id = args.id
this.getData()
- },
- // 微信小程序分享
- onShareAppMessage(res) {
- return {
- title: this.detail.name,
- path: '/pages_order/product/productDetail?id=' + this.id
- }
+
+ // 设置分享路径
+ this.share.path = '/pages_order/product/productDetail?id=' + this.id
},
onPullDownRefresh() {
this.getData()
@@ -157,6 +153,10 @@
uni.stopPullDownRefresh()
if(res.code == 200){
this.detail = res.result
+
+ // 设置分享信息
+ this.share.title = res.result.name
+ this.share.imageUrl = this.$utils.getImageOne(res.result.image)
}
})
},
diff --git a/pages_order/renting/rentingDetail.vue b/pages_order/renting/rentingDetail.vue
index b16ee3a..f36ff5b 100644
--- a/pages_order/renting/rentingDetail.vue
+++ b/pages_order/renting/rentingDetail.vue
@@ -169,12 +169,9 @@
this.queryParams.orderId = options.id
this.params.orderId = options.id
- },
- onShareAppMessage(res) {
- return {
- title: this.detail.title,
- path: '/pages_order/renting/rentingDetail?id=' + this.id
- }
+
+ // 设置分享路径
+ this.share.path = '/pages_order/renting/rentingDetail?id=' + this.id
},
onPullDownRefresh() {
this.getDetail()
@@ -208,6 +205,10 @@
this.params.name = res.result.title
this.detail = res.result
+
+ // 设置分享信息
+ this.share.title = res.result.title
+ this.share.imageUrl = this.$utils.getImageOne(res.result.image)
}
})
},
diff --git a/pages_order/scenicSpot/scenicSpotDetail.vue b/pages_order/scenicSpot/scenicSpotDetail.vue
index faeb184..75b7cdb 100644
--- a/pages_order/scenicSpot/scenicSpotDetail.vue
+++ b/pages_order/scenicSpot/scenicSpotDetail.vue
@@ -106,6 +106,9 @@
this.queryParams.orderId = options.id
this.params.orderId = options.id
+
+ // 设置分享路径
+ this.share.path = '/pages_order/scenicSpot/scenicSpotDetail?id=' + this.id
},
onPullDownRefresh() {
this.getDetail()
@@ -113,12 +116,6 @@
onShow() {
this.getDetail()
},
- onShareAppMessage(res) {
- return {
- title: this.detail.name,
- path: '/pages_order/scenicSpot/scenicSpotDetail?id=' + this.id
- }
- },
methods: {
tabsClick({index}){
this.tagIndex = index
@@ -137,6 +134,10 @@
this.detail = res.result
this.detail.images = res.result.images && res.result.images.split(',')
+
+ // 设置分享信息
+ this.share.title = res.result.name
+ this.share.imageUrl = this.$utils.getImageOne(res.result.images)
}
})
},
diff --git a/pages_order/work/workDetail.vue b/pages_order/work/workDetail.vue
index c013147..3ada30c 100644
--- a/pages_order/work/workDetail.vue
+++ b/pages_order/work/workDetail.vue
@@ -143,6 +143,9 @@
this.queryParams.orderId = options.id
this.params.orderId = options.id
+
+ // 设置分享路径
+ this.share.path = '/pages_order/work/workDetail?id=' + this.id
},
onPullDownRefresh() {
this.getDetail()
@@ -150,12 +153,6 @@
onShow() {
this.getDetail()
},
- onShareAppMessage(res) {
- return {
- title: this.detail.title,
- path: '/pages_order/work/workDetail?id=' + this.id
- }
- },
methods: {
getDetail(){
let data = {
@@ -172,6 +169,9 @@
this.detail = res.result
this.detail.jobDetails = this.$utils.stringFormatHtml(res.result.jobDetails)
this.collectionFlag = res.result.collectionFlag
+
+ // 设置分享信息
+ this.share.title = res.result.title
}
})
},
diff --git a/store/store.js b/store/store.js
index 4869cba..9cc94cf 100644
--- a/store/store.js
+++ b/store/store.js
@@ -9,6 +9,7 @@ import api from '@/api/api.js'
const store = new Vuex.Store({
state: {
configList: {}, //配置列表
+ configListMax: {}, //配置列表
priceMap : {},//各项费用配置
shop : false,
userInfo : {}, //用户信息
@@ -38,8 +39,11 @@ const store = new Vuex.Store({
api('getConfig', res => {
if(res.code == 200){
res.result.forEach(n => {
- state.configList[n.keyIcon] = n.keyContent || n.keyName || n.keyDetails || n.keyImage;
+ state.configList[n.keyIcon] = n.keyContent || n.keyDetails || n.keyImage;
state.configList[n.keyIcon + '_keyValue'] = n.keyValue;
+
+
+ state.configListMax[n.keyIcon] = n;
});
}
})
diff --git a/utils/utils.js b/utils/utils.js
index db8df99..e7be72f 100644
--- a/utils/utils.js
+++ b/utils/utils.js
@@ -197,6 +197,40 @@ export const toLogin = function(){
}
}()
+//获取图片字符串中的第一张图片
+export function getImageOne(image){
+ if(!image){
+ return ''
+ }
+ let arr = image.split(',')
+ for (var index = 0; index < arr.length; index++) {
+ var element = arr[index].trim();
+ if(!element) continue;
+
+ // 获取文件扩展名
+ const lastDotIndex = element.lastIndexOf('.');
+ if(lastDotIndex === -1) continue;
+
+ const extension = element.substring(lastDotIndex + 1).toLowerCase();
+
+ // 检查是否为图片格式
+ const imageExtensions = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'svg'];
+ if(imageExtensions.includes(extension)){
+ return element
+ }
+ }
+
+ // 如果没有找到图片,返回第一个非空元素作为备选
+ for (var index = 0; index < arr.length; index++) {
+ var element = arr[index].trim();
+ if(element) {
+ return element
+ }
+ }
+
+ return ''
+}
+
export default {
toArray,
generateUUID,
@@ -211,5 +245,6 @@ export default {
redirectTo,
copyText,
stringFormatHtml,
- toLogin
+ toLogin,
+ getImageOne
}
\ No newline at end of file