From 60eb793299721711a71b234e66e034bb9fb1d5e8 Mon Sep 17 00:00:00 2001 From: Codex User Date: Tue, 8 Sep 2026 13:22:05 +0800 Subject: [PATCH] fix: make CMS content live and migrate to MySQL --- cms/admin/src/App.tsx | 82 +++-- cms/admin/src/style.css | 2 + cms/server/.env.example | 15 + cms/server/package-lock.json | 500 +++++++--------------------- cms/server/package.json | 4 +- cms/server/src/db.js | 394 ++++------------------ cms/server/src/export-sqlite.js | 11 + cms/server/src/import-mysql.js | 19 ++ cms/server/src/index.js | 66 ++-- cms/server/src/migrate-sqlite.js | 27 ++ cms/server/src/seed.js | 36 +- src/components/Layout/GlobalCTA.tsx | 6 + src/pages/Ameba/index.tsx | 31 +- src/pages/Home/home.css | 2 + src/pages/Home/index.tsx | 35 +- src/pages/SelfCheck/index.tsx | 38 ++- src/services/cms.ts | 12 +- 17 files changed, 455 insertions(+), 825 deletions(-) create mode 100644 cms/server/.env.example create mode 100644 cms/server/src/export-sqlite.js create mode 100644 cms/server/src/import-mysql.js create mode 100644 cms/server/src/migrate-sqlite.js diff --git a/cms/admin/src/App.tsx b/cms/admin/src/App.tsx index 955a7e8..d95f635 100644 --- a/cms/admin/src/App.tsx +++ b/cms/admin/src/App.tsx @@ -3,19 +3,20 @@ import { useState, useEffect } from 'react' const API_BASE = '' // 同域,相对路径 const SIDEBAR = [ { key: 'config', label: '1 全局配置' }, - { key: 'home', label: '2 首页模块' }, - { key: 'ameba', label: '3 阿美巴页面' }, - { key: 'evolution', label: '4 企业进化' }, - { key: 'methods', label: '5 方法与能力' }, - { key: 'services', label: '6 产品服务' }, - { key: 'cases', label: '7 案例管理' }, - { key: 'articles', label: '8 认知观察' }, - { key: 'selfcheck', label: '9 自我对照' }, - { key: 'diag_q', label: '10 诊断问卷' }, - { key: 'diag_config', label: '11 诊断配置' }, - { key: 'diag_reports', label: '12 诊断记录' }, - { key: 'diag_leads', label: '13 留资统计' }, - { key: 'contact_leads', label: '14 咨询线索' }, + { key: 'texts', label: '2 全站文案' }, + { key: 'home', label: '3 首页模块' }, + { key: 'ameba', label: '4 阿美巴页面' }, + { key: 'evolution', label: '5 企业进化' }, + { key: 'methods', label: '6 方法与能力' }, + { key: 'services', label: '7 产品服务' }, + { key: 'cases', label: '8 案例管理' }, + { key: 'articles', label: '9 认知观察' }, + { key: 'selfcheck', label: '10 自我对照' }, + { key: 'diag_q', label: '11 诊断问卷' }, + { key: 'diag_config', label: '12 诊断配置' }, + { key: 'diag_reports', label: '13 诊断记录' }, + { key: 'diag_leads', label: '14 留资统计' }, + { key: 'contact_leads', label: '15 咨询线索' }, { key: 'password', label: '⚙ 修改密码' }, ] @@ -39,6 +40,14 @@ function api(path:string, token:string, opts:RequestInit={}){ return fetch(path,{...opts, headers}).then(r=>r.json()) } +const FIELD_LABELS:Record = { + site_title:'网站标题', slogan:'网站标语', seo_title:'SEO标题', seo_desc:'SEO描述', seo_keywords:'SEO关键词', hotline:'热线电话', contact_email:'联系邮箱', contact_address:'联系地址', cta_text:'行动按钮文字', cta_link:'行动按钮链接', + brand_position:'品牌定位', mission:'使命/介绍', philosophy:'经营哲学', practice:'服务理念', steps:'步骤', scenarios:'适用场景', description:'描述', + original_state:'原始状态', goal:'目标', gap:'差距', root_cause:'根因', ameba_intervention:'阿美巴介入', evolution_path:'进化路径', actions:'行动', phased_result:'阶段性结果', continuous_iteration:'持续迭代', + guide:'引导语', questions:'问题配置', logic_text:'结果逻辑说明', next_guide:'下一步引导', +} +const fieldLabel=(key:string)=>FIELD_LABELS[key] ? `${FIELD_LABELS[key]}(${key})` : key + export default function App(){ const {token,login,logout}=useAuth() const [user,setUser]=useState('') @@ -66,6 +75,7 @@ export default function App(){

{SIDEBAR.find(s=>s.key===cur)?.label}

内容与布局解耦 · 只改内容不改架构
{cur==='config' && } + {cur==='texts' && } {cur==='home' && } {cur==='ameba' && } {cur==='evolution' && } @@ -85,6 +95,17 @@ export default function App(){ ) } +function Texts({token}:{token:string}){ + const [list,setList]=useState([]) + useEffect(()=>{api('/api/cms/texts',token).then(j=>setList(j.data||[]))},[]) + const update=(i:number,key:string,value:any)=>{const n=[...list]; n[i]={...n[i],[key]:value}; setList(n)} + const save=()=>api('/api/cms/texts',token,{method:'PUT',body:JSON.stringify(list)}).then(j=>alert(j.msg||'保存成功')) + return

全站文案

这里的内容会覆盖首页、阿美巴页和全站行动区的默认文字。保存后刷新前台即可看到。

+ {list.map((it,i)=>