<template>
  <div>
    <div style="margin-bottom:16px">
      <p style="color:#666;font-size:13px;margin-bottom:12px">一键同步各终端配置（公众号菜单、小程序代码、PC装修等）</p>
      <el-button type="primary" @click="syncAll" :loading="syncing">🔄 全部同步</el-button>
    </div>
    <el-table :data="syncLogs" border empty-text="暂无同步记录">
      <el-table-column label="终端" prop="terminal" width="120" />
      <el-table-column label="操作" prop="action" width="160" />
      <el-table-column label="状态" width="80">
        <template #default="{row}"><el-tag :type="row.status===1?'success':'danger'" size="small">{{row.status===1?'成功':'失败'}}</el-tag></template>
      </el-table-column>
      <el-table-column label="消息" prop="message" show-overflow-tooltip />
      <el-table-column label="时间" width="160">
        <template #default="{row}">{{row.create_time||''}}</template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import request from '../../../utils/request'

const syncLogs = ref([])
const syncing = ref(false)

async function syncAll() {
  syncing.value = true
  try { await request.post('/terminal/sync-all'); ElMessage.success('同步任务已触发') } catch(e) { ElMessage.error(e.message) }
  syncing.value = false
}

onMounted(async () => {
  try { const res = await request.get('/terminal/logs'); syncLogs.value = res || [] } catch(e) {}
})
</script>
