feat(feedback): 留言反馈全链路 — 公开弹窗(验证码+IP限频) + 后台管理(状态流转/删除/角标) + nginx /admin/ 反代修复502

This commit is contained in:
3970260761 committed 2026-11-12 01:55:01 +08:00
1 parent 9d75776d52
commit 55b1111d96
6 files changed
+534 -2

No files matched your search

+6
View File
@@ -32,6 +32,12 @@
- **生成记录**:翻译/OCR/修图/转换等 9 个工具自动留痕,数据存本地
- **体验优化**:全站中文默认、收藏与最近使用、菜单一键展开/收起、宽屏自适应、品牌页脚等数十项细节
### 留言反馈(2026.11 新增)
- **访客提交**:顶栏「留言反馈」按钮打开弹窗 —— 类型(功能建议/意见建议/Bug 反馈/其他)+ 内容(上限 1000 字)+ 联系方式(可选),图形验证码防刷,同一 IP 一小时内限提交 1 次
- **管理后台**:`/admin` 切到「留言反馈」标签(`X-Admin-Token` 鉴权,令牌存本地 `it-tools-admin-token`),列出时间/类型/内容/联系方式/真实 IP,支持状态流转(未处理→已处理→已回复)与删除,导航标签带未处理数角标;窄屏下表格容器内横向滚动不撑破页面
- **链路**:公开页 → relay `POST /feedback`(验证码校验 + IP 限频)落盘 `data/feedback.json`;管理接口经 nginx `location /admin/` 反代到 `it-tools-relay:8091`。公网入口 https://it.88531.cn/
## 优势
- **一次激活,全站通用**:输入一次卡密,全部授权功能解锁,无需逐个购买
+2
View File
@@ -92,6 +92,7 @@ declare module '@vue/runtime-core' {
Encryption: typeof import('./src/tools/encryption/encryption.vue')['default']
EtaCalculator: typeof import('./src/tools/eta-calculator/eta-calculator.vue')['default']
FavoriteButton: typeof import('./src/components/FavoriteButton.vue')['default']
FeedbackModal: typeof import('./src/components/FeedbackModal.vue')['default']
FormatTransformer: typeof import('./src/components/FormatTransformer.vue')['default']
GenHistory: typeof import('./src/tools/gen-history/GenHistory.vue')['default']
GitMemo: typeof import('./src/tools/git-memo/git-memo.vue')['default']
@@ -193,6 +194,7 @@ declare module '@vue/runtime-core' {
NRadioButton: typeof import('naive-ui')['NRadioButton']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSelect: typeof import('naive-ui')['NSelect']
NSlider: typeof import('naive-ui')['NSlider']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
+15
View File
@@ -17,6 +17,21 @@ server {
proxy_read_timeout 10s;
}
# admin console SPA route (exact match beats the /admin/ API prefix below,
# otherwise nginx 301s /admin -> /admin/ and the API proxy swallows the UI)
location = /admin {
try_files $uri /index.html;
}
# admin console API (relay does its own Bearer auth; must beat SPA fallback)
location /admin/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://it-tools-relay:8091;
proxy_connect_timeout 5s;
proxy_read_timeout 30s;
}
# license relay (card activation etc; auth gate itself must stay open)
location /relay/ {
client_max_body_size 2g;
+267
View File
@@ -0,0 +1,267 @@
<script setup lang="ts">
import { ref, watch } from 'vue';
import { useMessage } from 'naive-ui';
// 站内留言反馈弹窗(与授权系统无关,任何人可提交)
const props = defineProps<{ show: boolean }>();
const emit = defineEmits<{ (e: 'update:show', v: boolean): void }>();
const message = useMessage();
const TYPES = ['功能建议', '意见反馈'];
const typeOptions = TYPES.map(t => ({ label: t, value: t }));
const type = ref('功能建议');
const content = ref('');
const contact = ref('');
const captchaId = ref('');
const captchaImg = ref('');
const captchaCode = ref('');
const err = ref('');
const submitting = ref(false);
function close() {
emit('update:show', false);
}
async function loadCaptcha() {
try {
const res = await fetch('/relay/feedback/captcha');
const b = await res.json();
if (b.code === 200) {
captchaId.value = b.data.id;
captchaImg.value = `data:image/png;base64,${b.data.img}`;
err.value = '';
}
else {
captchaImg.value = '';
err.value = b.message || '验证码加载失败';
}
}
catch {
captchaImg.value = '';
err.value = '网络异常,验证码加载失败';
}
}
watch(() => props.show, (v) => {
if (v) {
err.value = '';
captchaCode.value = '';
loadCaptcha();
}
});
async function submit() {
if (submitting.value) {
return;
}
if (!content.value.trim()) {
err.value = '请填写留言内容';
return;
}
if (!captchaCode.value.trim()) {
err.value = '请输入图形验证码';
return;
}
submitting.value = true;
err.value = '';
try {
const res = await fetch('/relay/feedback', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
type: type.value,
content: content.value,
contact: contact.value,
captcha_id: captchaId.value,
captcha_code: captchaCode.value,
}),
});
const b = await res.json().catch(() => ({} as any));
if (b.code === 200) {
message.success('提交成功,我们会通过你留的联系方式回复');
content.value = '';
contact.value = '';
captchaCode.value = '';
close();
return;
}
err.value = b.message || `提交失败(${res.status})`;
// 验证码一次性:除了限频(429)以外都换一张,避免用户对着旧码重试
if (res.status !== 429) {
loadCaptcha();
captchaCode.value = '';
}
}
catch {
err.value = '网络异常,请稍后重试';
}
finally {
submitting.value = false;
}
}
</script>
<template>
<n-modal
:show="show"
preset="card"
class="fb-modal"
title="💬 留言反馈"
:style="{ width: 'min(580px, 94vw)' }"
:bordered="false"
@update:show="(v: boolean) => emit('update:show', v)"
>
<div class="fb-hint">与授权系统无关,任何人都可以留言;内容我们会在后台查看,留了联系方式会回复你。</div>
<div class="fb-row">
<label class="fb-label">留言类型</label>
<n-select v-model:value="type" :options="typeOptions" size="medium" />
</div>
<div class="fb-row">
<label class="fb-label">留言内容 <i>*</i></label>
<n-input
v-model:value="content"
type="textarea"
:rows="6"
maxlength="1000"
show-count
placeholder="请描述你的功能建议或遇到的问题,越具体越好…"
/>
</div>
<div class="fb-row">
<label class="fb-label">联系方式(可选)</label>
<n-input
v-model:value="contact"
:maxlength="64"
placeholder="QQ / 微信 / 邮箱,方便我们回复你"
/>
</div>
<div class="fb-row">
<label class="fb-label">图形验证码 <i>*</i></label>
<div class="fb-captcha-line">
<n-input
v-model:value="captchaCode"
:maxlength="4"
placeholder="4 位字符"
class="fb-captcha-input"
@keyup.enter="submit"
/>
<img
v-if="captchaImg"
class="fb-captcha-img"
:src="captchaImg"
alt="图形验证码"
title="点击换一张"
@click="loadCaptcha"
>
<span v-else class="fb-captcha-img fb-captcha-loading" @click="loadCaptcha">加载中…</span>
<span class="fb-captcha-refresh" role="button" tabindex="0" @click="loadCaptcha">换一张</span>
</div>
</div>
<div v-if="err" class="fb-err">{{ err }}</div>
<template #footer>
<div class="fb-foot">
<span class="fb-limit">同一 IP 一小时内限提交 1 次</span>
<span class="fb-foot-btns">
<n-button quaternary @click="close">取消</n-button>
<n-button type="primary" :loading="submitting" @click="submit">提交留言</n-button>
</span>
</div>
</template>
</n-modal>
</template>
<!-- n-modal 会 teleport 到 body,故这里用非 scoped 样式(类名统一 fb- 前缀) -->
<style lang="less">
.fb-modal {
.fb-hint {
font-size: 14.5px;
line-height: 1.6;
opacity: 0.75;
margin-bottom: 16px;
}
.fb-row {
margin-bottom: 14px;
}
.fb-label {
display: block;
font-size: 14.5px;
margin-bottom: 6px;
i {
color: #e0115f;
font-style: normal;
}
}
.fb-captcha-line {
display: flex;
align-items: center;
gap: 10px;
}
.fb-captcha-input {
width: 140px;
flex: none;
}
.fb-captcha-img {
height: 40px;
border-radius: 6px;
cursor: pointer;
border: 1px solid rgba(128, 128, 128, 0.35);
background: rgba(128, 128, 128, 0.12);
padding: 0 12px;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 14.5px;
user-select: none;
}
.fb-captcha-refresh {
font-size: 14.5px;
cursor: pointer;
opacity: 0.8;
text-decoration: underline;
&:hover {
opacity: 1;
}
}
.fb-err {
margin-top: 10px;
font-size: 14.5px;
color: #d03050;
word-break: break-all;
}
.fb-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
flex-wrap: wrap;
}
.fb-limit {
font-size: 14px;
opacity: 0.6;
}
.fb-foot-btns {
display: inline-flex;
gap: 10px;
}
}
</style>
+87
View File
@@ -16,6 +16,7 @@ import { useToolStore } from '@/tools/tools.store';
import { useTracker } from '@/modules/tracker/tracker.services';
import CollapsibleToolMenu from '@/components/CollapsibleToolMenu.vue';
import UserMenu from '@/components/UserMenu.vue';
import FeedbackModal from '@/components/FeedbackModal.vue';
const themeVars = useThemeVars();
const styleStore = useStyleStore();
@@ -31,6 +32,42 @@ if (isLoggedIn.value) {
const version = config.app.version;
const commitSha = config.app.lastCommitSha.slice(0, 7);
// ---- 站内留言反馈(右上角入口,弹窗提交,与授权系统无关) ----
const showFeedback = ref(false);
// ---- 页脚售后微信:点击复制 ----
const WECHAT_ID = 'q3970260761';
const wechatCopied = ref(false);
async function copyWechat() {
let ok = false;
try {
await navigator.clipboard.writeText(WECHAT_ID);
ok = true;
}
catch {
// 剪贴板 API 不可用(非 https / 老浏览器)时退回 execCommand
try {
const ta = document.createElement('textarea');
ta.value = WECHAT_ID;
ta.style.position = 'fixed';
ta.style.opacity = '0';
document.body.appendChild(ta);
ta.select();
ok = document.execCommand('copy');
document.body.removeChild(ta);
}
catch {
ok = false;
}
}
if (ok) {
wechatCopied.value = true;
setTimeout(() => {
wechatCopied.value = false;
}, 2000);
}
}
const { tracker } = useTracker();
const { t } = useI18n();
@@ -193,6 +230,18 @@ onBeforeUnmount(() => {
<UserMenu />
<!-- 全站右上角:留言反馈(与授权系统无关,任何人可提交) -->
<c-tooltip position="bottom" :tooltip="'给我们留言:功能建议 / 意见反馈'">
<c-button
round
class="feedback-btn"
:bordered="false"
@click="showFeedback = true"
>
✍️ <span class="feedback-btn-text">留言反馈</span>
</c-button>
</c-tooltip>
<c-tooltip position="bottom" :tooltip="'查看授权功能与购买'">
<RouterLink to="/pricing" class="pricing-link">
<c-button
@@ -241,8 +290,22 @@ onBeforeUnmount(() => {
title="https://gitea.88531.cn/jinghui/it-tools-pro"
>🐙 开源 gitea.88531.cn</c-link>
</span>
<span class="footer-sep">·</span>
<span>
<span
class="footer-wechat"
role="button"
tabindex="0"
title="点击复制售后微信 q3970260761"
@click="copyWechat"
@keyup.enter="copyWechat"
>💬 售后微信 {{ wechatCopied ? '已复制 ✓' : 'q3970260761' }}</span>
</span>
</div>
<!-- 留言反馈弹窗 -->
<FeedbackModal v-model:show="showFeedback" />
<!-- 右下角回到顶部火箭 -->
<button v-show="showTop" class="back-top" title="回到顶部" aria-label="回到顶部" @click="scrollToTop">🚀</button>
</template>
@@ -321,6 +384,16 @@ onBeforeUnmount(() => {
opacity: 0.55;
}
// 售后微信:点击复制(固定底栏下 pointer-events:none,这里单独放行)
.footer-wechat {
cursor: pointer;
pointer-events: auto;
&:hover {
color: #0e9384;
}
}
:deep(a) {
color: #838587;
text-decoration: none;
@@ -363,6 +436,13 @@ onBeforeUnmount(() => {
flex-shrink: 0;
}
// 右上角「留言反馈」入口:与顶栏其它文字按钮同规格
.feedback-btn {
font-size: 13px;
white-space: nowrap;
flex-shrink: 0;
}
@media (max-width: 900px) {
// 窄屏顶栏放不下完整文字时收缩为纯图标,并收紧间距,避免溢出右边缘
.top-nav {
@@ -375,6 +455,13 @@ onBeforeUnmount(() => {
padding-left: 8px;
padding-right: 8px;
}
.feedback-btn {
.feedback-btn-text {
display: none;
}
padding-left: 8px;
padding-right: 8px;
}
}
.top-nav {
+157 -2
View File
@@ -19,7 +19,10 @@ const loginPass = ref('');
function authHeaders(): Record<string, string> {
const h: Record<string, string> = {};
if (token.value) {
// Bearer = logged-in admin session (channel 2); X-Admin-Token = bootstrap
// ADMIN_TOKEN paste flow (channel 1). Send both so either kind works.
h['Authorization'] = `Bearer ${token.value}`;
h['X-Admin-Token'] = token.value;
}
return h;
}
@@ -61,6 +64,7 @@ async function login() {
authed.value = true;
localStorage.setItem(TOKEN_KEY, token.value);
loadOverview();
loadFeedback();
}
}
catch (e: any) {
@@ -372,6 +376,55 @@ async function saveReco() {
}
}
// ============ 留言反馈(网站访客提交,与授权系统无关) ============
const feedback = ref<any[]>([]);
async function loadFeedback() {
try {
const b = await api('/admin/feedback');
feedback.value = b.data ?? [];
} catch (e: any) {
setMsg(`留言加载失败:${e.message}`);
}
}
async function fbSetStatus(f: any, status: string) {
try {
const b = await api('/admin/feedback', { method: 'POST', body: JSON.stringify({ id: f.id, status }) });
setMsg(b.code === 200 ? '已更新留言状态' : (b.message || '状态更新失败'));
if (b.code === 200) f.status = status;
} catch (e: any) {
setMsg(`状态更新失败:${e.message}`);
}
}
function fbOnStatus(f: any, e: Event) {
fbSetStatus(f, (e.target as HTMLSelectElement).value);
}
async function fbDelete(f: any) {
if (!window.confirm('确定删除这条留言?删除后无法恢复。')) return;
try {
const b = await api('/admin/feedback', { method: 'POST', body: JSON.stringify({ id: f.id, action: 'delete' }) });
setMsg(b.code === 200 ? '已删除' : (b.message || '删除失败'));
if (b.code === 200) feedback.value = feedback.value.filter(x => x.id !== f.id);
} catch (e: any) {
setMsg(`删除失败:${e.message}`);
}
}
function fbTime(ts: any) {
try {
const d = new Date(Number(ts) * 1000);
const p = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
} catch {
return String(ts ?? '');
}
}
const fbNewCount = computed(() => feedback.value.filter(f => f.status === 'new').length);
function recoAdd() {
reco.value.unshift({ path: '', icon: '🧰', name: '', desc: '', enabled: true });
}
@@ -389,9 +442,9 @@ function recoMove(i: number, d: -1 | 1) {
reco.value.splice(j, 0, it);
}
const tab = ref<'overview' | 'files' | 'usage' | 'storage' | 'reco'>('overview');
const tab = ref<'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'feedback'>('overview');
function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco' | 'feedback') {
tab.value = id;
if (id === 'overview') {
loadOverview();
@@ -405,6 +458,9 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
if (id === 'storage') {
loadStorage();
}
if (id === 'feedback') {
loadFeedback();
}
}
</script>
@@ -436,6 +492,10 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
<div class="adm-nav-item" :class="{ active: tab === 'usage' }" @click="switchTab('usage')">📈 使用统计</div>
<div class="adm-nav-item" :class="{ active: tab === 'storage' }" @click="switchTab('storage')">💾 存储设置</div>
<div class="adm-nav-item" :class="{ active: tab === 'reco' }" @click="switchTab('reco')">🏠 首页推荐</div>
<div class="adm-nav-item" :class="{ active: tab === 'feedback' }" @click="switchTab('feedback')">
💬 留言反馈
<span v-if="fbNewCount > 0" class="adm-badge bad" style="margin-left: 6px">{{ fbNewCount }}</span>
</div>
</div>
<a href="javascript:;" class="adm-logout" @click="authed = false; localStorage.removeItem(TOKEN_KEY)">退出</a>
</div>
@@ -642,6 +702,55 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
</div>
</div>
</template>
<!-- 留言反馈:网站访客提交的留言,按时间倒序 -->
<template v-if="tab === 'feedback'">
<div class="adm-toolbar">
<span class="adm-sub">
共 {{ feedback.length }} 条 · 未处理 {{ fbNewCount }} 条(同一 IP 一小时内限提交 1 次 + 图形验证码)
</span>
<button class="adm-btn adm-btn-sm" @click="loadFeedback">🔄 刷新</button>
</div>
<div class="adm-fb-scroll">
<table class="adm-table">
<thead>
<tr>
<th>时间</th>
<th>类型</th>
<th>内容</th>
<th>联系方式</th>
<th>IP</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="f in feedback" :key="f.id">
<td class="adm-fb-time">{{ fbTime(f.ts) }}</td>
<td>
<span class="adm-badge" :class="f.type === '功能建议' ? 'ok' : 'admin'">{{ f.type }}</span>
</td>
<td class="adm-fb-content">{{ f.content }}</td>
<td class="adm-fb-contact">{{ f.contact || '—' }}</td>
<td class="adm-fb-ip">{{ f.ip }}</td>
<td>
<select class="adm-select" :value="f.status" @change="fbOnStatus(f, $event)">
<option value="new">未处理</option>
<option value="replied">已回复</option>
<option value="done">已处理</option>
</select>
</td>
<td class="adm-fb-ops">
<a href="javascript:;" class="adm-link" @click="fbDelete(f)">删除</a>
</td>
</tr>
<tr v-if="!feedback.length">
<td colspan="7" class="adm-none">暂无留言,访客提交后会显示在这里</td>
</tr>
</tbody>
</table>
</div>
</template>
</div>
</div>
</div>
@@ -751,6 +860,33 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
gap: 7px;
}
// ---- 留言反馈列表 ----
.adm-fb-time {
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.adm-fb-content {
max-width: 460px;
white-space: pre-wrap;
word-break: break-word;
line-height: 1.6;
}
.adm-fb-contact,
.adm-fb-ip {
white-space: nowrap;
}
.adm-fb-ip {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.adm-fb-ops {
white-space: nowrap;
}
.adm-reco-row {
display: flex;
align-items: center;
@@ -972,6 +1108,25 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'storage' | 'reco') {
}
}
/* 留言反馈表:窄视口容器内横向滚动,表头保持横排不被挤成竖列 */
.adm-fb-scroll {
overflow-x: auto;
-webkit-overflow-scrolling: touch;
.adm-table {
min-width: 820px;
th {
white-space: nowrap;
}
td {
word-break: break-word;
max-width: 360px;
}
}
}
.adm-badge {
font-size: 11px;
padding: 1px 8px;