<template>
  <div class="cms-page">
    <el-card shadow="never" class="tabs-card">
      <div class="cms-tabs">
        <div v-for="t in tabs" :key="t.key" class="cms-tab" :class="{active:aT===t.key}" @click="switchTab(t.key)">
          <span>{{ t.icon }}</span> {{ t.label }}
        </div>
      </div>
    </el-card>

    <!-- 文章管理 -->
    <div v-show="aT==='articles'">
      <div class="action-bar">
        <el-button type="primary" @click="openArticle()"><el-icon><Plus /></el-icon>写文章</el-button>
        <el-select v-model="artCat" placeholder="全部分类" clearable style="width:150px" @change="fetchArticles"><el-option v-for="c in cats" :key="c.id" :label="c.name" :value="c.id" /></el-select>
        <el-input v-model="artKw" placeholder="搜索标题" clearable style="width:200px" @clear="fetchArticles" @keyup.enter="fetchArticles" />
      </div>
      <el-card shadow="never">
        <el-table :data="artList" border v-loading="artLoad" style="width:100%">
          <el-table-column label="标题" min-width="260"><template #default="{row}">{{ row.title }}</template></el-table-column>
          <el-table-column label="分类" width="100" align="center"><template #default="{row}">{{ row.cat_name||'-' }}</template></el-table-column>
          <el-table-column label="作者" width="100" align="center"><template #default="{row}">{{ row.author||'admin' }}</template></el-table-column>
          <el-table-column label="浏览" width="70" align="center"><template #default="{row}">{{ row.views||0 }}</template></el-table-column>
          <el-table-column label="状态" width="80" align="center"><template #default="{row}"><el-tag :type="row.status===1?'success':'info'" size="small">{{ row.status===1?'已发布':'草稿' }}</el-tag></template></el-table-column>
          <el-table-column prop="created_at" label="发布时间" width="160" align="center" />
          <el-table-column label="操作" width="120" align="center">
            <template #default="{row}"><el-button size="small" @click="openArticle(row)">编辑</el-button><el-popconfirm title="删除？" @confirm="delArticle(row.id)"><template #reference><el-button size="small" type="danger">删除</el-button></template></el-popconfirm></template>
          </el-table-column>
        </el-table>
        <div class="pagination-wrap"><el-pagination v-model:page-size="artPS" v-model:current-page="artP" :total="artTotal" layout="total,prev,pager,next" @current-change="fetchArticles" /></div>
      </el-card>
    </div>

    <!-- 文章分类 -->
    <div v-show="aT==='cats'">
      <div class="action-bar"><el-button type="primary" @click="openCat()"><el-icon><Plus /></el-icon>新增分类</el-button></div>
      <el-card shadow="never">
        <el-table :data="cats" border style="width:600px">
          <el-table-column prop="name" label="分类名称" min-width="160"><template #default="{row}"><el-input v-if="row._edit" v-model="row.name" size="small" style="width:140px" /><span v-else>{{ row.name }}</span></template></el-table-column>
          <el-table-column prop="sort" label="排序" width="80" align="center"><template #default="{row}"><el-input-number v-if="row._edit" v-model="row.sort" :min="0" size="small" style="width:70px" /><span v-else>{{ row.sort||0 }}</span></template></el-table-column>
          <el-table-column label="操作" width="160" align="center">
            <template #default="{row,$index}">
              <el-button v-if="!row._edit" size="small" @click="row._edit=true">编辑</el-button>
              <el-button v-if="row._edit" size="small" type="primary" @click="saveCat(row)">保存</el-button>
              <el-popconfirm title="删除？" @confirm="delCat($index)"><template #reference><el-button size="small" type="danger">删除</el-button></template></el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <!-- 帮助中心 -->
    <div v-show="aT==='help'">
      <div class="action-bar"><el-button type="primary" @click="openHelp()"><el-icon><Plus /></el-icon>新增帮助</el-button></div>
      <el-card shadow="never">
        <el-table :data="helpList" border v-loading="helpLoad" style="width:100%">
          <el-table-column prop="title" label="标题" min-width="260" />
          <el-table-column prop="sort" label="排序" width="70" align="center" />
          <el-table-column label="状态" width="80" align="center"><template #default="{row}"><el-tag :type="row.status===1?'success':'info'" size="small">{{ row.status===1?'显示':'隐藏' }}</el-tag></template></el-table-column>
          <el-table-column prop="created_at" label="创建时间" width="160" align="center" />
          <el-table-column label="操作" width="120" align="center">
            <template #default="{row}"><el-button size="small" @click="openHelp(row)">编辑</el-button><el-popconfirm title="删除？" @confirm="delHelp(row.id)"><template #reference><el-button size="small" type="danger">删除</el-button></template></el-popconfirm></template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <!-- 单页管理 -->
    <div v-show="aT==='pages'">
      <div class="action-bar"><el-button type="primary" @click="openPage()"><el-icon><Plus /></el-icon>新建页面</el-button></div>
      <el-card shadow="never">
        <el-table :data="pageList" border v-loading="pageLoad" style="width:100%">
          <el-table-column prop="title" label="页面名称" min-width="180" />
          <el-table-column label="类型" width="120" align="center"><template #default="{row}"><el-tag size="small">{{ {about:'关于我们',policy:'隐私政策',service:'服务条款',custom:'自定义'}[row.type]||row.type }}</el-tag></template></el-table-column>
          <el-table-column label="状态" width="80" align="center"><template #default="{row}"><el-tag :type="row.status===1?'success':'info'" size="small">{{ row.status===1?'启用':'停用' }}</el-tag></template></el-table-column>
          <el-table-column prop="created_at" label="创建时间" width="160" align="center" />
          <el-table-column label="操作" width="120" align="center">
            <template #default="{row}"><el-button size="small" @click="openPage(row)">编辑</el-button><el-popconfirm title="删除？" @confirm="delPage(row.id)"><template #reference><el-button size="small" type="danger">删除</el-button></template></el-popconfirm></template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>

    <!-- 文章编辑弹窗 -->
    <el-dialog v-model="artVis" :title="artEdit?'编辑文章':'写文章'" width="750px" top="5vh">
      <el-form :model="artForm" label-width="80px">
        <el-form-item label="标题" required><el-input v-model="artForm.title" maxlength="100" show-word-limit /></el-form-item>
        <el-row :gutter="16">
          <el-col :span="12"><el-form-item label="分类"><el-select v-model="artForm.category_id" placeholder="选择分类" clearable style="width:100%"><el-option v-for="c in cats" :key="c.id" :label="c.name" :value="c.id" /></el-select></el-form-item></el-col>
          <el-col :span="6"><el-form-item label="作者"><el-input v-model="artForm.author" placeholder="admin" /></el-form-item></el-col>
          <el-col :span="6"><el-form-item label="排序"><el-input-number v-model="artForm.sort" :min="0" style="width:100%" /></el-form-item></el-col>
        </el-row>
        <el-form-item label="封面图">
          <el-upload :action="uploadUrl" :headers="uh" :show-file-list="false" :on-success="r=>artForm.cover=r.data.url">
            <el-image v-if="artForm.cover" :src="artForm.cover" style="width:120px;height:68px;border-radius:6px" />
            <el-button v-else size="small">上传封面</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="摘要"><el-input v-model="artForm.summary" type="textarea" :rows="2" maxlength="200" show-word-limit /></el-form-item>
        <el-form-item label="正文"><el-input v-model="artForm.content" type="textarea" :rows="14" placeholder="支持HTML格式" /></el-form-item>
        <el-form-item label="状态"><el-switch v-model="artForm.status" :active-value="1" :inactive-value="0" active-text="发布" inactive-text="草稿" /></el-form-item>
      </el-form>
      <template #footer><el-button @click="artVis=false">取消</el-button><el-button type="primary" @click="saveArticle">保存</el-button></template>
    </el-dialog>

    <!-- 帮助弹窗 -->
    <el-dialog v-model="helpVis" :title="helpEdit?'编辑帮助':'新增帮助'" width="650px">
      <el-form :model="helpForm" label-width="80px">
        <el-form-item label="标题" required><el-input v-model="helpForm.title" maxlength="100" /></el-form-item>
        <el-form-item label="分类"><el-input v-model="helpForm.category" placeholder="如：购物指南、退换政策" style="width:300px" /></el-form-item>
        <el-row :gutter="16">
          <el-col :span="12"><el-form-item label="排序"><el-input-number v-model="helpForm.sort" :min="0" style="width:100%" /></el-form-item></el-col>
          <el-col :span="12"><el-form-item label="显示"><el-switch v-model="helpForm.status" :active-value="1" :inactive-value="0" /></el-form-item></el-col>
        </el-row>
        <el-form-item label="内容"><el-input v-model="helpForm.content" type="textarea" :rows="8" placeholder="支持HTML格式" /></el-form-item>
      </el-form>
      <template #footer><el-button @click="helpVis=false">取消</el-button><el-button type="primary" @click="saveHelp">保存</el-button></template>
    </el-dialog>

    <!-- 单页弹窗 -->
    <el-dialog v-model="pageVis" :title="pageEdit?'编辑页面':'新建页面'" width="650px">
      <el-form :model="pageForm" label-width="80px">
        <el-form-item label="标题" required><el-input v-model="pageForm.title" maxlength="50" /></el-form-item>
        <el-form-item label="类型"><el-select v-model="pageForm.type" style="width:200px"><el-option label="关于我们" value="about" /><el-option label="隐私政策" value="policy" /><el-option label="服务条款" value="service" /><el-option label="自定义" value="custom" /></el-select></el-form-item>
        <el-form-item label="状态"><el-switch v-model="pageForm.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" /></el-form-item>
        <el-form-item label="内容"><el-input v-model="pageForm.content" type="textarea" :rows="12" placeholder="支持HTML格式" /></el-form-item>
      </el-form>
      <template #footer><el-button @click="pageVis=false">取消</el-button><el-button type="primary" @click="savePage">保存</el-button></template>
    </el-dialog>

    <!-- 分类弹窗 -->
    <el-dialog v-model="catVis" title="新增分类" width="400px">
      <el-form :model="catForm" label-width="80px">
        <el-form-item label="名称"><el-input v-model="catForm.name" /></el-form-item>
        <el-form-item label="排序"><el-input-number v-model="catForm.sort" :min="0" style="width:100%" /></el-form-item>
      </el-form>
      <template #footer><el-button @click="catVis=false">取消</el-button><el-button type="primary" @click="saveCatNew">保存</el-button></template>
    </el-dialog>
  </div>
    <!-- SEO 文章生成器 -->
    <div v-show="aT==='seo'">
      <el-alert type="info" :closable="false" show-icon style="margin-bottom:12px" title="自动SEO文章生成器：每天固定时间从商品规格/标题/描述提取数值，结合 SEO 关键词与用户搜索长尾词，按多种模式生成去AI化文章存入草稿箱，审核后发布获客。" />
      <el-card shadow="never" style="margin-bottom:12px">
        <el-row :gutter="12" align="middle">
          <el-col :span="4"><b>AI 对接状态</b></el-col>
          <el-col :span="10"><el-tag :type="seoCfg.ai_configured?'success':'warning'">{{ seoCfg.ai_configured?'已配置 AI API Key':'未配置 API Key' }}</el-tag><span v-if="seoCfg.ai_model" style="margin-left:10px;color:#909399">模型: {{ seoCfg.ai_model }}</span></el-col>
          <el-col :span="10"><span style="color:#909399">未配置时请先到「AI配置」填写自己的智能体 API Key</span></el-col>
        </el-row>
      </el-card>
      <el-card shadow="never" style="margin-bottom:12px">
        <template #header><div style="display:flex;justify-content:space-between;align-items:center"><b>📝 生成任务</b><el-button type="primary" size="small" @click="seoOpenTask()"><el-icon><Plus /></el-icon>新建任务</el-button></div></template>
        <el-table :data="seoTasks" border v-loading="seoLoad" style="width:100%">
          <el-table-column prop="name" label="任务名称" min-width="140" />
          <el-table-column label="启用" width="70" align="center"><template #default="{row}"><el-switch v-model="row.enabled" :active-value="1" :inactive-value="0" @change="seoSaveTask(row)" /></template></el-table-column>
          <el-table-column prop="generate_time" label="每日时间" width="90" align="center" />
          <el-table-column prop="daily_count" label="每日篇数" width="80" align="center" />
          <el-table-column label="生成模式" width="110" align="center"><template #default="{row}">{{ {spec:'规格解析',qa:'问答对话',scene:'场景种草',compare:'对比分析',random:'随机混用'}[row.mode]||row.mode }}</template></el-table-column>
          <el-table-column label="关键词来源" width="100" align="center"><template #default="{row}">{{ {combo:'商品+长尾',product:'仅商品词',search:'仅搜索词'}[row.keyword_source]||'-' }}</template></el-table-column>
          <el-table-column label="结果" width="80" align="center"><template #default="{row}"><el-tag :type="row.article_status===1?'success':'info'" size="small">{{ row.article_status===1?'直接发布':'草稿' }}</el-tag></template></el-table-column>
          <el-table-column prop="last_run_date" label="最近生成" width="100" align="center"><template #default="{row}">{{ row.last_run_date||'-' }}</template></el-table-column>
          <el-table-column label="操作" width="210" align="center"><template #default="{row}"><el-button size="small" @click="seoOpenTask(row)">编辑</el-button><el-button size="small" type="primary" @click="seoRunTask(row)">立即生成</el-button><el-popconfirm title="删除任务？" @confirm="seoDelTask(row.id)"><template #reference><el-button size="small" type="danger">删除</el-button></template></el-popconfirm></template></el-table-column>
        </el-table>
      </el-card>
      <el-row :gutter="12">
        <el-col :span="12"><el-card shadow="never"><template #header><b>🔍 用户搜索词（长尾词来源）</b></template><el-table :data="seoKeywords" border size="small" max-height="300" style="width:100%"><el-table-column prop="keyword" label="搜索词" min-width="160" /><el-table-column prop="count" label="次数" width="80" align="center" /><el-table-column prop="last_seen" label="最近" width="110" align="center" /><el-table-column label="操作" width="70" align="center"><template #default="{row}"><el-button size="small" type="danger" link @click="seoDelKw(row.id)">删</el-button></template></el-table-column></el-table><div v-if="!seoKeywords.length" style="text-align:center;color:#909399;padding:20px">暂无搜索记录，用户在本商城搜索后会在此累积</div></el-card></el-col>
        <el-col :span="12"><el-card shadow="never"><template #header><b>🪵 生成日志</b></template><el-table :data="seoLogs" border size="small" max-height="300" style="width:100%"><el-table-column prop="gen_date" label="日期" width="90" align="center" /><el-table-column label="模式" width="90" align="center"><template #default="{row}">{{ {spec:'规格',qa:'问答',scene:'场景',compare:'对比'}[row.mode]||row.mode||'-' }}</template></el-table-column><el-table-column prop="title" label="标题" min-width="150"><template #default="{row}">{{ row.title || (row.status==='skip'?'(跳过:已生成)':'') }}</template></el-table-column><el-table-column label="状态" width="80" align="center"><template #default="{row}"><el-tag :type="{success:'success',error:'danger',skip:'info'}[row.status]" size="small">{{ {success:'成功',error:'失败',skip:'跳过'}[row.status]||row.status }}</el-tag></template></el-table-column></el-table></el-card></el-col>
      </el-row>
    </div>

</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import axios from 'axios'

const API = axios.create({ baseURL: '/api/admin' })
API.interceptors.request.use(c => { c.headers.Authorization = 'Bearer ' + localStorage.getItem('admin_token'); return c })
const uploadUrl = '/api/admin/upload/image'
const uh = { Authorization: 'Bearer ' + localStorage.getItem('admin_token') }

const tabs = [
  { key:'articles', icon:'📰', label:'文章管理' },
  { key:'cats', icon:'📁', label:'文章分类' },
  { key:'help', icon:'❓', label:'帮助中心' },
  { key:'pages', icon:'📄', label:'单页管理' },
  { key:'seo', icon:'🤖', label:'SEO文章生成' },
]
const aT = ref('articles')
function switchTab(k) { aT.value=k; if(k==='articles')fetchArticles(); else if(k==='cats')fetchCats(); else if(k==='help')fetchHelp(); else if(k==='pages')fetchPages(); else if(k==='seo')loadSeo() }

// ===== 文章 =====
const artList=ref([]); const artLoad=ref(false); const artP=ref(1); const artPS=ref(10); const artTotal=ref(0)
const artCat=ref(''); const artKw=ref('')
const cats=ref([]); const artVis=ref(false); const artEdit=ref(null)
const artForm=reactive({title:'',category_id:null,author:'',sort:0,cover:'',summary:'',content:'',status:1})

async function fetchArticles() {
  artLoad.value=true
  try { const r=await API.get('/articles',{params:{page:artP.value,pageSize:artPS.value,category_id:artCat.value||undefined,keyword:artKw.value||undefined}}); artList.value=r.data.data?.list||[]; artTotal.value=r.data.data?.total||0 }
  catch{artList.value=[];artTotal.value=0}finally{artLoad.value=false}
}
async function fetchCats() { try{const r=await API.get('/article-categories'); cats.value=(r.data.data||[]).map(c=>({...c,_edit:false}))}catch{} }
function openArticle(row) {
  artEdit.value=row?.id||null
  if(row) Object.assign(artForm,{title:row.title,category_id:row.category_id,author:row.author,sort:row.sort,cover:row.cover,summary:row.summary,content:row.content,status:row.status})
  else Object.assign(artForm,{title:'',category_id:null,author:'admin',sort:0,cover:'',summary:'',content:'',status:1})
  artVis.value=true
}
async function saveArticle() {
  if(!artForm.title) return ElMessage.warning('请填写标题')
  try {
    if(artEdit.value) await API.put('/articles/'+artEdit.value, artForm)
    else await API.post('/articles', artForm)
    ElMessage.success('保存成功'); artVis.value=false; fetchArticles()
  } catch{ElMessage.error('保存失败')}
}
async function delArticle(id) { try{await API.delete('/articles/'+id);ElMessage.success('已删除');fetchArticles()}catch{} }

// ===== 分类弹窗新增 =====
const catVis=ref(false); const catForm=reactive({name:'',sort:0})
function openCat(){catForm.name='';catForm.sort=0;catVis.value=true}
async function saveCatNew() {
  if(!catForm.name) return ElMessage.warning('请填写名称')
  try{await API.post('/article-categories',catForm);ElMessage.success('保存成功');catVis.value=false;fetchCats()}catch{ElMessage.error('保存失败')}
}
async function saveCat(row) {
  try{await API.put('/article-categories/'+row.id,{name:row.name,sort:row.sort});row._edit=false;ElMessage.success('保存成功')}catch{ElMessage.error('保存失败')}
}
async function delCat(i) { const c=cats.value[i]; try{if(c.id)await API.delete('/article-categories/'+c.id);cats.value.splice(i,1);ElMessage.success('已删除')}catch{} }

// ===== 帮助 =====
const helpList=ref([]); const helpLoad=ref(false); const helpVis=ref(false); const helpEdit=ref(null)
const helpForm=reactive({title:'',category:'',sort:0,content:'',status:1})
async function fetchHelp() { try{const r=await API.get('/helps');helpList.value=r.data.data||[]}catch{helpList.value=[]}finally{helpLoad.value=false} }
function openHelp(row) {
  helpEdit.value=row?.id||null
  if(row) Object.assign(helpForm,{title:row.title,category:row.category,sort:row.sort,content:row.content,status:row.status})
  else Object.assign(helpForm,{title:'',category:'帮助中心',sort:0,content:'',status:1})
  helpVis.value=true
}
async function saveHelp() {
  if(!helpForm.title) return ElMessage.warning('请填写标题')
  try{if(helpEdit.value) await API.put('/helps/'+helpEdit.value,helpForm);else await API.post('/helps',helpForm);ElMessage.success('保存成功');helpVis.value=false;fetchHelp()}catch{ElMessage.error('保存失败')}
}
async function delHelp(id) { try{await API.delete('/helps/'+id);ElMessage.success('已删除');fetchHelp()}catch{} }

// ===== 单页 =====
const pageList=ref([]); const pageLoad=ref(false); const pageVis=ref(false); const pageEdit=ref(null)
const pageForm=reactive({title:'',type:'custom',content:'',status:1})
async function fetchPages() { try{const r=await API.get('/pages');pageList.value=r.data.data||[]}catch{pageList.value=[]}finally{pageLoad.value=false} }
function openPage(row) {
  pageEdit.value=row?.id||null
  if(row) Object.assign(pageForm,{title:row.title,type:row.type,content:row.content,status:row.status})
  else Object.assign(pageForm,{title:'',type:'custom',content:'',status:1})
  pageVis.value=true
}
async function savePage() {
  if(!pageForm.title) return ElMessage.warning('请填写标题')
  try{if(pageEdit.value) await API.put('/pages/'+pageEdit.value,pageForm);else await API.post('/pages',pageForm);ElMessage.success('保存成功');pageVis.value=false;fetchPages()}catch{ElMessage.error('保存失败')}
}
async function delPage(id) { try{await API.delete('/pages/'+id);ElMessage.success('已删除');fetchPages()}catch{} }

onMounted(()=>{fetchArticles();fetchCats();fetchPages();loadSeo()})

// ===== SEO 文章生成器 =====
const seoCfg = ref({ ai_configured:false, ai_model:'' })
const seoTasks = ref([]); const seoLoad = ref(false)
const seoKeywords = ref([]); const seoLogs = ref([])
const seoTaskVis = ref(false); const seoTaskEdit = ref(null)
const seoTaskForm = reactive({ name:'', enabled:1, generate_time:'06:30', daily_count:1, mode:'random', category_id:0, max_price:0, keyword_source:'combo', article_status:0 })

async function loadSeo() {
  seoLoad.value = true
  try {
    const [cfg, tasks, kw, logs, catsR] = await Promise.all([
      API.get('/seo/config'), API.get('/seo/tasks'), API.get('/seo/keywords'), API.get('/seo/logs'), API.get('/seo/categories')
    ])
    seoCfg.value = cfg.data.data||{}
    seoTasks.value = tasks.data.data||[]
    seoKeywords.value = kw.data.data||[]
    seoLogs.value = logs.data.data||[]
    seoCatOptions.value = (catsR.data.data||[]).map(c=>c)
  } catch(e) { /* 若某接口失败忽略 */ }
  finally { seoLoad.value = false }
}
const seoCatOptions = ref([])

function seoOpenTask(row) {
  seoTaskEdit.value = row?.id || null
  if(row) Object.assign(seoTaskForm,{ name:row.name, enabled:row.enabled, generate_time:row.generate_time, daily_count:row.daily_count, mode:row.mode, category_id:row.category_id, max_price:row.max_price, keyword_source:row.keyword_source, article_status:row.article_status })
  else Object.assign(seoTaskForm,{ name:'', enabled:1, generate_time:'06:30', daily_count:1, mode:'random', category_id:0, max_price:0, keyword_source:'combo', article_status:0 })
  seoTaskVis.value = true
}
async function seoSaveTask(row) {
  try {
    if(row && row.id) await API.put('/seo/tasks/'+row.id, { ...row, daily_count:Number(row.daily_count)||1 })
    else ElMessage.warning('请使用「编辑」保存任务')
  } catch(e){ ElMessage.error('保存失败') }
}
async function seoSubmitTask() {
  if(!seoTaskForm.name.trim()) return ElMessage.warning('请填写任务名称')
  try {
    const body = { ...seoTaskForm, daily_count:Number(seoTaskForm.daily_count)||1, max_price:Number(seoTaskForm.max_price)||0, category_id:Number(seoTaskForm.category_id)||0 }
    if(seoTaskEdit.value) await API.put('/seo/tasks/'+seoTaskEdit.value, body)
    else await API.post('/seo/tasks', body)
    ElMessage.success('保存成功'); seoTaskVis.value=false; loadSeo()
  } catch(e){ ElMessage.error('保存失败') }
}
async function seoDelTask(id) {
  try { await API.delete('/seo/tasks/'+id); ElMessage.success('已删除'); loadSeo() } catch(e){ ElMessage.error('删除失败') }
}
async function seoRunTask(row) {
  try {
    ElMessage.info('正在生成，请稍候（需配置 AI Key）…')
    const r = await API.post('/seo/tasks/'+row.id+'/run')
    ElMessage.success(r.data.message || '完成'); loadSeo()
  } catch(e){ ElMessage.error(e.response?.data?.message || '生成失败') }
}
async function seoDelKw(id) {
  try { await API.delete('/seo/keywords/'+id); ElMessage.success('已删除'); loadSeo() } catch(e){}
}
</script>

<style scoped>
.cms-page { max-width: 1400px; }
.tabs-card { margin-bottom:16px; padding:4px 0; }
.cms-tabs { display:flex; gap:4px; }
.cms-tab { display:flex; align-items:center; gap:6px; padding:10px 18px; border-radius:8px; cursor:pointer; font-size:14px; transition:all .2s; }
.cms-tab:hover { background:#f5f7fa; }
.cms-tab.active { background:#ecf5ff; color:#409eff; font-weight:600; }
.action-bar { display:flex; gap:8px; margin-bottom:16px; flex-wrap:wrap; }
.pagination-wrap { display:flex; justify-content:flex-end; padding:16px 0 0; }
</style>
