From e87a06415611a280cddc0180f8b19a22523504f2 Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Tue, 13 May 2025 15:45:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E6=A8=A1=E5=9D=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=B8=8E=E5=85=A8=E9=9D=A2=E9=A1=B9=E7=9B=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E8=B0=83=E6=95=B4=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 类型定义: - 完善 SurveyItem 类型定义,添加所有必要字段 - 优化类型注解,增强代码可维护性 - 更新 components.d.ts 类型声明文件 2. 组件重构: - 将 SuvreyItem 组件变量名从 item 统一修改为 survey - 添加类型标注,提高代码健壮性 - 修复模板中的变量引用 - 优化 MarketItem、Navigation 和 Search 组件 3. 功能优化: - 将删除和保存模板功能从 Index.vue 移至 useSurveyData.ts 钩子中 - 优化函数导出,提高代码复用性 - 改进 Home 组件与问卷模块的交互逻辑 4. 样式优化: - 精简 SCSS 代码,移除冗余样式和注释 - 将样式从 Index.vue 移至 SuvreyItem.vue 组件内部 - 优化样式结构,提高可维护性 5. 资源添加: - 新增 tabbar 图标资源,统一底部导航栏样式 --- components.d.ts | 3 + public/tabbar/home.png | Bin 0 -> 829 bytes public/tabbar/mine.png | Bin 0 -> 488 bytes public/tabbar/yl.png | Bin 0 -> 1543 bytes src/components/MarketItem/MarketItem.vue | 95 ++--- src/components/Navigation/Index.vue | 44 +- src/components/Search/Index.vue | 5 +- src/layouts/redirect.vue | 18 +- src/views/Home/Index.vue | 16 +- src/views/Home/components/Market/Index.vue | 41 +- src/views/Home/components/NewSurvey/index.vue | 3 +- src/views/Survey/Index.vue | 401 +----------------- .../Survey/components/EmptyContainer.vue | 19 + src/views/Survey/components/SuvreyItem.vue | 339 +++++++++++++++ src/views/Survey/hooks/useSurveyData.ts | 95 +++++ src/views/Survey/types/survey.d.ts | 18 + 16 files changed, 612 insertions(+), 485 deletions(-) create mode 100644 public/tabbar/home.png create mode 100644 public/tabbar/mine.png create mode 100644 public/tabbar/yl.png create mode 100644 src/views/Survey/components/EmptyContainer.vue create mode 100644 src/views/Survey/components/SuvreyItem.vue create mode 100644 src/views/Survey/hooks/useSurveyData.ts create mode 100644 src/views/Survey/types/survey.d.ts diff --git a/components.d.ts b/components.d.ts index d721417..7b3424c 100644 --- a/components.d.ts +++ b/components.d.ts @@ -17,6 +17,7 @@ declare module 'vue' { ElDropdown: typeof import('element-plus/es')['ElDropdown'] ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem'] ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu'] + ElEmpty: typeof import('element-plus/es')['ElEmpty'] ElIcon: typeof import('element-plus/es')['ElIcon'] ElInput: typeof import('element-plus/es')['ElInput'] ElOption: typeof import('element-plus/es')['ElOption'] @@ -59,6 +60,8 @@ declare module 'vue' { VanStepper: typeof import('vant/es')['Stepper'] VanSwitch: typeof import('vant/es')['Switch'] VanTab: typeof import('vant/es')['Tab'] + VanTabbar: typeof import('vant/es')['Tabbar'] + VanTabbarItem: typeof import('vant/es')['TabbarItem'] VanTabs: typeof import('vant/es')['Tabs'] VanTag: typeof import('vant/es')['Tag'] YLCascader: typeof import('./src/components/YLCascader.vue')['default'] diff --git a/public/tabbar/home.png b/public/tabbar/home.png new file mode 100644 index 0000000000000000000000000000000000000000..6d181be451b136c41f72630a4a38a9c3a52ada98 GIT binary patch literal 829 zcmV-D1H$}?P)Px%_en%SRA@u(n9pkyK@`W|n@!VH+KNg*FvPf>-9Vry9;6q&Sn$WeOTj~rqWA}R z(Z9iyc<8~K;z1Cv76nfVMf6yu-AOh=LF+|5XezsTPX-z&Ym?o{ZUTkf>%1SI`Ocf& zeGlP)K6pU6AqOA#$>oXz)RHMF5yF1z_fYncpg<-T^>p;y*OF>$)cZ;0gd#OcL&AOGG~b;FVJ9 zQ_@(*;N^08dUkep(XuS9w6XsnFlKJ=*8g_g222uLb8~YGmSyQ$o{S4T>^czD zr%I`2G*&FQl=6lUqM8+(@nrjK``t5$R6;Z?B_A#3CYE!|Y=$;LQ9-w_%>=tph-? z2UJKYPXWMXAw=0^10x65%`Xu>YBrnS`+?PJwbI1I#4SWTmK1*E;N5O_t=Vj@#sS&3 zJzppkmg4Ms>mvte=4YPg=}FbVr(UnmF!P-_yRm^2(Ubk!tSF!^mtwJaHwTX@;5d%a z|9Gx=M8T0?&Rp@dic2Z42_eoVz5PKDtoXhkJNMHwN7r@l0YEWHY$DoLO06XBIjhy` zky5F&3;+W^(R$*<%}%U@xAi|s zH;H-?8?4o80|%(l30BWP5%>^5BX`NcM=o)+#>Sm6t9<_euBE^}2Kpu{00000NkvXX Hu0mjfJ>!HR literal 0 HcmV?d00001 diff --git a/public/tabbar/mine.png b/public/tabbar/mine.png new file mode 100644 index 0000000000000000000000000000000000000000..15c4ad3d1f620c20687a87b4f94e4bdafdf3691b GIT binary patch literal 488 zcmVP)Y=_g7NpX%e(}Y_H}N^xllr||UF^ER+{KU# z5_YcPJX#I5TL9+F(N#eMCv#ow`r^id_ZQ|mQR%9nG|+XT5`Zk#XQvWm|MDLFOBx$= z##KxK7y|?#o+1UKN`5@hz?+gcgE<;s!nC13kdsi(0PP9E+Ac~H;dVOu{K0E(csDPs zI*!{s+sd?BX&Mn~*~?*P_fiXAI-kzPM5q}dse;Do#OBc}Y|Lpz^4_{`Y8VgC) zl!HbnNF|;6+WE}dho_vJ{unAbK8;v=zfAaZZ`c)5DF=Jsg3F1y&O4&!2&Y eoTc@@oAwW8ZLx8!_ZTPu0000Px)!AV3xRA@u(m~Tu~WgN%9zvtZBfq^bSnyykuFo=p?xWt%Dti(BVjm>hc7j3=> z+qefv%C+S>FIuzF!h7LGt7W>W8~xGNbkpf7UD2qNFvP};;h)?vya*xQd%5TN#e-gU zfpfW+>t(xao|otRe$VrHzR&N^a~{GxeQ2I?BVpi;jg8M~n)Vfd%qU`X=(@h9s;X-6 zUPMb6xX0u91VB|RFwDH6rl#gtEVhwsVg@%&^MS0atQ;w2T4*pL>XcG07eYJ%;0*vT z#0c{NfHMG2N-0x`=#h}0lyXGVv>wAS{4fu6S8Wxuv$YR^`pKC#vEe zkEad5N?T{5)y(`DfPHZ&u0r8ar7RKENAT}74CAS|z};@QpNJl?b7tnx2L=XS&&bGl znTQ^a6`t=rKRcby^Oj}(31E2yUuhVI78kh35)~#ESl9GaR=gy(1s0d2wsnCk3qM`yhIXSj)Jv}`*di1F6 zHzK;g%wGT~F$|+JVVyH8D+`sCl}JrZ#qHa-ZJ|SxIUEjKxL`0CN$mlj&sXShI08dM zL&K(N1`-CY22$|F#l>iAYnv1vQTINI0W((<(QoQ3LqsZBb{K}C4snw@c(S$pc3szt zeLmkWM6@Dojjfhty;@gS*Bg45OyH84ONpotzz^!k8@@S2^p4Br+Lespd!0__yM29q z|E8s-Idxs%$;@?kkJSD^Adp{QUwUS42-y)(tVIRI89UXmh`}XZuOw&v; zP1Bcf@KAZwbsa~J9KoeacXl*AJspb{Et;4w5D1Jnt|?FZ@bK`u^z?MqjUJlvZ5Y7g zhGATt>J(RUs-~hk0^7E28}F8C7J; z9sP2w{H?L^IiP9UN6aj$tEFx7{d144)b zW^Nig8<{Sb>-U6#&jN6oDG~h<3~cgMX#rd%BGvlGpJY(H!|U~~%FN9C3&1iP@V^15 zd-h)e6otN9mQ`3+S9c+vsxkr~^wrfI5!*7RNw%fxQC`*|X222c=-eFU3G;3olW1kepY-DRjczQ^nJ z?u-OIp0u+8X=rFj(=<(=jZesSXlO{Cr+o_-E_^WD-{ElF(sf<)`~CSsh+F;r{k@U? t?8E(L1s)IZT>0DwpDSe}jXQ4@{~whWqD@tGDzN|n002ovPDHLkV1jBz-sJ!Q literal 0 HcmV?d00001 diff --git a/src/components/MarketItem/MarketItem.vue b/src/components/MarketItem/MarketItem.vue index 80bc7db..b307303 100644 --- a/src/components/MarketItem/MarketItem.vue +++ b/src/components/MarketItem/MarketItem.vue @@ -1,54 +1,51 @@ @@ -135,13 +132,15 @@ onMounted(() => { \ No newline at end of file diff --git a/src/views/Survey/components/SuvreyItem.vue b/src/views/Survey/components/SuvreyItem.vue new file mode 100644 index 0000000..42f0070 --- /dev/null +++ b/src/views/Survey/components/SuvreyItem.vue @@ -0,0 +1,339 @@ + + + + + \ No newline at end of file diff --git a/src/views/Survey/hooks/useSurveyData.ts b/src/views/Survey/hooks/useSurveyData.ts new file mode 100644 index 0000000..09fdf0e --- /dev/null +++ b/src/views/Survey/hooks/useSurveyData.ts @@ -0,0 +1,95 @@ +import { + getSurveysPage, deleteSurveys, + saveTemplates +} from '@/api/home'; +import { ref } from 'vue'; +import { + showDialog, + showConfirmDialog, + showFailToast, + showToast +} from 'vant'; + +const form = ref({ + page: 0, + pageSize: 10, + project_name: '' +}); + +const searchValue = ref(''); +const survey = ref([]); +const total = ref(0); +const loading = ref(false); +const finished = ref(false); + +async function fetchSurveys() { + const params = { + page: form.value.page, + per_page: form.value.pageSize, + group_id: 0, + project_name: searchValue.value + }; + const res = await getSurveysPage(params); + if (res.data.code === 0) { + survey.value = survey.value.concat(res.data.data); + total.value = res.data.meta.total; + survey.value.forEach((item) => { + const sceneName = JSON.parse(JSON.stringify(item.scene_name)); + const nameList = sceneName.split('-'); + if (nameList.length > 0) { + item.scene_name = nameList[1] ? nameList[1] : nameList[0]; + } + + const timeList = item.created_at.split(' '); + if (nameList.length) { + item.created_at = timeList[0]; + } + }); + loading.value = false; + // 数据全部加载完成 + if (survey.value.length >= total.value) { + finished.value = true; + } + } else { + // Toast() + } +}; + +function deleteItem(item) { + showDialog({ + title: `确认删除问卷${item.project_name} ?`, + showCancelButton: true, + confirmButtonColor: '#03B03C' + }) + .then(async () => { + const res = await deleteSurveys(item.sn); + if (res.data.message) { + showToast(res.data.message); + } else { + showToast('删除成功!'); + } + form.value.page = 1; + survey.value = []; + await fetchSurveys(); + }) + .catch(() => { + // on cancel + }); +}; + +// 保存为模板 +async function saveTemplate(item) { + const data = JSON.parse(JSON.stringify(item)); + const res = await saveTemplates(item.sn, data); + if (res.data.code === 200 || res.data.code === 201) { + showConfirmDialog({ + message: '模板保存成功,请前往模板市场查看!', + showCancelButton: false + }); + } else { + showFailToast(res.data); + } +} +; + +export { form, fetchSurveys, loading, finished, survey, total, searchValue, deleteItem, saveTemplate }; \ No newline at end of file diff --git a/src/views/Survey/types/survey.d.ts b/src/views/Survey/types/survey.d.ts new file mode 100644 index 0000000..1839f39 --- /dev/null +++ b/src/views/Survey/types/survey.d.ts @@ -0,0 +1,18 @@ +type SurveyItem = { + scene_name: string + project_name: string + created_at: string + created_user?: string + scene_code_info?: number + owner?: string + source?: number + status?: number + answer_num?: number | string + recycle_progress?: string + recycle_time?: string + sn: string + is_time?: boolean + start_time?: string + end_time?: string | null + status_txt?: string +} \ No newline at end of file