11.28提交
This commit is contained in:
@@ -1,22 +1,25 @@
|
||||
<template>
|
||||
<view class="zhinan-list-page">
|
||||
<!-- 头部导航栏 -->
|
||||
<uni-nav-bar
|
||||
<view class="navbox">
|
||||
<view class="status_bar"></view>
|
||||
<uni-nav-bar
|
||||
left-icon="left"
|
||||
:title="title"
|
||||
@clickLeft="goBack"
|
||||
fixed
|
||||
|
||||
color="#8B2316"
|
||||
height="180rpx"
|
||||
|
||||
:border="false"
|
||||
backgroundColor="#eeeeee"
|
||||
>
|
||||
<template v-slot:right>
|
||||
<view class="nav-right" @click="goGot">
|
||||
<view class="nav-right" @click="goGot" >
|
||||
<up-image :src="hotImg" width="40rpx" height="40rpx"></up-image>
|
||||
</view>
|
||||
</template>
|
||||
</uni-nav-bar>
|
||||
</view>
|
||||
<!-- 固定搜索栏 -->
|
||||
<view class="search-container-fixed filter-bar">
|
||||
<view class="search-box" @click="goToSearch">
|
||||
@@ -48,7 +51,7 @@
|
||||
class="guideline-item"
|
||||
v-for="(item, index) in guidelinesList"
|
||||
:key="item.uuid || index"
|
||||
@click="viewGuideline(item)"
|
||||
|
||||
>
|
||||
<!-- 指南信息 -->
|
||||
<view class="item-content">
|
||||
@@ -57,8 +60,9 @@
|
||||
<view class="item-date">{{ formatDate(item.releaseTime) }}</view>
|
||||
<!-- 操作按钮 -->
|
||||
<view class="item-action">
|
||||
<view class="download-btn" @click.stop="viewGuideline(item)" v-if="!downLoadList.includes(item.uuid)">
|
||||
<up-icon name="download" color="#8D2316" size="28"></up-icon>
|
||||
<view class="download-btn" @click.stop="downLoad(item)" v-if="!downLoadtaskList.includes(item.uuid)">
|
||||
<uni-icons type="arrow-down" size="26" color="#8D2316"></uni-icons>
|
||||
<!-- <up-icon name="download" color="#8D2316" size="56rpx" ></up-icon> -->
|
||||
</view>
|
||||
<view
|
||||
v-else
|
||||
@@ -139,7 +143,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ref, onMounted,computed,nextTick} from "vue";
|
||||
import api from "@/api/api.js";
|
||||
import { onShow, onLoad } from "@dcloudio/uni-app";
|
||||
import docUrl from "@/utils/docUrl.js";
|
||||
@@ -163,6 +167,13 @@ const title = ref("");
|
||||
const sort = ref(2);
|
||||
const showInnerSort = ref(false);
|
||||
const innerSortTitle = ref("上传时间");
|
||||
import downloadStore from "@/store/downloadStoreFile.js";
|
||||
const downloadTasks=ref([]);
|
||||
const downLoadtaskList=computed(()=>{
|
||||
console.log('downLoadtaskList');
|
||||
console.log(downloadTasks.value.map((item)=>item.id));
|
||||
return downloadTasks.value.map((item)=>item.id);
|
||||
});
|
||||
const chooseInnerSort = (index) => {
|
||||
sort.value = index;
|
||||
if (index == 1) {
|
||||
@@ -197,6 +208,15 @@ const toggleInnerSort = () => {
|
||||
showInnerSort.value = !showInnerSort.value;
|
||||
};
|
||||
onShow(() => {
|
||||
console.log('onShow');
|
||||
syncTasksFromStore();
|
||||
// 监听store变化
|
||||
downloadStore.addListener((tasks) => {
|
||||
downloadTasks.value = tasks;
|
||||
|
||||
});
|
||||
// 恢复正在下载的任务
|
||||
resumeDownloadingTasks();
|
||||
// 页面显示时,如果列表为空则加载数据
|
||||
if (guidelinesList.value.length === 0) {
|
||||
loadGuidelinesList(true);
|
||||
@@ -213,6 +233,13 @@ const goToSearch = () => {
|
||||
uni.navigateTo({
|
||||
url: `/pages_app/search/search?keywords=${q}&title=${t}${type}`,
|
||||
});
|
||||
// const goSearch=()=>{
|
||||
// uni.sendNativeEvent('goHomeSearch', {
|
||||
// msg: 'goHomeSearch'
|
||||
// },ret => {
|
||||
// console.log(ret);
|
||||
// })
|
||||
// }
|
||||
};
|
||||
|
||||
// scroll-view 下拉刷新
|
||||
@@ -392,51 +419,185 @@ const downloadGuideline = (item) => {
|
||||
fail: (err) => {
|
||||
console.error("下载失败:", err);
|
||||
uni.showToast({
|
||||
title: "下载失败",
|
||||
title: "下载失败1",
|
||||
icon: "none",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 查看指南(支持常用文档直链:pdf/doc/docx/xls/xlsx/ppt/pptx/txt)
|
||||
const viewGuideline = (item) => {
|
||||
if (!item.path) {
|
||||
const downLoad = (item) => {
|
||||
if(!item.path){
|
||||
uni.showToast({
|
||||
title: "暂无下载链接",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const pdfUrl = docUrl + item.path;
|
||||
let url = "https://view.xdocin.com/view?src=" + encodeURIComponent(pdfUrl);
|
||||
uni.downloadFile({
|
||||
url: pdfUrl,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
let index = downLoadList.value.find((cell) => item.uuid == cell.id);
|
||||
if (!index) {
|
||||
downLoadList.value.push(item.uuid);
|
||||
uni.setStorageSync("downLoadPdf", downLoadList.value);
|
||||
}
|
||||
navTo({
|
||||
url:
|
||||
"/pages_app/webview/webview?url=" +
|
||||
encodeURIComponent(url) +
|
||||
"&title=" +
|
||||
item.title,
|
||||
});
|
||||
}
|
||||
},
|
||||
addDownloadTask({
|
||||
url: docUrl + item.path,
|
||||
title: item.title,
|
||||
id: item.uuid,
|
||||
});
|
||||
};
|
||||
// 查看指南(支持常用文档直链:pdf/doc/docx/xls/xlsx/ppt/pptx/txt)
|
||||
const viewGuideline = (cell) => {
|
||||
console.log(cell);
|
||||
if (!cell.path) {
|
||||
uni.showToast({
|
||||
title: "暂无下载链接",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const pdfUrl = docUrl + cell.path;
|
||||
console.log(downloadTasks.value);
|
||||
downloadTasks.value.forEach(item => {
|
||||
if(item.id == cell.uuid) {
|
||||
uni.openDocument({
|
||||
filePath: item.localPath,
|
||||
success: () => console.log('打开成功'),
|
||||
fail: (err) => console.error('打开失败', err)
|
||||
});
|
||||
}
|
||||
});
|
||||
// let url = "https://view.xdocin.com/view?src=" + encodeURIComponent(pdfUrl);
|
||||
// uni.downloadFile({
|
||||
// url: pdfUrl,
|
||||
// success: (res) => {
|
||||
// if (res.statusCode === 200) {
|
||||
// uni.openDocument({
|
||||
// filePath: res.tempFilePath, // 临时文件路径
|
||||
// fileType: 'pdf',
|
||||
// success: () => console.log('打开成功'),
|
||||
// fail: (err) => console.error('打开失败', err)
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// });
|
||||
};
|
||||
|
||||
// 返回上一页
|
||||
const goBack = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
|
||||
// 添加下载任务
|
||||
const addDownloadTask = (item) => {
|
||||
// 使用store添加任务
|
||||
const taskIndex = downloadStore.addTask(item);
|
||||
// 同步任务列表
|
||||
syncTasksFromStore();
|
||||
// 开始下载
|
||||
startDownload(taskIndex);
|
||||
};
|
||||
|
||||
// 开始下载
|
||||
const startDownload = (index) => {
|
||||
const taskItem = downloadStore.getTask(index);
|
||||
if (!taskItem) return;
|
||||
if(taskItem.status == "loading"){
|
||||
uni.showToast({
|
||||
title: "正在下载",
|
||||
icon: "none",
|
||||
});
|
||||
return false;
|
||||
};
|
||||
downloadStore.updateTask(index, {
|
||||
status: "loading"
|
||||
});
|
||||
|
||||
const task = uni.downloadFile({
|
||||
url: taskItem.url,
|
||||
success: (res1) => {
|
||||
console.log("res1:"+JSON.stringify(res1));
|
||||
if (res1.statusCode === 200) {
|
||||
downloadStore.updateTask(index, {
|
||||
status: "completed",
|
||||
filePath: res1.tempFilePath,
|
||||
});
|
||||
|
||||
uni.showToast({
|
||||
title: "下载成功",
|
||||
icon: "none",
|
||||
});
|
||||
|
||||
|
||||
uni.saveFile({
|
||||
tempFilePath: res1.tempFilePath,
|
||||
success: function (res2) {
|
||||
console.log("res2:"+JSON.stringify(res2));
|
||||
uni.getSavedFileInfo({
|
||||
filePath: res2.savedFilePath,
|
||||
success: function (res) {
|
||||
console.log("res:"+JSON.stringify(res));
|
||||
console.log("size:"+res.size);
|
||||
downloadStore.updateTask(index, {
|
||||
status: "completed",
|
||||
localPath: res2.savedFilePath,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
} else {
|
||||
downloadStore.updateTask(index, {
|
||||
status: "failed",
|
||||
});
|
||||
removeTask(index);
|
||||
uni.showToast({
|
||||
title: "下载失败2",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
downloadStore.updateTask(index, {
|
||||
status: "failed",
|
||||
});
|
||||
removeTask(index);
|
||||
uni.showToast({
|
||||
title: "下载失败3: " + (err.errMsg || "未知错误"),
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// 监听下载进度
|
||||
task.onProgressUpdate((update) => {
|
||||
const currentTask = downloadStore.getTask(index);
|
||||
if (currentTask && currentTask.status === "downloading") {
|
||||
downloadStore.updateTask(index, {
|
||||
progress: update.progress
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 保存task对象到store(用于暂停/继续)
|
||||
downloadStore.updateTask(index, {
|
||||
task: task,
|
||||
});
|
||||
};
|
||||
|
||||
const syncTasksFromStore = () => {
|
||||
downloadTasks.value = downloadStore.getTasks();
|
||||
};
|
||||
const removeTask = (index) => {
|
||||
downloadStore.removeTask(index);
|
||||
syncTasksFromStore();
|
||||
};
|
||||
// 恢复正在下载的任务
|
||||
const resumeDownloadingTasks = () => {
|
||||
// 使用 nextTick 确保在页面渲染后再恢复下载任务
|
||||
nextTick(() => {
|
||||
downloadStore.resumeDownloadingTasks((index) => {
|
||||
// 重新开始下载(uni.downloadFile不支持断点续传,所以从0开始)
|
||||
console.log("恢复下载任务:", downloadStore.getTask(index)?.url);
|
||||
startDownload(index);
|
||||
});
|
||||
});
|
||||
};
|
||||
// 测试加载更多功能
|
||||
const testLoadMore = () => {
|
||||
console.log("=== 手动测试加载更多 ===");
|
||||
@@ -490,7 +651,7 @@ $white: #ffffff;
|
||||
}
|
||||
.popup-panel {
|
||||
position: fixed;
|
||||
top: 256rpx; /* 紧贴筛选栏 */
|
||||
top:285rpx;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background: #fff;
|
||||
@@ -544,18 +705,18 @@ $white: #ffffff;
|
||||
|
||||
.guidelines-scroll-view {
|
||||
position: fixed;
|
||||
top: 285rpx;
|
||||
top: calc(var(--status-bar-height) + 44px + 106rpx);
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 99;
|
||||
height: calc(100vh - 180rpx);
|
||||
height: calc(100vh - var(--status-bar-height) - 44px - 106rpx);
|
||||
background-color: $bg-color;
|
||||
}
|
||||
// 固定搜索容器
|
||||
.search-container-fixed {
|
||||
position: fixed;
|
||||
top: 180rpx; // 导航栏高度
|
||||
top: calc(var(--status-bar-height) + 44px); // 导航栏高度
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 90;
|
||||
@@ -658,12 +819,12 @@ $white: #ffffff;
|
||||
justify-content: center;
|
||||
border-radius: 50%;
|
||||
background-color: rgba(255, 71, 87, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
// transition: all 0.3s ease;
|
||||
|
||||
&:active {
|
||||
transform: scale(0.95);
|
||||
background-color: rgba(255, 71, 87, 0.2);
|
||||
}
|
||||
// &:active {
|
||||
// transform: scale(0.95);
|
||||
// background-color: rgba(255, 71, 87, 0.2);
|
||||
// }
|
||||
}
|
||||
|
||||
.view-btn {
|
||||
|
||||
Reference in New Issue
Block a user