mirror of https://github.com/halo-dev/halo
feat: add sticky block component (#4919)
#### What type of PR is this? /kind feature /area console /milestone 2.11.x #### What this PR does / why we need it: 添加 `<StickyBlock />` 组件,用于将元素固定在顶部或者底部。 此外,此 PR 针对主题设置、插件设置、系统设置等表单可能较长的页面使用了此组件。 <img width="1214" alt="图片" src="https://github.com/halo-dev/halo/assets/21301288/abc849eb-a9a9-4d0a-b81c-d7430815660d"> #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/4548 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? ```release-note 添加 `<StickyBlock />` 组件,用于将元素固定在顶部或者底部,并为主题 / 插件 / 系统设置的底部保存按钮区域做了适配。 ```pull/4924/head
parent
0102f7a227
commit
925f8d0ea4
|
@ -14,6 +14,7 @@ import { apiClient } from "@/utils/api-client";
|
||||||
import { useSettingFormConvert } from "@console/composables/use-setting-form";
|
import { useSettingFormConvert } from "@console/composables/use-setting-form";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||||
|
import StickyBlock from "@/components/sticky-block/StickyBlock.vue";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
@ -86,17 +87,19 @@ await suspense();
|
||||||
:data="configMapFormData[group]"
|
:data="configMapFormData[group]"
|
||||||
/>
|
/>
|
||||||
</FormKit>
|
</FormKit>
|
||||||
<div v-permission="['system:themes:manage']" class="pt-5">
|
<StickyBlock
|
||||||
<div class="flex justify-start">
|
v-permission="['system:themes:manage']"
|
||||||
<VButton
|
class="-mx-4 -mb-4 rounded-b-base rounded-t-lg bg-white p-4 pt-5"
|
||||||
:loading="saving"
|
position="bottom"
|
||||||
type="secondary"
|
>
|
||||||
@click="$formkit.submit(group || '')"
|
<VButton
|
||||||
>
|
:loading="saving"
|
||||||
{{ $t("core.common.buttons.save") }}
|
type="secondary"
|
||||||
</VButton>
|
@click="$formkit.submit(group || '')"
|
||||||
</div>
|
>
|
||||||
</div>
|
{{ $t("core.common.buttons.save") }}
|
||||||
|
</VButton>
|
||||||
|
</StickyBlock>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -14,6 +14,7 @@ import type { ConfigMap, Plugin, Setting } from "@halo-dev/api-client";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||||
import { toRaw } from "vue";
|
import { toRaw } from "vue";
|
||||||
|
import StickyBlock from "@/components/sticky-block/StickyBlock.vue";
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
@ -82,17 +83,20 @@ const handleSaveConfigMap = async () => {
|
||||||
/>
|
/>
|
||||||
</FormKit>
|
</FormKit>
|
||||||
</div>
|
</div>
|
||||||
<div v-permission="['system:plugins:manage']" class="pt-5">
|
|
||||||
<div class="flex justify-start">
|
<StickyBlock
|
||||||
<VButton
|
v-permission="['system:plugins:manage']"
|
||||||
:loading="saving"
|
class="-mx-4 -mb-4 rounded-b-base rounded-t-lg bg-white p-4 pt-5"
|
||||||
type="secondary"
|
position="bottom"
|
||||||
@click="$formkit.submit(group || '')"
|
>
|
||||||
>
|
<VButton
|
||||||
{{ $t("core.common.buttons.save") }}
|
:loading="saving"
|
||||||
</VButton>
|
type="secondary"
|
||||||
</div>
|
@click="$formkit.submit(group || '')"
|
||||||
</div>
|
>
|
||||||
|
{{ $t("core.common.buttons.save") }}
|
||||||
|
</VButton>
|
||||||
|
</StickyBlock>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -82,7 +82,7 @@ provide<Ref<Setting | undefined>>("setting", setting);
|
||||||
</VPageHeader>
|
</VPageHeader>
|
||||||
|
|
||||||
<div class="m-0 md:m-4">
|
<div class="m-0 md:m-4">
|
||||||
<VCard :body-class="['!p-0']">
|
<VCard :body-class="['!p-0', '!overflow-visible']">
|
||||||
<template #header>
|
<template #header>
|
||||||
<VTabbar
|
<VTabbar
|
||||||
v-model:active-id="activeTab"
|
v-model:active-id="activeTab"
|
||||||
|
@ -91,7 +91,7 @@ provide<Ref<Setting | undefined>>("setting", setting);
|
||||||
type="outline"
|
type="outline"
|
||||||
></VTabbar>
|
></VTabbar>
|
||||||
</template>
|
</template>
|
||||||
<div class="bg-white">
|
<div class="rounded-b-base bg-white">
|
||||||
<template v-for="tab in tabs" :key="tab.id">
|
<template v-for="tab in tabs" :key="tab.id">
|
||||||
<component :is="tab.component" v-if="activeTab === tab.id" />
|
<component :is="tab.component" v-if="activeTab === tab.id" />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { computed } from "vue";
|
||||||
import { toRaw } from "vue";
|
import { toRaw } from "vue";
|
||||||
import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core";
|
import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
|
import StickyBlock from "@/components/sticky-block/StickyBlock.vue";
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
@ -86,17 +87,20 @@ const { isLoading: isMutating, mutate } = useMutation({
|
||||||
>
|
>
|
||||||
<FormKitSchema :schema="toRaw(formSchema)" :data="configMapData" />
|
<FormKitSchema :schema="toRaw(formSchema)" :data="configMapData" />
|
||||||
</FormKit>
|
</FormKit>
|
||||||
<div class="pt-5">
|
|
||||||
<div class="flex justify-start">
|
<StickyBlock
|
||||||
<VButton
|
v-permission="['system:configmaps:manage']"
|
||||||
:loading="isMutating"
|
class="-mx-4 -mb-4 rounded-b-base rounded-t-lg bg-white p-4 pt-5"
|
||||||
type="secondary"
|
position="bottom"
|
||||||
@click="$formkit.submit(name)"
|
>
|
||||||
>
|
<VButton
|
||||||
{{ $t("core.common.buttons.save") }}
|
:loading="isMutating"
|
||||||
</VButton>
|
type="secondary"
|
||||||
</div>
|
@click="$formkit.submit(name)"
|
||||||
</div>
|
>
|
||||||
|
{{ $t("core.common.buttons.save") }}
|
||||||
|
</VButton>
|
||||||
|
</StickyBlock>
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { computed, ref, type Ref, inject, toRaw } from "vue";
|
||||||
|
|
||||||
// components
|
// components
|
||||||
import { Toast, VButton } from "@halo-dev/components";
|
import { Toast, VButton } from "@halo-dev/components";
|
||||||
|
import StickyBlock from "@/components/sticky-block/StickyBlock.vue";
|
||||||
|
|
||||||
// hooks
|
// hooks
|
||||||
import { useSettingFormConvert } from "@console/composables/use-setting-form";
|
import { useSettingFormConvert } from "@console/composables/use-setting-form";
|
||||||
|
@ -67,35 +68,36 @@ const handleSaveConfigMap = async () => {
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Transition mode="out-in" name="fade">
|
<Transition mode="out-in" name="fade">
|
||||||
<div class="bg-white p-4">
|
<div class="p-4">
|
||||||
<div>
|
<FormKit
|
||||||
<FormKit
|
v-if="group && formSchema && configMapFormData?.[group]"
|
||||||
v-if="group && formSchema && configMapFormData?.[group]"
|
:id="group"
|
||||||
:id="group"
|
v-model="configMapFormData[group]"
|
||||||
v-model="configMapFormData[group]"
|
:name="group"
|
||||||
:name="group"
|
:actions="false"
|
||||||
:actions="false"
|
:preserve="true"
|
||||||
:preserve="true"
|
type="form"
|
||||||
type="form"
|
@submit="handleSaveConfigMap"
|
||||||
@submit="handleSaveConfigMap"
|
>
|
||||||
|
<FormKitSchema
|
||||||
|
:schema="toRaw(formSchema)"
|
||||||
|
:data="configMapFormData[group]"
|
||||||
|
/>
|
||||||
|
</FormKit>
|
||||||
|
|
||||||
|
<StickyBlock
|
||||||
|
v-permission="['system:configmaps:manage']"
|
||||||
|
class="-mx-4 -mb-4 rounded-b-base rounded-t-lg bg-white p-4 pt-5"
|
||||||
|
position="bottom"
|
||||||
|
>
|
||||||
|
<VButton
|
||||||
|
:loading="saving"
|
||||||
|
type="secondary"
|
||||||
|
@click="$formkit.submit(group || '')"
|
||||||
>
|
>
|
||||||
<FormKitSchema
|
{{ $t("core.common.buttons.save") }}
|
||||||
:schema="toRaw(formSchema)"
|
</VButton>
|
||||||
:data="configMapFormData[group]"
|
</StickyBlock>
|
||||||
/>
|
|
||||||
</FormKit>
|
|
||||||
</div>
|
|
||||||
<div v-permission="['system:configmaps:manage']" class="pt-5">
|
|
||||||
<div class="flex justify-start">
|
|
||||||
<VButton
|
|
||||||
:loading="saving"
|
|
||||||
type="secondary"
|
|
||||||
@click="$formkit.submit(group || '')"
|
|
||||||
>
|
|
||||||
{{ $t("core.common.buttons.save") }}
|
|
||||||
</VButton>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Transition>
|
</Transition>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useEventListener } from "@vueuse/core";
|
||||||
|
import { ref, onMounted } from "vue";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
position?: "top" | "bottom";
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
position: "top",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const stickyBlock = ref<HTMLElement | null>(null);
|
||||||
|
const isSticky = ref(false);
|
||||||
|
|
||||||
|
function computeSticky() {
|
||||||
|
if (!stickyBlock.value) return;
|
||||||
|
const rect = stickyBlock.value?.getBoundingClientRect();
|
||||||
|
|
||||||
|
if (props.position === "top") {
|
||||||
|
isSticky.value = rect.top <= 0;
|
||||||
|
} else {
|
||||||
|
isSticky.value = rect.bottom >= window.innerHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
computeSticky();
|
||||||
|
});
|
||||||
|
|
||||||
|
useEventListener("scroll", computeSticky);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
ref="stickyBlock"
|
||||||
|
:class="{ 'sticky-element': true, 'sticky-shadow': isSticky }"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.sticky-element {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sticky-shadow {
|
||||||
|
box-shadow: 0px -5px 10px -5px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Reference in New Issue