已合并
feat: [任务]: AI策略页面的代码块复制按钮添加复制功能 #1753
Zhangjunwei创建于 5 天前
feat: [任务]: AI策略页面的代码块复制按钮添加复制功能 #1753
已合并
Pull Request已成功合入, 合并人@opengauss_bot
(感谢 Zhangjunwei 的贡献)5 天前 创建了 pull request,commit a89c9785
5 天前 关联了issue:[任务]: AI策略页面的代码块复制按钮添加复制功能
opengauss-ci-bot
5 天前 评论:
5 天前 评论:
openGauss pipeline is running. Please wait a moment...


5 天前 添加了label:sig/Infra
opengauss_bot
5 天前 评论:
5 天前 评论:
Welcome To openGauss Community
Hey @jwzmiao , thanks for your contribution to the community.
Bot Usage Manual
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.
Contact Guide
If you have any questions, please contact the SIG: Infra ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @ailoooong, @amhani, @cctvcat, @gzbang, @jwzmiao, @libiao2024, @liuyong2000139, @persimmonzzz, @zhangxubo .


此处折叠了54条消息 查看更多
5 天前 删除了label:codecheck-success
5 天前 添加了label:codecheck-running
opengauss-ci-bot
5 天前 评论:
5 天前 评论:
5 天前 添加了label:codecheck-success
5 天前 删除了label:codecheck-running
相关 Issue
resolve https://gitcode.com/opengauss/website/issues/336
需求摘要
📋 需求分析
1. 需求背景
/{zh,en}/ai-coding-assistants/)中代码块的复制按钮添加点击复制代码内容的功能2. 功能需求
核心改动:
LayoutCharter.vue中,为渲染结果里<button class="copy">元素绑定点击事件,实现复制对应代码块内容到剪贴板TheAICodingAssistant.vueL12-L31 中的复制逻辑实现验收标准:
/{zh}/ai-coding-assistants/页面,点击代码块旁的复制按钮,代码内容被复制到剪贴板/{en}/ai-coding-assistants/页面,同样可正常复制3. 已知约束
app\.vitepress\src-new\views\charter目录下的任何文件(已废弃)index.mdfrontmattercategory: charter→App.vueL45-L66 做布局映射 →LayoutCharter.vue渲染 markdown 内容,改动需在此链路下生效Change Type: feat
Decision: 为现有复制按钮新增点击复制代码内容的功能,属于前端交互功能增强,不涉及后端数据变更。
设计概览
0. 仓情概览
app/.vitepress/src-new/(别名~@/)pnpm dev/pnpm build/pnpm lint~@/i18n/;路由由 VitePress markdown 驱动 +App.vuefrontmattercategory映射布局;SEO.geo/tdks/+.geo/jsonld/rules/components.md §SSR/SSG 注意事项(window/document 只能在 onMounted 内访问)、rules/components.md §禁止事项(禁止 setup 顶层直接访问 window/document)1. 整体方案
LayoutCharter.vue的onMounted中为.code-block容器动态创建<button class="copy">并绑定点击复制逻辑;路由切换时通过watch(route.path)重新挂载按钮app/.vitepress/src-new/layouts/LayoutCharter.vue— 添加 copy 按钮创建与点击事件绑定逻辑 +.copied视觉反馈样式app/zh|en/ai-coding-assistants/index.md)、views/charter/目录(已废弃)、composables/useClipboard.ts、i18n/common/、package.json2. 数据流转
<Content />渲染 markdown → 生成.code-block > pre > codeDOM 结构onMounted遍历.charter-content-card .code-block,为每个创建<button class="copy">并 appendChild.copy→ 读取相邻<pre>的textContent→navigator.clipboard.writeText()→ 按钮添加.copied类(图标变 checkmark)+useMessagetoast → 2s 后移除.copied类3. 关键改动点
app/.vitepress/src-new/layouts/LayoutCharter.vue<Content />渲染 markdown 内容,CSS 已有.copy按钮样式(L240-269)但 DOM 中不存在<button class="copy">元素(经rg核实:markdown 中无此元素、VitePress 自定义主题未引入useCopyCode、theme/index.ts 无 copy 逻辑)onMounted中为每个.code-block创建 copy 按钮,绑定点击复制;点击后按钮图标临时变为 checkmark,2s 后恢复;路由切换后重新挂载按钮// script setup 新增 import import { useMessage } from '@opensig/opendesign'; import { useLocale } from '~@/composables/useLocale'; const message = useMessage(); const { t } = useLocale(); const setupCopyButtons = () => { const card = document.querySelector('.charter-content-card'); if (!card) return; card.querySelectorAll('.code-block').forEach((block) => { if (block.querySelector('.copy')) return; const btn = document.createElement('button'); btn.className = 'copy'; btn.addEventListener('click', () => { const code = block.querySelector('pre')?.textContent ?? ''; navigator.clipboard.writeText(code).then(() => { message.success({ content: t('common.COPY_SUCCESS') }); btn.classList.add('copied'); setTimeout(() => btn.classList.remove('copied'), 2000); }); }); block.appendChild(btn); }); }; onMounted(setupCopyButtons); // .../* global style 新增 */ .charter-content-card .copy.copied { background-image: url('~@/assets/svg-icons/icon-checkmark.svg'); }4. 边界情况
navigator.clipboard在非 HTTPS / 旧浏览器下为 undefined →writeText会 reject,需try/catch并message.danger({ content: t('common.COPY_FAILED') })<Content />重新渲染时 DOM 被替换,已创建的按钮消失 →watch(route.path, () => nextTick(setupCopyButtons))重新挂载common-en.ts中COPY_SUCCESS/COPY_FAILED当前文案为中文(与common-zh.ts一致),属于既有 i18n 缺陷,本次不改(避免扩大范围)5. 测试策略
pnpm lint、pnpm build/zh/ai-coding-assistants/和/en/ai-coding-assistants/页面所有.code-block均出现 copy 按钮6. 预览验证清单
/zh/ai-coding-assistants/页面 hover 代码块出现 copy 按钮,点击后代码复制到剪贴板/en/ai-coding-assistants/页面同样可正常复制自动化校验
当前PR是否有AI参与
__1. AI Agent平台: OpenCode
__2. AI模型: alibaba-cn/glm-5.1
__3. Prompt上下文: 你是 portal 仓资深前端开发,服务开源社区官网仓。基于 architect 通过评审的设计文档, 在 portal 本地 working copy 里直接做代码改动。
希望检视人员了解