瀏覽代碼

feat(attachmentList):附件 新增预览,分享,下载
fix(checkIn):修复打卡记录数据重复渲染问题

HMY 1 年之前
父節點
當前提交
970001a7b8

+ 90 - 6
components/ygoa/attachmentList.vue

@@ -5,7 +5,13 @@
 		<uni-row :gutter="0">
 			<uni-col v-for="(attachment, index) in attachments" :key="index" :xs="{span: 24}" :sm="6">
 				<view class="attachment">
-					<text @click="seeAttachment(attachment.path)">{{ attachment.fileName || '空' }}</text>
+					<text @click="seeAttachment(attachment.path)">{{ attachment.fileName || '附件名为空' }}</text>
+					<view class="icon-container">
+						<uni-icons @click="shareAttachment(attachment.path)" :size="14" color="#2196f3" type="redo-filled"
+							style="margin-left:10px;">分享</uni-icons>
+						<uni-icons @click="copyAttachment(attachment.path)" :size="14" color="#2196f3" type="download-filled"
+							style="margin-left:10px;">复制链接</uni-icons>
+					</view>
 				</view>
 			</uni-col>
 		</uni-row>
@@ -13,9 +19,10 @@
 </template>
 
 <script setup lang="ts">
+	import config from '@/config';
 	import $tab from '@/plugins/tab';
 	import { onMounted, ref } from 'vue';
-
+	import $modal from '@/plugins/modal.js'
 
 	onMounted(() => {
 		startAttachmentCheck();
@@ -34,7 +41,6 @@
 	//检查附件列表是否有数据
 	function startAttachmentCheck() {
 		intervalId.value = setInterval(() => {
-			console.log(111);
 			if (props.attachments) {
 				console.log('props', props.attachments);
 				clearInterval(intervalId.value); // 清除定时器    
@@ -44,14 +50,92 @@
 
 	//预览文件
 	function seeAttachment(path) {
-		// console.log('path',path);
-		$tab.navigateTo('/pages/message/detail/URLView?type=doc&url=' + encodeURIComponent(path));
+		console.log('path',path);
+		// 下载文件
+		wx.downloadFile({
+			url: config.baseUrlPre + path, // 需要下载的文件地址
+			success:  (res)=> {
+				if (res.statusCode === 200) {
+					// 下载成功,打开文档(临时文件路径res.tempFilePath)
+					wx.openDocument({
+						filePath: res.tempFilePath,
+						success: function (res) {
+							console.log('文档打开成功');
+						},
+						fail: function (err) {
+							// $modal.alert('err', JSON.stringify(err))
+							console.error('打开文档失败:', err);
+						}
+					});
+				} else {
+					// $modal.alert('err1')
+					console.error('下载文件失败,状态码:', res.statusCode);
+				}
+			},
+			fail:  (err)=> {
+				console.error('下载文件失败:', err);
+				// $modal.alert('err2', JSON.stringify(err))
+			}
+		});
+
+	}
+
+	//文件分享
+	function shareAttachment(path) {
+		uni.downloadFile({
+			url: config.baseUrlPre + path,
+			success: (res) => {
+				if (res.statusCode === 200) {
+					wx.shareFileMessage({
+						filePath: res.tempFilePath,
+						fileName: path.split('/').pop(),
+						success() { },
+						fail: console.error,
+					})
+				}
+			}
+		});
+
+	}
+
+	//复制下载链接
+	function copyAttachment(path) {
+		// 显示操作菜单,引导用户复制链接
+		wx.showActionSheet({
+			itemList: ['复制下载链接'],
+			success: function (res) {
+				if (res.tapIndex === 0) {
+					wx.setClipboardData({
+						data: config.baseUrlPre + path,
+						success: function (res) {
+							wx.showToast({
+								title: '下载链接已复制',
+								icon: 'success'
+							});
+						}
+					});
+				}
+			}
+		});
 	}
 </script>
 
 <style lang="scss">
 	.attachment {
-		color: blue;
+		color: #2196f3;
 		margin-left: 5px;
+		display: flex;
+		/* 使用 flexbox 布局 */
+		justify-content: space-between;
+		/* 在空余空间时,图标靠右 */
+		align-items: center;
+		/* 垂直居中对齐 */
+	}
+
+	.icon-container {
+		display: flex;
+		/* 图标使用 flexbox 布局 */
+		justify-content: flex-end;
+		/* 使图标靠右 */
 	}
 </style>

+ 18 - 9
pages/message/detail/URLView.vue

@@ -8,19 +8,28 @@
 	import { onLoad } from '@dcloudio/uni-app';
 	import { ref } from 'vue';
 	import config from '@/config';
-	
+
 	const url = ref('');
 	onLoad((options) => {
-		if(options.type=='doc'){
-			const previewDocUrl='https://view.xdocin.com/view?src='
-			// const baseUrlSub=config.baseUrl.substring(0, config.baseUrl.indexOf("/", config.baseUrl.indexOf("//") + 2))
-			url.value = decodeURIComponent(previewDocUrl+config.baseUrlPre+options.url)
-		}else{
-			url.value = decodeURIComponent(options.url)
+		switch (options.type) {
+			case 'doc':
+				const previewDocUrl = 'https://view.xdocin.com/view?src='
+				url.value = decodeURIComponent(previewDocUrl + config.baseUrlPre + options.url);
+				break
+			// case 'download':
+			// 	url.value = decodeURIComponent(config.baseUrlPre + options.url);
+			// 	break
+			default:
+				url.value = decodeURIComponent(options.url)
 		}
-		console.log('url.value',url.value);
+		// if(options.type=='doc'){
+		// 	const previewDocUrl='https://view.xdocin.com/view?src='
+		// 	url.value = decodeURIComponent(previewDocUrl+config.baseUrlPre+options.url)
+		// }else{
+		// 	url.value = decodeURIComponent(options.url)
+		// }
+		console.log('url', url.value);
 	});
-	
 </script>
 
 <style lang="scss">

+ 11 - 8
pages/message/detail/index.vue

@@ -8,14 +8,11 @@
 			</template>
 			<view class="message_container">
 				<uni-card :border="false" :is-shadow="false" spacing="0px" margin="0px">
-
 					<view class="message_contant">
 						<u-parse :content="msgInfo.content" :selectable="true" @navigate="parseNavigate">
 						</u-parse>
 					</view>
-					<view>
-						<attachment-list :attachments="attachments"></attachment-list>
-					</view>
+					
 					<view class="message_info">
 						<uni-row :gutter="20">
 							<uni-col :xs="{span: 24}" :sm="{span: 16, offset: 1}">
@@ -33,6 +30,12 @@
 					</view>
 
 				</uni-card>
+				
+			</view>
+		</uni-card>
+		<uni-card>
+			<view v-if="attachments.length>0">
+				<attachment-list :attachments="attachments" ></attachment-list>
 			</view>
 		</uni-card>
 	</view>
@@ -83,10 +86,9 @@
 				name: returnParams.name,
 				content: returnParams.noticeContent,
 			}
-			if (returnParams.affixUrl) {
-				attachments.value = returnParams.affixUrl;
-				console.log(attachments.value);
-			}
+			
+			attachments.value = returnParams.affixUrl;
+				
 		})
 	}
 
@@ -103,6 +105,7 @@
 				name: returnParams.name,
 				content: returnParams.content,
 			}
+			attachments.value = returnParams.fileList;
 		})
 	}
 

+ 9 - 20
pages/mine/checkIn/checkIn.vue

@@ -255,7 +255,6 @@
 	const pSize = ref(5)
 
 	function complete(list, total, pageNo) {
-		console.log('000', pageNo);
 		if (pageNo == 1) {
 			paging.value.complete(list);
 			return
@@ -264,7 +263,6 @@
 		if (pSize.value * pageNo < total) {
 			paging.value.complete(list)
 		} else {
-			console.log('complete([])');
 			paging.value.complete([])
 		}
 	}
@@ -281,20 +279,15 @@
 			pSize: pSize.value,
 			p: 1
 		}
-		getMyQDQtAttendance(params).then(({
-			returnParams
-		}) => {
-			const list = returnParams.list;
-			const records = [];
-			list.forEach(item => {
-				const record = {
+		getMyQDQtAttendance(params).then(({returnParams}) => {
+			const list = returnParams.list.map(item => {
+				return {
 					date: item.att_date.substring(0, 10),
 					morning: item.time.split(',')[item.type.split(',').indexOf("1")],
 					evening: item.time.split(',')[item.type.split(',').indexOf("2")],
-				};
-				records.push(record);
+				}
 			});
-			clockRecords.value = records;
+			clockRecords.value = list;
 			complete(clockRecords.value, returnParams.total, returnParams.current)
 		})
 	}
@@ -315,6 +308,7 @@
 		}
 	}
 
+	//上拉加载事件
 	function scrollQuery(pageNo, pSize) {
 		const params = {
 			type: 1, //不设时间区间
@@ -324,10 +318,7 @@
 			pSize: pSize,
 			p: pageNo
 		}
-		getMyQDQtAttendance(params).then(({
-			returnParams
-		}) => {
-
+		getMyQDQtAttendance(params).then(({returnParams}) => {
 			const list = returnParams.list.map(item => {
 				return {
 					date: item.att_date.substring(0, 10),
@@ -335,18 +326,16 @@
 					evening: item.time.split(',')[item.type.split(',').indexOf("2")],
 				}
 			});
-			console.log('list', list);
+			// console.log('list', list);
 
 			// clockRecords.value.push(...list);
 			// complete(list,returnParams.total,pageNo)
-			
+		
 			// 去重逻辑
 			const existingDates = new Set(clockRecords.value.map(record => record.date));
 			const newRecords = list.filter(item => !existingDates.has(item.date));
-
 			// 更新 clockRecords
 			clockRecords.value.push(...newRecords);
-
 			// 调用 complete 函数,传入新记录和总数
 			complete(newRecords, returnParams.total, pageNo);
 

+ 11 - 10
pages/mine/index.vue

@@ -41,26 +41,27 @@
 					<text class="title">编辑资料</text>
 					<text class="desc">></text>
 				</view>
-				<view class="function-item" @click="waitWork">
+				<!-- <view class="function-item" @click="waitWork">
 					<text class="ygoa-icon icon-waitWork"></text>
 					<text class="title">待办事项</text>
 					<text class="desc">></text>
-				</view>
+				</view> -->
 				<view class="function-item" @click="checkIn">
 					<text class="ygoa-icon icon-checkIn"></text>
 					<text class="title">我的考勤</text>
 					<text class="desc">></text>
 				</view>
-				<view class="function-item" @click="setting">
-					<text class="ygoa-icon icon-setting"></text>
-					<text class="title">应用设置</text>
-					<text class="desc">></text>
-				</view>
+				
 				<view class="function-item" @click="clockIn">
 					<text class="ygoa-icon icon-clockIn"></text>
 					<text class="title">我的打卡</text>
 					<text class="desc">></text>
 				</view>
+				<view class="function-item" @click="setting">
+					<text class="ygoa-icon icon-setting"></text>
+					<text class="title">应用设置</text>
+					<text class="desc">></text>
+				</view>
 			</view>
 		</uni-card>
 
@@ -141,9 +142,9 @@
 	};
 
 	// 待办事项的函数
-	function waitWork() {
-		$tab.navigateTo('/pages/mine/waitWork/waitWork')
-	}
+	// function waitWork() {
+	// 	$tab.navigateTo('/pages/mine/waitWork/waitWork')
+	// }
 
 	// 我的考勤的函数
 	function checkIn() {