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