hookehuyr

feat(打卡): 支持计数打卡类型并优化提交逻辑

添加计数打卡类型的支持,包括动态字段显示和额外数据提交
重构提交逻辑,将校验和数据处理分离到单独方法
优化UI文本显示,使其更通用化
...@@ -20,9 +20,12 @@ export function useCheckin() { ...@@ -20,9 +20,12 @@ export function useCheckin() {
20 const loading = ref(false) 20 const loading = ref(false)
21 const message = ref('') 21 const message = ref('')
22 const fileList = ref([]) 22 const fileList = ref([])
23 - const activeType = ref('text') // 当前选中的打卡类型 23 + const activeType = ref('') // 当前选中的打卡类型
24 const maxCount = ref(5) 24 const maxCount = ref(5)
25 25
26 + // 打卡类型
27 + const checkinType = computed(() => route.query.type)
28 +
26 // 用于记忆不同类型的文件列表 29 // 用于记忆不同类型的文件列表
27 const fileListMemory = ref({ 30 const fileListMemory = ref({
28 text: [], 31 text: [],
...@@ -35,6 +38,11 @@ export function useCheckin() { ...@@ -35,6 +38,11 @@ export function useCheckin() {
35 * 是否可以提交 38 * 是否可以提交
36 */ 39 */
37 const canSubmit = computed(() => { 40 const canSubmit = computed(() => {
41 + // 如果是计数打卡,交由组件内部校验
42 + if (checkinType.value === 'count') {
43 + return true
44 + }
45 +
38 if (activeType.value === 'text') { 46 if (activeType.value === 'text') {
39 // 文字打卡:必须填写内容且长度不少于10个字符 47 // 文字打卡:必须填写内容且长度不少于10个字符
40 return message.value.trim() !== '' && message.value.trim().length >= 10 48 return message.value.trim() !== '' && message.value.trim().length >= 10
...@@ -249,25 +257,24 @@ export function useCheckin() { ...@@ -249,25 +257,24 @@ export function useCheckin() {
249 257
250 /** 258 /**
251 * 提交打卡 259 * 提交打卡
260 + * @param {Object} extraData - 额外提交数据
252 */ 261 */
253 - const onSubmit = async () => { 262 + const onSubmit = async (extraData = {}) => {
254 if (uploading.value) return 263 if (uploading.value) return
255 264
256 // 表单验证 265 // 表单验证
257 - if (activeType.value === 'text') { 266 + if (checkinType.value !== 'count') {
258 - if (message.value.trim().length < 10) { 267 + if (activeType.value === 'text') {
259 - showToast('打卡内容至少需要10个字符') 268 + if (message.value.trim().length < 10) {
260 - return 269 + showToast('打卡内容至少需要10个字符')
261 - } 270 + return
262 - } else { 271 + }
263 - if (fileList.value.length === 0) { 272 + } else {
264 - showToast('请先上传文件') 273 + if (fileList.value.length === 0) {
265 - return 274 + showToast('请先上传文件')
275 + return
276 + }
266 } 277 }
267 - // if (message.value.trim() === '') {
268 - // showToast('请输入打卡留言')
269 - // return
270 - // }
271 } 278 }
272 279
273 uploading.value = true 280 uploading.value = true
...@@ -284,6 +291,7 @@ export function useCheckin() { ...@@ -284,6 +291,7 @@ export function useCheckin() {
284 file_type: activeType.value, 291 file_type: activeType.value,
285 meta_id: [], 292 meta_id: [],
286 makeup_time: route.query.is_patch ? route.query.date : '', 293 makeup_time: route.query.is_patch ? route.query.date : '',
294 + ...extraData
287 } 295 }
288 296
289 // 如果有文件,添加文件ID 297 // 如果有文件,添加文件ID
......
This diff is collapsed. Click to expand it.