交互:表情面板 + 短文快发盒 + 双 UI 手机导航重做 + 社交链接与统计脚本接入
评论表情 - 发布 / 回复 / 编辑三处输入框挂上表情面板(EmojiPicker + emoji.js): 「表情 / 颜文字」两个 tab,光标处插入(insertAtCursor,未聚焦追加到 末尾),面板自己管点外 / Esc 收起 - 操作钮 ✎ ✕ ↩ 圆图标改文字钮(回复 / 编辑 / 删除),删除悬停给红, 补 focus-visible;编辑态去掉「正在改定此评:」交给 placeholder 双 UI 手机导航(参考 innei.in 的底部胶囊 + 上拉菜单) - 余白:顶栏手机端整条退场,底部悬浮 dock(品牌 + NavBurger 汉堡), 点开上拉毛玻璃菜单:mono 序号 01-05 + 中文大字 + 英文小字,当前项 强调色 + 左缘短杠,逐项错峰 45ms 入场;dock 在菜单之下原位变 ✕ - classic:顶栏 brand 居中(三列网格)+ NavBurger + 下拉纸片;下滑隐藏 上滑唤回——上滑要累计 40px 才算数(页面高度稳定时浏览器会回弹几十 像素,那种「假上滑」不拉回顶栏);首页 .sticky-head 用 var(--topbar-h) 跟随顶栏一起滑 - NavBurger 两套 UI 共用;经典手机 FAB 避开右下角主题浮钮 sticky 失效修复 - body overflow-x:hidden 把 body 变成滚动容器,页内所有 position:sticky 全部失明(首页筛选条吸顶从来没生效过)→ 改 overflow-x:clip, 只裁剪不建滚动容器 - 余白手机端 .article-layout 裸 1fr 的自动最小尺寸是 min-content, 长 token 把整列顶到 592px 横向溢出 → minmax(0,1fr) + overflow-wrap 短文快发盒(QuickShort,Twitter 式) - 时间线顶部内联发布盒:头像 + 输入框 + 发布(Ctrl/⌘+Enter),手机收进 右下角 FAB + 上拉 sheet;只有管理员会话在场才渲染(/api/admin/me 探测),发布走真实 createPost(kind:short)——标题 / slug / 阅读时长 后端自动生成。读者社交登录是阶段二产物,后端就绪前访客无法登录, 所以天然只有站主可见;要放开给读者发,换探测和发布接口即可 - 经典 FAB 避开右下角主题浮钮(bottom 72),余白贴安全区(bottom 20) 社交链接 + 统计脚本接入 - Settings 的 social_links 前台两处渲染:经典左栏「常读标签」区域改为 「社交账号」图标行(url 域名推导图标:GitHub / Telegram / X / 邮箱 信封,认不出显示名称文字),右栏卡片下方 Twitter 式页脚小字区三排 (导航行 / 社交图标行 / 项目源码 + 版权行)——项目源码是固定入口 (本站 git remote),与版权同为固定元素,后台配置挤不掉 - Settings 加 custom_js:后台贴完整 <script> 片段(GA / Plausible / Umami),DOMParser 解析后逐个重建 script 节点插进 head(innerHTML 塞的 script 不会执行);公开页每页注入一次,/admin 不注入; 站主自己的代码不做清洗(洗 JS 只会把统计脚本洗坏) - 订阅卡删掉:RSS 入口在页脚小字里,一张卡只为一个链接不值得 杂项 - vite dev 加 --host:手机连局域网直接评审 - 评论 mock 的状态浮层窄屏上移,给底部 dock 让位 - 经典页脚在 12px 页边距下的排版对齐 验证 - 后端 go test 全绿;前端构建通过 - 浏览器逐状态过目:双 UI × 亮暗 × 桌面/手机;表情插入 / 短文发布真实 入库(测试内容已删)/ dock 与 sheet 开合 / FAB 与主题浮钮不重叠 / 顶栏隐藏与筛选条跟随同步
This commit is contained in:
@@ -1,24 +1,14 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { site } from '../site'
|
||||
import { publicApi } from '../api'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { socialIcon } from '../socialIcons'
|
||||
import ThemeSwitcher from './ThemeSwitcher.vue'
|
||||
|
||||
// vivid 用顶部导航(VividNav)代替左栏。这里直接不渲染,顺带省掉一次
|
||||
// 标签请求 —— 视图本身不用知道 UI 版本。
|
||||
// vivid 用顶部导航(VividNav)代替左栏。这里直接不渲染。
|
||||
const isVivid = computed(() => site.ui_id === 'vivid')
|
||||
|
||||
const tags = ref([])
|
||||
|
||||
onMounted(async () => {
|
||||
if (isVivid.value) return
|
||||
try {
|
||||
const data = await publicApi.tags()
|
||||
tags.value = (data.tags || []).slice(0, 8)
|
||||
} catch (e) {
|
||||
tags.value = []
|
||||
}
|
||||
})
|
||||
// 社交 / 源码链接(后台「高级 → 社交链接」填写);url 必填,空的丢弃
|
||||
const social = computed(() => (site.social_links || []).filter((s) => s && s.url))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -48,12 +38,23 @@ onMounted(async () => {
|
||||
</RouterLink>
|
||||
</nav>
|
||||
|
||||
<div v-if="tags.length" class="tagbox">
|
||||
<p class="eyebrow">常读标签</p>
|
||||
<div class="tags">
|
||||
<RouterLink v-for="t in tags" :key="t.id" :to="`/tag/${t.slug}`" class="tag-chip">
|
||||
{{ t.name }}
|
||||
</RouterLink>
|
||||
<!-- 社交账号(后台「高级 → 社交链接」填写):已知域名给图标,认不出显示名称 -->
|
||||
<div v-if="social.length" class="social-box">
|
||||
<p class="eyebrow">社交账号</p>
|
||||
<div class="social-row">
|
||||
<a
|
||||
v-for="s in social"
|
||||
:key="s.label + s.url"
|
||||
class="social-link"
|
||||
:href="s.url"
|
||||
:title="s.label"
|
||||
:aria-label="s.label"
|
||||
:target="s.url.startsWith('http') ? '_blank' : undefined"
|
||||
:rel="s.url.startsWith('http') ? 'noopener' : undefined"
|
||||
>
|
||||
<svg v-if="socialIcon(s.url)" viewBox="0 0 24 24" aria-hidden="true"><path :d="socialIcon(s.url)" /></svg>
|
||||
<span v-else>{{ s.label }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -142,18 +143,45 @@ onMounted(async () => {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.tagbox {
|
||||
.social-box {
|
||||
border-top: 1px solid var(--line);
|
||||
padding-top: 14px;
|
||||
}
|
||||
|
||||
.tags {
|
||||
.social-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.social-link {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 32px;
|
||||
height: 30px;
|
||||
border-radius: 6px;
|
||||
color: var(--muted);
|
||||
transition: color 0.2s, background-color 0.2s;
|
||||
}
|
||||
|
||||
.social-link:hover {
|
||||
color: var(--accent);
|
||||
background: var(--paper-sunken);
|
||||
}
|
||||
|
||||
/* 认不出的域名没有图标,回落成名称文字 */
|
||||
.social-link span {
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.social-link svg {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
fill: currentColor;
|
||||
}
|
||||
|
||||
.theme-box {
|
||||
border-top: 1px solid var(--line);
|
||||
padding-top: 14px;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<script setup>
|
||||
// 两套 UI 共用的菜单开合钮:两条横线,open 时并成 ✕。颜色走 token
|
||||
// (--ink-soft / --accent 在 classic 和 vivid 里都有定义),尺寸 40px、
|
||||
// 触屏 44px。菜单开合的其余行为(锁滚动、Esc、路由收起)归各个顶栏管。
|
||||
defineProps({
|
||||
open: { type: Boolean, default: false }
|
||||
})
|
||||
defineEmits(['toggle'])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
class="nav-burger"
|
||||
type="button"
|
||||
:class="{ open }"
|
||||
:aria-expanded="open"
|
||||
@click="$emit('toggle')"
|
||||
>
|
||||
<i /><i />
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.nav-burger {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
gap: 5px;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: none;
|
||||
cursor: pointer;
|
||||
touch-action: manipulation;
|
||||
}
|
||||
|
||||
.nav-burger i {
|
||||
display: block;
|
||||
width: 17px;
|
||||
height: 1.6px;
|
||||
margin: 0 auto;
|
||||
border-radius: 2px;
|
||||
background: var(--ink-soft);
|
||||
transition: transform 0.3s var(--ease, ease), background-color 0.2s;
|
||||
}
|
||||
|
||||
.nav-burger:hover i {
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
/* 两条线向中间并拢旋转成 ✕:位移 = (线高 + gap) / 2 */
|
||||
.nav-burger.open i:nth-child(1) {
|
||||
transform: translateY(3.3px) rotate(45deg);
|
||||
}
|
||||
.nav-burger.open i:nth-child(2) {
|
||||
transform: translateY(-3.3px) rotate(-45deg);
|
||||
}
|
||||
|
||||
@media (pointer: coarse) {
|
||||
.nav-burger {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.nav-burger i {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,319 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { adminApi } from '../api'
|
||||
|
||||
// Twitter 式短文发布盒,挂在时间线顶部。
|
||||
//
|
||||
// 只有管理员会话在场才渲染(adminApi.me 探测):发布走真实的
|
||||
// adminApi.createPost(kind: short —— 后端自动生成标题 / slug / 阅读时长)。
|
||||
// 读者侧的社交登录是评论区阶段二的产物,后端就绪前访客本来就无法
|
||||
// 「登录」,所以这里天然只有站主能看到;以后要放开给读者发,把探测和
|
||||
// 发布接口换成读者体系的即可,UI 不用动。
|
||||
//
|
||||
// 桌面(>640px):内联在时间线顶部;手机:右下角 FAB,点开底部上拉 sheet。
|
||||
// 两份 textarea 共享同一个 draft(v-model 同源),媒体查询切换可见性。
|
||||
// 发布后 emit('published'),由宿主刷新时间线。
|
||||
|
||||
const emit = defineEmits(['published'])
|
||||
|
||||
const shown = ref(false)
|
||||
const userName = ref('')
|
||||
const draft = ref('')
|
||||
const publishing = ref(false)
|
||||
const error = ref('')
|
||||
const sheetOpen = ref(false)
|
||||
|
||||
const initial = computed(() => (userName.value || 'O').trim().slice(0, 1).toUpperCase())
|
||||
const canPost = computed(() => draft.value.trim().length > 0 && !publishing.value)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const d = await adminApi.me()
|
||||
if (d.user) {
|
||||
userName.value = String(d.user)
|
||||
shown.value = true
|
||||
}
|
||||
} catch {
|
||||
shown.value = false
|
||||
}
|
||||
})
|
||||
|
||||
// 系统会话过期(发布 401)时提示重新登录
|
||||
const expired = ref(false)
|
||||
|
||||
function onKey(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') publish()
|
||||
}
|
||||
|
||||
async function publish() {
|
||||
if (!canPost.value) return
|
||||
publishing.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await adminApi.createPost({
|
||||
kind: 'short',
|
||||
content_md: draft.value.trim(),
|
||||
status: 'published'
|
||||
})
|
||||
draft.value = ''
|
||||
sheetOpen.value = false
|
||||
emit('published')
|
||||
} catch (e) {
|
||||
if (String(e.message).includes('401') || String(e.message).includes('Unauthorized')) {
|
||||
expired.value = true
|
||||
error.value = '登录已过期,刷新页面重新登录后再发。'
|
||||
} else {
|
||||
error.value = e.message || '发布失败'
|
||||
}
|
||||
} finally {
|
||||
publishing.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="shown" class="qs-root">
|
||||
<!-- 桌面:内联 -->
|
||||
<div class="qs-inline">
|
||||
<div class="qs-card">
|
||||
<span class="qs-av">{{ initial }}</span>
|
||||
<div class="qs-body">
|
||||
<textarea v-model="draft" class="qs-input" rows="2" placeholder="记点短的…" @keydown="onKey" />
|
||||
<div class="qs-acts">
|
||||
<span v-if="error" class="qs-err">{{ error }}</span>
|
||||
<span v-else class="qs-tip">Ctrl / ⌘ + Enter 发布</span>
|
||||
<button type="button" class="qs-send" :disabled="!canPost" @click="publish">
|
||||
{{ publishing ? '发布中…' : '发布' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 手机:FAB + 上拉 sheet -->
|
||||
<button type="button" class="qs-fab" aria-label="写短文" @click="sheetOpen = true">+</button>
|
||||
|
||||
<Transition name="qs-sheet">
|
||||
<div v-if="sheetOpen" class="qs-overlay">
|
||||
<div class="qs-scrim" @click="sheetOpen = false" />
|
||||
<div class="qs-sheet">
|
||||
<div class="qs-sheet-head">
|
||||
<span>写短文</span>
|
||||
<button type="button" class="qs-close" aria-label="关闭" @click="sheetOpen = false">✕</button>
|
||||
</div>
|
||||
<textarea v-model="draft" class="qs-input" rows="4" placeholder="记点短的…" @keydown="onKey" />
|
||||
<div class="qs-acts">
|
||||
<span v-if="error" class="qs-err">{{ error }}</span>
|
||||
<span v-else class="qs-tip">Ctrl / ⌘ + Enter 发布</span>
|
||||
<button type="button" class="qs-send" :disabled="!canPost" @click="publish">
|
||||
{{ publishing ? '发布中…' : '发布' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.qs-inline {
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.qs-card {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
background: var(--card);
|
||||
}
|
||||
|
||||
.qs-av {
|
||||
flex: none;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent-soft);
|
||||
color: var(--accent);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.qs-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.qs-input {
|
||||
display: block;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background: none;
|
||||
resize: vertical;
|
||||
font: inherit;
|
||||
font-size: 14.5px;
|
||||
line-height: 1.7;
|
||||
color: var(--ink);
|
||||
min-height: 44px;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.qs-input:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.qs-acts {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.qs-tip {
|
||||
font-size: 12px;
|
||||
color: var(--faint);
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.qs-err {
|
||||
font-size: 12.5px;
|
||||
color: #a64953;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.qs-send {
|
||||
flex: none;
|
||||
padding: 6px 18px;
|
||||
border: 0;
|
||||
border-radius: 999px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.qs-send:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* 手机:FAB 常驻右下,点开上拉 sheet */
|
||||
.qs-fab {
|
||||
display: none;
|
||||
position: fixed;
|
||||
right: 16px;
|
||||
bottom: 72px;
|
||||
z-index: 80;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border: 0;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
font-size: 24px;
|
||||
line-height: 1;
|
||||
box-shadow: 0 10px 30px -8px rgba(28, 28, 30, 0.45);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.qs-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 120;
|
||||
}
|
||||
|
||||
.qs-scrim {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: color-mix(in srgb, #000 32%, transparent);
|
||||
}
|
||||
|
||||
.qs-sheet {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
right: 10px;
|
||||
bottom: max(10px, env(safe-area-inset-bottom));
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 20px;
|
||||
background: var(--card);
|
||||
padding: 12px 14px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.qs-sheet-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 700;
|
||||
font-size: 14px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.qs-close {
|
||||
border: 0;
|
||||
background: none;
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.qs-inline {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.qs-fab {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 641px) {
|
||||
.qs-overlay {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.qs-sheet-enter-active,
|
||||
.qs-sheet-leave-active {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
/* sheet 过渡(进:从底部长出来;出:沉回去) */
|
||||
.qs-sheet-enter-active {
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
.qs-sheet-enter-active .qs-sheet {
|
||||
transition: transform 0.4s cubic-bezier(0.22, 1.2, 0.36, 1), opacity 0.3s ease;
|
||||
}
|
||||
.qs-sheet-enter-from {
|
||||
opacity: 0;
|
||||
}
|
||||
.qs-sheet-enter-from .qs-sheet {
|
||||
transform: translateY(48px);
|
||||
opacity: 0;
|
||||
}
|
||||
.qs-sheet-leave-active {
|
||||
transition: opacity 0.18s ease;
|
||||
}
|
||||
.qs-sheet-leave-active .qs-sheet {
|
||||
transition: transform 0.18s ease;
|
||||
}
|
||||
.qs-sheet-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
.qs-sheet-leave-to .qs-sheet {
|
||||
transform: translateY(40px);
|
||||
}
|
||||
</style>
|
||||
@@ -2,11 +2,28 @@
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { publicApi } from '../api'
|
||||
import { site } from '../site'
|
||||
import { socialIcon } from '../socialIcons'
|
||||
import { relativeDate } from '../utils'
|
||||
|
||||
// vivid 是单栏布局,右栏整体不渲染(省掉 latest/tags 两次请求)。
|
||||
const isVivid = computed(() => site.ui_id === 'vivid')
|
||||
|
||||
// 项目源码仓库是固定入口(本站 git remote),不来自后台配置 —— 和版权一样
|
||||
// 固定渲染在自己的那排;后台填的社交账号单独一排,URL 撞车的去重。
|
||||
const PROJECT_REPO = 'https://git.gopher.ink/mirrors2/ONE'
|
||||
|
||||
// 社交 / 源码链接(后台「高级 → 社交链接」填写);url 必填,空的丢弃。
|
||||
// 有图标的(按域名推导)渲染成单色图标,认不出的显示名称文字。
|
||||
const social = computed(() => (site.social_links || []).filter((s) => s && s.url && s.url !== PROJECT_REPO))
|
||||
|
||||
const links = [
|
||||
{ to: '/', label: '首页' },
|
||||
{ to: '/archive', label: '归档' },
|
||||
{ to: '/tags', label: '标签' },
|
||||
{ to: '/projects', label: '作品' },
|
||||
{ to: '/about', label: '关于' }
|
||||
]
|
||||
|
||||
const latest = ref([])
|
||||
const tags = ref([])
|
||||
|
||||
@@ -55,11 +72,46 @@ onMounted(async () => {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card">
|
||||
<p class="eyebrow">订阅</p>
|
||||
<p class="bio">用 RSS 阅读器跟进更新。</p>
|
||||
<a class="pill pill-ghost" href="/rss.xml">RSS / feed.xml</a>
|
||||
</section>
|
||||
<!-- 订阅卡删掉了:RSS 入口在下方页脚小字里,一张卡片只为一个链接不值得 -->
|
||||
|
||||
<!-- 页脚信息(Twitter 式:右栏卡片下方的小字区)。通栏 ClassicFoot
|
||||
已删:右栏在窄屏会堆到信息流下方,卡片之后正好接页脚小字,
|
||||
所有宽度都不缺位。 -->
|
||||
<footer class="rail-foot">
|
||||
<nav class="foot-links" aria-label="页脚导航">
|
||||
<template v-for="(l, i) in links" :key="l.to">
|
||||
<span v-if="i" class="dot">·</span>
|
||||
<RouterLink :to="l.to">{{ l.label }}</RouterLink>
|
||||
</template>
|
||||
<span class="dot">·</span>
|
||||
<a href="/rss.xml">RSS</a>
|
||||
</nav>
|
||||
<!-- 后台填的社交账号:单独一排 -->
|
||||
<div v-if="social.length" class="social-row">
|
||||
<a
|
||||
v-for="s in social"
|
||||
:key="s.label + s.url"
|
||||
class="social-icon"
|
||||
:href="s.url"
|
||||
:title="s.label"
|
||||
:aria-label="s.label"
|
||||
:target="s.url.startsWith('http') ? '_blank' : undefined"
|
||||
:rel="s.url.startsWith('http') ? 'noopener' : undefined"
|
||||
>
|
||||
<svg v-if="socialIcon(s.url)" viewBox="0 0 24 24" aria-hidden="true"><path :d="socialIcon(s.url)" /></svg>
|
||||
<span v-else>{{ s.label }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<!-- 项目信息:固定的源码图标 + 版权,永远在 -->
|
||||
<div class="foot-meta">
|
||||
<a class="social-icon" :href="PROJECT_REPO" title="项目源码" aria-label="项目源码" target="_blank" rel="noopener">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true"><path :d="socialIcon(PROJECT_REPO)" /></svg>
|
||||
</a>
|
||||
<span class="copyright">
|
||||
{{ site.footer_note }}<template v-if="site.icp"> · {{ site.icp }}</template>
|
||||
</span>
|
||||
</div>
|
||||
</footer>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
@@ -142,4 +194,78 @@ onMounted(async () => {
|
||||
color: var(--faint);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
/* 页脚小字区:无卡片边框,Twitter 式侧栏页脚。classic 的页脚信息只在这里
|
||||
出现(通栏 ClassicFoot 已删):右栏在窄屏会堆到信息流下方,卡片之后
|
||||
正好接页脚小字,所有宽度都不缺位。 */
|
||||
.rail-foot {
|
||||
padding: 4px 6px 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.9;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.foot-links a {
|
||||
color: var(--faint);
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
.foot-links a:hover {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.dot {
|
||||
margin: 0 4px;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* 图标 + 版权同排:源码等入口是单色小图标,hover 才亮成强调色 */
|
||||
.social-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.foot-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
/* 项目信息行和上面的社交账号排拉开一截:它们是两类信息 */
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.social-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 22px;
|
||||
height: 22px;
|
||||
padding: 0 3px;
|
||||
border-radius: 6px;
|
||||
color: var(--faint);
|
||||
font-size: 12px;
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
.social-icon:hover {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.social-icon svg {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
fill: currentColor;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
/* 窄屏:底部留白加高,右下角浮动主题钮压不到页脚小字 */
|
||||
@media (max-width: 780px) {
|
||||
.rail-right {
|
||||
padding-bottom: 96px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,18 +1,127 @@
|
||||
<script setup>
|
||||
import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { RouterLink, useRoute } from 'vue-router'
|
||||
import { site } from '../site'
|
||||
import NavBurger from './NavBurger.vue'
|
||||
|
||||
// 手机端导航。原来把 5 个链接平铺在顶栏里:375px 挤成一排小字,
|
||||
// 触点只有十几像素高,320px 的屏还会折行。改成 brand + 汉堡钮,
|
||||
// 点开一片下拉「纸片」(不是全屏——classic 的性格是轻,浮一层纸就够)。
|
||||
// 主题切换不走这里:App.vue 的浮动 ThemeSwitcher 只在窄屏出现,职责不重。
|
||||
// 桌面(>780px)整个顶栏不存在,导航走左栏。
|
||||
|
||||
const route = useRoute()
|
||||
const open = ref(false)
|
||||
const hidden = ref(false)
|
||||
const burger = ref(null)
|
||||
|
||||
const links = [
|
||||
{ to: '/', label: '首页' },
|
||||
{ to: '/archive', label: '归档' },
|
||||
{ to: '/tags', label: '标签' },
|
||||
{ to: '/projects', label: '作品' },
|
||||
{ to: '/about', label: '关于' }
|
||||
]
|
||||
|
||||
function isOn(l) {
|
||||
return l.to === '/' ? route.path === '/' : route.path.startsWith(l.to)
|
||||
}
|
||||
|
||||
// 下滑藏顶栏、上滑唤回。dead zone 滤掉手指微抖;滚回页首(没滚出顶栏多远)
|
||||
// 或菜单开着时强制显示 —— 纸片锚在顶栏下面,顶栏藏了纸片会悬空。
|
||||
// 上滑唤回要累计上移 40px 才算数:页面加载后字体/内容稳定时高度会收缩,
|
||||
// 浏览器把滚动位置回弹几十像素,那种「假上滑」不该把顶栏拉回来。
|
||||
let lastY = typeof window === 'undefined' ? 0 : window.scrollY
|
||||
let hideY = 0
|
||||
function onScroll() {
|
||||
const y = window.scrollY
|
||||
if (open.value || y <= 80) {
|
||||
hidden.value = false
|
||||
lastY = y
|
||||
return
|
||||
}
|
||||
const delta = y - lastY
|
||||
lastY = y
|
||||
if (delta > 4) {
|
||||
hidden.value = true
|
||||
hideY = y
|
||||
} else if (delta < -4 && hideY - y > 40) {
|
||||
hidden.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function toggle() {
|
||||
open.value ? close() : (open.value = true)
|
||||
}
|
||||
function close() {
|
||||
open.value = false
|
||||
const b = burger.value?.$el || burger.value
|
||||
nextTick(() => b?.focus?.({ preventScroll: true }))
|
||||
}
|
||||
function onKey(e) {
|
||||
if (e.key === 'Escape') close()
|
||||
}
|
||||
// 点顶栏和纸片以外的地方收起(scrim 也兜了一层)
|
||||
function onDocDown(e) {
|
||||
if (open.value && !e.target.closest?.('.topbar')) close()
|
||||
}
|
||||
// 点了链接 → 路由变了 → 收起
|
||||
watch(() => route.fullPath, () => { open.value = false })
|
||||
// 顶栏藏没藏广播到 <html>:首页的 sticky-head(标题 + 内容切换 tabs)吸顶
|
||||
// 偏移用的是 var(--topbar-h),这里翻成 0 它就跟着顶栏一起滑上去
|
||||
watch(hidden, (v) => {
|
||||
document.documentElement.classList.toggle('topbar-hidden', v)
|
||||
})
|
||||
|
||||
// 窗口拉宽回桌面必须自己退场:v-if 是 JS 状态,CSS 媒体查询管不着它
|
||||
const mqWide = window.matchMedia('(min-width: 781px)')
|
||||
function onWide(e) { if (e.matches) open.value = false }
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('scroll', onScroll, { passive: true })
|
||||
window.addEventListener('keydown', onKey)
|
||||
document.addEventListener('pointerdown', onDocDown, true)
|
||||
mqWide.addEventListener('change', onWide)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('scroll', onScroll)
|
||||
window.removeEventListener('keydown', onKey)
|
||||
document.removeEventListener('pointerdown', onDocDown, true)
|
||||
mqWide.removeEventListener('change', onWide)
|
||||
document.documentElement.classList.remove('topbar-hidden')
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- 窄屏时左栏收起,导航回到顶部 -->
|
||||
<header class="topbar">
|
||||
<!-- 窄屏时左栏收起,导航回到顶部;下滑隐藏、上滑唤回 -->
|
||||
<header class="topbar" :class="{ hidden }">
|
||||
<RouterLink to="/" class="brand">{{ site.site_title || 'ONE' }}</RouterLink>
|
||||
<nav class="links">
|
||||
<RouterLink to="/">首页</RouterLink>
|
||||
<RouterLink to="/archive">归档</RouterLink>
|
||||
<RouterLink to="/tags">标签</RouterLink>
|
||||
<RouterLink to="/projects">作品</RouterLink>
|
||||
<RouterLink to="/about">关于</RouterLink>
|
||||
</nav>
|
||||
<NavBurger
|
||||
ref="burger"
|
||||
class="burger"
|
||||
:open="open"
|
||||
aria-controls="c-menu"
|
||||
:aria-label="open ? '关闭菜单' : '打开菜单'"
|
||||
@toggle="toggle"
|
||||
/>
|
||||
|
||||
<!-- 半透明幕布:垫在顶栏(z 20)之下、页面内容之上,点它收起 -->
|
||||
<Transition name="c-scrim">
|
||||
<div v-if="open" class="scrim" @click="close" />
|
||||
</Transition>
|
||||
|
||||
<Transition name="c-sheet">
|
||||
<div v-if="open" id="c-menu" class="sheet">
|
||||
<nav class="links" aria-label="站点导航">
|
||||
<RouterLink
|
||||
v-for="l in links"
|
||||
:key="l.to"
|
||||
:to="l.to"
|
||||
:class="{ on: isOn(l) }"
|
||||
>{{ l.label }}</RouterLink>
|
||||
</nav>
|
||||
</div>
|
||||
</Transition>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
@@ -23,16 +132,28 @@ import { site } from '../site'
|
||||
|
||||
@media (max-width: 780px) {
|
||||
.topbar {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 14px;
|
||||
/* 三列网格:brand 落在正中列居中,汉堡钉死右列;下滑整条上移隐藏 */
|
||||
display: grid;
|
||||
grid-template-columns: 44px 1fr 44px;
|
||||
align-items: center;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 20;
|
||||
padding: 10px 18px;
|
||||
padding: 9px 12px;
|
||||
background: color-mix(in srgb, var(--paper) 80%, transparent);
|
||||
backdrop-filter: blur(10px) saturate(160%);
|
||||
border-bottom: 1px solid var(--line);
|
||||
transition: transform 0.32s var(--ease, ease);
|
||||
}
|
||||
|
||||
.topbar.hidden {
|
||||
transform: translateY(-110%);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.topbar {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-transparency: reduce) {
|
||||
@@ -43,19 +164,105 @@ import { site } from '../site'
|
||||
}
|
||||
|
||||
.brand {
|
||||
grid-column: 2;
|
||||
justify-self: center;
|
||||
font-family: var(--serif);
|
||||
font-size: 17px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.burger {
|
||||
grid-column: 3;
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
/* 幕布在自己的顶栏层叠上下文里,z -1 垫在 brand / 汉堡 / 纸片下面,
|
||||
但整个上下文(z 20)仍盖过页面内容 */
|
||||
.scrim {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: -1;
|
||||
background: color-mix(in srgb, var(--ink) 24%, transparent);
|
||||
}
|
||||
|
||||
/* 浮动纸片:贴着顶栏下方悬一层,和右栏卡片同一套「纸」的语言 */
|
||||
.sheet {
|
||||
position: absolute;
|
||||
top: calc(100% + 6px);
|
||||
left: 8px;
|
||||
right: 8px;
|
||||
padding: 6px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 14px;
|
||||
background: color-mix(in srgb, var(--paper) 96%, transparent);
|
||||
backdrop-filter: blur(20px) saturate(160%);
|
||||
box-shadow: 0 18px 50px -18px rgba(28, 28, 30, 0.35);
|
||||
}
|
||||
|
||||
@media (prefers-reduced-transparency: reduce) {
|
||||
.sheet {
|
||||
background: var(--paper);
|
||||
backdrop-filter: none;
|
||||
}
|
||||
}
|
||||
|
||||
.links {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
flex-direction: column;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.links a.router-link-exact-active {
|
||||
.links a {
|
||||
display: block;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
color: var(--ink-soft);
|
||||
transition: background-color 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.links a.on {
|
||||
color: var(--accent);
|
||||
background: var(--accent-soft);
|
||||
}
|
||||
|
||||
.links a:active {
|
||||
color: var(--accent);
|
||||
background: var(--accent-soft);
|
||||
}
|
||||
|
||||
.c-sheet-enter-active {
|
||||
transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.22, 1.2, 0.36, 1);
|
||||
}
|
||||
.c-sheet-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(-8px) scale(0.98);
|
||||
}
|
||||
.c-sheet-leave-active {
|
||||
transition: opacity 0.15s ease, transform 0.15s ease;
|
||||
}
|
||||
.c-sheet-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-6px);
|
||||
}
|
||||
.c-scrim-enter-active,
|
||||
.c-scrim-leave-active {
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
.c-scrim-enter-from,
|
||||
.c-scrim-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.c-sheet-enter-active,
|
||||
.c-sheet-leave-active,
|
||||
.c-scrim-enter-active,
|
||||
.c-scrim-leave-active {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<script setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { computed, nextTick, ref } from 'vue'
|
||||
import { reader } from '../../reader'
|
||||
import { insertAtCursor, placeCursor } from '../../utils'
|
||||
import CommentMarkdown from './CommentMarkdown.vue'
|
||||
import EmojiPicker from './EmojiPicker.vue'
|
||||
import { BRANDS, PROVIDER_LABEL } from './brands'
|
||||
import { relativeDate } from '../../utils'
|
||||
|
||||
@@ -52,6 +54,27 @@ const editing = computed(() => s.editing && s.editing.id === props.c.id)
|
||||
const replyDraft = ref('')
|
||||
const editDraft = ref('')
|
||||
|
||||
// 表情 / 颜文字:回复框和编辑框各挂一个面板,插入到各自的光标处
|
||||
const replyEl = ref(null)
|
||||
const editEl = ref(null)
|
||||
const replyEmoji = ref(false)
|
||||
const editEmoji = ref(false)
|
||||
function pickReply(text) {
|
||||
const r = insertAtCursor(replyEl.value, replyDraft.value, text)
|
||||
replyDraft.value = r.value
|
||||
nextTick(() => placeCursor(replyEl.value, r.pos))
|
||||
}
|
||||
function pickEdit(text) {
|
||||
const r = insertAtCursor(editEl.value, editDraft.value, text)
|
||||
editDraft.value = r.value
|
||||
nextTick(() => placeCursor(editEl.value, r.pos))
|
||||
}
|
||||
function onCancel() {
|
||||
replyEmoji.value = false
|
||||
editEmoji.value = false
|
||||
props.api.cancel()
|
||||
}
|
||||
|
||||
function startReply() {
|
||||
replyDraft.value = ''
|
||||
props.api.startReply(props.c)
|
||||
@@ -66,13 +89,15 @@ async function onReply() {
|
||||
const ok = await props.api.submit(text, props.c)
|
||||
if (ok) {
|
||||
replyDraft.value = ''
|
||||
replyEmoji.value = false
|
||||
props.api.cancel()
|
||||
}
|
||||
}
|
||||
async function onSave() {
|
||||
const text = editDraft.value.trim()
|
||||
if (!text) return
|
||||
await props.api.saveEdit(props.c, text)
|
||||
const ok = await props.api.saveEdit(props.c, text)
|
||||
if (ok) editEmoji.value = false
|
||||
}
|
||||
async function onRemove() {
|
||||
if (!window.confirm('删掉这条评论?')) return
|
||||
@@ -132,16 +157,25 @@ function replyNameOf(r) {
|
||||
|
||||
<!-- 编辑态:把正文换成输入框 -->
|
||||
<div v-if="editing" class="cm-field cm-field-inline">
|
||||
<textarea v-model="editDraft" class="cm-input" rows="3" :maxlength="maxLen"
|
||||
<textarea ref="editEl" v-model="editDraft" class="cm-input" rows="3" :maxlength="maxLen"
|
||||
placeholder="编辑这条评论…" aria-label="编辑评论" />
|
||||
<div class="cm-bar">
|
||||
<span class="cm-bar-l" />
|
||||
<span class="cm-bar-r">
|
||||
<button type="button" class="cm-link" @click="api.cancel">取消</button>
|
||||
<button
|
||||
type="button"
|
||||
class="cm-emoji-btn"
|
||||
:class="{ on: editEmoji }"
|
||||
aria-label="插入表情"
|
||||
title="表情"
|
||||
@click="editEmoji = !editEmoji"
|
||||
>😊</button>
|
||||
<button type="button" class="cm-link" @click="onCancel">取消</button>
|
||||
<button type="button" class="cm-send" :disabled="!editDraft.trim() || s.submitting" @click="onSave">
|
||||
{{ s.submitting ? '保存中…' : '保存' }}
|
||||
</button>
|
||||
</span>
|
||||
<EmojiPicker v-if="editEmoji" @pick="pickEdit" @close="editEmoji = false" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -164,6 +198,7 @@ function replyNameOf(r) {
|
||||
<!-- 回复框 -->
|
||||
<div v-if="replying" class="cm-field cm-field-inline">
|
||||
<textarea
|
||||
ref="replyEl"
|
||||
v-model="replyDraft"
|
||||
class="cm-input"
|
||||
rows="3"
|
||||
@@ -174,11 +209,20 @@ function replyNameOf(r) {
|
||||
<div class="cm-bar">
|
||||
<span class="cm-bar-l">回应 <b>{{ name }}</b></span>
|
||||
<span class="cm-bar-r">
|
||||
<button type="button" class="cm-link" @click="api.cancel">取消</button>
|
||||
<button
|
||||
type="button"
|
||||
class="cm-emoji-btn"
|
||||
:class="{ on: replyEmoji }"
|
||||
aria-label="插入表情"
|
||||
title="表情"
|
||||
@click="replyEmoji = !replyEmoji"
|
||||
>😊</button>
|
||||
<button type="button" class="cm-link" @click="onCancel">取消</button>
|
||||
<button type="button" class="cm-send" :disabled="!replyDraft.trim() || s.submitting" @click="onReply">
|
||||
{{ s.submitting ? '发送中…' : '发送' }}
|
||||
</button>
|
||||
</span>
|
||||
<EmojiPicker v-if="replyEmoji" @pick="pickReply" @close="replyEmoji = false" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, nextTick, onMounted, ref } from 'vue'
|
||||
import { site } from '../../site'
|
||||
import { reader, loadReader, signIn, signOut } from '../../reader'
|
||||
import { readerApi } from '../../api'
|
||||
import { useComments } from '../../composables/useComments'
|
||||
import { insertAtCursor, placeCursor } from '../../utils'
|
||||
import CommentItem from './CommentItem.vue'
|
||||
import EmojiPicker from './EmojiPicker.vue'
|
||||
import { BRANDS } from './brands'
|
||||
|
||||
// 文章评论区。classic 和 vivid 共用这一份 DOM —— 两边只是 CSS 不同
|
||||
@@ -35,11 +37,21 @@ const MAX_LEN = 500
|
||||
const draft = ref('')
|
||||
const canSend = computed(() => draft.value.trim().length > 0 && !s.submitting && draft.value.length <= MAX_LEN)
|
||||
|
||||
// 表情 / 颜文字:面板挂在工具条上方,插入到光标处
|
||||
const draftEl = ref(null)
|
||||
const emojiOpen = ref(false)
|
||||
function pickEmoji(text) {
|
||||
const r = insertAtCursor(draftEl.value, draft.value, text)
|
||||
draft.value = r.value
|
||||
nextTick(() => placeCursor(draftEl.value, r.pos))
|
||||
}
|
||||
|
||||
async function onSend() {
|
||||
if (!canSend.value) return
|
||||
const ok = await submit(draft.value.trim(), s.replyTo)
|
||||
if (ok) {
|
||||
draft.value = ''
|
||||
emojiOpen.value = false
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
@@ -136,6 +148,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="cm-field">
|
||||
<textarea
|
||||
ref="draftEl"
|
||||
v-model="draft"
|
||||
class="cm-input"
|
||||
rows="3"
|
||||
@@ -149,11 +162,20 @@ onMounted(() => {
|
||||
<button type="button" class="cm-link" @click="signOut">退出</button>
|
||||
</span>
|
||||
<span class="cm-bar-r">
|
||||
<button
|
||||
type="button"
|
||||
class="cm-emoji-btn"
|
||||
:class="{ on: emojiOpen }"
|
||||
aria-label="插入表情"
|
||||
title="表情"
|
||||
@click="emojiOpen = !emojiOpen"
|
||||
>😊</button>
|
||||
<span class="cm-len" :class="{ over: draft.length > MAX_LEN }">{{ draft.length }}/{{ MAX_LEN }}</span>
|
||||
<button type="button" class="cm-send" :disabled="!canSend" @click="onSend">
|
||||
{{ s.submitting ? '发送中…' : '发送' }}
|
||||
</button>
|
||||
</span>
|
||||
<EmojiPicker v-if="emojiOpen" @pick="pickEmoji" @close="emojiOpen = false" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { EMOJI_GROUPS, KAOMOJI } from './emoji'
|
||||
|
||||
// 表情 / 颜文字选择面板。挂在输入区工具条上(宿主的 .cm-bar 要 position:relative),
|
||||
// 面板绝对定位在条上方盖住输入框。点选只往上抛 pick,插到光标还是追加由宿主定;
|
||||
// 自己负责点外面 / Esc 收起。工具条按钮本身不在面板里,outside 判定要放过它,
|
||||
// 否则「点按钮收起」会变成 pointerdown 先收、click 再开,永远关不上。
|
||||
const emit = defineEmits(['pick', 'close'])
|
||||
|
||||
const tab = ref('emoji')
|
||||
const el = ref(null)
|
||||
|
||||
function onDocDown(e) {
|
||||
if (el.value && !el.value.contains(e.target) && !e.target.closest?.('.cm-emoji-btn')) {
|
||||
emit('close')
|
||||
}
|
||||
}
|
||||
function onKey(e) {
|
||||
if (e.key === 'Escape') emit('close')
|
||||
}
|
||||
onMounted(() => {
|
||||
// 默认朝上弹;工具条离视口顶太近放不下时翻到下方(手机键盘压小视口时常见)
|
||||
const space = el.value.parentElement.getBoundingClientRect().top
|
||||
if (space < el.value.offsetHeight + 16) el.value.classList.add('is-below')
|
||||
document.addEventListener('pointerdown', onDocDown, true)
|
||||
document.addEventListener('keydown', onKey)
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('pointerdown', onDocDown, true)
|
||||
document.removeEventListener('keydown', onKey)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="el" class="cm-emoji" role="group" aria-label="插入表情或颜文字">
|
||||
<div class="cm-emoji-tabs" role="tablist" aria-label="表情类型">
|
||||
<button type="button" role="tab" :aria-selected="tab === 'emoji'" :class="{ on: tab === 'emoji' }" @click="tab = 'emoji'">表情</button>
|
||||
<button type="button" role="tab" :aria-selected="tab === 'kaomoji'" :class="{ on: tab === 'kaomoji' }" @click="tab = 'kaomoji'">颜文字</button>
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'emoji'" class="cm-emoji-grid">
|
||||
<template v-for="g in EMOJI_GROUPS" :key="g.label">
|
||||
<span class="cm-emoji-cat">{{ g.label }}</span>
|
||||
<button
|
||||
v-for="e in g.items"
|
||||
:key="e"
|
||||
type="button"
|
||||
class="cm-emoji-item"
|
||||
:aria-label="`插入 ${e}`"
|
||||
@click="emit('pick', e)"
|
||||
>{{ e }}</button>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div v-else class="cm-emoji-list">
|
||||
<button
|
||||
v-for="k in KAOMOJI"
|
||||
:key="k"
|
||||
type="button"
|
||||
class="cm-emoji-item cm-kao"
|
||||
:aria-label="`插入 ${k}`"
|
||||
@click="emit('pick', k)"
|
||||
>{{ k }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,58 @@
|
||||
// 评论表情选择的数据(仅前端用,后端只存 Markdown 文本,emoji 就是普通字符)。
|
||||
// emoji 手挑常用的一百来个,分组只是为了在面板里好找;颜文字选能打的经典款。
|
||||
// 刻意不引第三方 emoji 库:面板是静态数据 + 两列 tab,一个依赖都不值得加。
|
||||
|
||||
export const EMOJI_GROUPS = [
|
||||
{
|
||||
label: '笑脸',
|
||||
items: [
|
||||
'😀', '😃', '😄', '😁', '😆', '😅', '😂', '🤣',
|
||||
'😊', '😇', '🙂', '😉', '😍', '🥰', '😘', '😗',
|
||||
'😙', '😚', '😋', '😜', '🤪', '🤨', '🧐', '🤓'
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '心情',
|
||||
items: [
|
||||
'😎', '🥳', '😏', '😒', '😞', '😔', '😟', '😕',
|
||||
'🙁', '☹️', '😣', '😖', '😫', '😩', '🥺', '😢',
|
||||
'😭', '😤', '😠', '😡', '🤬', '😱', '😨', '😰'
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
items: [
|
||||
'🤔', '🤭', '🤫', '🤥', '😶', '😐', '😑', '😬',
|
||||
'🙄', '😯', '😦', '😧', '😮', '😲', '🥱', '😴',
|
||||
'🤤', '😪', '😵', '🤐', '🤢', '🤮', '🤧', '🤒'
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '手势',
|
||||
items: [
|
||||
'👍', '👎', '👊', '✊', '🤛', '🤜', '✌️', '🤞',
|
||||
'🤟', '🤘', '🤙', '👌', '🤌', '👈', '👉', '👆',
|
||||
'👇', '☝️', '✋', '🤚', '🖐️', '🖖', '👋', '🤝'
|
||||
]
|
||||
},
|
||||
{
|
||||
label: '其他',
|
||||
items: [
|
||||
'🙏', '💪', '👀', '🧠', '❤️', '🧡', '💛', '💚',
|
||||
'💙', '💜', '🖤', '🤍', '💯', '💢', '💥', '💫',
|
||||
'💦', '💨', '🎉', '🎊', '🎁', '🌸', '🌙', '⭐',
|
||||
'✨', '🔥', '💡', '📚', '✏️', '🎮', '🎵', '🚀'
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
// 颜文字一行一个;反斜杠记得转义
|
||||
export const KAOMOJI = [
|
||||
'(。◕‿◕。)', 'ヾ(≧▽≦*)o', '(^▽^)', '( ̄▽ ̄)', '(*^▽^*)', 'o(≧∇≦)o',
|
||||
'٩(๑❛ᴗ❛๑)۶', '✧(≖ ◡ ≖✿)', '(๑•̀ㅂ•́)و✧', '( •̀ᴗ•́ )و ̑̑', '( ¬‿¬)', '( ˘▽˘ )っ♨',
|
||||
'(´,,•ω•,,)♡', '(。•́‿•̀。)', '(๑•́ ₃ •̀๑)', '♡(˃͈ દ ˂͈ ༶ )', '(´・ω・`)', '(・ω・)',
|
||||
'¯\\_(ツ)_/¯', '┐(´д`)┌', '╮(╯▽╰)╭', '( ̄_ ̄|||)', 'o_O', '( ^_^ )',
|
||||
'(╥﹏╥)', '(ㄒoㄒ)', 'ಥ_ಥ', '(ToT)', 'QAQ', 'T_T',
|
||||
'(╯°□°)╯︵ ┻━┻', '(╬ Ò﹏Ó)', '┬─┬ ノ( ゜-゜ノ)', 'orz', '_(:з」∠)_', 'ᕕ( ᐛ )ᕗ',
|
||||
'(っ˘̩╭╮˘̩)っ', '(ง •_•)ง'
|
||||
]
|
||||
Reference in New Issue
Block a user