hookehuyr

refactor(CheckInList): 移除未使用的二级弹框代码并优化格式

清理不再使用的课程列表弹框相关代码,包括组件逻辑和模板
优化模板格式以提高可读性
1 <template> 1 <template>
2 <!-- 列表主体 --> 2 <!-- 列表主体 -->
3 <div :class="wrapper_class" :style="scroll_style"> 3 <div :class="wrapper_class" :style="scroll_style">
4 - <button 4 + <button v-for="item in items" :key="item.id"
5 - v-for="item in items"
6 - :key="item.id"
7 class="CheckInListItem flex flex-col items-center p-2 rounded-lg border transition-colors bg-white/70 border-gray-100 hover:bg-white" 5 class="CheckInListItem flex flex-col items-center p-2 rounded-lg border transition-colors bg-white/70 border-gray-100 hover:bg-white"
8 - :class="{ 'is-active': selected_item?.id === item.id }" 6 + :class="{ 'is-active': selected_item?.id === item.id }" @click="handle_select(item)">
9 - @click="handle_select(item)"
10 - >
11 <div class="Icon w-12 h-12 rounded-full flex items-center justify-center mb-1 transition-colors bg-gray-100" 7 <div class="Icon w-12 h-12 rounded-full flex items-center justify-center mb-1 transition-colors bg-gray-100"
12 - :class="{ 'is-active': selected_item?.id === item.id }" 8 + :class="{ 'is-active': selected_item?.id === item.id }">
13 - > 9 + <van-icon v-if="item.task_type === 'checkin'" name="edit" size="1.5rem"
14 - <van-icon v-if="item.task_type === 'checkin'" name="edit" size="1.5rem" :color="item.is_gray ? 'gray' : ''" /> 10 + :color="item.is_gray ? 'gray' : ''" />
15 - <van-icon v-if="item.task_type === 'upload'" name="tosend" size="1.5rem" :color="item.is_gray ? 'gray' : ''" /> 11 + <van-icon v-if="item.task_type === 'upload'" name="tosend" size="1.5rem"
16 - <van-icon v-if="item.task_type === 'count'" name="point-gift-o" size="1.5rem" :color="item.is_gray ? 'gray' : ''" /> 12 + :color="item.is_gray ? 'gray' : ''" />
13 + <van-icon v-if="item.task_type === 'count'" name="point-gift-o" size="1.5rem"
14 + :color="item.is_gray ? 'gray' : ''" />
17 </div> 15 </div>
18 <span :class="['text-xs', item.is_gray ? 'text-gray-500' : '']">{{ item.name }}</span> 16 <span :class="['text-xs', item.is_gray ? 'text-gray-500' : '']">{{ item.name }}</span>
19 </button> 17 </button>
...@@ -23,9 +21,7 @@ ...@@ -23,9 +21,7 @@
23 <div v-if="selected_item" class="mt-3"> 21 <div v-if="selected_item" class="mt-3">
24 <button 22 <button
25 class="SubmitBtn mt-2 w-full bg-gradient-to-r from-green-500 to-green-600 text-white py-2 rounded-lg flex items-center justify-center" 23 class="SubmitBtn mt-2 w-full bg-gradient-to-r from-green-500 to-green-600 text-white py-2 rounded-lg flex items-center justify-center"
26 - @click="handle_submit" 24 + @click="handle_submit" :disabled="submitting">
27 - :disabled="submitting"
28 - >
29 <template v-if="submitting"> 25 <template v-if="submitting">
30 <div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"></div> 26 <div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"></div>
31 提交中... 27 提交中...
...@@ -35,7 +31,7 @@ ...@@ -35,7 +31,7 @@
35 </div> 31 </div>
36 32
37 <!-- 二级弹框(课程列表,使用mock数据) --> 33 <!-- 二级弹框(课程列表,使用mock数据) -->
38 - <van-popup 34 + <!--<van-popup
39 :show="inner_popup_show" 35 :show="inner_popup_show"
40 @update:show="(v) => inner_popup_show = v" 36 @update:show="(v) => inner_popup_show = v"
41 round 37 round
...@@ -49,21 +45,21 @@ ...@@ -49,21 +45,21 @@
49 <h3 class="font-medium">课程列表</h3> 45 <h3 class="font-medium">课程列表</h3>
50 <van-icon name="cross" @click="close_inner_popup" /> 46 <van-icon name="cross" @click="close_inner_popup" />
51 </div> 47 </div>
52 - <!-- 简单文本列表:仅显示标题与开始/结束日期 --> 48 + <!~~ 简单文本列表:仅显示标题与开始/结束日期 ~~>
53 <div class="rounded-lg bg-white/80 divide-y"> 49 <div class="rounded-lg bg-white/80 divide-y">
54 <div v-for="task in inner_courses" :key="task.id" class="taskItem bg-white rounded-lg shadow px-4 py-3 mb-3" @click="handle_click(task)"> 50 <div v-for="task in inner_courses" :key="task.id" class="taskItem bg-white rounded-lg shadow px-4 py-3 mb-3" @click="handle_click(task)">
55 <div class="flex items-center justify-between"> 51 <div class="flex items-center justify-between">
56 - <!-- 左侧图标:垂直居中,占用较小空间 --> 52 + <!~~ 左侧图标:垂直居中,占用较小空间 ~~>
57 <div class="iconWrapper flex items-center justify-center w-8 mr-3 text-gray-500"> 53 <div class="iconWrapper flex items-center justify-center w-8 mr-3 text-gray-500">
58 <van-icon name="notes-o" size="1.2rem" /> 54 <van-icon name="notes-o" size="1.2rem" />
59 </div> 55 </div>
60 - <!-- 中间内容:占据剩余空间 --> 56 + <!~~ 中间内容:占据剩余空间 ~~>
61 <div class="left flex-1"> 57 <div class="left flex-1">
62 <div class="taskTitle text-sm font-semibold text-gray-800">{{ task.title }}</div> 58 <div class="taskTitle text-sm font-semibold text-gray-800">{{ task.title }}</div>
63 <div class="taskDates text-xs text-gray-600 mt-1">开始时间:{{ dayjs(task.begin_date).format('YYYY-MM-DD') }}</div> 59 <div class="taskDates text-xs text-gray-600 mt-1">开始时间:{{ dayjs(task.begin_date).format('YYYY-MM-DD') }}</div>
64 <div v-if="task.end_date" class="taskDates text-xs text-gray-600 mt-1">截止时间:{{ dayjs(task.end_date).format('YYYY-MM-DD') }}</div> 60 <div v-if="task.end_date" class="taskDates text-xs text-gray-600 mt-1">截止时间:{{ dayjs(task.end_date).format('YYYY-MM-DD') }}</div>
65 </div> 61 </div>
66 - <!-- 右侧按钮:占用较小空间,右对齐 --> 62 + <!~~ 右侧按钮:占用较小空间,右对齐 ~~>
67 <div class="right flex items-center justify-end w-20 ml-3"> 63 <div class="right flex items-center justify-end w-20 ml-3">
68 <van-button type="success" size="small" round class="w-full" @click="go_task_home(task.id)">查看</van-button> 64 <van-button type="success" size="small" round class="w-full" @click="go_task_home(task.id)">查看</van-button>
69 </div> 65 </div>
...@@ -71,7 +67,7 @@ ...@@ -71,7 +67,7 @@
71 </div> 67 </div>
72 </div> 68 </div>
73 </div> 69 </div>
74 - </van-popup> 70 + </van-popup>-->
75 </template> 71 </template>
76 72
77 <script setup> 73 <script setup>
...@@ -92,6 +88,10 @@ import dayjs from 'dayjs' ...@@ -92,6 +88,10 @@ import dayjs from 'dayjs'
92 /** 88 /**
93 * @function props 89 * @function props
94 * @description 组件接收的属性定义。 90 * @description 组件接收的属性定义。
91 + * @property {CheckInItem[]} items - 打卡项列表。
92 + * @property {boolean} [dense] - 是否紧凑模式,默认 `false`。
93 + * @property {boolean} [scroll] - 是否启用滚动区域,默认 `false`。
94 + * @property {boolean} [plain] - 是否普通模式,默认 `false`。
95 */ 95 */
96 const props = defineProps({ 96 const props = defineProps({
97 items: { type: Array, default: () => [] }, 97 items: { type: Array, default: () => [] },
...@@ -103,6 +103,7 @@ const props = defineProps({ ...@@ -103,6 +103,7 @@ const props = defineProps({
103 /** 103 /**
104 * @function emits 104 * @function emits
105 * @description 组件对外抛出的事件。 105 * @description 组件对外抛出的事件。
106 + * @event submit-success - 提交成功时触发,携带打卡项ID。
106 */ 107 */
107 const emit = defineEmits(['submit-success']) 108 const emit = defineEmits(['submit-success'])
108 109
...@@ -110,10 +111,10 @@ const router = useRouter() ...@@ -110,10 +111,10 @@ const router = useRouter()
110 const selected_item = ref(null) 111 const selected_item = ref(null)
111 const submitting = ref(false) 112 const submitting = ref(false)
112 // 父弹框联动(仅弹框模式下有效) 113 // 父弹框联动(仅弹框模式下有效)
113 -const parent_popup = inject('parent_popup_control', null) 114 +// const parent_popup = inject('parent_popup_control', null)
114 // 二级弹框与数据 115 // 二级弹框与数据
115 -const inner_popup_show = ref(false) 116 +// const inner_popup_show = ref(false)
116 -const inner_courses = ref([]) 117 +// const inner_courses = ref([])
117 118
118 /** 119 /**
119 * @function wrapper_class 120 * @function wrapper_class
...@@ -228,69 +229,71 @@ const handle_submit = async () => { ...@@ -228,69 +229,71 @@ const handle_submit = async () => {
228 * @description 打开二级弹框并填充示例任务列表(本地构造)。 229 * @description 打开二级弹框并填充示例任务列表(本地构造)。
229 * @returns {void} 230 * @returns {void}
230 */ 231 */
231 -const open_inner_popup = () => { 232 +// const open_inner_popup = () => {
232 - inner_courses.value = build_course_list() 233 +// inner_courses.value = build_course_list()
233 - inner_popup_show.value = true 234 +// inner_popup_show.value = true
234 -} 235 +// }
235 236
236 /** 237 /**
237 * @function close_inner_popup 238 * @function close_inner_popup
238 * @description 关闭二级弹框;若处于弹框模式则重新打开父级弹框。 239 * @description 关闭二级弹框;若处于弹框模式则重新打开父级弹框。
239 * @returns {void} 240 * @returns {void}
240 */ 241 */
241 -const close_inner_popup = () => { 242 +// const close_inner_popup = () => {
242 - inner_popup_show.value = false 243 +// inner_popup_show.value = false
243 - if (!props.plain && parent_popup && typeof parent_popup.reopenParent === 'function') { 244 +// if (!props.plain && parent_popup && typeof parent_popup.reopenParent === 'function') {
244 - // 略微延迟,避免与二级弹框关闭动画冲突 245 +// // 略微延迟,避免与二级弹框关闭动画冲突
245 - setTimeout(() => parent_popup.reopenParent(), 150) 246 +// setTimeout(() => parent_popup.reopenParent(), 150)
246 - } 247 +// }
247 -} 248 +// }
248 249
249 /** 250 /**
250 * @function build_course_list 251 * @function build_course_list
251 * @description 构造示例任务数据(仅标题与开始/结束日期)。 252 * @description 构造示例任务数据(仅标题与开始/结束日期)。
252 * @returns {Array<{id:string,title:string,begin_date:string,end_date?:string}>} 253 * @returns {Array<{id:string,title:string,begin_date:string,end_date?:string}>}
253 */ 254 */
254 -const build_course_list = () => { 255 +// const build_course_list = () => {
255 - const now = new Date() 256 +// const now = new Date()
256 - /** 257 +// /**
257 - * @function add_days 258 +// * @function add_days
258 - * @description 在当前日期基础上增加指定天数。 259 +// * @description 在当前日期基础上增加指定天数。
259 - * @param {number} days - 增加的天数(可为负数)。 260 +// * @param {number} days - 增加的天数(可为负数)。
260 - * @returns {Date} 261 +// * @returns {Date}
261 - */ 262 +// */
262 - const add_days = (days) => { 263 +// const add_days = (days) => {
263 - const d = new Date(now) 264 +// const d = new Date(now)
264 - d.setDate(d.getDate() + days) 265 +// d.setDate(d.getDate() + days)
265 - return d 266 +// return d
266 - } 267 +// }
267 - /** 268 +// /**
268 - * @function to_yyyy_mm_dd 269 +// * @function to_yyyy_mm_dd
269 - * @description 格式化日期为 YYYY-MM-DD 字符串。 270 +// * @description 格式化日期为 YYYY-MM-DD 字符串。
270 - * @param {Date} date - 日期对象。 271 +// * @param {Date} date - 日期对象。
271 - * @returns {string} 272 +// * @returns {string}
272 - */ 273 +// */
273 - const to_yyyy_mm_dd = (date) => { 274 +// const to_yyyy_mm_dd = (date) => {
274 - const y = date.getFullYear() 275 +// const y = date.getFullYear()
275 - const m = String(date.getMonth() + 1).padStart(2, '0') 276 +// const m = String(date.getMonth() + 1).padStart(2, '0')
276 - const d = String(date.getDate()).padStart(2, '0') 277 +// const d = String(date.getDate()).padStart(2, '0')
277 - return `${y}-${m}-${d}` 278 +// return `${y}-${m}-${d}`
278 - } 279 +// }
279 - return [ 280 +// return [
280 - { id: 'task-1', title: '课程打卡任务一', begin_date: to_yyyy_mm_dd(add_days(-2)), end_date: to_yyyy_mm_dd(add_days(5)) }, 281 +// { id: 'task-1', title: '课程打卡任务一', begin_date: to_yyyy_mm_dd(add_days(-2)), end_date: to_yyyy_mm_dd(add_days(5)) },
281 - { id: 'task-2', title: '课程打卡任务二', begin_date: to_yyyy_mm_dd(add_days(-1)), end_date: to_yyyy_mm_dd(add_days(6)) }, 282 +// { id: 'task-2', title: '课程打卡任务二', begin_date: to_yyyy_mm_dd(add_days(-1)), end_date: to_yyyy_mm_dd(add_days(6)) },
282 - { id: 'task-3', title: '课程打卡任务三', begin_date: to_yyyy_mm_dd(add_days(0)), end_date: to_yyyy_mm_dd(add_days(7)) }, 283 +// { id: 'task-3', title: '课程打卡任务三', begin_date: to_yyyy_mm_dd(add_days(0)), end_date: to_yyyy_mm_dd(add_days(7)) },
283 - { id: 'task-4', title: '课程打卡任务四', begin_date: to_yyyy_mm_dd(add_days(1)) }, 284 +// { id: 'task-4', title: '课程打卡任务四', begin_date: to_yyyy_mm_dd(add_days(1)) },
284 - ] 285 +// ]
285 -} 286 +// }
286 287
287 // 该组件当前不展示封面图片,移除不再使用的图片处理方法 288 // 该组件当前不展示封面图片,移除不再使用的图片处理方法
288 </script> 289 </script>
289 290
290 <style lang="less" scoped> 291 <style lang="less" scoped>
291 .CheckInListWrapper { 292 .CheckInListWrapper {
293 +
292 // 列表项样式 294 // 列表项样式
293 .CheckInListItem { 295 .CheckInListItem {
296 +
294 // 选中态样式 297 // 选中态样式
295 &.is-active { 298 &.is-active {
296 border-color: #bbf7d0; // 绿色边框 299 border-color: #bbf7d0; // 绿色边框
......