Files
JayuCloud/YumiNail-Frontend/src/components/admin/AdminResponsiveModal.vue
T

130 lines
4.4 KiB
Vue
Raw Normal View History

<template>
<a-modal
v-bind="$attrs"
:open="open"
:title="title"
:width="mergedWidth"
:centered="!isMobile"
2026-05-23 15:16:40 +08:00
:wrap-class-name="mergedWrapClassName"
:style="mergedStyle"
:body-style="mergedBodyStyle"
@update:open="handleOpenChange"
@cancel="handleCancel"
@ok="handleOk"
>
<slot />
<template v-if="$slots.footer" #footer>
<slot name="footer" />
</template>
</a-modal>
</template>
<script setup lang="ts">
/**
* AdminResponsiveModal page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import type { CSSProperties } from 'vue'
2026-05-23 15:16:40 +08:00
import { computed, useAttrs } from 'vue'
import { useAdminViewport } from '@/composables/useAdminViewport'
2026-05-23 15:16:40 +08:00
import { CONFIRM_ENTER_DISABLED_CLASS } from '@/composables/useConfirmEnter'
2026-05-23 18:44:57 +08:00
/**
* Purpose: modalInstanceSeed supports AdminResponsiveModal.vue by holding or executing the modal instance seed page or API role.
* Usage: import, call, read, or update this let from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 15:16:40 +08:00
let modalInstanceSeed = 0
2026-05-23 18:44:57 +08:00
/**
* Purpose: props supports AdminResponsiveModal.vue by holding or executing the props page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const props = withDefaults(defineProps<{
open: boolean
title?: string
desktopWidth?: string | number
mobileBodyPadding?: string
2026-05-23 15:16:40 +08:00
confirmOnEnter?: boolean
}>(), {
title: '',
desktopWidth: 720,
2026-05-23 15:16:40 +08:00
mobileBodyPadding: '16px 16px 104px',
confirmOnEnter: true
})
2026-05-23 18:44:57 +08:00
/**
* Purpose: emit supports AdminResponsiveModal.vue by holding or executing the emit page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const emit = defineEmits<{
(event: 'update:open', value: boolean): void
(event: 'cancel', value?: unknown): void
(event: 'ok', value?: unknown): void
}>()
const { isMobile } = useAdminViewport()
2026-05-23 18:44:57 +08:00
/**
* Purpose: attrs supports AdminResponsiveModal.vue by holding or executing the attrs page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 15:16:40 +08:00
const attrs = useAttrs()
2026-05-23 18:44:57 +08:00
/**
* Purpose: modalInstanceClass supports AdminResponsiveModal.vue by holding or executing the modal instance class page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 15:16:40 +08:00
const modalInstanceClass = `admin-responsive-modal-${modalInstanceSeed++}`
/** mergedWidth is a reactive state variable used by the template and event handlers. */
const mergedWidth = computed(() => (isMobile.value ? '100vw' : props.desktopWidth))
/** mergedStyle is a reactive state variable used by the template and event handlers. */
const mergedStyle = computed(() => (
isMobile.value
? {
top: '0px',
maxWidth: '100vw',
paddingBottom: '0px'
}
: undefined
))
2026-05-23 18:44:57 +08:00
/**
* Purpose: mergedWrapClassName supports AdminResponsiveModal.vue by holding or executing the merged wrap class name page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-05-23 15:16:40 +08:00
const mergedWrapClassName = computed(() => (
[
attrs.wrapClassName || attrs['wrap-class-name'],
isMobile.value ? 'admin-mobile-modal' : '',
props.confirmOnEnter ? '' : CONFIRM_ENTER_DISABLED_CLASS,
modalInstanceClass
]
.filter(Boolean)
.join(' ')
))
/** mergedBodyStyle is a reactive state variable used by the template and event handlers. */
const mergedBodyStyle = computed(() => (
isMobile.value
? ({
maxHeight: 'calc(100vh - 124px)',
overflowY: 'auto',
padding: props.mobileBodyPadding
} as CSSProperties)
: undefined
))
/** handleOpenChange is a local helper used by this page script. */
const handleOpenChange = (value: boolean) => {
emit('update:open', value)
}
/** handleCancel is a local helper used by this page script. */
const handleCancel = (event?: unknown) => {
emit('update:open', false)
emit('cancel', event)
}
/** handleOk is a local helper used by this page script. */
const handleOk = (event?: unknown) => {
emit('ok', event)
}
</script>