refactor(plan):优化计划类型标签显示逻辑并简化 API 调用
移除 `shouldShowPlanTypeTag` 方法中不必要的 `plan` 参数,因为其判断逻辑仅依赖于计划列表长度。同时简化 `usePlanApi.ts` 中的请求返回逻辑,避免多余的变量赋值。此外,统一了 API 模块的导入路径为 `@/api`,以提高路径一致性与可维护性。
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import type { PlanCreateIn, PlanDeleteIn, PlanGetIn, PlanReorderIn, PlanUpdateIn } from '../api'
|
||||
import { Service } from '../api'
|
||||
import type { PlanCreateIn, PlanDeleteIn, PlanGetIn, PlanReorderIn, PlanUpdateIn } from '@/api'
|
||||
import { Service } from '@/api'
|
||||
|
||||
export function usePlanApi() {
|
||||
const loading = ref(false)
|
||||
@@ -11,8 +11,7 @@ export function usePlanApi() {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: PlanGetIn = planId ? { planId } : {}
|
||||
const response = await Service.getPlanApiPlanGetPost(params)
|
||||
return response
|
||||
return await Service.getPlanApiPlanGetPost(params)
|
||||
} catch (error) {
|
||||
console.error('获取计划失败:', error)
|
||||
message.error('获取计划失败')
|
||||
|
||||
@@ -22,12 +22,7 @@
|
||||
class="plan-button"
|
||||
>
|
||||
<span class="plan-name">{{ plan.name }}</span>
|
||||
<a-tag
|
||||
v-if="shouldShowPlanTypeTag(plan)"
|
||||
size="small"
|
||||
color="blue"
|
||||
class="plan-type-tag"
|
||||
>
|
||||
<a-tag v-if="shouldShowPlanTypeTag()" size="small" color="blue" class="plan-type-tag">
|
||||
{{ getPlanTypeLabel(plan.type) }}
|
||||
</a-tag>
|
||||
</a-button>
|
||||
@@ -72,7 +67,7 @@ const handlePlanClick = debounce((planId: string) => {
|
||||
|
||||
// 判断是否需要显示计划类型标签
|
||||
// 当所有计划的类型都相同时不显示标签,否则显示非默认类型的标签
|
||||
const shouldShowPlanTypeTag = (plan: Plan) => {
|
||||
const shouldShowPlanTypeTag = () => {
|
||||
// 如果只有一个计划或没有计划,不显示类型标签
|
||||
if (props.planList.length <= 1) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user