hookehuyr

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

添加计数打卡类型的支持,包括动态字段显示和额外数据提交
重构提交逻辑,将校验和数据处理分离到单独方法
优化UI文本显示,使其更通用化
......@@ -20,9 +20,12 @@ export function useCheckin() {
const loading = ref(false)
const message = ref('')
const fileList = ref([])
const activeType = ref('text') // 当前选中的打卡类型
const activeType = ref('') // 当前选中的打卡类型
const maxCount = ref(5)
// 打卡类型
const checkinType = computed(() => route.query.type)
// 用于记忆不同类型的文件列表
const fileListMemory = ref({
text: [],
......@@ -35,6 +38,11 @@ export function useCheckin() {
* 是否可以提交
*/
const canSubmit = computed(() => {
// 如果是计数打卡,交由组件内部校验
if (checkinType.value === 'count') {
return true
}
if (activeType.value === 'text') {
// 文字打卡:必须填写内容且长度不少于10个字符
return message.value.trim() !== '' && message.value.trim().length >= 10
......@@ -249,11 +257,13 @@ export function useCheckin() {
/**
* 提交打卡
* @param {Object} extraData - 额外提交数据
*/
const onSubmit = async () => {
const onSubmit = async (extraData = {}) => {
if (uploading.value) return
// 表单验证
if (checkinType.value !== 'count') {
if (activeType.value === 'text') {
if (message.value.trim().length < 10) {
showToast('打卡内容至少需要10个字符')
......@@ -264,10 +274,7 @@ export function useCheckin() {
showToast('请先上传文件')
return
}
// if (message.value.trim() === '') {
// showToast('请输入打卡留言')
// return
// }
}
}
uploading.value = true
......@@ -284,6 +291,7 @@ export function useCheckin() {
file_type: activeType.value,
meta_id: [],
makeup_time: route.query.is_patch ? route.query.date : '',
...extraData
}
// 如果有文件,添加文件ID
......
This diff is collapsed. Click to expand it.