front/src/components/InvitePoster.vue
zzh 25445bc146 feat: 完善日夜间主题与揽收下单体验
统一暗色模式页面/顶栏/Handsontable 选中色,调整下单到仓方式文案与提示,CustomLeftMenu 卡片统一 60px;补充揽收单、问题件处理与 H5 相关页面。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-04 11:49:23 +08:00

193 lines
4.1 KiB
Vue

<script lang="ts" setup>
import { onMounted, onBeforeUnmount, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
import { buildInvitePosterDataUrl } from '@/utils/invitePoster';
defineOptions({ name: 'InvitePoster' });
const props = withDefaults(
defineProps<{
value: string;
inviteCode?: string;
/** 展示宽度(高度按海报比例自适应) */
displayWidth?: number | string;
showDownload?: boolean;
alt?: string;
}>(),
{
inviteCode: '',
displayWidth: '100%',
showDownload: true,
alt: 'invite-poster',
},
);
const emit = defineEmits<{
ready: [dataUrl: string];
fail: [];
}>();
const { t } = useI18n();
const dataUrl = ref('');
const loading = ref(false);
const failed = ref(false);
let renderSeq = 0;
async function render() {
const seq = ++renderSeq;
failed.value = false;
dataUrl.value = '';
if (!props.value) return;
loading.value = true;
try {
const url = await buildInvitePosterDataUrl({
inviteUrl: props.value,
inviteCode: props.inviteCode,
});
if (seq !== renderSeq) return;
dataUrl.value = url;
emit('ready', url);
} catch {
if (seq !== renderSeq) return;
failed.value = true;
emit('fail');
} finally {
if (seq === renderSeq) {
loading.value = false;
}
}
}
function downloadPoster() {
if (!dataUrl.value) return;
const a = document.createElement('a');
a.href = dataUrl.value;
a.download = 'invite-poster.jpg';
a.rel = 'noopener';
document.body.appendChild(a);
a.click();
a.remove();
Message.success(t('h5.invite.posterSaved'));
}
onMounted(() => {
void render();
});
onBeforeUnmount(() => {
renderSeq += 1;
});
watch(
() => [props.value, props.inviteCode] as const,
() => {
void render();
},
);
defineExpose({
getDataUrl: () => dataUrl.value,
refresh: render,
download: downloadPoster,
});
</script>
<template>
<div class="invite-poster">
<div v-if="loading" class="invite-poster__loading">
<a-spin :size="28" />
<p>{{ t('h5.invite.posterLoading') }}</p>
</div>
<template v-else-if="dataUrl">
<img
:src="dataUrl"
:alt="alt"
class="invite-poster__img"
:style="{ width: typeof displayWidth === 'number' ? `${displayWidth}px` : displayWidth }"
/>
<button
v-if="showDownload"
type="button"
class="invite-poster__save"
@click="downloadPoster"
>
{{ t('h5.invite.savePoster') }}
</button>
<p class="invite-poster__tip">{{ t('h5.invite.posterTip') }}</p>
</template>
<div v-else-if="failed" class="invite-poster__fail">
<p>{{ t('h5.invite.posterFailed') }}</p>
<button type="button" class="invite-poster__retry" @click="render">
{{ t('h5.invite.posterRetry') }}
</button>
</div>
</div>
</template>
<style scoped lang="less">
.invite-poster {
text-align: center;
}
.invite-poster__img {
display: block;
max-width: 100%;
height: auto;
margin: 0 auto;
border-radius: 12px;
box-shadow: 0 8px 24px rgba(8, 52, 115, 0.14);
background: var(--app-card-bg);
}
.invite-poster__loading,
.invite-poster__fail {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
min-height: 160px;
padding: 28px 12px;
font-size: 13px;
color: var(--color-text-3);
}
.invite-poster__loading p,
.invite-poster__fail p {
margin: 0;
}
.invite-poster__retry {
height: 32px;
padding: 0 14px;
border: 1px solid color-mix(in srgb, var(--app-primary-color) 35%, var(--color-border-2));
border-radius: 8px;
background: var(--app-card-bg);
color: var(--app-primary-color);
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.invite-poster__save {
margin-top: 12px;
height: 36px;
padding: 0 18px;
border: none;
border-radius: 10px;
background: var(--app-primary-color);
color: #fff;
font-size: 13px;
font-weight: 600;
cursor: pointer;
}
.invite-poster__tip {
margin: 10px 0 0;
font-size: 12px;
color: var(--color-text-3);
line-height: 1.5;
}
</style>