Files
syops/frontend/src/features/chat/components/TrainingShareModal.vue
T
runny 1034435355 fix(auth): 企微提醒卡片深链登录后回跳原目标
- 新增 shared/utils/redirect.ts 安全回跳校验(防开放重定向)
- 路由守卫未登录跳转携带 redirect 完整深链,已登录访问登录页优先回跳
- 登录成功统一按 redirect 深链落地,支持企微卡片点击直达精益培训模块
2026-09-11 04:09:56 +08:00

161 lines
6.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!--
features/chat/components/TrainingShareModal.vue
用途:员工培训分享弹窗——把"当前培训模块深链 + 二维码"提供给有培训管理权限的 HR/管理员,
供其复制链接或下载二维码后分发给员工(企微/短信/海报等渠道)。
依赖:qrcode(前端生成二维码 dataURL)、copyTextToClipboard(shared/utils/clipboard)、useMessage。
逻辑:由 TrainingWorkspacePanel 以 v-model:open 控制显隐;打开时按 shareUrl 生成二维码;
接收方打开链接 → 登录 → 由面板深链逻辑自动定位到对应培训模块(见 TrainingWorkspacePanel.vue)。
-->
<script setup lang="ts">
import { ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import QRCode from 'qrcode';
import { Copy, Download, Share2, XCircle } from 'lucide-vue-next';
import { copyTextToClipboard } from '@/shared/utils/clipboard';
import { useMessage } from '@/shared/composables/useMessage';
const props = defineProps<{
open: boolean;
/** 分享深链:/chat/<agentId>?training_type=<code>,由调用方拼好完整绝对地址。 */
shareUrl: string;
/** 当前分享的培训模块名称,仅用于弹窗内文案展示。 */
trainingName: string;
}>();
const emit = defineEmits<{
'update:open': [open: boolean];
}>();
const { t } = useI18n();
const msg = useMessage();
const qrDataUrl = ref('');
const qrGenerating = ref(false);
watch(
() => [props.open, props.shareUrl] as const,
async ([open, url]) => {
if (!open || !url) return;
qrGenerating.value = true;
try {
// 纠错级别 H:二维码可能被打印后裁剪/污损,取最高冗余保证扫码成功率。
qrDataUrl.value = await QRCode.toDataURL(url, { width: 240, margin: 2, errorCorrectionLevel: 'H' });
} catch {
qrDataUrl.value = '';
} finally {
qrGenerating.value = false;
}
},
{ immediate: true },
);
const closeModal = () => emit('update:open', false);
/**
* 复制培训深链到剪贴板(兼容企微 WebView 等 clipboard API 受限环境)。
* AI 触发时机:HR 在分享弹窗点击“复制链接”时调用;结果必须用 useMessage 明确反馈成败。
*/
const copyShareLink = async () => {
const ok = await copyTextToClipboard(props.shareUrl);
if (ok) {
msg.success(t('chat.training.share.copied'));
} else {
msg.error(t('chat.training.share.copyFailed'));
}
};
/**
* 把当前二维码下载为 PNG 图片,供 HR 插入海报/群公告等离线场景。
* AI 触发时机:HR 在分享弹窗点击“下载二维码”时调用;二维码未生成完成时禁止下载。
*/
const downloadQrCode = () => {
if (!qrDataUrl.value) return;
const link = document.createElement('a');
link.href = qrDataUrl.value;
link.download = `training-share-qr-${Date.now()}.png`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
</script>
<template>
<Teleport to="body">
<div
v-if="open"
class="fixed inset-0 z-[100] flex items-center justify-center bg-slate-950/80 p-4 backdrop-blur-sm"
@click.self="closeModal"
>
<div class="relative w-full max-w-md overflow-hidden rounded-3xl bg-white shadow-2xl">
<div class="flex items-center justify-between border-b border-default px-6 py-4">
<h3 class="flex items-center gap-2 text-lg font-semibold text-primary">
<Share2 class="h-5 w-5 text-brand-600" />
{{ $t('chat.training.share.title') }}
</h3>
<button
type="button"
class="flex h-8 w-8 items-center justify-center rounded-full bg-surface-soft text-secondary transition hover:bg-surface hover:text-primary"
:aria-label="$t('chat.training.share.close')"
@click="closeModal"
>
<XCircle class="h-5 w-5" />
</button>
</div>
<div class="flex flex-col gap-4 px-6 py-5">
<p class="text-sm leading-6 text-secondary">
{{ $t('chat.training.share.description', { name: trainingName }) }}
</p>
<!-- 培训链接:只读展示 + 一键复制,避免长链接被截断导致复制不全。 -->
<div>
<div class="text-xs font-medium text-secondary">{{ $t('chat.training.share.linkLabel') }}</div>
<div class="mt-1.5 flex items-center gap-2">
<input
type="text"
readonly
:value="shareUrl"
class="input-field h-9 min-w-0 flex-1 truncate text-xs"
@focus="($event.target as HTMLInputElement).select()"
/>
<button
type="button"
class="inline-flex h-9 shrink-0 items-center gap-1.5 rounded-xl bg-brand-600 px-3.5 text-xs font-medium text-white transition hover:bg-brand-700"
@click="copyShareLink"
>
<Copy class="h-4 w-4" />
{{ $t('chat.training.share.copyLink') }}
</button>
</div>
</div>
<!-- 培训二维码:扫码与链接等价,未登录用户扫码后先登录再自动直达对应模块。 -->
<div>
<div class="text-xs font-medium text-secondary">{{ $t('chat.training.share.qrLabel') }}</div>
<div class="mt-1.5 flex items-center gap-4">
<div class="flex h-40 w-40 shrink-0 items-center justify-center rounded-2xl border border-default bg-surface-soft">
<img
v-if="qrDataUrl"
:src="qrDataUrl"
:alt="$t('chat.training.share.qrLabel')"
class="h-36 w-36"
/>
<span v-else class="text-xs text-secondary">{{ qrGenerating ? '...' : '--' }}</span>
</div>
<button
type="button"
class="inline-flex h-9 items-center gap-1.5 rounded-xl border border-default bg-white px-3.5 text-xs font-medium text-secondary transition hover:bg-surface-soft disabled:cursor-not-allowed disabled:opacity-60"
:disabled="!qrDataUrl"
@click="downloadQrCode"
>
<Download class="h-4 w-4" />
{{ $t('chat.training.share.downloadQr') }}
</button>
</div>
</div>
</div>
</div>
</div>
</Teleport>
</template>