From eb8837717edccadebbceceb172fe1f182ed4415d Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 24 Jan 2024 10:36:12 +0800 Subject: [PATCH] refactor: condition of modal component visible (#54) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 Halo 2.12 中重构了 Modal 组件的显示控制方式,此 PR 用于简化 Modal 弹窗的显示逻辑。 See https://github.com/halo-dev/halo/pull/5078 /kind improvement ```release-note None ``` --- build.gradle | 2 +- console/src/components/AppActionButton.vue | 10 +---- console/src/components/AppDetailModal.vue | 38 +++++++------------ console/src/components/AppStoreTab.vue | 4 +- console/src/components/AppVersionCheckBar.vue | 34 ++++------------- console/src/components/PaymentCheckModal.vue | 17 ++++----- .../ThemeOrPluginVersionCheckBar.vue | 31 +++++---------- .../components/detail/DetailReleaseItem.vue | 10 +---- .../ViewAppStoreOperationItem.vue | 19 +--------- .../composables/use-payment-check-modal.ts | 19 ++-------- console/src/views/AppStore.vue | 4 +- src/main/resources/plugin.yaml | 2 +- 12 files changed, 51 insertions(+), 139 deletions(-) diff --git a/build.gradle b/build.gradle index 914ee93..60bf62d 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,6 @@ build { } halo { - version = '2.11' + version = '2.12.0-alpha.1' debug = true } \ No newline at end of file diff --git a/console/src/components/AppActionButton.vue b/console/src/components/AppActionButton.vue index 2faf65f..ecb5238 100644 --- a/console/src/components/AppActionButton.vue +++ b/console/src/components/AppActionButton.vue @@ -31,8 +31,7 @@ const { app } = toRefs(props); const { installing, handleInstall } = useAppDownload(app); const { isSatisfies, hasInstalled } = useAppCompare(app); -const { paymentCheckModal, paymentCheckModalVisible, onPaymentCheckModalClose, handleOpenCreateOrderPage } = - usePaymentCheckModal(app); +const { paymentCheckModalVisible, handleOpenCreateOrderPage } = usePaymentCheckModal(app); const actions = computed((): Action[] => { return [ @@ -87,10 +86,5 @@ const action = computed(() => { > {{ action.label }} - + diff --git a/console/src/components/AppDetailModal.vue b/console/src/components/AppDetailModal.vue index 56163c1..1c85f19 100644 --- a/console/src/components/AppDetailModal.vue +++ b/console/src/components/AppDetailModal.vue @@ -18,51 +18,35 @@ import TablerDownload from "~icons/tabler/download"; const props = withDefaults( defineProps<{ - visible: boolean; tab?: string; - app?: ApplicationSearchResult; + app: ApplicationSearchResult; }>(), { - visible: false, tab: "readme", - app: undefined, } ); const emit = defineEmits<{ - (event: "update:visible", visible: boolean): void; (event: "close"): void; }>(); -const onVisibleChange = (visible: boolean) => { - emit("update:visible", visible); +const { app } = toRefs(props); - if (!visible) { - setTimeout(() => { - activeId.value = "readme"; - emit("close"); - }, 200); - } -}; - -const { app, visible } = toRefs(props); +const modal = ref(); const { data: appDetail, isLoading, isFetching, } = useQuery({ - queryKey: ["store-app", app, visible], + queryKey: ["store-app", app], queryFn: async () => { - if (!visible.value || !app.value) { - return; - } const { data } = await storeApiClient.get( `/apis/api.store.halo.run/v1alpha1/applications/${app.value?.application.metadata.name}` ); return data; }, - enabled: computed(() => visible.value && !!app.value), + enabled: computed(() => !!app.value), }); const title = computed(() => { @@ -77,9 +61,10 @@ const activeId = ref(props.tab); watch( () => appDetail.value, (value) => { - if (!(props.visible && value)) { + if (!value) { return; } + const { screen: { width, height }, navigator: { language }, @@ -96,20 +81,23 @@ watch( referrer: document.referrer, }, }); + }, + { + immediate: true, } ); diff --git a/console/src/components/detail/DetailReleaseItem.vue b/console/src/components/detail/DetailReleaseItem.vue index 3eebe1a..5727632 100644 --- a/console/src/components/detail/DetailReleaseItem.vue +++ b/console/src/components/detail/DetailReleaseItem.vue @@ -42,8 +42,7 @@ const { } = useAppDownload(app); const { matchedPlugin, matchedTheme, appType, hasInstalled: appHasInstalled } = useAppCompare(app); -const { paymentCheckModal, paymentCheckModalVisible, onPaymentCheckModalClose, handleOpenCreateOrderPage } = - usePaymentCheckModal(app); +const { paymentCheckModalVisible, handleOpenCreateOrderPage } = usePaymentCheckModal(app); const hasInstalled = computed(() => { if (appType.value === "PLUGIN") { @@ -256,10 +255,5 @@ const { isLoading: installing, mutate: handleInstall } = useMutation({ - + diff --git a/console/src/components/operation-items/ViewAppStoreOperationItem.vue b/console/src/components/operation-items/ViewAppStoreOperationItem.vue index b01c228..a9fe09f 100644 --- a/console/src/components/operation-items/ViewAppStoreOperationItem.vue +++ b/console/src/components/operation-items/ViewAppStoreOperationItem.vue @@ -1,6 +1,6 @@ diff --git a/console/src/composables/use-payment-check-modal.ts b/console/src/composables/use-payment-check-modal.ts index a593e4a..15f42d9 100644 --- a/console/src/composables/use-payment-check-modal.ts +++ b/console/src/composables/use-payment-check-modal.ts @@ -2,24 +2,14 @@ import type { ApplicationSearchResult } from "@/types"; import storeApiClient from "@/utils/store-api-client"; import type { DetailedUser } from "@halo-dev/api-client"; import { Dialog } from "@halo-dev/components"; -import { nextTick, ref, type Ref } from "vue"; +import { ref, type Ref } from "vue"; import { useRouter } from "vue-router"; export function usePaymentCheckModal(app: Ref) { const router = useRouter(); - // payment check modal - // fixme: Refactor VModal to simplify the code - const paymentCheckModal = ref(false); const paymentCheckModalVisible = ref(false); - function onPaymentCheckModalClose() { - paymentCheckModalVisible.value = false; - setTimeout(() => { - paymentCheckModal.value = false; - }, 200); - } - async function handleOpenCreateOrderPage() { const { data: user } = await storeApiClient.get("/apis/api.console.halo.run/v1alpha1/users/-"); @@ -41,11 +31,8 @@ export function usePaymentCheckModal(app: Ref { - paymentCheckModalVisible.value = true; - }); + paymentCheckModalVisible.value = true; } - return { paymentCheckModal, paymentCheckModalVisible, handleOpenCreateOrderPage, onPaymentCheckModalClose }; + return { paymentCheckModalVisible, handleOpenCreateOrderPage }; } diff --git a/console/src/views/AppStore.vue b/console/src/views/AppStore.vue index 699073b..1387763 100644 --- a/console/src/views/AppStore.vue +++ b/console/src/views/AppStore.vue @@ -170,12 +170,10 @@ const { data, isFetching, isLoading, refetch } = useQuery(); function handleOpenDetailModal(app: ApplicationSearchResult) { selectedApp.value = app; - detailModal.value = true; } const handleSelectPrevious = async () => { @@ -418,7 +416,7 @@ watch([selectedPriceMode, selectedType, selectedSort, onlyQueryInstalled, keywor - +