Skip to content

Commit

Permalink
refactor: condition of modal component visible (#54)
Browse files Browse the repository at this point in the history
在 Halo 2.12 中重构了 Modal 组件的显示控制方式,此 PR 用于简化 Modal 弹窗的显示逻辑。

See halo-dev/halo#5078

/kind improvement

```release-note
None
```
  • Loading branch information
ruibaby authored Jan 24, 2024
1 parent 4a8cefb commit eb88377
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 139 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ build {
}

halo {
version = '2.11'
version = '2.12.0-alpha.1'
debug = true
}
10 changes: 2 additions & 8 deletions console/src/components/AppActionButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down Expand Up @@ -87,10 +86,5 @@ const action = computed(() => {
>
{{ action.label }}
</VButton>
<PaymentCheckModal
v-if="paymentCheckModal"
v-model="paymentCheckModalVisible"
:app="app"
@close="onPaymentCheckModalClose"
/>
<PaymentCheckModal v-if="paymentCheckModalVisible && app" :app="app" @close="paymentCheckModalVisible = false" />
</template>
38 changes: 13 additions & 25 deletions console/src/components/AppDetailModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationDetail>({
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(() => {
Expand All @@ -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 },
Expand All @@ -96,20 +81,23 @@ watch(
referrer: document.referrer,
},
});
},
{
immediate: true,
}
);
</script>

<template>
<VModal
ref="modal"
:title="title"
:visible="visible"
:width="1200"
:layer-closable="true"
height="calc(100vh - 20px)"
:mount-to-body="true"
:body-class="['!as-p-0']"
@update:visible="onVisibleChange"
@close="emit('close')"
>
<template #actions>
<slot name="actions" />
Expand Down Expand Up @@ -188,7 +176,7 @@ watch(
</div>
</div>
<template #footer>
<VButton @click="onVisibleChange(false)">关闭</VButton>
<VButton @click="modal.close()">关闭</VButton>
</template>
</VModal>
</template>
4 changes: 1 addition & 3 deletions console/src/components/AppStoreTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ const { data, isFetching, isLoading, refetch } = useQuery<ListResponse<Applicati
});
// detail modal
const detailModal = ref(false);
const selectedApp = ref<ApplicationSearchResult>();
function handleOpenDetailModal(app: ApplicationSearchResult) {
selectedApp.value = app;
detailModal.value = true;
}
const handleSelectPrevious = async () => {
Expand Down Expand Up @@ -257,7 +255,7 @@ watch([selectedPriceMode, selectedSort, keyword], () => {
:size-options="[10, 20, 30, 50, 100]"
/>
</div>
<AppDetailModal v-model:visible="detailModal" :app="selectedApp">
<AppDetailModal v-if="selectedApp" :app="selectedApp" @close="selectedApp = undefined">
<template #actions>
<span @click="handleSelectPrevious">
<IconArrowLeft />
Expand Down
34 changes: 8 additions & 26 deletions console/src/components/AppVersionCheckBar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import AppDetailModal from "./AppDetailModal.vue";
import { nextTick, ref, toRefs } from "vue";
import { ref, toRefs } from "vue";
import { useAppDownload } from "@/composables/use-app-download";
import RiArrowUpCircleLine from "~icons/ri/arrow-up-circle-line";
import type { ApplicationSearchResult } from "@/types";
Expand All @@ -21,22 +21,7 @@ const { hasUpdate, isSatisfies } = useAppCompare(app);
const { upgrading, handleUpgrade } = useAppDownload(app);
const detailModal = ref(false);
const detailModalVisible = ref(false);
function handleOpenDetailModal() {
detailModal.value = true;
nextTick(() => {
detailModalVisible.value = true;
});
}
function onDetailModalClose() {
detailModalVisible.value = false;
setTimeout(() => {
detailModal.value = false;
}, 200);
}
</script>

<template>
Expand All @@ -57,7 +42,7 @@ function onDetailModalClose() {
<div v-if="isSatisfies" class="as-truncate as-text-xs as-text-gray-500">
有新版本,<span
class="as-cursor-pointer as-text-gray-900 hover:as-text-gray-600"
@click="handleOpenDetailModal"
@click="detailModalVisible = true"
>
查看详情
</span>
Expand All @@ -67,18 +52,15 @@ function onDetailModalClose() {
</span>
</div>
<div v-else class="as-truncate as-text-xs as-text-gray-500">
有新版本,<span class="as-cursor-pointer as-text-gray-900 hover:as-text-gray-600" @click="handleOpenDetailModal"
>版本不兼容
有新版本,<span
class="as-cursor-pointer as-text-gray-900 hover:as-text-gray-600"
@click="detailModalVisible = true"
>
版本不兼容
</span>
</div>
</div>
</template>

<AppDetailModal
v-if="detailModal"
v-model:visible="detailModalVisible"
:app="app"
tab="releases"
@close="onDetailModalClose"
/>
<AppDetailModal v-if="detailModalVisible" :app="app" tab="releases" @close="detailModalVisible = false" />
</template>
17 changes: 8 additions & 9 deletions console/src/components/PaymentCheckModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ import type { ApplicationDetail, ApplicationSearchResult } from "@/types";
import storeApiClient from "@/utils/store-api-client";
import { Dialog, VButton, VLoading, VModal } from "@halo-dev/components";
import { useQuery, useQueryClient } from "@tanstack/vue-query";
import { ref } from "vue";
const queryClient = useQueryClient();
const props = withDefaults(
defineProps<{
app?: ApplicationSearchResult;
app: ApplicationSearchResult;
}>(),
{
app: undefined,
}
{}
);
const visible = defineModel({ type: Boolean, default: false });
const emit = defineEmits<{
(event: "close"): void;
}>();
const modal = ref();
useQuery<ApplicationDetail>({
queryKey: ["app-payment-check"],
queryFn: async () => {
Expand All @@ -31,7 +30,7 @@ useQuery<ApplicationDetail>({
},
onSuccess(data) {
if (data?.bought) {
visible.value = false;
modal.value.close();
Dialog.success({
title: "支付成功",
description: "感谢购买,现在已经可以安装此应用了",
Expand All @@ -51,14 +50,14 @@ useQuery<ApplicationDetail>({
</script>

<template>
<VModal v-model:visible="visible" :width="400" title="提示" @close="emit('close')">
<VModal ref="modal" :width="400" title="提示" @close="emit('close')">
<div class="gap-2 p-2 as-flex as-flex-col as-items-center as-justify-center">
<VLoading />
<div class="text-xs text-gray-600">正在检测支付状态,请稍后...</div>
</div>

<template #footer>
<VButton @click="emit('close')">关闭</VButton>
<VButton @click="modal.close()">关闭</VButton>
</template>
</VModal>
</template>
31 changes: 9 additions & 22 deletions console/src/components/ThemeOrPluginVersionCheckBar.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup>
import type { Plugin, Theme } from "@halo-dev/api-client";
import AppDetailModal from "./AppDetailModal.vue";
import { nextTick, ref, toRefs } from "vue";
import { ref, toRefs } from "vue";
import { usePluginVersion } from "@/composables/use-plugin-version";
import { useAppDownload } from "@/composables/use-app-download";
import RiArrowUpCircleLine from "~icons/ri/arrow-up-circle-line";
Expand Down Expand Up @@ -41,22 +41,7 @@ const { hasUpdate, matchedApp } = useVersion();
const { isSatisfies } = useAppCompare(matchedApp);
const { upgrading, handleUpgrade } = useAppDownload(matchedApp);
const detailModal = ref(false);
const detailModalVisible = ref(false);
function handleOpenDetailModal() {
detailModal.value = true;
nextTick(() => {
detailModalVisible.value = true;
});
}
function onDetailModalClose() {
detailModalVisible.value = false;
setTimeout(() => {
detailModal.value = false;
}, 200);
}
</script>

<template>
Expand All @@ -77,7 +62,7 @@ function onDetailModalClose() {
<div v-if="isSatisfies" class="as-truncate as-text-xs as-text-gray-500">
有新版本,<span
class="as-cursor-pointer as-text-gray-900 hover:as-text-gray-600"
@click="handleOpenDetailModal"
@click="detailModalVisible = true"
>
查看详情
</span>
Expand All @@ -87,18 +72,20 @@ function onDetailModalClose() {
</span>
</div>
<div v-else class="as-truncate as-text-xs as-text-gray-500">
有新版本,<span class="as-cursor-pointer as-text-gray-900 hover:as-text-gray-600" @click="handleOpenDetailModal"
>版本不兼容
有新版本,<span
class="as-cursor-pointer as-text-gray-900 hover:as-text-gray-600"
@click="detailModalVisible = true"
>
版本不兼容
</span>
</div>
</div>
</template>

<AppDetailModal
v-if="detailModal"
v-model:visible="detailModalVisible"
v-if="detailModalVisible && matchedApp"
:app="matchedApp"
tab="releases"
@close="onDetailModalClose"
@close="detailModalVisible = false"
/>
</template>
10 changes: 2 additions & 8 deletions console/src/components/detail/DetailReleaseItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -256,10 +255,5 @@ const { isLoading: installing, mutate: handleInstall } = useMutation({
</div>
</div>
</div>
<PaymentCheckModal
v-if="paymentCheckModal"
v-model="paymentCheckModalVisible"
:app="app"
@close="onPaymentCheckModalClose"
/>
<PaymentCheckModal v-if="paymentCheckModalVisible && app" :app="app" @close="paymentCheckModalVisible = false" />
</template>
Loading

0 comments on commit eb88377

Please sign in to comment.