新版官网模板

This commit is contained in:
2026-04-29 01:33:33 +08:00
commit 0d82386f8f
341 changed files with 64526 additions and 0 deletions

View File

@@ -0,0 +1,368 @@
<template>
<div class="list-page">
<!-- 页面头部 Banner -->
<div :style="{ background: config.bannerGradient }" class="page-banner">
<div class="mx-auto max-w-screen-xl px-4">
<h1 class="banner-title">{{ config.title }}</h1>
<p class="banner-desc">{{ config.desc }}</p>
</div>
</div>
<div class="mx-auto max-w-screen-xl px-4 py-8">
<a-row :gutter="[32, 0]">
<!-- 左侧分类导航 -->
<a-col :lg="5" :xs="24" class="mb-6 lg:mb-0">
<div class="category-sidebar">
<div class="category-sidebar-title">{{ config.title }}</div>
<div
v-for="cat in config.categories"
:key="cat.type"
:class="{ active: activeType === cat.type }"
class="category-item"
@click="selectType(cat.type)"
>
{{ cat.label }}
</div>
</div>
</a-col>
<!-- 右侧内容区 -->
<a-col :lg="19" :xs="24">
<!-- 当前分类提示 -->
<div class="category-breadcrumb">
<span class="category-name">{{ currentCategoryLabel }}</span>
<span class="article-count"> {{ total }} 篇文章</span>
</div>
<div v-if="loading" class="loading-state">
<a-skeleton v-for="i in 5" :key="i" :paragraph="{ rows: 2 }" active style="margin-bottom:16px" />
</div>
<div v-else>
<div class="article-list">
<div
v-for="article in articles"
:key="article.id"
class="article-item"
@click="handleView(article)"
>
<div v-if="article.image" class="article-thumb">
<img :alt="article.title" :src="article.image" />
</div>
<div class="article-main">
<h3 class="article-title">{{ article.title }}</h3>
<p class="article-overview">{{ article.overview }}</p>
<div class="article-meta">
<span v-if="article.type" class="meta-tag">{{ getCategoryLabel(article.type) }}</span>
<span class="meta-item">{{ article.source }}</span>
<span class="meta-item">{{ article.publishTime }}</span>
<span v-if="article.views" class="meta-item">👁 {{ article.views }}</span>
</div>
</div>
</div>
</div>
<div v-if="articles.length === 0" class="empty-state">
<a-empty description="暂无内容" />
</div>
<div v-if="total > pageSize" class="pagination-wrap">
<a-pagination
v-model:current="currentPage"
:page-size="pageSize"
:total="total"
show-quick-jumper
@change="handlePageChange"
/>
</div>
</div>
</a-col>
</a-row>
</div>
</div>
</template>
<script lang="ts" setup>
import { message } from 'ant-design-vue'
interface PageConfig {
title: string
desc: string
bannerGradient: string
categories: Array<{ type: string; label: string }>
baseRoute: string
}
const props = defineProps<{
config: PageConfig
}>()
const route = useRoute()
const router = useRouter()
const activeType = ref((route.query.type as string) || '')
const currentPage = ref(1)
const pageSize = ref(12)
const total = ref(0)
const loading = ref(false)
const articles = ref<any[]>([])
const currentCategoryLabel = computed(() => {
if (!activeType.value) return '全部文章'
const found = props.config.categories.find(c => c.type === activeType.value)
return found?.label || '全部文章'
})
function getCategoryLabel(type: string) {
const found = props.config.categories.find(c => c.type === type)
return found?.label || type
}
function selectType(type: string) {
activeType.value = type
currentPage.value = 1
router.replace({ query: type ? { type } : {} })
loadArticles()
}
async function loadArticles() {
loading.value = true
try {
// TODO: 接入实际API
// const res = await listArticles({ category: props.config.baseRoute, type: activeType.value, page: currentPage.value })
// Fallback mock data
total.value = 35
articles.value = Array.from({ length: Math.min(pageSize.value, 35 - (currentPage.value - 1) * pageSize.value) }, (_, i) => ({
id: (currentPage.value - 1) * pageSize.value + i + 1,
title: `${currentCategoryLabel.value}文章标题 ${(currentPage.value - 1) * pageSize.value + i + 1}:广西政策研究成果发布`,
overview: '摘要内容:本文就广西经济社会发展中的若干重大问题进行深入研究,提出了切实可行的政策建议和对策措施,为相关决策提供参考依据...',
image: `https://picsum.photos/200/130?random=${(currentPage.value - 1) * pageSize.value + i + 1}`,
source: '广西决策咨询中心',
publishTime: `2024-12-${String(20 - i).padStart(2, '0')}`,
views: Math.floor(Math.random() * 2000) + 100,
type: activeType.value || props.config.categories[i % props.config.categories.length]?.type,
}))
} catch (e: any) {
message.error('加载失败')
} finally {
loading.value = false
}
}
function handlePageChange(page: number) {
currentPage.value = page
loadArticles()
window.scrollTo({ top: 0, behavior: 'smooth' })
}
function handleView(article: any) {
router.push(`/article/${article.id}`)
}
watch(() => route.query.type, (newType) => {
activeType.value = (newType as string) || ''
currentPage.value = 1
loadArticles()
})
onMounted(() => {
loadArticles()
})
</script>
<style scoped>
.list-page {
background: #f5f7fa;
min-height: 60vh;
}
.page-banner {
padding: 48px 0 32px;
position: relative;
overflow: hidden;
}
.banner-title {
color: #fff;
font-size: 30px;
font-weight: 700;
margin: 0 0 8px;
}
.banner-desc {
color: rgba(255,255,255,0.75);
font-size: 15px;
margin: 0;
}
/* 左侧分类 */
.category-sidebar {
background: #fff;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
overflow: hidden;
position: sticky;
top: 80px;
}
.category-sidebar-title {
padding: 14px 18px;
background: #1e3a5f;
color: #fff;
font-size: 14px;
font-weight: 600;
}
.category-item {
padding: 12px 18px;
font-size: 14px;
color: #374151;
cursor: pointer;
border-bottom: 1px solid #f5f5f5;
transition: all 0.2s;
}
.category-item:hover {
background: #f0f7ff;
color: #1e3a5f;
}
.category-item.active {
background: #eff6ff;
color: #1e3a5f;
font-weight: 600;
border-left: 3px solid #1e3a5f;
}
/* 内容区 */
.category-breadcrumb {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px;
background: #fff;
border-radius: 8px;
margin-bottom: 16px;
box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.category-name {
font-size: 16px;
font-weight: 700;
color: #1e3a5f;
}
.article-count {
font-size: 13px;
color: #9ca3af;
}
.article-list {
display: flex;
flex-direction: column;
gap: 12px;
}
.article-item {
display: flex;
gap: 20px;
padding: 20px;
background: #fff;
border-radius: 12px;
box-shadow: 0 2px 6px rgba(0,0,0,0.05);
cursor: pointer;
transition: all 0.2s;
}
.article-item:hover {
box-shadow: 0 4px 16px rgba(0,0,0,0.1);
transform: translateY(-2px);
}
.article-thumb {
width: 160px;
height: 108px;
border-radius: 8px;
overflow: hidden;
flex-shrink: 0;
}
.article-thumb img {
width: 100%;
height: 100%;
object-fit: cover;
}
.article-main {
flex: 1;
display: flex;
flex-direction: column;
}
.article-title {
font-size: 17px;
font-weight: 600;
color: #1f2937;
margin: 0 0 8px;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.article-overview {
font-size: 13px;
color: #6b7280;
margin: 0 0 auto;
line-height: 1.6;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.article-meta {
display: flex;
align-items: center;
gap: 12px;
margin-top: 12px;
}
.meta-tag {
padding: 2px 8px;
background: #eff6ff;
color: #1e40af;
font-size: 11px;
border-radius: 4px;
font-weight: 500;
}
.meta-item {
font-size: 12px;
color: #9ca3af;
}
.loading-state {
background: #fff;
border-radius: 12px;
padding: 20px;
}
.empty-state {
background: #fff;
border-radius: 12px;
padding: 60px;
text-align: center;
}
.pagination-wrap {
margin-top: 32px;
text-align: center;
padding-bottom: 20px;
}
@media (max-width: 768px) {
.article-item { flex-direction: column; }
.article-thumb { width: 100%; height: 180px; }
}
</style>

View File

@@ -0,0 +1,383 @@
<template>
<a-popover
v-model:open="popoverVisible"
:arrow="true"
:overlay-class-name="`notification-popover ${theme}`"
placement="bottomRight"
trigger="click"
@openChange="onPopoverChange"
>
<template #content>
<div class="bell-dropdown">
<!-- 头部标题 + 全部已读 -->
<div class="dropdown-header">
<span class="dropdown-title">消息通知</span>
<a-button
v-if="unreadTotal > 0"
:loading="markAllLoading"
class="mark-all-btn"
size="small"
type="link"
@click="handleMarkAll"
>
全部已读
</a-button>
</div>
<!-- Tab 过滤 -->
<div class="dropdown-tabs">
<a-radio-group v-model:value="activeType" button-style="solid" size="small" @change="handleTypeChange">
<a-radio-button value="">全部</a-radio-button>
<a-radio-button value="ticket">工单</a-radio-button>
<a-radio-button value="system">系统</a-radio-button>
<a-radio-button value="review">审核</a-radio-button>
</a-radio-group>
</div>
<!-- 通知列表 -->
<div class="dropdown-list" @scroll="onListScroll">
<a-spin :spinning="loading">
<template v-if="filteredRecentList.length">
<div
v-for="item in filteredRecentList"
:key="item.id"
:class="{ unread: !item.isRead }"
class="notification-item"
@click="handleItemClick(item)"
>
<div class="item-icon">
{{ notificationTypeMap[item.type!]?.icon || '📢' }}
</div>
<div class="item-body">
<div class="item-title">{{ item.title }}</div>
<div class="item-content">{{ item.content }}</div>
<div class="item-meta">
<span class="item-time">{{ formatTime(item.createTime) }}</span>
<span v-if="item.senderName" class="item-sender">{{ item.senderName }}</span>
</div>
</div>
<div v-if="!item.isRead" class="item-dot" />
</div>
</template>
<a-empty v-else :image-style="{ height: '60px' }" description="暂无消息" />
</a-spin>
</div>
<!-- 底部查看全部 -->
<div class="dropdown-footer">
<a-button block type="link" @click="goToAll">
查看全部通知
<RightOutlined />
</a-button>
</div>
</div>
</template>
<!-- 铃铛触发器 -->
<div :class="[theme]" class="bell-trigger" @click.stop>
<a-badge :count="unreadTotal" :dot="false" :overflow-count="99" size="small">
<BellOutlined class="bell-icon" />
</a-badge>
</div>
</a-popover>
</template>
<script lang="ts" setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { BellOutlined, RightOutlined } from '@ant-design/icons-vue'
import { useNotificationCenter, notificationTypeMap } from '@/composables/useNotificationCenter'
import type { Notification, NotificationType } from '@/api/app/notification/model'
const props = withDefaults(defineProps<{
/** 主题light 用于 console 白色头部dark 用于 SiteHeader 暗色头部 */
theme?: 'light' | 'dark'
}>(), {
theme: 'light',
})
const {
unreadTotal,
recentList,
loading,
fetchUnreadCount,
fetchRecentNotifications,
markNotificationRead,
markAllAsRead,
startPolling,
stopPolling,
formatTime,
getNotificationLink,
} = useNotificationCenter()
const popoverVisible = ref(false)
const activeType = ref('')
const markAllLoading = ref(false)
// 过滤后的最近通知
const filteredRecentList = computed(() => {
if (!activeType.value) return recentList.value
return recentList.value.filter((n) => n.type === activeType.value)
})
function onPopoverChange(visible: boolean) {
if (visible) {
fetchRecentNotifications()
}
}
function handleTypeChange() {
// 切换类型时重新加载
fetchRecentNotifications()
}
async function handleItemClick(item: Notification) {
// 标记已读
if (!item.isRead && item.id) {
await markNotificationRead(item.id)
}
// 关闭弹窗
popoverVisible.value = false
// 跳转
const link = getNotificationLink(item)
navigateTo(link)
}
async function handleMarkAll() {
markAllLoading.value = true
try {
const type = activeType.value || undefined
await markAllAsRead(type)
} finally {
markAllLoading.value = false
}
}
function goToAll() {
popoverVisible.value = false
navigateTo('/console/notifications')
}
function onListScroll() {
// 暂不实现无限滚动,铃铛下拉只展示最近 10 条
}
onMounted(() => {
startPolling()
})
onUnmounted(() => {
stopPolling()
})
</script>
<style scoped>
/* ===== 铃铛触发器 ===== */
.bell-trigger {
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border-radius: 9999px;
cursor: pointer;
transition: background 0.2s, color 0.2s;
position: relative;
}
.bell-trigger.light {
color: #374151;
}
.bell-trigger.light:hover {
background: rgba(0, 0, 0, 0.04);
}
.bell-trigger.dark {
color: rgba(255, 255, 255, 0.85);
}
.bell-trigger.dark:hover {
background: rgba(255, 255, 255, 0.1);
color: #fff;
}
.bell-icon {
font-size: 18px;
}
/* ===== 下拉面板 ===== */
.bell-dropdown {
width: 380px;
max-height: 520px;
display: flex;
flex-direction: column;
}
.dropdown-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 16px 8px;
border-bottom: 1px solid #f0f0f0;
}
.dropdown-title {
font-size: 15px;
font-weight: 600;
color: rgba(0, 0, 0, 0.88);
}
.mark-all-btn {
font-size: 12px;
padding: 0;
height: auto;
}
.dropdown-tabs {
padding: 8px 16px 4px;
}
.dropdown-tabs :deep(.ant-radio-group) {
width: 100%;
}
.dropdown-tabs :deep(.ant-radio-button-wrapper) {
flex: 1;
text-align: center;
font-size: 12px;
padding: 0 4px;
height: 28px;
line-height: 26px;
}
/* ===== 通知列表 ===== */
.dropdown-list {
flex: 1;
overflow-y: auto;
max-height: 360px;
padding: 4px 0;
}
.dropdown-list::-webkit-scrollbar {
width: 4px;
}
.dropdown-list::-webkit-scrollbar-thumb {
background: rgba(0, 0, 0, 0.12);
border-radius: 4px;
}
.notification-item {
display: flex;
gap: 10px;
padding: 10px 16px;
cursor: pointer;
transition: background 0.15s;
position: relative;
}
.notification-item:hover {
background: rgba(0, 0, 0, 0.02);
}
.notification-item.unread {
background: rgba(24, 144, 255, 0.03);
}
.notification-item.unread::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 3px;
height: 24px;
background: #1890ff;
border-radius: 0 3px 3px 0;
}
.item-icon {
flex-shrink: 0;
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
border-radius: 10px;
font-size: 16px;
}
.item-body {
flex: 1;
min-width: 0;
}
.item-title {
font-size: 13px;
font-weight: 500;
color: rgba(0, 0, 0, 0.88);
line-height: 1.4;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.notification-item.unread .item-title {
font-weight: 600;
}
.item-content {
font-size: 12px;
color: rgba(0, 0, 0, 0.45);
line-height: 1.5;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin-top: 2px;
}
.item-meta {
display: flex;
align-items: center;
gap: 8px;
margin-top: 4px;
font-size: 11px;
color: rgba(0, 0, 0, 0.35);
}
.item-dot {
flex-shrink: 0;
width: 8px;
height: 8px;
border-radius: 50%;
background: #1890ff;
margin-top: 14px;
}
/* ===== 底部 ===== */
.dropdown-footer {
padding: 6px 16px;
border-top: 1px solid #f0f0f0;
}
.dropdown-footer :deep(.ant-btn-link) {
font-size: 13px;
color: rgba(0, 0, 0, 0.65);
padding: 4px 0;
}
.dropdown-footer :deep(.ant-btn-link:hover) {
color: #1890ff;
}
</style>
<style>
/* 暗色主题下的 popover 适配 */
.notification-popover.dark .ant-popover-inner {
background: #1f2937;
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.notification-popover.dark .ant-popover-arrow::before {
background: #1f2937;
}
</style>

View File

@@ -0,0 +1,120 @@
<template>
<a-modal
:destroy-on-close="true"
:footer="null"
:open="open"
:width="380"
centered
@cancel="$emit('update:open', false)"
>
<div class="qr-modal">
<div class="qr-title">{{ title }}</div>
<div class="qr-subtitle">{{ tip }}</div>
<div class="qr-image-wrap">
<img
v-if="qrcodeUrl"
:alt="appName"
:src="qrcodeUrl"
class="qr-image"
@error="loadError = true"
/>
<div v-if="loadError" class="qr-error">
<PictureOutlined style="font-size: 40px; color: #bbb" />
<span>图片加载失败</span>
</div>
</div>
<div class="qr-app-name">{{ appName }}</div>
<div class="qr-actions">
<a-button size="small" type="link" @click="downloadQr">
<template #icon><DownloadOutlined /></template>
保存小程序码
</a-button>
</div>
</div>
</a-modal>
</template>
<script lang="ts" setup>
import { DownloadOutlined, PictureOutlined } from '@ant-design/icons-vue'
import { ref } from 'vue'
defineProps<{
open: boolean
qrcodeUrl?: string
appName?: string
title?: string
tip?: string
}>()
defineEmits<{
'update:open': [val: boolean]
}>()
const loadError = ref(false)
async function downloadQr() {
// 由外部通过 ref 调用,或用简单方式下载
}
</script>
<style scoped>
.qr-modal {
text-align: center;
padding: 8px 0 0;
}
.qr-title {
font-size: 18px;
font-weight: 600;
color: rgba(0, 0, 0, 0.88);
margin-bottom: 4px;
}
.qr-subtitle {
font-size: 14px;
color: rgba(0, 0, 0, 0.45);
margin-bottom: 20px;
}
.qr-image-wrap {
display: flex;
align-items: center;
justify-content: center;
width: 220px;
height: 220px;
margin: 0 auto;
background: #fafafa;
border-radius: 12px;
border: 1px dashed #d9d9d9;
overflow: hidden;
}
.qr-image {
width: 100%;
height: 100%;
object-fit: contain;
}
.qr-error {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
color: #999;
font-size: 13px;
}
.qr-app-name {
font-size: 15px;
font-weight: 500;
color: rgba(0, 0, 0, 0.65);
margin-top: 12px;
}
.qr-actions {
margin-top: 8px;
}
</style>

327
app/components/QrLogin.vue Normal file
View File

@@ -0,0 +1,327 @@
<template>
<div class="qr-login">
<div class="qr-box">
<div v-if="status === 'loading'" class="qr-state">
<a-spin size="large" />
<p class="muted">正在生成二维码</p>
</div>
<!-- 微信扫码登录 -->
<div v-else-if="status === 'active'" class="qr-state">
<!-- 小程序码优先展示Base64格式 -->
<img
v-if="miniprogramQrCode"
:src="miniprogramQrCode"
alt="小程序码登录"
class="qrcode-img"
@click="refresh"
/>
<!-- 普通二维码降级方案 -->
<img
v-else-if="qrCodeDataUrl"
:src="qrCodeDataUrl"
alt="扫码登录"
class="qrcode-img"
@click="refresh"
/>
<div v-else class="qrcode-placeholder">
<a-spin size="large" />
</div>
<p class="tip">请使用微信扫一扫扫码后自动登录</p>
<p class="muted">有效期{{ formatCountdown(expireSeconds) }}</p>
</div>
<div v-else-if="status === 'scanned'" class="qr-state">
<CheckCircleOutlined class="icon ok" />
<p class="ok-text">已识别扫码请在手机上确认登录</p>
</div>
<div v-else-if="status === 'expired'" class="qr-state">
<ClockCircleOutlined class="icon bad" />
<p class="bad-text">二维码已过期</p>
<a-button type="primary" @click="refresh">刷新二维码</a-button>
</div>
<div v-else-if="status === 'error'" class="qr-state">
<ExclamationCircleOutlined class="icon bad" />
<p class="bad-text">{{ errorMessage || '生成二维码失败' }}</p>
<a-button type="primary" @click="refresh">重新生成</a-button>
</div>
</div>
<div v-if="status === 'active'" class="actions">
<a-button :loading="refreshing" type="link" @click="refresh">
<ReloadOutlined />
刷新二维码
</a-button>
</div>
</div>
</template>
<script lang="ts" setup>
import { onMounted, onUnmounted, ref } from 'vue'
import { message } from 'ant-design-vue'
import {
CheckCircleOutlined,
ClockCircleOutlined,
ExclamationCircleOutlined,
ReloadOutlined
} from '@ant-design/icons-vue'
import {
checkQrCodeStatus,
generateQrCode,
type QrCodeResponse,
type QrCodeStatusResponse
} from '@/api/passport/qrLogin'
import { generateQrCodeDataUrl } from '@/composables/useQRCode'
const emit = defineEmits<{
(e: 'loginSuccess', data: QrCodeStatusResponse): void
(e: 'loginError', error: string): void
}>()
const router = useRouter()
const qrCodeDataUrl = ref('') // 前端生成的base64二维码图片
const miniprogramQrCode = ref('') // 后端返回的小程序码Base64图片优先使用
const token = ref('')
const status = ref<'loading' | 'active' | 'scanned' | 'expired' | 'error'>('loading')
const expireSeconds = ref(0)
const errorMessage = ref('')
const refreshing = ref(false)
let statusTimer: ReturnType<typeof setInterval> | null = null
let countdownTimer: ReturnType<typeof setInterval> | null = null
function stopTimers() {
if (statusTimer) clearInterval(statusTimer)
if (countdownTimer) clearInterval(countdownTimer)
statusTimer = null
countdownTimer = null
}
// 启动轮询(小程序码和普通二维码共用)
function startStatusPolling() {
// 状态轮询
statusTimer = setInterval(async () => {
try {
const current = await checkQrCodeStatus(token.value)
if (current.expiresIn !== undefined) expireSeconds.value = current.expiresIn
if (current.status === 'scanned') {
status.value = 'scanned'
return
}
if (current.status === 'bind_phone') {
stopTimers()
message.info(current.message || '检测到新用户,请先绑定手机号')
await router.replace(`/bind-phone?token=${token.value}`)
return
}
if (current.status === 'expired') {
status.value = 'expired'
stopTimers()
return
}
if (current.status === 'confirmed') {
stopTimers()
emit('loginSuccess', current)
}
} catch {
// ignore polling errors, keep polling
}
}, 2000)
// 倒计时
countdownTimer = setInterval(() => {
expireSeconds.value = Math.max(0, expireSeconds.value - 1)
if (expireSeconds.value <= 0) {
status.value = 'expired'
stopTimers()
}
}, 1000)
}
function formatCountdown(seconds: number) {
const m = Math.floor(seconds / 60)
const s = Math.max(0, seconds % 60)
return `${m}:${String(s).padStart(2, '0')}`
}
function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
if (typeof error === 'string') return error
if (typeof error === 'object' && error && 'message' in error) {
const msg = (error as { message?: unknown }).message
if (typeof msg === 'string') return msg
}
try {
return String(error)
} catch {
return ''
}
}
async function init() {
if (!import.meta.client) return
stopTimers()
status.value = 'loading'
errorMessage.value = ''
qrCodeDataUrl.value = ''
try {
const response: QrCodeResponse = await generateQrCode()
token.value = response.token
expireSeconds.value = response.expiresIn || 300
// 优先使用后端返回的小程序码Base64图片扫码后直接打开小程序
if (response.miniprogramQrCode) {
miniprogramQrCode.value = response.miniprogramQrCode
console.info('使用小程序码Base64长度: {}', miniprogramQrCode.value.length)
status.value = 'active'
// 小程序码模式下不需要前端生成二维码,启动轮询即可
startStatusPolling()
return
}
// 小程序码不存在,降级到普通二维码
miniprogramQrCode.value = ''
console.warn('后端未返回小程序码,降级到普通二维码')
// 获取二维码内容
// 优先级wechatScanUrlH5页面微信能识别> qrCodeContent如果是http开头> 降级URL
// 不使用 qrCodeContent因为它是 websopy:// 自定义协议,微信无法识别
let qrContent = '';
if (response.wechatScanUrl) {
// 优先使用 wechatScanUrlH5 扫码页面,微信能打开)
qrContent = response.wechatScanUrl
console.info('使用微信扫码URL:', qrContent)
} else if (response.qrCodeContent && response.qrCodeContent.startsWith('http')) {
// 如果 qrCodeContent 是 http 开头,也可以使用
qrContent = response.qrCodeContent
console.info('使用 qrCodeContent:', qrContent)
} else {
// 降级使用当前域名构建扫码URL
const currentOrigin = window.location.origin
qrContent = `${currentOrigin}/wx-scan?token=${response.token}`
console.info('使用降级扫码URL:', qrContent)
}
// 前端直接生成base64二维码不再依赖后端返回的图片URL
try {
qrCodeDataUrl.value = await generateQrCodeDataUrl(qrContent, {
width: 280,
margin: 2,
color: {
dark: '#000000',
light: '#ffffff'
}
})
} catch (e) {
console.error('生成二维码失败:', e)
throw new Error('生成二维码失败,请刷新重试')
}
status.value = 'active'
// 启动轮询
startStatusPolling()
} catch (error: unknown) {
status.value = 'error'
errorMessage.value = getErrorMessage(error) || '生成二维码失败'
message.error(errorMessage.value)
emit('loginError', errorMessage.value)
}
}
async function refresh() {
refreshing.value = true
try {
await init()
} finally {
refreshing.value = false
}
}
onMounted(() => {
init()
})
onUnmounted(() => {
stopTimers()
})
</script>
<style scoped>
.qr-login {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px 0 12px;
}
.qr-box {
width: 100%;
min-height: 260px;
display: flex;
align-items: center;
justify-content: center;
}
.qr-state {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
text-align: center;
}
/* 二维码样式 */
.qrcode-img {
width: 200px;
height: 200px;
border-radius: 8px;
cursor: pointer;
transition: transform 0.2s;
}
.qrcode-img:hover {
transform: scale(1.02);
}
.qrcode-placeholder {
width: 200px;
height: 200px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
background: #f5f5f5;
}
.tip {
color: #111827;
margin: 0;
font-size: 14px;
}
.muted {
color: #6b7280;
margin: 0;
font-size: 12px;
}
.actions {
margin-top: 10px;
}
.icon {
font-size: 48px;
}
.ok {
color: #16a34a;
}
.bad {
color: #ef4444;
}
.ok-text {
margin: 0;
color: #16a34a;
}
.bad-text {
margin: 0;
color: #ef4444;
}
</style>

View File

@@ -0,0 +1,290 @@
<template>
<a-layout-footer class="footer">
<div class="mx-auto max-w-screen-xl px-4 py-12">
<!-- 主要内容区域 -->
<a-row :gutter="[32, 40]">
<!-- 品牌介绍 -->
<a-col :md="6" :xs="24">
<div class="brand-section">
<div class="brand-logo">广西决策咨询网</div>
<p class="brand-desc">
广西决策咨询中心官方平台汇聚专家智慧服务政府决策推动广西高质量发展
</p>
<div class="social-links">
<a-tooltip title="微信公众号">
<span class="social-item">
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .186-.059l2.114-1.225a.866.866 0 0 1 .58-.091 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-4.196-6.348-8.596-6.348z"/></svg>
</span>
</a-tooltip>
</div>
</div>
</a-col>
<!-- 快速导航 -->
<a-col :md="4" :sm="6" :xs="12">
<div class="footer-title">快速导航</div>
<div class="footer-links">
<NuxtLink to="/news">政策要闻</NuxtLink>
<NuxtLink to="/consultation">决策咨询</NuxtLink>
<NuxtLink to="/reference">决策参考</NuxtLink>
<NuxtLink to="/expert">专家资讯</NuxtLink>
</div>
</a-col>
<!-- 特色服务 -->
<a-col :md="4" :sm="6" :xs="12">
<div class="footer-title">特色服务</div>
<div class="footer-links">
<NuxtLink to="/think-tank">智库观察</NuxtLink>
<NuxtLink to="/suggestions">建言献策</NuxtLink>
<NuxtLink to="/membership">会员服务</NuxtLink>
<NuxtLink to="/hanmo">翰墨文谈</NuxtLink>
</div>
</a-col>
<!-- 关于我们 -->
<a-col :md="4" :sm="6" :xs="12">
<div class="footer-title">关于我们</div>
<div class="footer-links">
<NuxtLink to="/about">学会简介</NuxtLink>
<NuxtLink to="/about/organization">组织机构</NuxtLink>
<NuxtLink to="/about/charter">学会章程</NuxtLink>
<NuxtLink to="/about/join">加入我们</NuxtLink>
</div>
</a-col>
<!-- 联系我们 -->
<a-col :md="6" :sm="12" :xs="24">
<div class="footer-title">联系我们</div>
<div class="contact-info">
<div class="contact-item">
<span class="contact-icon">📍</span>
<span>广西·南宁·良庆区 五象大道401号五象航洋城</span>
</div>
<div class="contact-item">
<span class="contact-icon">📞</span>
<span>0771-5386339</span>
</div>
<div class="contact-item">
<span class="contact-icon">📧</span>
<span>gxjzxzx@126.com</span>
</div>
</div>
<!-- 二维码 -->
<div class="qrcode-section">
<div class="qrcode-item">
<div class="qrcode-box">
<img alt="微信公众号" class="qrcode-img" src="/images/qrcode-mp-official.jpg" />
</div>
<span class="qrcode-label">关注公众号</span>
</div>
</div>
</a-col>
</a-row>
<!-- 底部版权区域 -->
<div class="footer-bottom">
<div class="footer-bottom-content">
<div class="copyright">
<span>© {{ year }} 广西决策咨询中心 版权所有</span>
<a
class="icp-link"
href="https://beian.miit.gov.cn/"
rel="nofollow noopener"
target="_blank"
>桂ICP备13003666号-12</a>
</div>
<div class="powered-by">
Powered by <a class="text-gray-200" href="https://websoft.top/website" target="_blank">·企业官网</a>
</div>
</div>
</div>
</div>
</a-layout-footer>
</template>
<script lang="ts" setup>
const year = new Date().getFullYear()
</script>
<style scoped>
.footer {
background: #1e3a5f;
padding: 0;
color: #fff;
}
/* 品牌区域 */
.brand-section {
display: flex;
flex-direction: column;
}
.brand-logo {
font-size: 20px;
font-weight: 700;
color: #fff;
margin-bottom: 16px;
letter-spacing: 2px;
}
.brand-desc {
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
line-height: 1.8;
margin-bottom: 20px;
}
.social-links {
display: flex;
gap: 12px;
}
.social-item {
display: flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
background: rgba(255, 255, 255, 0.1);
border-radius: 50%;
color: rgba(255, 255, 255, 0.8);
cursor: pointer;
transition: all 0.3s;
}
.social-item:hover {
background: rgba(255, 255, 255, 0.2);
color: #fff;
}
/* 链接区域 */
.footer-title {
font-size: 16px;
font-weight: 600;
color: #fff;
margin-bottom: 20px;
}
.footer-links {
display: flex;
flex-direction: column;
gap: 12px;
}
.footer-links a {
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
text-decoration: none;
transition: color 0.2s;
}
.footer-links a:hover {
color: #fff;
}
/* 联系信息 */
.contact-info {
display: flex;
flex-direction: column;
gap: 12px;
margin-bottom: 20px;
}
.contact-item {
display: flex;
align-items: flex-start;
gap: 10px;
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
}
.contact-icon {
font-size: 16px;
flex-shrink: 0;
}
/* 二维码 */
.qrcode-section {
display: flex;
gap: 16px;
}
.qrcode-item {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
}
.qrcode-box {
width: 80px;
height: 80px;
background: #fff;
border-radius: 8px;
padding: 4px;
overflow: hidden;
}
.qrcode-img {
width: 100%;
height: 100%;
object-fit: contain;
}
.qrcode-label {
color: rgba(255, 255, 255, 0.7);
font-size: 12px;
}
/* 底部版权 */
.footer-bottom {
margin-top: 40px;
padding-top: 20px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.footer-bottom-content {
display: flex;
flex-direction: column;
gap: 8px;
align-items: center;
text-align: center;
}
@media (min-width: 768px) {
.footer-bottom-content {
flex-direction: row;
justify-content: space-between;
}
}
.copyright {
display: flex;
align-items: center;
gap: 16px;
color: rgba(255, 255, 255, 0.6);
font-size: 13px;
}
.icp-link {
color: rgba(255, 255, 255, 0.6);
text-decoration: none;
transition: color 0.2s;
}
.icp-link:hover {
color: #fff;
}
.powered-by {
color: rgba(255, 255, 255, 0.4);
font-size: 12px;
}
/* 覆盖 a-layout-footer 默认样式 */
.footer :deep(.ant-layout-footer) {
padding: 0;
}
</style>

View File

@@ -0,0 +1,370 @@
<template>
<a-affix :offset-top="0">
<a-layout-header class="header">
<div class="nav-bar mx-auto max-w-screen-xl px-4 h-full">
<!-- 左侧Logo + 菜单 -->
<div class="flex items-center gap-8 nav-left">
<!-- Logo -->
<NuxtLink class="flex items-center logo-link cursor-pointer flex-shrink-0" to="/">
<div class="logo-text">决策咨询网</div>
</NuxtLink>
<!-- PC 导航菜单 -->
<a-menu
:selected-keys="selectedKeys"
class="menu hidden md:flex"
mode="horizontal"
theme="dark"
>
<template v-for="item in nav" :key="item.key">
<a-sub-menu v-if="item.children && item.children.length" :key="item.key">
<template #title>
<NuxtLink :to="item.to" class="nav-item-wrapper">
<span>{{ item.label }}</span>
<span v-if="item.badge" :class="getBadgeClass(item.badge)">{{ item.badge }}</span>
</NuxtLink>
</template>
<a-menu-item v-for="sub in item.children" :key="sub.key">
<a v-if="sub.href" :href="sub.href" class="nav-item-wrapper" rel="noopener" target="_blank">{{ sub.label }}</a>
<NuxtLink v-else :to="sub.to">{{ sub.label }}</NuxtLink>
</a-menu-item>
</a-sub-menu>
<a-menu-item v-else :key="item.to">
<NuxtLink :to="item.to" class="nav-item-wrapper">
<span>{{ item.label }}</span>
<span v-if="item.badge" :class="getBadgeClass(item.badge)">{{ item.badge }}</span>
</NuxtLink>
</a-menu-item>
</template>
</a-menu>
</div>
<!-- 右侧操作区 -->
<div class="flex items-center gap-2 flex-shrink-0 nav-right">
<!-- PC 登录/头像 -->
<div class="hidden md:flex items-center gap-3">
<template v-if="!isAuthed">
<a-button type="primary" @click="navigateTo('/login')">{{ '登录' }}</a-button>
</template>
<template v-else>
<!-- 用户头像 -->
<a-dropdown :trigger="['hover']" placement="bottomRight">
<a-space>
<a-avatar :size="32" :src="userAvatar">
<template v-if="!userAvatar" #icon>
<UserOutlined />
</template>
</a-avatar>
<span class="text-gray-100">{{ userName }}</span>
</a-space>
<template #overlay>
<a-menu @click="onUserMenuClick">
<a-menu-item key="profile"><ProfileOutlined style="margin-right: 8px" />个人信息</a-menu-item>
<a-menu-item key="my-suggestions"><MessageOutlined style="margin-right: 8px" />我的建言</a-menu-item>
<template v-if="isSuperAdmin">
<a-menu-divider />
<a-menu-item key="admin"> 后台管理</a-menu-item>
</template>
<a-menu-divider />
<a-menu-item key="logout">{{ '退出登录' }}</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
</div>
<!-- 移动端汉堡菜单按钮 -->
<button class="md:hidden flex flex-col justify-center items-center w-10 h-10 gap-1.5 rounded-lg bg-white/10 hover:bg-white/20 border border-white/20 transition-colors" @click="open = true">
<span class="block w-5 h-0.5 bg-white rounded-full"></span>
<span class="block w-5 h-0.5 bg-white rounded-full"></span>
<span class="block w-5 h-0.5 bg-white rounded-full"></span>
</button>
</div>
</div>
</a-layout-header>
</a-affix>
<a-drawer v-model:open="open" :title="'导航' || '导航'" placement="right">
<a-menu :selected-keys="selectedKeys" mode="inline">
<template v-for="item in nav" :key="item.key">
<a-sub-menu v-if="item.children && item.children.length" :key="item.key">
<template #title>{{ item.label }}</template>
<a-menu-item v-for="sub in item.children" :key="sub.key">
<a v-if="sub.href" :href="sub.href" rel="noopener" target="_blank" @click="open = false">{{ sub.label }}</a>
<span v-else @click="onNav(sub.to)">{{ sub.label }}</span>
</a-menu-item>
</a-sub-menu>
<a-menu-item v-else :key="item.to" @click="onNav(item.to)">
<NuxtLink :to="item.to" class="nav-item-wrapper">
<span>{{ item.label }}</span>
<span v-if="item.badge" :class="getBadgeClass(item.badge)">{{ item.badge }}</span>
</NuxtLink>
</a-menu-item>
</template>
</a-menu>
<div class="mt-4">
<a-button v-if="!isAuthed" block type="primary" @click="onNav('/login')">{{ '登录' || '登录' }}</a-button>
<template v-else>
<a-button block class="mb-2" type="primary" @click="onNav('/profile')">个人中心</a-button>
<a-button v-if="isSuperAdmin" block @click="onNav('/admin')"> 后台管理</a-button>
<a-button block class="mt-2" danger @click="logout">{{ '退出登录' || '退出登录' }}</a-button>
</template>
</div>
</a-drawer>
</template>
<script lang="ts" setup>
import { mainNav } from '@/config/nav'
import { getUserInfo } from '@/api/layout'
import type { User } from '@/api/system/user/model'
import { getToken, removeToken } from '@/utils/token-util'
import { clearAuthz, setAuthzFromUser } from '@/utils/permission'
import { UserOutlined, ProfileOutlined, MessageOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
const nav = computed(() => mainNav)
const route = useRoute()
const open = ref(false)
const selectedKeys = computed(() => {
const hit = nav.value.find((n) => n.to === route.path)
if (hit) return [hit.to]
if (route.path.startsWith('/news')) return ['/news']
if (route.path.startsWith('/consultation')) return ['/consultation']
if (route.path.startsWith('/reference')) return ['/reference']
if (route.path.startsWith('/expert')) return ['/expert']
if (route.path.startsWith('/think-tank')) return ['/think-tank']
if (route.path.startsWith('/suggestions')) return ['/suggestions']
if (route.path.startsWith('/membership')) return ['/membership']
if (route.path.startsWith('/hanmo')) return ['/hanmo']
if (route.path.startsWith('/about')) return ['/about']
return ['/']
})
// 获取 badge 样式类
function getBadgeClass(badge: string) {
const baseClass = 'ml-1.5 px-1.5 py-0.5 text-xs font-medium rounded'
if (badge === 'HOT') {
return `${baseClass} bg-orange-500 text-white`
}
if (badge === 'NEW') {
return `${baseClass} bg-green-500 text-white`
}
return `${baseClass} bg-gray-500 text-white`
}
const siteName = ref('广西决策咨询网')
const token = ref('')
const user = ref<User | null>(null)
const isAuthed = computed(() => !!token.value)
const userName = computed(() => String(user.value?.nickname || user.value?.username || '已登录'))
const isSuperAdmin = computed(() => !!(user.value as any)?.isAdmin)
const userAvatar = computed(() => {
const candidate =
user.value?.avatarUrl ||
user.value?.avatar ||
user.value?.merchantAvatar ||
user.value?.logo ||
''
if (typeof candidate !== 'string') return ''
const normalized = candidate.trim()
if (!normalized || normalized === 'null' || normalized === 'undefined') return ''
return normalized
})
function onNav(to: string) {
open.value = false
navigateTo(to)
}
async function refreshAuth() {
token.value = getToken()
if (!token.value) {
user.value = null
clearAuthz()
return
}
try {
user.value = await getUserInfo()
setAuthzFromUser(user.value)
} catch {
// token may be expired; keep authed UI but without profile info
clearAuthz()
}
}
function goConsoleCenter() {
if (!isAuthed.value) return navigateTo('/login')
open.value = false
navigateTo('/profile')
}
function logout() {
removeToken()
try {
localStorage.removeItem('TenantId')
localStorage.removeItem('UserId')
} catch {
// ignore
}
clearAuthz()
user.value = null
token.value = ''
open.value = false
navigateTo('/')
}
function onUserMenuClick(info: { key: string }) {
if (info.key === 'profile') return navigateTo('/profile')
if (info.key === 'my-suggestions') return navigateTo('/my/suggestions')
if (info.key === 'admin') return navigateTo('/admin')
if (info.key === 'logout') return logout()
}
onMounted(() => {
refreshAuth()
window.addEventListener('auth-token-changed', refreshAuth)
window.addEventListener('storage', refreshAuth)
})
onUnmounted(() => {
window.removeEventListener('auth-token-changed', refreshAuth)
window.removeEventListener('storage', refreshAuth)
})
</script>
<style scoped>
.header {
background: #111827;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
padding: 0;
height: 64px;
}
/* 两栏布局:左侧 logo+菜单,右侧操作按钮 */
.nav-bar {
display: flex;
align-items: center;
justify-content: space-between;
}
.nav-left {
display: flex;
align-items: center;
gap: 5rem; /* logo 与菜单的间距 */
}
.nav-right {
display: flex;
align-items: center;
}
.menu {
background: transparent;
border-bottom: none;
min-width: 0;
}
.logo-link {
text-decoration: none;
display: flex;
align-items: center;
}
.logo-text {
color: #fff;
font-family: 'Alimama FangYuanTi VF,sans-serif', sans-serif;
font-size: 20px;
font-weight: 700;
letter-spacing: 0.04em;
white-space: nowrap;
line-height: 1;
background: linear-gradient(135deg, #ffffff 0%, #a5c8ff 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
transition: opacity 0.2s;
}
.logo-link:hover .logo-text {
opacity: 0.85;
}
.nav-item-wrapper {
display: inline-flex;
align-items: center;
}
/* ── 统一去掉选中/展开/hover 时的蓝色,改为白色文字 + 底部橙线 ── */
/* 选中项背景去掉 */
:deep(.ant-menu-dark .ant-menu-item-selected),
:deep(.ant-menu-dark .ant-menu-submenu-selected > .ant-menu-submenu-title),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-item-selected),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-submenu-selected > .ant-menu-submenu-title) {
background-color: transparent !important;
color: #fff !important;
}
/* 选中时底部橙线 */
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-item-selected),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-submenu-selected) {
background-color: transparent !important;
border-bottom: 2px solid #f97316 !important;
}
/* sub-menu 展开/hover 时标题不变蓝 */
:deep(.ant-menu-dark .ant-menu-submenu-open > .ant-menu-submenu-title),
:deep(.ant-menu-dark .ant-menu-submenu-active > .ant-menu-submenu-title),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-submenu-open),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-submenu-active) {
background-color: transparent !important;
color: #fff !important;
}
:deep(.ant-menu-dark .ant-menu-submenu-open > .ant-menu-submenu-title > .ant-menu-title-content),
:deep(.ant-menu-dark .ant-menu-submenu-active > .ant-menu-submenu-title > .ant-menu-title-content),
:deep(.ant-menu-dark .ant-menu-submenu-open > .ant-menu-submenu-title > .ant-menu-title-content a),
:deep(.ant-menu-dark .ant-menu-submenu-active > .ant-menu-submenu-title > .ant-menu-title-content a) {
color: #fff !important;
}
/* 展开箭头不变蓝 */
:deep(.ant-menu-dark .ant-menu-submenu-open > .ant-menu-submenu-title .ant-menu-submenu-arrow),
:deep(.ant-menu-dark .ant-menu-submenu-active > .ant-menu-submenu-title .ant-menu-submenu-arrow) {
color: rgba(255, 255, 255, 0.65) !important;
}
/* 所有菜单项 hover/active 时文字统一白色 */
:deep(.ant-menu-dark .ant-menu-item-active > .ant-menu-item-content),
:deep(.ant-menu-dark .ant-menu-item-active > .ant-menu-item-content a),
:deep(.ant-menu-dark .ant-menu-item-open > .ant-menu-item-content),
:deep(.ant-menu-dark .ant-menu-item-open > .ant-menu-item-content a),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-item-active),
:deep(.ant-menu-dark.ant-menu-horizontal > .ant-menu-item-active a) {
color: #fff !important;
}
/* 所有菜单项默认文字颜色(覆盖 ant-menu-item a 的蓝色) */
:deep(.ant-menu-dark .ant-menu-item a),
:deep(.ant-menu-dark .ant-menu-submenu-title a) {
color: rgba(255, 255, 255, 0.85) !important;
}
:deep(.ant-menu-dark .ant-menu-item a:hover),
:deep(.ant-menu-dark .ant-menu-submenu-title a:hover) {
color: #fff !important;
}
/* 选中项文字强制白色 */
:deep(.ant-menu-dark .ant-menu-item-selected a),
:deep(.ant-menu-dark .ant-menu-submenu-selected .ant-menu-submenu-title a) {
color: #fff !important;
}
/* 控制台按钮:白色边框 + 白色文字hover 加白色背景 */
.console-btn {
background: transparent !important;
border-color: rgba(255, 255, 255, 0.45) !important;
color: #fff !important;
}
.console-btn:hover {
border-color: #fff !important;
background: rgba(255, 255, 255, 0.1) !important;
color: #fff !important;
}
</style>

View File

@@ -0,0 +1,609 @@
<template>
<div :class="{ 'fullscreen': isFullscreen }" class="markdown-editor-wrapper">
<!-- 编辑器工具栏 -->
<div class="editor-toolbar">
<div class="toolbar-left">
<a-space>
<a-tooltip title="标题">
<a-button size="small" @click="insertAtCursor('# ')">
<template #icon><span class="toolbar-icon">H</span></template>
</a-button>
</a-tooltip>
<a-divider type="vertical" />
<a-tooltip title="加粗">
<a-button size="small" @click="insertWrap('**', '**')">
<template #icon><span class="toolbar-icon bold">B</span></template>
</a-button>
</a-tooltip>
<a-tooltip title="斜体">
<a-button size="small" @click="insertWrap('*', '*')">
<template #icon><span class="toolbar-icon italic">I</span></template>
</a-button>
</a-tooltip>
<a-tooltip title="删除线">
<a-button size="small" @click="insertWrap('~~', '~~')">
<template #icon><span class="toolbar-icon">S</span></template>
</a-button>
</a-tooltip>
<a-divider type="vertical" />
<a-tooltip title="引用">
<a-button size="small" @click="insertAtCursor('> ')">
<template #icon><span class="toolbar-icon">&gt;</span></template>
</a-button>
</a-tooltip>
<a-tooltip title="代码块">
<a-button size="small" @click="insertCodeBlock">
<template #icon><span class="toolbar-icon">&lt;/&gt;</span></template>
</a-button>
</a-tooltip>
<a-tooltip title="行内代码">
<a-button size="small" @click="insertWrap('`', '`')">
<template #icon><span class="toolbar-icon">`</span></template>
</a-button>
</a-tooltip>
<a-divider type="vertical" />
<a-tooltip title="链接">
<a-button size="small" @click="insertLink">
<template #icon><LinkOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip title="图片">
<a-button size="small" @click="handleImageUpload">
<template #icon><PictureOutlined /></template>
</a-button>
</a-tooltip>
<a-divider type="vertical" />
<a-tooltip title="有序列表">
<a-button size="small" @click="insertAtCursor('1. ')">
<template #icon><UnorderedListOutlined /></template>
</a-button>
</a-tooltip>
<a-tooltip title="无序列表">
<a-button size="small" @click="insertAtCursor('- ')">
<template #icon><OrderedListOutlined /></template>
</a-button>
</a-tooltip>
<a-divider type="vertical" />
<a-tooltip title="水平线">
<a-button size="small" @click="insertAtCursor('\n---\n')">
<template #icon><MinusOutlined /></template>
</a-button>
</a-tooltip>
</a-space>
</div>
<div class="toolbar-right">
<a-button size="small" @click="toggleFullscreen">
<template #icon><FullscreenOutlined v-if="!isFullscreen" /><FullscreenExitOutlined v-else /></template>
</a-button>
</div>
</div>
<!-- 编辑区域 -->
<div class="editor-body">
<div class="editor-pane">
<textarea
ref="textareaRef"
v-model="localValue"
:placeholder="placeholder"
:style="{ height: isFullscreen ? '100%' : 'auto' }"
class="markdown-textarea"
@input="handleInput"
@keydown="handleKeydown"
@scroll="syncScroll"
/>
</div>
<div v-if="showPreview" class="preview-pane">
<div class="preview-label">预览</div>
<div class="markdown-preview" v-html="renderedHtml"></div>
</div>
</div>
<!-- 隐藏的文件上传 -->
<a-upload
ref="uploadRef"
:before-upload="beforeImageUpload"
:custom-request="handleCoverUpload"
:show-upload-list="false"
accept="image/*"
style="display: none"
/>
<!-- 插入链接弹窗 -->
<a-modal
v-model:open="showLinkModal"
:width="400"
title="插入链接"
@ok="insertLinkConfirm"
>
<a-form :model="linkForm" layout="vertical">
<a-form-item label="链接文本" required>
<a-input v-model:value="linkForm.text" placeholder="显示的文本" />
</a-form-item>
<a-form-item label="链接地址" required>
<a-input v-model:value="linkForm.url" placeholder="https://..." />
</a-form-item>
</a-form>
</a-modal>
<!-- 字数统计 -->
<div class="editor-footer">
<span class="word-count">{{ wordCount }} 字</span>
<span class="char-count">{{ charCount }} 字符</span>
</div>
</div>
</template>
<script lang="ts" setup>
import {
LinkOutlined,
PictureOutlined,
UnorderedListOutlined,
OrderedListOutlined,
MinusOutlined,
FullscreenOutlined,
FullscreenExitOutlined,
} from '@ant-design/icons-vue'
import { marked } from 'marked'
import hljs from 'highlight.js'
import 'highlight.js/styles/github.css'
import { message } from 'ant-design-vue'
import { uploadFile } from '@/api/system/file'
interface Props {
modelValue: string
placeholder?: string
showPreview?: boolean
minHeight?: string
}
const props = withDefaults(defineProps<Props>(), {
placeholder: '请输入 Markdown 内容...',
showPreview: true,
minHeight: '300px',
})
const emit = defineEmits<{
'update:modelValue': [value: string]
}>()
// 配置 marked
marked.setOptions({
highlight: function(code: string, lang: string) {
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(code, { language: lang }).value
}
return hljs.highlightAuto(code).value
},
breaks: true,
gfm: true,
})
const textareaRef = ref<HTMLTextAreaElement | null>(null)
const uploadRef = ref<any>(null)
const localValue = ref(props.modelValue)
const isFullscreen = ref(false)
const showLinkModal = ref(false)
const linkForm = reactive({
text: '',
url: '',
})
// 监听外部值变化
watch(() => props.modelValue, (newVal) => {
if (newVal !== localValue.value) {
localValue.value = newVal
}
})
// 计算属性
const renderedHtml = computed(() => {
if (!localValue.value) return '<p class="placeholder-hint">预览区域</p>'
try {
return marked.parse(localValue.value) as string
} catch (e) {
return '<p class="error-hint">渲染出错</p>'
}
})
const wordCount = computed(() => {
const text = localValue.value.trim()
if (!text) return 0
return text.split(/\s+/).filter(Boolean).length
})
const charCount = computed(() => localValue.value.length)
// 方法
function handleInput() {
emit('update:modelValue', localValue.value)
}
function handleKeydown(e: KeyboardEvent) {
// Tab 键插入空格
if (e.key === 'Tab') {
e.preventDefault()
insertAtCursor(' ')
}
// Ctrl/Cmd + B 加粗
if ((e.ctrlKey || e.metaKey) && e.key === 'b') {
e.preventDefault()
insertWrap('**', '**')
}
// Ctrl/Cmd + I 斜体
if ((e.ctrlKey || e.metaKey) && e.key === 'i') {
e.preventDefault()
insertWrap('*', '*')
}
// Ctrl/Cmd + K 链接
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault()
insertLink()
}
}
function insertAtCursor(text: string) {
const textarea = textareaRef.value
if (!textarea) return
const start = textarea.selectionStart
const end = textarea.selectionEnd
const before = localValue.value.substring(0, start)
const after = localValue.value.substring(end)
localValue.value = before + text + after
emit('update:modelValue', localValue.value)
nextTick(() => {
textarea.focus()
textarea.selectionStart = textarea.selectionEnd = start + text.length
})
}
function insertWrap(before: string, after: string) {
const textarea = textareaRef.value
if (!textarea) return
const start = textarea.selectionStart
const end = textarea.selectionEnd
const selectedText = localValue.value.substring(start, end) || '文本'
const text = before + selectedText + after
localValue.value = localValue.value.substring(0, start) + text + localValue.value.substring(end)
emit('update:modelValue', localValue.value)
nextTick(() => {
textarea.focus()
textarea.selectionStart = start + before.length
textarea.selectionEnd = start + before.length + selectedText.length
})
}
function insertCodeBlock() {
const textarea = textareaRef.value
if (!textarea) return
const start = textarea.selectionStart
const end = textarea.selectionEnd
const selectedText = localValue.value.substring(start, end) || '代码'
const text = '\n```javascript\n' + selectedText + '\n```\n'
localValue.value = localValue.value.substring(0, start) + text + localValue.value.substring(end)
emit('update:modelValue', localValue.value)
nextTick(() => {
textarea.focus()
textarea.selectionStart = start + 14 // 跳过 ```javascript\n
textarea.selectionEnd = start + 14 + selectedText.length
})
}
function insertLink() {
const textarea = textareaRef.value
if (textarea) {
const selectedText = localValue.value.substring(textarea.selectionStart, textarea.selectionEnd)
linkForm.text = selectedText || ''
}
showLinkModal.value = true
}
function insertLinkConfirm() {
if (!linkForm.text.trim()) {
message.warning('请输入链接文本')
return
}
if (!linkForm.url.trim()) {
message.warning('请输入链接地址')
return
}
insertAtCursor(`[${linkForm.text}](${linkForm.url})`)
showLinkModal.value = false
linkForm.text = ''
linkForm.url = ''
}
function handleImageUpload() {
const input = document.createElement('input')
input.type = 'file'
input.accept = 'image/*'
input.onchange = async (e) => {
const file = (e.target as HTMLInputElement).files?.[0]
if (file) {
await uploadAndInsertImage(file)
}
}
input.click()
}
function beforeImageUpload(file: File) {
if (!file.type.startsWith('image/')) {
message.error('只能上传图片文件')
return false
}
if (file.size > 5 * 1024 * 1024) {
message.error('图片大小不能超过 5MB')
return false
}
return true
}
async function uploadAndInsertImage(file: File) {
try {
message.loading({ content: '上传图片中...', key: 'upload' })
const record = await uploadFile(file)
const url = (record?.url || record?.downloadUrl || '').trim()
if (!url) throw new Error('上传成功但未返回图片地址')
insertAtCursor(`![${file.name}](${url})`)
message.success({ content: '图片上传成功', key: 'upload' })
} catch (e: any) {
message.error({ content: e?.message || '图片上传失败', key: 'upload' })
}
}
async function handleCoverUpload(option: any) {
await uploadAndInsertImage(option.file)
option.onSuccess?.()
}
function syncScroll(e: Event) {
const textarea = e.target as HTMLTextAreaElement
const preview = textarea.parentElement?.nextElementSibling?.querySelector('.markdown-preview') as HTMLElement
if (preview) {
const ratio = textarea.scrollTop / (textarea.scrollHeight - textarea.clientHeight)
preview.scrollTop = ratio * (preview.scrollHeight - preview.clientHeight)
}
}
function toggleFullscreen() {
isFullscreen.value = !isFullscreen.value
}
// 暴露方法
defineExpose({
focus: () => textareaRef.value?.focus(),
insertText: insertAtCursor,
})
</script>
<style scoped>
.markdown-editor-wrapper {
border: 1px solid #d9d9d9;
border-radius: 8px;
overflow: hidden;
background: #fff;
display: flex;
flex-direction: column;
}
.markdown-editor-wrapper.fullscreen {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
border-radius: 0;
}
.editor-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background: #fafafa;
border-bottom: 1px solid #f0f0f0;
}
.toolbar-left {
flex: 1;
}
.toolbar-right {
margin-left: 12px;
}
.toolbar-icon {
font-family: Georgia, serif;
font-weight: 700;
font-size: 12px;
}
.toolbar-icon.bold {
font-weight: 900;
}
.toolbar-icon.italic {
font-style: italic;
}
.editor-body {
display: flex;
flex: 1;
min-height: v-bind(minHeight);
overflow: hidden;
}
.editor-pane {
flex: 1;
display: flex;
flex-direction: column;
}
.markdown-textarea {
flex: 1;
padding: 16px;
border: none;
outline: none;
resize: none;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 14px;
line-height: 1.7;
color: #24292e;
background: #fff;
}
.markdown-textarea::placeholder {
color: #aaa;
}
.preview-pane {
flex: 1;
border-left: 1px solid #f0f0f0;
display: flex;
flex-direction: column;
overflow: hidden;
}
.preview-label {
padding: 8px 16px;
font-size: 12px;
color: #999;
background: #fafafa;
border-bottom: 1px solid #f0f0f0;
}
.markdown-preview {
flex: 1;
padding: 16px;
overflow-y: auto;
font-size: 14px;
line-height: 1.8;
color: #24292e;
}
.markdown-preview :deep(.placeholder-hint),
.markdown-preview :deep(.error-hint) {
color: #aaa;
font-style: italic;
}
.markdown-preview :deep(h1) {
font-size: 1.8em;
font-weight: 700;
margin: 0.5em 0;
padding-bottom: 0.3em;
border-bottom: 1px solid #eaecef;
}
.markdown-preview :deep(h2) {
font-size: 1.5em;
font-weight: 600;
margin: 0.8em 0 0.4em;
padding-bottom: 0.25em;
border-bottom: 1px solid #eaecef;
}
.markdown-preview :deep(h3) {
font-size: 1.25em;
font-weight: 600;
margin: 0.6em 0 0.3em;
}
.markdown-preview :deep(p) {
margin: 0.8em 0;
}
.markdown-preview :deep(code) {
padding: 0.2em 0.4em;
background: #f6f8fa;
border-radius: 4px;
font-family: 'Monaco', 'Menlo', monospace;
font-size: 0.9em;
}
.markdown-preview :deep(pre) {
padding: 16px;
background: #f6f8fa;
border-radius: 8px;
overflow-x: auto;
}
.markdown-preview :deep(pre code) {
padding: 0;
background: transparent;
}
.markdown-preview :deep(blockquote) {
margin: 1em 0;
padding: 0.5em 1em;
border-left: 4px solid #dfe2e5;
color: #6a737d;
background: #f6f8fa;
}
.markdown-preview :deep(ul),
.markdown-preview :deep(ol) {
padding-left: 2em;
margin: 0.8em 0;
}
.markdown-preview :deep(li) {
margin: 0.3em 0;
}
.markdown-preview :deep(a) {
color: #0366d6;
text-decoration: none;
}
.markdown-preview :deep(a:hover) {
text-decoration: underline;
}
.markdown-preview :deep(img) {
max-width: 100%;
border-radius: 8px;
}
.markdown-preview :deep(hr) {
margin: 1.5em 0;
border: none;
border-top: 1px solid #dfe2e5;
}
.markdown-preview :deep(table) {
width: 100%;
border-collapse: collapse;
margin: 1em 0;
}
.markdown-preview :deep(th),
.markdown-preview :deep(td) {
padding: 8px 12px;
border: 1px solid #dfe2e5;
}
.markdown-preview :deep(th) {
background: #f6f8fa;
font-weight: 600;
}
.editor-footer {
display: flex;
gap: 16px;
padding: 6px 12px;
font-size: 12px;
color: #999;
background: #fafafa;
border-top: 1px solid #f0f0f0;
}
</style>

View File

@@ -0,0 +1,171 @@
<template>
<div class="markdown-renderer" v-html="renderedHtml"></div>
</template>
<script lang="ts" setup>
import { marked } from 'marked'
import hljs from 'highlight.js'
import 'highlight.js/styles/github.css'
interface Props {
content: string
}
const props = defineProps<Props>()
// 配置 marked
marked.setOptions({
highlight: function(code: string, lang: string) {
if (lang && hljs.getLanguage(lang)) {
return hljs.highlight(code, { language: lang }).value
}
return hljs.highlightAuto(code).value
},
breaks: true,
gfm: true,
})
const renderedHtml = computed(() => {
if (!props.content) return ''
try {
return marked.parse(props.content) as string
} catch (e) {
return '<p>渲染出错</p>'
}
})
</script>
<style scoped>
.markdown-renderer {
font-size: 15px;
line-height: 1.8;
color: rgba(0, 0, 0, 0.85);
}
.markdown-renderer :deep(h1) {
font-size: 1.8em;
font-weight: 700;
margin: 0.5em 0;
padding-bottom: 0.3em;
border-bottom: 1px solid #eaecef;
}
.markdown-renderer :deep(h2) {
font-size: 1.5em;
font-weight: 600;
margin: 0.8em 0 0.4em;
padding-bottom: 0.25em;
border-bottom: 1px solid #eaecef;
}
.markdown-renderer :deep(h3) {
font-size: 1.25em;
font-weight: 600;
margin: 0.6em 0 0.3em;
}
.markdown-renderer :deep(h4),
.markdown-renderer :deep(h5),
.markdown-renderer :deep(h6) {
font-weight: 600;
margin: 0.5em 0;
}
.markdown-renderer :deep(p) {
margin: 0.8em 0;
}
.markdown-renderer :deep(code) {
padding: 0.2em 0.4em;
background: #f6f8fa;
border-radius: 4px;
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 0.9em;
}
.markdown-renderer :deep(pre) {
padding: 16px;
background: #f6f8fa;
border-radius: 8px;
overflow-x: auto;
margin: 1em 0;
}
.markdown-renderer :deep(pre code) {
padding: 0;
background: transparent;
font-size: 0.9em;
}
.markdown-renderer :deep(blockquote) {
margin: 1em 0;
padding: 0.5em 1em;
border-left: 4px solid #dfe2e5;
color: #6a737d;
background: #f6f8fa;
border-radius: 0 8px 8px 0;
}
.markdown-renderer :deep(blockquote p) {
margin: 0.3em 0;
}
.markdown-renderer :deep(ul),
.markdown-renderer :deep(ol) {
padding-left: 2em;
margin: 0.8em 0;
}
.markdown-renderer :deep(li) {
margin: 0.3em 0;
}
.markdown-renderer :deep(a) {
color: #1890ff;
text-decoration: none;
}
.markdown-renderer :deep(a:hover) {
text-decoration: underline;
}
.markdown-renderer :deep(img) {
max-width: 100%;
border-radius: 8px;
margin: 1em 0;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.markdown-renderer :deep(hr) {
margin: 1.5em 0;
border: none;
border-top: 1px solid #dfe2e5;
}
.markdown-renderer :deep(table) {
width: 100%;
border-collapse: collapse;
margin: 1em 0;
border-radius: 8px;
overflow: hidden;
}
.markdown-renderer :deep(th),
.markdown-renderer :deep(td) {
padding: 10px 14px;
border: 1px solid #dfe2e5;
}
.markdown-renderer :deep(th) {
background: #f6f8fa;
font-weight: 600;
}
.markdown-renderer :deep(tr:hover) {
background: #fafafa;
}
.markdown-renderer :deep(input[type="checkbox"]) {
margin-right: 0.5em;
}
</style>

View File

@@ -0,0 +1,102 @@
<template>
<div :class="{ 'has-image': showImage && article.image }" class="article-item">
<NuxtLink :to="article.link || `/article/${article.id}`" class="article-link">
<div class="article-content">
<div class="article-title">{{ article.title }}</div>
<div class="article-meta">
<span v-if="article.source" class="source">{{ article.source }}</span>
<span class="date">{{ article.date }}</span>
</div>
</div>
<img v-if="showImage && article.image" :alt="article.title" :src="article.image" class="article-image" />
</NuxtLink>
</div>
</template>
<script lang="ts" setup>
interface Article {
id: number
title: string
date: string
source?: string
image?: string
link?: string
}
defineProps<{
article: Article
showImage?: boolean
}>()
</script>
<style scoped>
.article-item {
padding: 10px 0;
border-bottom: 1px dashed #eee;
}
.article-item:last-child {
border-bottom: none;
}
.article-link {
display: flex;
align-items: flex-start;
gap: 12px;
text-decoration: none;
color: inherit;
}
.article-content {
flex: 1;
min-width: 0;
}
.article-title {
font-size: 14px;
color: #333;
line-height: 1.5;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
transition: color 0.2s;
}
.article-link:hover .article-title {
color: #1e3a5f;
}
.article-meta {
display: flex;
align-items: center;
gap: 12px;
margin-top: 6px;
font-size: 12px;
color: #999;
}
.source {
color: #e74c3c;
}
.article-image {
width: 100px;
height: 70px;
object-fit: cover;
border-radius: 4px;
flex-shrink: 0;
}
.has-image .article-title {
-webkit-line-clamp: 1;
}
@media (max-width: 576px) {
.article-image {
width: 80px;
height: 56px;
}
}
</style>

View File

@@ -0,0 +1,58 @@
<template>
<div class="section-header">
<div class="header-left">
<span class="icon">{{ icon }}</span>
<h2 class="title">{{ title }}</h2>
</div>
<NuxtLink v-if="moreLink" :to="moreLink" class="more-link">
查看更多
</NuxtLink>
</div>
</template>
<script lang="ts" setup>
defineProps<{
title: string
icon?: string
moreLink?: string
}>()
</script>
<style scoped>
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 24px;
padding-bottom: 16px;
border-bottom: 3px solid #1e3a5f;
}
.header-left {
display: flex;
align-items: center;
gap: 12px;
}
.icon {
font-size: 24px;
}
.title {
font-size: 22px;
font-weight: 700;
color: #1e3a5f;
margin: 0;
}
.more-link {
color: #666;
font-size: 14px;
text-decoration: none;
transition: color 0.2s;
}
.more-link:hover {
color: #1e3a5f;
}
</style>

View File

@@ -0,0 +1,570 @@
<template>
<a-modal
:destroy-on-close="true"
:footer="footerContent"
:mask-closable="false"
:open="visible"
:title="title"
:width="payMethod === 'native' ? 480 : 420"
@cancel="handleClose"
>
<!-- 订单信息 -->
<div class="mb-5">
<a-descriptions :column="1" bordered size="small">
<a-descriptions-item label="订单号">
<span class="font-mono text-sm">{{ orderNo }}</span>
</a-descriptions-item>
<a-descriptions-item label="订单金额">
<span class="text-xl font-bold text-orange-500">¥{{ payPrice }}</span>
</a-descriptions-item>
</a-descriptions>
</div>
<!-- 支付方式选择 -->
<div v-if="!started" class="space-y-3">
<div class="text-sm text-gray-500 mb-2">请选择支付方式</div>
<!-- 微信支付 -->
<div
v-if="availableMethods.wechat"
:class="{ active: selectedMethod === 'wechat' }"
class="pay-method-item"
@click="selectedMethod = 'wechat'"
>
<svg class="h-8 w-8" fill="#07C160" viewBox="0 0 24 24">
<path d="M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-4.196-6.348-8.596-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.11.24-.245 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1-.023-.156.49.49 0 0 1 .201-.398C23.024 18.48 24 16.82 24 14.98c0-3.21-2.931-5.837-6.656-6.088V8.87a5.755 5.755 0 0 0-.407-.012zm-1.155 2.26c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.97-.982zm4.857 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982z"/>
</svg>
<div class="flex-1 ml-3">
<div class="font-medium">微信支付</div>
<div class="text-xs text-gray-400">推荐</div>
</div>
<a-radio :checked="selectedMethod === 'wechat'" />
</div>
<!-- 支付宝 -->
<div
v-if="availableMethods.alipay"
:class="{ active: selectedMethod === 'alipay' }"
class="pay-method-item"
@click="selectedMethod = 'alipay'"
>
<svg class="h-8 w-8" fill="#1677FF" viewBox="0 0 24 24">
<path d="M21.97 11.1c-1.23-.79-2.75-1.04-4.33-.86-1.09-1.65-2.78-2.59-4.72-2.59-2.91 0-5.27 2.27-5.27 5.06 0 2.07 1.25 3.89 3.1 4.78V13.2c-.42-.11-.86-.17-1.32-.17-2.56 0-4.64 2.03-4.64 4.53 0 2.51 2.08 4.53 4.64 4.53.32 0 .63-.03.93-.08v2.58c-.31.04-.63.06-.95.06-3.45 0-6.25-2.74-6.25-6.1 0-3.36 2.8-6.1 6.25-6.1 1.01 0 1.95.24 2.78.67-.05-.32-.08-.65-.08-.99 0-2.59 2.15-4.69 4.79-4.69 1.52 0 2.88.68 3.78 1.75.19-.03.38-.05.58-.05 1.94 0 3.51 1.57 3.51 3.51 0 1.06-.48 2-1.24 2.64 1.1.4 1.83 1.47 1.83 2.67 0 1.73-1.49 3.13-3.32 3.13-.65 0-1.26-.18-1.78-.5.06.22.1.45.1.69 0 2.07-1.7 3.75-3.79 3.75-.45 0-.89-.07-1.3-.22v2.49c.45.13.92.2 1.4.2 2.97 0 5.38-2.36 5.38-5.26 0-2.22-1.32-4.15-3.22-4.93zm-8.16 2.09c-.46 0-.84-.37-.84-.83s.38-.84.84-.84.84.38.84.84-.38.83-.84.83zm5.14-.83c0-.46.38-.84.84-.84s.84.38.84.84-.38.83-.84.83-.84-.37-.84-.83zm-.87 2.49l-.69-.55c-.34-.27-.55-.67-.55-1.1 0-.74.61-1.34 1.36-1.34.46 0 .88.24 1.12.62l.77.62c.01-.35-.28-.67-.64-.8v-.06h-.09c-.54 0-.98-.44-.98-.98s.44-.98.98-.98.98.44.98.98v.03h.05l.15.12c.57.45.91 1.14.91 1.87 0 1.21-.89 2.23-2.05 2.48l-.33-.91h-.01zm-2.24-1.38h.08c.34 0 .61-.27.61-.61s-.27-.61-.61-.61h-.08v1.22zm.61 2.16c-.14.04-.29.06-.45.06h-.16v-1.16h.25c.26 0 .47.1.47.36 0 .38-.06.67-.11.74zm-.11-3.52c.18 0 .32-.14.32-.32s-.14-.32-.32-.32-.32.14-.32.32.14.32.32.32zm0 1.86c-.18 0-.32.14-.32.32s.14.32.32.32.32-.14.32-.32-.14-.32-.32-.32z"/>
</svg>
<div class="flex-1 ml-3">
<div class="font-medium">支付宝</div>
<div class="text-xs text-gray-400">安全便捷</div>
</div>
<a-radio :checked="selectedMethod === 'alipay'" />
</div>
<!-- 余额支付 -->
<div
v-if="availableMethods.balance && userBalance !== undefined"
:class="{ active: selectedMethod === 'balance' }"
class="pay-method-item"
@click="selectedMethod = 'balance'"
>
<div class="flex items-center justify-center h-8 w-8 rounded-full bg-yellow-100 text-yellow-600">
<WalletOutlined />
</div>
<div class="flex-1 ml-3">
<div class="font-medium">余额支付</div>
<div class="text-xs text-gray-400">可用余额¥{{ userBalance }}</div>
</div>
<a-radio :checked="selectedMethod === 'balance'" />
</div>
</div>
<!-- Native 二维码支付 -->
<div v-else-if="payMethod === 'native' && !paid" class="text-center">
<div v-if="loading" class="py-10">
<a-spin size="large" />
<div class="mt-3 text-gray-500">正在获取支付二维码...</div>
</div>
<div v-else-if="codeUrl" class="py-4">
<div class="text-sm text-gray-500 mb-4">请使用微信/支付宝扫描下方二维码完成支付</div>
<div class="flex justify-center bg-white p-4 rounded-lg">
<a-qrcode :size="200" :value="codeUrl" />
</div>
<div class="mt-4 text-sm text-gray-500">
<template v-if="countdown > 0">
二维码 {{ countdown }} 秒后过期请尽快支付
</template>
<a-button v-else size="small" type="link" @click="rebuildQrcode">
二维码已过期点击重新获取
</a-button>
</div>
</div>
<div v-else-if="errorMsg" class="py-10 text-center">
<a-result :sub-title="errorMsg" status="error" title="获取二维码失败">
<template #extra>
<a-button type="primary" @click="rebuildQrcode">重试</a-button>
</template>
</a-result>
</div>
</div>
<!-- 等待支付状态 -->
<div v-else-if="!paid" class="text-center py-6">
<a-spin size="large" />
<div class="mt-4">
<div class="text-base font-medium">等待支付中...</div>
<div class="text-sm text-gray-500 mt-1">
{{ selectedMethod === 'balance' ? '正在处理余额支付...' : '请在支付页面完成付款' }}
</div>
</div>
</div>
<!-- 支付成功 -->
<div v-else class="text-center py-6">
<a-result status="success" sub-title="您的订单已支付成功页面即将跳转..." title="支付成功">
<template #extra>
<a-button type="primary" @click="handleSuccess">查看订单</a-button>
<a-button @click="handleClose">继续逛逛</a-button>
</template>
</a-result>
</div>
<!-- 错误提示 -->
<div v-if="errorMsg && !paid" class="mt-4">
<a-alert :message="errorMsg" show-icon type="error" />
</div>
</a-modal>
<!-- 支付宝跳转提示 -->
<a-modal
v-model:open="alipayRedirectVisible"
:footer="null"
:mask-closable="false"
centered
title="正在跳转支付宝"
>
<div class="text-center py-6">
<a-spin size="large" />
<div class="mt-4 text-base">正在跳转到支付宝支付页面</div>
<div class="text-sm text-gray-500 mt-2">
如果支付页面没有弹出<a :href="alipayUrl" target="_blank">点击这里</a>继续支付
</div>
</div>
</a-modal>
</template>
<script lang="ts" setup>
import { ref, computed, watch, h } from 'vue'
import { message } from 'ant-design-vue'
import { WalletOutlined } from '@ant-design/icons-vue'
import {
detectPayEnvironment,
isWechatBrowser,
isAlipayBrowser,
createWechatJsapiPay,
createWechatH5Pay,
createWechatNativePay,
createAlipayPay,
queryPayStatus
} from '@/api/payment'
import type { PayResult } from '@/api/payment'
/** Props */
const props = defineProps<{
visible: boolean
orderNo: string
orderId?: number
payPrice: string | number
/** 可用支付方式,默认全部 */
availableMethods?: {
wechat?: boolean
alipay?: boolean
balance?: boolean
native?: boolean
}
/** 用户余额(余额支付时) */
userBalance?: number
/** 标题 */
title?: string
}>()
/** Emits */
const emit = defineEmits<{
(e: 'update:visible', val: boolean): void
(e: 'success', result: PayResult): void
(e: 'close'): void
}>()
/** 状态 */
const selectedMethod = ref<'wechat' | 'alipay' | 'balance'>('wechat')
const started = ref(false)
const loading = ref(false)
const paid = ref(false)
const errorMsg = ref('')
const codeUrl = ref('')
const countdown = ref(0)
const alipayRedirectVisible = ref(false)
const alipayUrl = ref('')
// 轮询定时器
let pollTimer: ReturnType<typeof setTimeout> | null = null
let countdownTimer: ReturnType<typeof setInterval> | null = null
/** 默认可用支付方式 */
const defaultMethods = { wechat: true, alipay: true, balance: true, native: true }
const methods = computed(() => ({ ...defaultMethods, ...props.availableMethods }))
/** 实际使用的支付方式 */
const payMethod = computed(() => {
if (!started.value) return 'select'
const env = detectPayEnvironment()
// 微信浏览器内 → JSAPI
if (selectedMethod.value === 'wechat' && isWechatBrowser()) {
return 'wechat_jsapi'
}
// 支付宝浏览器内 → 支付宝 WAP
if (selectedMethod.value === 'alipay' && isAlipayBrowser()) {
return 'alipay_wap'
}
// 桌面端 / 其他情况 → Native 或 H5
if (env === 'desktop') {
return 'native'
}
return 'h5'
})
/** 底部按钮 */
const footerContent = computed(() => {
if (paid.value || started.value) return null
return [
h('a-button', { onClick: handleClose }, '取消'),
h('a-button', {
type: 'primary',
loading: loading.value,
onClick: startPay
}, `确认支付 ¥${props.payPrice}`)
]
})
/** 关闭弹窗 */
function handleClose() {
stopPoll()
emit('update:visible', false)
emit('close')
}
/** 支付成功 */
function handleSuccess() {
stopPoll()
emit('success', { orderNo: props.orderNo })
handleClose()
}
/** 开始支付 */
async function startPay() {
errorMsg.value = ''
loading.value = true
try {
const params = {
orderNo: props.orderNo,
subject: `订单支付-${props.orderNo}`,
body: 'WebSoft 产品订单',
totalAmount: Math.round(Number(props.payPrice) * 100) // 转为分
}
let result: PayResult
switch (payMethod.value) {
case 'wechat_jsapi':
result = await createWechatJsapiPay({
...params,
openId: await getWxOpenId()
})
await handleWechatJsapiResult(result)
break
case 'native':
started.value = true
result = await createWechatNativePay(params)
handleNativeResult(result)
break
case 'h5':
if (selectedMethod.value === 'wechat') {
result = await createWechatH5Pay({ ...params, returnUrl: window.location.href })
handleH5Result(result, 'wechat')
} else {
result = await createAlipayPay({ ...params, returnUrl: window.location.href })
handleH5Result(result, 'alipay')
}
break
case 'alipay_wap':
result = await createAlipayPay({ ...params, returnUrl: window.location.href })
handleH5Result(result, 'alipay')
break
case 'balance':
await handleBalancePay()
break
default:
throw new Error('不支持的支付方式')
}
} catch (err: unknown) {
const e = err as Error
errorMsg.value = e.message || '发起支付失败'
message.error(errorMsg.value)
} finally {
loading.value = false
}
}
/** 处理微信 JSAPI 支付结果 */
async function handleWechatJsapiResult(result: PayResult) {
// 如果返回的是跳转链接H5支付链接直接跳转
if (result.mwebUrl) {
window.location.href = result.mwebUrl
return
}
// JSAPI 调起支付
if (result.prepayId) {
const appId = result.codeUrl || '' // 实际应该从后端获取
const timestamp = String(Math.floor(Date.now() / 1000))
const nonceStr = Math.random().toString(36).slice(2)
const pkg = `prepay_id=${result.prepayId}`
const signType = 'MD5'
const paySign = '' // 后端需要返回签名
try {
// 动态加载微信 JSSDK
await loadWechatJSSDK()
// @ts-ignore
window.WeixinJSBridge?.invoke('getBrandWCPayRequest', {
appId,
timeStamp: timestamp,
nonceStr,
package: pkg,
signType,
paySign
}, (res: { err_msg: string }) => {
if (res.err_msg === 'get_brand_wcpay_request:ok') {
paid.value = true
startPoll()
} else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
errorMsg.value = '用户取消支付'
} else {
errorMsg.value = res.err_msg
}
})
} catch {
// 如果 JSSDK 不可用,降级到 H5 支付
const h5Result = await createWechatH5Pay({
orderNo: props.orderNo,
subject: `订单支付-${props.orderNo}`,
totalAmount: Math.round(Number(props.payPrice) * 100)
})
if (h5Result.mwebUrl) {
window.location.href = h5Result.mwebUrl
} else {
throw new Error('JSAPI 支付失败')
}
}
}
}
/** 处理 Native 支付结果 */
function handleNativeResult(result: PayResult) {
loading.value = false
if (result.codeUrl) {
codeUrl.value = result.codeUrl
// 二维码有效期 2 分钟
countdown.value = 120
startCountdown()
startPoll()
} else if (result.qrcode) {
codeUrl.value = result.qrcode
countdown.value = 120
startCountdown()
startPoll()
} else {
errorMsg.value = '获取支付二维码失败'
}
}
/** 处理 H5 支付结果 */
function handleH5Result(result: PayResult, type: 'wechat' | 'alipay') {
if (type === 'alipay' && (result.paymentUrl || result.payUrl)) {
const url = result.paymentUrl || result.payUrl
if (result.paymentUrl?.includes('https://openapi.alipay.com')) {
// PC 场景:显示二维码
alipayRedirectVisible.value = true
alipayUrl.value = url
} else if (result.paymentUrl?.includes('https://m.alipay.com')) {
// H5 场景:直接跳转
window.location.href = url
} else {
// 未知格式,直接跳转
window.location.href = url
}
started.value = true
startPoll()
} else if (type === 'wechat' && result.mwebUrl) {
window.location.href = result.mwebUrl
}
}
/** 余额支付 */
async function handleBalancePay() {
started.value = true
loading.value = false
// 余额支付直接查询状态
try {
const status = await queryPayStatus(props.orderNo)
if (status.paid || status.payStatus === 1) {
paid.value = true
} else {
startPoll()
}
} catch {
// 轮询查询
startPoll()
}
}
/** 轮询支付状态 */
async function startPoll() {
stopPoll()
pollTimer = setTimeout(async () => {
try {
const status = await queryPayStatus(props.orderNo)
if (status.paid || status.payStatus === 1) {
paid.value = true
stopPoll()
setTimeout(() => handleSuccess(), 1500)
} else {
startPoll()
}
} catch {
startPoll()
}
}, 2000)
}
/** 停止轮询 */
function stopPoll() {
if (pollTimer) {
clearTimeout(pollTimer)
pollTimer = null
}
if (countdownTimer) {
clearInterval(countdownTimer)
countdownTimer = null
}
}
/** 二维码倒计时 */
function startCountdown() {
countdownTimer = setInterval(() => {
if (countdown.value > 0) {
countdown.value--
} else {
stopPoll()
}
}, 1000)
}
/** 重新获取二维码 */
async function rebuildQrcode() {
loading.value = true
errorMsg.value = ''
codeUrl.value = ''
try {
const params = {
orderNo: props.orderNo,
subject: `订单支付-${props.orderNo}`,
totalAmount: Math.round(Number(props.payPrice) * 100)
}
const result = await createWechatNativePay(params)
handleNativeResult(result)
} catch (err: unknown) {
const e = err as Error
errorMsg.value = e.message || '获取二维码失败'
} finally {
loading.value = false
}
}
/** 获取微信 OpenId */
async function getWxOpenId(): Promise<string> {
// 从 localStorage 或 Vuex 获取已存储的 openId
const stored = localStorage.getItem('wx_openid')
if (stored) return stored
// 如果没有,需要先通过 OAuth 获取
// 这里可以引导用户授权,或从后端获取
throw new Error('请先在微信中打开,或联系客服获取支付方式')
}
/** 动态加载微信 JSSDK */
async function loadWechatJSSDK(): Promise<void> {
return new Promise((resolve, reject) => {
// 如果已加载
if (window.WeixinJSBridge || window.jWeixin) {
resolve()
return
}
// 加载 JSSDK
const script = document.createElement('script')
script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'
script.onload = () => resolve()
script.onerror = () => reject(new Error('微信 JSSDK 加载失败'))
document.head.appendChild(script)
})
}
// 监听 visible 变化
watch(() => props.visible, (val) => {
if (!val) {
stopPoll()
started.value = false
paid.value = false
errorMsg.value = ''
codeUrl.value = ''
}
})
</script>
<style scoped>
.pay-method-item {
display: flex;
align-items: center;
padding: 12px 16px;
border: 2px solid #e5e7eb;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
}
.pay-method-item:hover {
border-color: #d1d5db;
}
.pay-method-item.active {
border-color: #1890ff;
background: #f0f9ff;
}
</style>