feat: 添加 PWA 安装支持,包括安装横幅和按钮;更新国际化文本;配置 PWA 清单和缓存策略
This commit is contained in:
42
packages/distribute/components/PWAInstallButton.vue
Normal file
42
packages/distribute/components/PWAInstallButton.vue
Normal file
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
const { t } = useI18n()
|
||||
const { canInstall, isInstalled, install } = usePWAInstall()
|
||||
const installing = ref(false)
|
||||
|
||||
async function handleInstall() {
|
||||
installing.value = true
|
||||
try {
|
||||
const success = await install()
|
||||
if (success) {
|
||||
// 可以显示成功提示
|
||||
console.log('PWA 安装成功')
|
||||
}
|
||||
}
|
||||
finally {
|
||||
installing.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UButton
|
||||
v-if="canInstall && !isInstalled"
|
||||
:loading="installing"
|
||||
size="md"
|
||||
icon="i-heroicons-arrow-down-tray"
|
||||
@click="handleInstall"
|
||||
>
|
||||
{{ t('installPWA') }}
|
||||
</UButton>
|
||||
<UBadge
|
||||
v-else-if="isInstalled"
|
||||
size="md"
|
||||
color="primary"
|
||||
variant="subtle"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<UIcon name="i-heroicons-check-circle" class="w-5 h-5" />
|
||||
{{ t('installed') }}
|
||||
</div>
|
||||
</UBadge>
|
||||
</template>
|
||||
Reference in New Issue
Block a user