瀏覽代碼

修改: 动态列表添加封面,详情分享补充分娩,首页经理人指数改成复制url,指引、动态、通知添加title

littleblue55 4 天之前
父節點
當前提交
7b7558477c

+ 3 - 2
pages/dynamic/dynamic/dynamic.vue

@@ -14,7 +14,7 @@
 						<image
 							mode="aspectFill"
 							style="width: 250rpx;height: 200rpx;"
-							:src="item.imgUrl ?? '/static/images/avatar-img/1.png'"></image>
+							:src="item.cover ? item.cover : '/static/images/avatar-img/1.png'"></image>
 					</view>
 					<view class="content-box">
 						<view class="title" style="margin-bottom: 30rpx;">
@@ -167,7 +167,8 @@
 						// width: 67%;
 						display: flex;
 						flex-direction: column;
-						justify-content: space-around;
+						// justify-content: space-around;
+						justify-content: center;
 						gap: 10rpx;
 						width: 100%;
 

+ 12 - 3
pages/dynamic/dynamicDetail/dynamicDetail.vue

@@ -26,6 +26,7 @@
 		date: "" // ISO格式日期
 	})
 	const currentId = ref(null);
+	const currentTitle = ref(null);
 	function formatDate(dateString) {
 		const options = {
 			year: 'numeric',
@@ -44,24 +45,32 @@
 	}
 	onLoad((option) => {
 		const {
-			id
+			id, title
 		} = option
 		currentId.value = id
+		currentTitle.value = title
+		uni.setNavigationBarTitle({
+			title: title
+		});
 		init(id)
 	})
 	
 	onShareAppMessage(async (res) => {
+		// console.log(announcement.value.title, 123)
 		return {
 			title: announcement.value.title,
-			path: `/pages/dynamic/dynamicDetail/dynamicDetail?id=${currentId.value}`
+			path: `/pages/dynamic/dynamicDetail/dynamicDetail?id=${currentId.value}&title=${currentTitle.value}`,
+			imageUrl: announcement.value.cover
 		};
 	})
 	
 	onShareTimeline(async () => {
+		// console.log(announcement.value.title, 1234)
 		// console.log(imgurl.value)
 		return {
 			title: announcement.value.title,
-			query: `id=${currentId.value}`
+			query: `id=${currentId.value}&title=${currentTitle.value}`,
+			imageUrl: announcement.value.cover
 		};
 	})
 </script>

+ 96 - 16
pages/goOnEdu/course/courseDetail/courseDetail.vue

@@ -50,8 +50,7 @@
 				</view>
 			</view>
 		</view>
-		<u-popup v-model="loginShow" 
-		:mask="false" :closeable='false' mode="bottom" :mask-close-able='false'
+		<u-popup v-model="loginShow" :mask="false" :closeable='false' mode="bottom" :mask-close-able='false'
 			safe-area-inset-bottom>
 			<view style="height: 70vh;padding: 40rpx;position: relative;background:none;">
 				<view style="text-align: center;margin: 70rpx 0;">
@@ -59,6 +58,8 @@
 				</view>
 			</view>
 		</u-popup>
+		<canvas canvas-id="shareCanvas"
+			:style="{ position: 'absolute', top: '-10000px', width: '750px', height: '600px' }"></canvas>
 	</view>
 
 </template>
@@ -69,7 +70,9 @@
 		loadCommentList,
 		sendComment
 	} from "@/api/edu.js"
-	import { getToken } from '@/utils/auth.js'
+	import {
+		getToken
+	} from '@/utils/auth.js'
 	import {
 		useAuthStore
 	} from '@/store/authStore'
@@ -84,7 +87,7 @@
 		onLoad,
 		onShow,
 		onShareAppMessage,
-		onShareTimeline	
+		onShareTimeline
 	} from '@dcloudio/uni-app'
 
 	const courseDetail = ref({});
@@ -113,7 +116,7 @@
 	})
 	// 评论列表
 	const commentList = ref([])
-	
+
 	// 点击tabs,切换
 	function onClickItem(e) {
 		if (currentTab.value != e) {
@@ -149,6 +152,80 @@
 		// console.log("购买该课程", courseDetail.value.id)
 	}
 
+	// 定义 Canvas 画布尺寸(按 5:4 比例)
+	const canvasWidth = ref(750); // 推荐 2倍图尺寸
+	const canvasHeight = ref(600);
+	const shareImageUrl = ref(''); // 存储处理后的图片路径
+
+	// 获取图片信息
+	const getImageInfo = (imgUrl) => {
+		return new Promise((resolve) => {
+			uni.getImageInfo({
+				src: imgUrl,
+				success: (res) => resolve(res),
+				fail: () => resolve(null)
+			});
+		});
+	};
+
+	// 动态裁剪并填充背景
+	const processShareImage = async (imgUrl) => {
+		try {
+			const imageInfo = await getImageInfo(imgUrl);
+			if (!imageInfo) return imgUrl;
+
+			const ctx = uni.createCanvasContext('shareCanvas', this);
+			const targetRatio = 5 / 4;
+			const originalRatio = imageInfo.width / imageInfo.height;
+
+			// 1. 绘制背景填充
+			ctx.setFillStyle('#FFFFFF'); // 自定义背景色
+			ctx.fillRect(0, 0, canvasWidth.value, canvasHeight.value);
+
+			// 2. 计算绘制区域
+			if (originalRatio < targetRatio) {
+				// 比例不足时:居中缩放 + 左右填充
+				const scale = canvasHeight.value / imageInfo.height;
+				const drawWidth = imageInfo.width * scale;
+				ctx.drawImage(
+					imageInfo.path,
+					(canvasWidth.value - drawWidth) / 2, // 水平居中
+					0,
+					drawWidth,
+					canvasHeight.value
+				);
+			} else {
+				// 比例足够时:裁剪中间区域
+				const cropWidth = imageInfo.height * targetRatio;
+				ctx.drawImage(
+					imageInfo.path,
+					(imageInfo.width - cropWidth) / 2, // 水平居中裁剪
+					0,
+					cropWidth,
+					imageInfo.height,
+					0,
+					0,
+					canvasWidth.value,
+					canvasHeight.value
+				);
+			}
+
+			// 3. 导出临时图片
+			ctx.draw(false, () => {
+				setTimeout(async () => { // 解决 Canvas 渲染延迟
+					const res = await uni.canvasToTempFilePath({
+						canvasId: 'shareCanvas',
+						fileType: 'jpg',
+						quality: 0.9
+					});
+					shareImageUrl.value = res.tempFilePath;
+				}, 300);
+			});
+		} catch (err) {
+			return imgUrl; // 降级处理
+		}
+	};
+
 	function toSend() {
 		sendComment({
 			courseId: courseId.value,
@@ -173,7 +250,7 @@
 
 		return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
 	}
-	
+
 	function showBuyAction() {
 		if (courseDetail.value.viewMode === '2' &&
 			!isMember.value &&
@@ -197,13 +274,14 @@
 		return authStore.userInfo.isMember == '0' ? false : true
 	})
 	const isLogin = computed(() => {
-		if(getToken() && authStore.isAuthenticated){
+		if (getToken() && authStore.isAuthenticated) {
 			return true
-		}else{
+		} else {
 			return false
 		}
 	})
 	const loginShow = ref(true)
+
 	function toLogin() {
 		// loginShow.value = false
 		let url = {
@@ -227,15 +305,15 @@
 		uni.setNavigationBarTitle({
 			title: title
 		});
-		if(isLogin.value){
+		if (isLogin.value) {
 			loginShow.value = false
-		}else{
+		} else {
 			loginShow.value = true
 		}
 		// loginShow.value = true
 	})
 	onShow(() => {
-		if(isLogin.value){
+		if (isLogin.value) {
 			init(courseId.value)
 			getComment(courseId.value)
 		}
@@ -270,15 +348,17 @@
 			new Date(formatDateS(b.commentTime)) - new Date(formatDateS(a.commentTime))
 		);
 	});
-	
+
 	onShareAppMessage(async (res) => {
+		const processedImage = await processShareImage(courseDetail.value.cover);
+		// console.log(processedImage)
 		return {
 			title: courseName.value,
 			path: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${courseId.value}&title=${courseName.value}`,
-			imageUrl: courseDetail.value.cover
+			imageUrl: processedImage
 		};
 	})
-	
+
 	onShareTimeline(async () => {
 		return {
 			title: courseName.value,
@@ -288,8 +368,8 @@
 	})
 </script>
 <style lang="scss">
-	.u-drawer-bottom{
-		background-color: transparent!important;
+	.u-drawer-bottom {
+		background-color: transparent !important;
 	}
 </style>
 <style lang="scss" scoped>

+ 8 - 3
pages/guide/guideDetail/guideDetail.vue

@@ -19,6 +19,7 @@
 		getGuideDetail
 	} from '@/api/notice.js'
 	const currentId = ref(null);
+	const currentTitle = ref(null);
 	const announcement = ref({
 		title: "",
 		content: "", // 假设这是后端返回的内容
@@ -43,16 +44,20 @@
 	}
 	onLoad((option) => {
 		const {
-			id
+			id, title
 		} = option
 		currentId.value = id
+		currentTitle.value = title
+		uni.setNavigationBarTitle({
+			title: title
+		});
 		init(id)
 	})
 	
 	onShareAppMessage(async (res) => {
 		return {
 			title: announcement.value.title,
-			path: `/pages/guide/guideDetail/guideDetail?id=${currentId.value}`
+			path: `/pages/guide/guideDetail/guideDetail?id=${currentId.value}&title=${currentTitle.value}`
 		};
 	})
 	
@@ -60,7 +65,7 @@
 		// console.log(imgurl.value)
 		return {
 			title: announcement.value.title,
-			query: `id=${currentId.value}`
+			query: `id=${currentId.value}&title=${currentTitle.value}`
 		};
 	})
 </script>

+ 12 - 3
pages/index/index.vue

@@ -5,6 +5,7 @@
 				<image :src="`${FILE_URL}/login-icon.png`" mode="aspectFit" style="width: 300rpx;"></image>
 			</view>
 		</u-navbar>
+		<!-- <u-link href="http://www.uviewui.com">蜀道难,难于上青天</u-link> -->
 		<view class="page-content">
 			<swiper class="swiper" circular indicator-dots style="border-radius: 20rpx;overflow: hidden;height: 200px">
 				<swiper-item v-for="(data, index) in swiperList" style="width: 100%;height: 100%;" :key="index">
@@ -145,6 +146,7 @@
 	import {
 		useTabbarStore
 	} from '@/store/tabbarStore.js'
+import { msg, msgSuccess } from '../../utils/common'
 	const tabbarStore = useTabbarStore()
 	// 底部导航栏数据
 	const tabbarList = computed(() => {
@@ -300,9 +302,16 @@
 			}
 		}
 		if (data.id === 'index') {
-			const src = encodeURIComponent(jlrzsUrl.value);
-			uni.navigateTo({
-				url: `/pages/webview/webview?url=${src}`
+			// const src = encodeURIComponent(jlrzsUrl.value);
+			
+			// uni.navigateTo({
+			// 	url: `/pages/webview/webview?url=${src}`
+			// });
+			uni.setClipboardData({
+				data: jlrzsUrl.value,
+				success: function () {
+					msg("链接已复制,请在浏览器中打开")
+				}
 			});
 			return
 		}

+ 8 - 3
pages/notice/noticeDetail/noticeDetail.vue

@@ -26,6 +26,7 @@
 		date: "" // ISO格式日期
 	})
 	const currentId = ref(null);
+	const currentTitle = ref(null);
 	function formatDate(dateString) {
 		const options = {
 			year: 'numeric',
@@ -44,16 +45,20 @@
 	}
 	onLoad((option) => {
 		const {
-			id
+			id, title
 		} = option
 		currentId.value = id
+		currentTitle.value = title
+		uni.setNavigationBarTitle({
+			title: title
+		});
 		init(id)
 	})
 	
 	onShareAppMessage(async (res) => {
 		return {
 			title: announcement.value.title,
-			path: `/pages/notice/noticeDetail/noticeDetail?id=${currentId.value}`
+			path: `/pages/notice/noticeDetail/noticeDetail?id=${currentId.value}&title=${currentTitle.value}`
 		};
 	})
 	
@@ -61,7 +66,7 @@
 		// console.log(imgurl.value)
 		return {
 			title: announcement.value.title,
-			query: `id=${currentId.value}`
+			query: `id=${currentId.value}&title=${currentTitle.value}`
 		};
 	})
 </script>