diff --git a/src/api/routine/gw.ts b/src/api/routine/gw.ts index de0cc37..26782a5 100644 --- a/src/api/routine/gw.ts +++ b/src/api/routine/gw.ts @@ -151,3 +151,10 @@ export function getGwFlowByIdApi(id: string) { export function gwTransferApi(params: any) { return post('/api/gw/transfer', params); } + +/** + * 分页查询某人的待办和已办公文 + */ +export function findUserTodosApi(approveStatus: string, jsId: string, pageNum: number = 1, pageSize: number = 20) { + return get('/api/gw/findUserTodos', { approveStatus, jsId, pageNum, pageSize }); +} diff --git a/src/pages/view/hr/jsQj/components/jsQjEdit.vue b/src/pages/view/hr/jsQj/components/jsQjEdit.vue index 5cc3908..46dbeff 100644 --- a/src/pages/view/hr/jsQj/components/jsQjEdit.vue +++ b/src/pages/view/hr/jsQj/components/jsQjEdit.vue @@ -46,11 +46,11 @@ const props = withDefaults(defineProps<{ }>(), { data: () => ({ id: "", - qjlx: "事假", - qjkstime: "2025-08-28 12:00:00", - qjjstime: "2025-08-29 12:00:00", - qjsc: "24小时", - qjsy: "测试请假", + qjlx: "", + qjkstime: "", + qjjstime: "", + qjsc: "", + qjsy: "", dkfs: 0, sprList: [], csrList: [], @@ -87,7 +87,7 @@ const [register, { setValue, getValue }] = useForm({ component: "BasicPicker", componentProps: { api: findByPid, - param: { pid: 1007011432 }, + param: { pid: 1405417393 }, rangeKey: "dictionaryValue", savaKey: "dictionaryCode", }, diff --git a/src/pages/view/routine/gwlz/gwFlow.vue b/src/pages/view/routine/gwlz/gwFlow.vue index 19ddf11..675b9a1 100644 --- a/src/pages/view/routine/gwlz/gwFlow.vue +++ b/src/pages/view/routine/gwlz/gwFlow.vue @@ -305,8 +305,7 @@ import { canPreview, previewFile as previewFileUtil, previewVideo as previewVideoUtil, - previewImage as previewImageUtil, - downloadFile as downloadFileUtil + previewImage as previewImageUtil } from "@/utils/filePreview"; // 类型定义 @@ -450,62 +449,28 @@ const canCurrentUserOperate = computed(() => { // 获取公文信息 const getGwInfo = async () => { - console.log("=== getGwInfo 开始执行 ==="); - console.log("当前 gwId.value:", gwId.value); - try { - console.log("准备调用API接口: getGwFlowByIdApi"); - console.log("API参数:", { id: gwId.value }); - // 调用新的API接口获取公文流程信息 const response = await getGwFlowByIdApi(gwId.value); - console.log("API调用完成,响应结果:", response); if (response.resultCode === 1) { - console.log("API调用成功,开始处理数据"); - // 设置公文信息 gwInfo.value = response.result.gwInfo; - console.log("设置公文信息:", gwInfo.value); - console.log("公文信息字段详情:", { - title: gwInfo.value.title, - docType: gwInfo.value.docType, - urgencyLevel: gwInfo.value.urgencyLevel, - tjrId: gwInfo.value.tjrId, - createdTime: gwInfo.value.createdTime - }); // 设置审批人、抄送人、操作日志信息 approvers.value = response.result.approvers || []; ccUsers.value = response.result.ccUsers || []; operationLogs.value = response.result.operationLogs || []; - - console.log("设置审批人:", approvers.value); - console.log("设置抄送人:", ccUsers.value); - console.log("设置操作日志:", operationLogs.value); - - console.log("成功获取公文流程信息:", { - gwInfo: gwInfo.value, - approvers: approvers.value, - ccUsers: ccUsers.value, - operationLogs: operationLogs.value - }); } else { - console.log("API调用失败,错误信息:", response.message); throw new Error(response.message || '获取数据失败'); } } catch (error) { - console.error("获取公文信息失败:", error); - console.log("API调用失败,无法获取数据"); - // 清空所有数据 gwInfo.value = {} as GwInfo; approvers.value = []; ccUsers.value = []; operationLogs.value = []; } - - console.log("=== getGwInfo 执行完成 ==="); }; @@ -566,9 +531,6 @@ const handleReject = () => { // 转办处理 const handleTransfer = () => { - // 跳转到转办页面 - console.log("转办公文:", gwId.value); - // 构建跳转参数,包含所有必要的数据 const params = { id: gwId.value, @@ -628,26 +590,13 @@ const approveGw = async () => { // 获取当前用户ID - 应该从jsData中获取 const currentUserId = getJs?.id; if (!currentUserId) { - console.error('无法获取当前用户信息,jsData:', getJs); throw new Error('无法获取当前用户信息'); } - console.log('=== 调试信息 ==='); - console.log('当前用户ID:', currentUserId); - console.log('jsData详情:', getJs); - console.log('userdata详情:', getUser); - console.log('审批人列表:', approvers.value); - console.log('审批人列表长度:', approvers.value?.length || 0); - // 获取当前用户在审批人列表中的ID const currentUserApproverId = getCurrentUserApproverId(currentUserId); - console.log('找到的审批人ID:', currentUserApproverId); if (!currentUserApproverId) { - console.error('无法找到当前用户的审批人记录,详细信息:'); - console.error('approvers数组:', approvers.value); - console.error('当前用户ID:', currentUserId); - console.error('用户信息:', { getUser, getJs }); throw new Error('无法获取当前用户的审批人记录'); } @@ -661,11 +610,8 @@ const approveGw = async () => { currentUserId: currentUserId }; - console.log('同意数据:', approveData); - // 调用同意API - 使用正确的API函数 const response = await gwApproveApi(approveData); - console.log('API响应:', response); // 隐藏加载提示 uni.hideLoading(); @@ -696,7 +642,6 @@ const approveGw = async () => { // 隐藏加载提示 uni.hideLoading(); - console.error("同意公文失败:", error); uni.showToast({ title: error.message || "同意失败", icon: "error", @@ -723,61 +668,23 @@ const getCurrentUserApproverStatus = () => { // 获取当前用户在审批人列表中的ID const getCurrentUserApproverId = (currentUserId: string) => { - console.log('=== getCurrentUserApproverId 函数调试 ==='); - console.log('传入的currentUserId:', currentUserId); - console.log('approvers.value:', approvers.value); - console.log('approvers.value长度:', approvers.value?.length || 0); - if (!approvers.value || approvers.value.length === 0) { - console.log('approvers数组为空或未定义,返回null'); return null; } // 查找当前用户对应的审批人记录 - console.log('开始查找审批人记录...'); - approvers.value.forEach((approver, index) => { - console.log(`审批人${index + 1}:`, { - id: approver.id, - userId: approver.userId, - userName: approver.userName, - deptName: approver.deptName, - order: approver.order, - status: approver.status, - approveStatus: approver.approveStatus - }); - }); - const currentUserApprover = approvers.value.find(approver => { const matchByUserId = approver.userId === currentUserId; const matchById = approver.id === currentUserId; - console.log(`检查审批人 ${approver.userName}:`, { - userId: approver.userId, - id: approver.id, - currentUserId: currentUserId, - matchByUserId, - matchById - }); return matchByUserId || matchById; }); - console.log('找到的审批人记录:', currentUserApprover); - const result = currentUserApprover?.id || null; - console.log('返回结果:', result); - - return result; + return currentUserApprover?.id || null; }; // 预览单个附件(从gwInfo直接获取) const previewSingleFile = () => { - console.log("=== 预览单个附件 ==="); - console.log("附件信息:", { - fileUrl: gwInfo.value.fileUrl, - fileName: gwInfo.value.fileName, - fileFormat: gwInfo.value.fileFormat - }); - if (!gwInfo.value.fileUrl) { - console.error("没有找到附件URL"); return; } @@ -785,10 +692,6 @@ const previewSingleFile = () => { const fileName = gwInfo.value.fileName || '未知文件'; const fileFormat = gwInfo.value.fileFormat || ''; - console.log("处理后的文件URL:", fileUrl); - console.log("文件名:", fileName); - console.log("文件格式:", fileFormat); - // 根据文件类型选择预览方式 if (isVideo(fileFormat)) { handlePreviewVideoSingle(fileUrl, fileName); @@ -805,7 +708,6 @@ const previewSingleFile = () => { // 下载单个附件 const downloadSingleFile = () => { if (!gwInfo.value.fileUrl) { - console.error("没有找到附件URL"); return; } @@ -814,39 +716,64 @@ const downloadSingleFile = () => { const fileFormat = gwInfo.value.fileFormat || ''; const fullFileName = fileFormat ? `${fileName}.${fileFormat}` : fileName; - console.log("下载单个附件:", { fileUrl, fullFileName }); - - downloadFileUtil(fileUrl, fullFileName) - .then(() => { - console.log('文件下载成功'); + // 方法1: 使用 fetch 和 blob 方式强制下载 + fetch(fileUrl) + .then(response => { + if (!response.ok) { + throw new Error('网络请求失败'); + } + return response.blob(); + }) + .then(blob => { + const downloadUrl = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = downloadUrl; + link.download = fullFileName; // 使用 download 属性强制下载 + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(downloadUrl); + uni.showToast({ - title: '下载成功', + title: '开始下载', icon: 'success' }); }) - .catch((error: any) => { - console.error('文件下载失败:', error); - uni.showToast({ - title: '下载失败', - icon: 'error' - }); + .catch(error => { + console.error('fetch下载失败:', error); + // 方法2: 如果fetch失败,尝试直接打开链接 + try { + const link = document.createElement('a'); + link.href = fileUrl; + link.download = fullFileName; + link.target = '_blank'; + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + uni.showToast({ + title: '开始下载', + icon: 'success' + }); + } catch (fallbackError) { + console.error('备用下载也失败:', fallbackError); + uni.showToast({ + title: '下载失败', + icon: 'error' + }); + } }); }; // 文件预览 const previewFile = (file: FileInfo) => { - console.log("=== 处理文件预览 ==="); - console.log("文件信息:", file); - // 确定文件URL和名称 const fileUrl = file.resourUrl ? imagUrl(file.resourUrl) : file.url; const fileName = file.resourName ? `${file.resourName}.${file.resSuf}` : file.name; const fileSuf = file.resSuf || file.name.split('.').pop() || ''; - console.log("处理后的文件URL:", fileUrl); - console.log("文件名:", fileName); - console.log("文件后缀:", fileSuf); - // 根据文件类型选择预览方式 if (isVideo(fileSuf)) { handlePreviewVideo(file); @@ -867,11 +794,7 @@ const handlePreviewDocument = (file: FileInfo) => { const fileSuf = file.resSuf || file.name.split('.').pop() || ''; previewFileUtil(fileUrl, fileName, fileSuf) - .then(() => { - console.log('文档预览成功'); - }) .catch((error: any) => { - console.error('文档预览失败:', error); // 预览失败时尝试下载 downloadFileAction(file); }); @@ -882,11 +805,7 @@ const handlePreviewDocumentSingle = (fileUrl: string, fileName: string, fileForm const fullFileName = fileFormat ? `${fileName}.${fileFormat}` : fileName; previewFileUtil(fileUrl, fullFileName, fileFormat) - .then(() => { - console.log('单个附件文档预览成功'); - }) .catch((error: any) => { - console.error('单个附件文档预览失败:', error); // 预览失败时尝试下载 downloadSingleFile(); }); @@ -894,35 +813,20 @@ const handlePreviewDocumentSingle = (fileUrl: string, fileName: string, fileForm // 视频预览 const handlePreviewVideo = (file: FileInfo) => { - console.log('=== 处理视频预览 ==='); - console.log('视频文件:', file); - const videoUrl = file.resourUrl ? imagUrl(file.resourUrl) : file.url; const videoName = file.resourName || file.name; - console.log('处理后的视频URL:', videoUrl); - previewVideoUtil(videoUrl, videoName) - .then(() => { - console.log('视频预览成功'); - }) .catch((error: any) => { - console.error('视频预览失败:', error); + // 视频预览失败时的处理 }); }; // 单个附件视频预览 const handlePreviewVideoSingle = (videoUrl: string, videoName: string) => { - console.log('=== 处理单个附件视频预览 ==='); - console.log('视频URL:', videoUrl); - console.log('视频名称:', videoName); - previewVideoUtil(videoUrl, videoName) - .then(() => { - console.log('单个附件视频预览成功'); - }) .catch((error: any) => { - console.error('单个附件视频预览失败:', error); + // 视频预览失败时的处理 }); }; @@ -931,25 +835,16 @@ const handlePreviewImage = (file: FileInfo) => { const imageUrl = file.resourUrl ? imagUrl(file.resourUrl) : file.url; previewImageUtil(imageUrl) - .then(() => { - console.log('图片预览成功'); - }) .catch((error: any) => { - console.error('图片预览失败:', error); + // 图片预览失败时的处理 }); }; // 单个附件图片预览 const handlePreviewImageSingle = (imageUrl: string) => { - console.log('=== 处理单个附件图片预览 ==='); - console.log('图片URL:', imageUrl); - previewImageUtil(imageUrl) - .then(() => { - console.log('单个附件图片预览成功'); - }) .catch((error: any) => { - console.error('单个附件图片预览失败:', error); + // 图片预览失败时的处理 }); }; @@ -963,24 +858,54 @@ const downloadFileAction = (file: FileInfo) => { const fileUrl = file.resourUrl ? imagUrl(file.resourUrl) : file.url; const fileName = file.resourName ? `${file.resourName}.${file.resSuf}` : file.name; - console.log("下载文件:", file); - console.log("下载URL:", fileUrl); - console.log("文件名:", fileName); - - downloadFileUtil(fileUrl, fileName) - .then(() => { - console.log('文件下载成功'); + // 方法1: 使用 fetch 和 blob 方式强制下载 + fetch(fileUrl) + .then(response => { + if (!response.ok) { + throw new Error('网络请求失败'); + } + return response.blob(); + }) + .then(blob => { + const downloadUrl = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = downloadUrl; + link.download = fileName; // 使用 download 属性强制下载 + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(downloadUrl); + uni.showToast({ - title: '下载成功', + title: '开始下载', icon: 'success' }); }) - .catch((error: any) => { - console.error('文件下载失败:', error); - uni.showToast({ - title: '下载失败', - icon: 'error' - }); + .catch(error => { + console.error('fetch下载失败:', error); + // 方法2: 如果fetch失败,尝试直接打开链接 + try { + const link = document.createElement('a'); + link.href = fileUrl; + link.download = fileName; + link.target = '_blank'; + link.style.display = 'none'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + uni.showToast({ + title: '开始下载', + icon: 'success' + }); + } catch (fallbackError) { + console.error('备用下载也失败:', fallbackError); + uni.showToast({ + title: '下载失败', + icon: 'error' + }); + } }); }; @@ -1150,113 +1075,74 @@ const getCreatorName = (tjrId: string) => { // 如果缓存中没有找到,返回ID return `用户${tjrId}`; } catch (error) { - console.error("获取创建人信息失败:", error); return `用户${tjrId}`; } }; onMounted(() => { - console.log("=== onMounted 开始执行 ==="); - // 尝试多种方式获取页面参数 let pageId = ""; // 方式1: 通过 getCurrentPages() 获取 const pages = getCurrentPages(); - console.log("getCurrentPages() 结果:", pages); if (pages.length > 0) { const currentPage = pages[pages.length - 1]; - console.log("当前页面对象:", currentPage); // 尝试不同的属性获取参数 const options = (currentPage as any).options || {}; - const route = (currentPage as any).route || ""; - const fullPath = (currentPage as any).fullPath || ""; - - console.log("页面参数 options:", options); - console.log("页面路由 route:", route); - console.log("完整路径 fullPath:", fullPath); pageId = options.id || ""; } // 方式2: 如果方式1没有获取到,尝试从URL解析 if (!pageId) { - console.log("尝试从URL解析参数"); try { // 获取当前页面URL const currentUrl = window.location.href; - console.log("当前页面URL:", currentUrl); // 在uni-app H5环境中,参数通常在hash部分 const hash = window.location.hash; - console.log("页面hash:", hash); if (hash && hash.includes('?')) { // 从hash中提取查询参数 const queryString = hash.split('?')[1]; - console.log("查询参数字符串:", queryString); // 解析查询参数 const urlParams = new URLSearchParams(queryString); pageId = urlParams.get('id') || ""; - console.log("从hash解析到的id:", pageId); } else { // 尝试从search部分解析(备用方案) const urlParams = new URLSearchParams(window.location.search); pageId = urlParams.get('id') || ""; - console.log("从search解析到的id:", pageId); } } catch (error) { - console.log("URL解析失败:", error); + // URL解析失败 } } // 方式3: 如果前两种方式都没有获取到,尝试从路由参数获取 if (!pageId) { - console.log("尝试从路由参数获取"); try { // 获取当前页面的完整路径 const currentPath = window.location.pathname; - console.log("当前页面路径:", currentPath); // 从路径中提取参数(如果路径包含参数) const pathMatch = currentPath.match(/\/gwFlow\/([^/?]+)/); if (pathMatch) { pageId = pathMatch[1]; - console.log("从路径提取的id:", pageId); } } catch (error) { - console.log("路径解析失败:", error); + // 路径解析失败 } } // 设置gwId gwId.value = pageId; - console.log("最终获取到的 gwId:", gwId.value); if (gwId.value) { - console.log("gwId 存在,开始调用 getGwInfo()"); getGwInfo(); - } else { - console.log("gwId 不存在,无法调用接口"); - console.log("请检查URL参数是否正确,例如: ?id=1157408920235544576"); - - // 显示调试信息 - console.log("=== 调试信息 ==="); - console.log("当前页面完整信息:", { - href: window.location.href, - pathname: window.location.pathname, - search: window.location.search, - hash: window.location.hash - }); - - // 不再需要测试ID,因为参数解析已经修复 - console.log("参数解析完成,但未找到有效的ID"); } - - console.log("=== onMounted 执行完成 ==="); }); diff --git a/src/pages/view/routine/gwlz/index.vue b/src/pages/view/routine/gwlz/index.vue index ea46c33..f5d6f9a 100644 --- a/src/pages/view/routine/gwlz/index.vue +++ b/src/pages/view/routine/gwlz/index.vue @@ -1,104 +1,110 @@ --> - + + + + + + {{ tab.label }} + + + + + + + + + + 加载中... + + + + + + + {{ data.title }} + + {{ getStatusText(data.gwStatus) }} + + + + + + + 类型: + {{ data.docType }} + 提交时间: + {{ formatDate(data.tjrtime) }} + + + + + + + + + + 📄 + + {{ getFileName(file) }} + + + + + + + + + + + + + + + 暂无数据 + + @@ -108,21 +114,12 @@ import { ref, computed, watch, onMounted, onUnmounted } from "vue"; import { onShow } from "@dcloudio/uni-app"; import { navigateTo } from "@/utils/uniapp"; import BasicSearch from "@/components/BasicSearch/Search.vue"; -import BasicLayout from "@/components/BasicLayout/Layout.vue"; -import BasicListLayout from "@/components/BasicListLayout/ListLayout.vue"; -import { useLayout } from "@/components/BasicListLayout/hooks/useLayout"; -import { gwFindPageApi } from "@/api/routine/gw"; +import { gwFindPageApi, findUserTodosApi } from "@/api/routine/gw"; import dayjs from "dayjs"; import { imagUrl } from "@/utils"; import { useUserStore } from "@/store/modules/user"; import { - isVideo, - isImage, - canPreview, - previewFile as previewFileUtil, - previewVideo as previewVideoUtil, - previewImage as previewImageUtil, - downloadFile as downloadFileUtil + previewFile as previewFileUtil } from "@/utils/filePreview"; // 附件类型定义 @@ -153,32 +150,20 @@ interface GwListItem { // 筛选标签 const filterTabs = [ + { key: "pending", label: "待办" }, + { key: "approved", label: "已办" }, { key: "all", label: "全部" }, - { key: "C", label: "审批中" }, - { key: "D", label: "已完结" }, ]; -const activeTab = ref("all"); +const activeTab = ref("pending"); const searchKeyword = ref(""); // 获取用户store const userStore = useUserStore(); -// 使用 BasicListLayout -const [register, { reload, setParam }] = useLayout({ - api: gwFindPageApi, - componentProps: { - defaultPageSize: 20, - }, - param: { - title: "", - docType: "", - gwStatus: "", - }, -}); - // 数据列表 const dataList = ref([]); +const loading = ref(false); // 获取当前教师ID const getCurrentTeacherId = () => { @@ -190,12 +175,13 @@ const getCurrentTeacherId = () => { const filteredGwList = computed(() => { let list = dataList.value; - // 按状态筛选 - if (activeTab.value !== "all") { - list = list.filter((item: GwListItem) => item.gwStatus === activeTab.value); + // 对于待办/已办标签,数据已经通过API筛选,不需要再次筛选 + // 只对"全部"标签进行状态筛选 + if (activeTab.value === "all") { + // 这里可以添加额外的筛选逻辑,如果需要的话 } - // 按关键词搜索 + // 按关键词搜索(对所有标签都适用) if (searchKeyword.value) { const keyword = searchKeyword.value.toLowerCase(); list = list.filter((item: GwListItem) => @@ -211,21 +197,135 @@ const filteredGwList = computed(() => { // 切换筛选标签 const switchTab = (tabKey: string) => { activeTab.value = tabKey; - // 更新查询参数并重新加载 - const gwStatus = tabKey === "all" ? "" : tabKey; - setParam({ gwStatus }); - reload(); + + // 获取当前教师ID + const currentTeacherId = getCurrentTeacherId(); + + if (tabKey === "all") { + // 全部:调用 findPage API + loadAllData(); + } else if (tabKey === "pending") { + // 待办:只调用 findUserTodos API,传 approveStatus = 'pending' + if (currentTeacherId) { + loadUserTodos('pending', currentTeacherId); + } else { + uni.showToast({ + title: '无法获取用户信息', + icon: 'error' + }); + } + } else if (tabKey === "approved") { + // 已办:只调用 findUserTodos API,传 approveStatus = 'approved' + if (currentTeacherId) { + loadUserTodos('approved', currentTeacherId); + } else { + uni.showToast({ + title: '无法获取用户信息', + icon: 'error' + }); + } + } +}; + +// 加载全部数据(调用 findPage 接口) +const loadAllData = async () => { + try { + loading.value = true; + uni.showLoading({ title: '加载中...' }); + + const response = await gwFindPageApi({ + title: searchKeyword.value, + docType: searchKeyword.value, + gwStatus: "" + }); + + // 检查响应格式 - 根据实际返回的数据结构 + const result = (response as any).data || response; + + // 适配分页查询返回的数据结构 {total, page, records, rows} + if (result.rows && Array.isArray(result.rows)) { + dataList.value = result.rows; + } else if (result.resultCode === 1) { + // 兼容旧的数据结构 + dataList.value = result.result || []; + } else { + uni.showToast({ + title: result.message || '加载失败', + icon: 'error' + }); + dataList.value = []; + } + } catch (error) { + console.error('加载全部数据失败:', error); + uni.showToast({ + title: '加载失败', + icon: 'error' + }); + dataList.value = []; + } finally { + loading.value = false; + uni.hideLoading(); + } +}; + +// 加载用户待办/已办数据(只调用 findUserTodos 分页接口) +const loadUserTodos = async (approveStatus: string, jsId: string) => { + try { + loading.value = true; + uni.showLoading({ title: '加载中...' }); + + // 只调用 findUserTodos 分页接口 + const response = await findUserTodosApi(approveStatus, jsId, 1, 1000); // 设置较大的pageSize以获取所有数据 + + // 检查响应格式 - 根据实际返回的数据结构 + const result = (response as any).data || response; + + // 适配分页查询返回的数据结构 {total, page, records, rows} + if (result.rows && Array.isArray(result.rows)) { + dataList.value = result.rows; + } else if (result.resultCode === 1) { + // 兼容旧的数据结构 + dataList.value = result.result || []; + } else { + uni.showToast({ + title: result.message || '加载失败', + icon: 'error' + }); + dataList.value = []; + } + } catch (error) { + console.error('加载用户待办/已办数据失败:', error); + uni.showToast({ + title: '加载失败', + icon: 'error' + }); + dataList.value = []; + } finally { + loading.value = false; + uni.hideLoading(); + } }; // 搜索处理 const handleSearch = (keyword: string) => { searchKeyword.value = keyword; - // 更新查询参数并重新加载,支持按标题和类型搜索 - setParam({ - title: keyword, - docType: keyword // 同时按类型搜索 - }); - reload(); + + // 根据当前标签决定搜索方式 + if (activeTab.value === "all") { + // 全部:使用 findPage API 搜索 + loadAllData(); + } else { + // 待办/已办:只调用 findUserTodos 接口 + const currentTeacherId = getCurrentTeacherId(); + if (currentTeacherId) { + loadUserTodos(activeTab.value, currentTeacherId); + } else { + uni.showToast({ + title: '无法获取用户信息', + icon: 'error' + }); + } + } }; // 跳转到详情页面 @@ -351,7 +451,6 @@ const parseFileList = (data: any) => { // 预览单个附件(从data直接获取) const previewAttachment = (data: any) => { if (!data.fileUrl) { - console.error("没有找到附件URL"); return; } @@ -359,24 +458,16 @@ const previewAttachment = (data: any) => { const fileName = data.fileName || '未知文件'; const fileFormat = data.fileFormat || ''; - // 根据文件类型选择预览方式 - if (isVideo(fileFormat)) { - previewVideoUtil(fileUrl, fileName) - .then(() => console.log('视频预览成功')) - .catch((error: any) => console.error('视频预览失败:', error)); - } else if (isImage(fileFormat)) { - previewImageUtil(fileUrl) - .then(() => console.log('图片预览成功')) - .catch((error: any) => console.error('图片预览失败:', error)); - } else if (canPreview(fileFormat)) { + + // 统一使用 kkview 预览 const fullFileName = fileFormat ? `${fileName}.${fileFormat}` : fileName; previewFileUtil(fileUrl, fullFileName, fileFormat) - .then(() => console.log('文档预览成功')) - .catch((error: any) => console.error('文档预览失败:', error)); - } else { - // 不支持预览的文件类型,直接下载 - downloadAttachment(data); - } + .catch((error: any) => { + uni.showToast({ + title: '预览失败', + icon: 'error' + }); + }); }; // 预览附件文件(从files数组获取) @@ -386,84 +477,21 @@ const previewAttachmentFile = (file: FileInfo) => { const fileSuf = getFileSuffix(file); if (!fileUrl) { - console.error("没有找到文件URL"); return; } - // 根据文件类型选择预览方式 - if (isVideo(fileSuf)) { - previewVideoUtil(fileUrl, fileName) - .then(() => console.log('视频预览成功')) - .catch((error: any) => console.error('视频预览失败:', error)); - } else if (isImage(fileSuf)) { - previewImageUtil(fileUrl) - .then(() => console.log('图片预览成功')) - .catch((error: any) => console.error('图片预览失败:', error)); - } else if (canPreview(fileSuf)) { - previewFileUtil(fileUrl, fileName, fileSuf) - .then(() => console.log('文档预览成功')) - .catch((error: any) => console.error('文档预览失败:', error)); - } else { - // 不支持预览的文件类型,直接下载 - downloadAttachmentFile(file); - } -}; - -// 下载单个附件 -const downloadAttachment = (data: any) => { - if (!data.fileUrl) { - console.error("没有找到附件URL"); - return; - } - const fileUrl = imagUrl(data.fileUrl); - const fileName = data.fileName || '未知文件'; - const fileFormat = data.fileFormat || ''; - const fullFileName = fileFormat ? `${fileName}.${fileFormat}` : fileName; - - downloadFileUtil(fileUrl, fullFileName) - .then(() => { - console.log('文件下载成功'); - uni.showToast({ - title: '下载成功', - icon: 'success' - }); - }) + // 统一使用 kkview 预览 + const fullFileName = fileSuf ? `${fileName}.${fileSuf}` : fileName; + previewFileUtil(fileUrl, fullFileName, fileSuf) .catch((error: any) => { - console.error('文件下载失败:', error); uni.showToast({ - title: '下载失败', + title: '预览失败', icon: 'error' }); }); }; -// 下载附件文件 -const downloadAttachmentFile = (file: FileInfo) => { - const fileUrl = file.resourUrl ? imagUrl(file.resourUrl) : (file.url ? imagUrl(file.url) : ''); - const fileName = file.resourName || file.name || '未知文件'; - - if (!fileUrl) { - console.error("没有找到文件URL"); - return; - } - - downloadFileUtil(fileUrl, fileName) - .then(() => { - console.log('文件下载成功'); - uni.showToast({ - title: '下载成功', - icon: 'success' - }); - }) - .catch((error: any) => { - console.error('文件下载失败:', error); - uni.showToast({ - title: '下载失败', - icon: 'error' - }); - }); -}; // 获取文件名 const getFileName = (file: FileInfo) => { @@ -508,17 +536,51 @@ watch(dataList, (val) => { // 页面显示时重新加载数据 onShow(() => { - reload(); + if (activeTab.value === "all") { + loadAllData(); + } else { + // 对于待办/已办,只调用 findUserTodos 接口 + const currentTeacherId = getCurrentTeacherId(); + if (currentTeacherId) { + loadUserTodos(activeTab.value, currentTeacherId); + } else { + uni.showToast({ + title: '无法获取用户信息', + icon: 'error' + }); + } + } }); // 页面加载时也加载一次数据 onMounted(() => { - reload(); + // 默认加载"待办"数据,只调用 findUserTodos 接口 + const currentTeacherId = getCurrentTeacherId(); + if (currentTeacherId) { + loadUserTodos('pending', currentTeacherId); + } else { + uni.showToast({ + title: '无法获取用户信息', + icon: 'error' + }); + } // 监听来自gwFlow页面的刷新事件 uni.$on('refreshGwList', () => { - console.log('收到刷新事件,重新加载数据'); - reload(); + if (activeTab.value === "all") { + loadAllData(); + } else { + // 对于待办/已办,只调用 findUserTodos 接口 + const currentTeacherId = getCurrentTeacherId(); + if (currentTeacherId) { + loadUserTodos(activeTab.value, currentTeacherId); + } else { + uni.showToast({ + title: '无法获取用户信息', + icon: 'error' + }); + } + } }); }); @@ -560,8 +622,14 @@ onUnmounted(() => { margin-bottom: 12px; } +.search-container { + display: flex; + gap: 8px; + align-items: center; +} + .search-input { - width: 100%; + flex: 1; height: 40px; background-color: #f8f9fa; border: 1px solid #e9ecef; @@ -571,6 +639,15 @@ onUnmounted(() => { color: #333; } +.search-button { + height: 40px !important; + width: 15% !important; + border-radius: 8px !important; + font-size: 14px !important; + font-weight: 500 !important; + flex-shrink: 0 !important; +} + .filter-tabs { display: flex; gap: 8px; @@ -722,7 +799,8 @@ onUnmounted(() => { border-radius: 6px; cursor: pointer; transition: all 0.3s ease; - max-width: 200px; + flex: 1; + min-width: 0; &:active { transform: translateY(1px); @@ -743,6 +821,7 @@ onUnmounted(() => { text-overflow: ellipsis; white-space: nowrap; flex: 1; + min-width: 0; } } @@ -814,6 +893,49 @@ onUnmounted(() => { } } +// 列表内容样式 +.list-content { + flex: 1; + padding: 15px; + overflow-y: auto; +} + +// 加载状态样式 +.loading-container { + display: flex; + justify-content: center; + align-items: center; + padding: 40px 20px; + background-color: white; + border-radius: 8px; + margin-bottom: 15px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); +} + +.loading-text { + font-size: 14px; + color: #666; + text-align: center; +} + +// 空状态样式 +.empty-container { + display: flex; + justify-content: center; + align-items: center; + padding: 60px 20px; + background-color: white; + border-radius: 8px; + margin-bottom: 15px; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); +} + +.empty-text { + font-size: 14px; + color: #999; + text-align: center; +} + // 加载动画 .gw-card { animation: fadeInUp 0.3s ease-out;