File size: 3,853 Bytes
dc649b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<script lang="ts" setup>
import { onMounted, ref } from 'vue';

import { ElMessage, ElMessageBox } from 'element-plus';

import { requestClient } from '#/api/request';

const loading = ref(false);
const tableData = ref([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(20);

async function fetchData() {
  loading.value = true;
  try {
    const data = await requestClient.get('/admin/source', {
      params: { page: page.value, page_size: pageSize.value },
    });
    tableData.value = data.list || [];
    total.value = data.total || 0;
  } finally {
    loading.value = false;
  }
}

async function handleTest(row: any) {
  try {
    const data = await requestClient.post(`/admin/source/${row.id}/test`);
    if (data.status === 'ok') {
      ElMessage.success(
        `连通成功,资源总数: ${data.total},分类数: ${data.category_count}`,
      );
    } else {
      ElMessage.error(`连接失败: ${data.error}`);
    }
  } catch {
    ElMessage.error('测试失败');
  }
}

async function handleToggleEnable(row: any) {
  try {
    const data = await requestClient.put(`/admin/source/${row.id}/enable`);
    row.is_active = data.is_active;
    ElMessage.success(data.is_active ? '已启用' : '已禁用');
  } catch {}
}

async function handleSync(row: any) {
  try {
    await ElMessageBox.confirm(
      `确认同步 ${row.name} 的每日增量数据?`,
      '触发同步',
    );
    const data = await requestClient.post('/admin/sync/trigger', undefined, {
      params: { range_type: 'daily', source_id: row.id },
    });
    ElMessage.success(
      `同步完成: 新增${data.new_vods}条,更新${data.updated_vods}条`,
    );
    fetchData();
  } catch {}
}

function handlePageChange(val: number) {
  page.value = val;
  fetchData();
}

onMounted(fetchData);
</script>

<template>
  <div class="p-4">
    <div class="mb-4 flex items-center justify-between">
      <h2 class="text-lg font-semibold">资源站管理</h2>
    </div>
    <el-table :data="tableData" border stripe v-loading="loading">
      <el-table-column label="ID" prop="id" width="60" />
      <el-table-column label="站点名称" prop="name" width="120" />
      <el-table-column label="编码" prop="code" width="80" />
      <el-table-column
        label="API地址"
        min-width="200"
        prop="base_url"
        show-overflow-tooltip
      />
      <el-table-column label="M3U8来源" prop="play_from_m3u8" width="120" />
      <el-table-column label="云播来源" prop="play_from_yun" width="120" />
      <el-table-column label="状态" width="80">
        <template #default="{ row }">
          <el-tag :type="row.is_active ? 'success' : 'info'" size="small">
            {{ row.is_active ? '启用' : '禁用' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="同步状态" prop="last_sync_status" width="100" />
      <el-table-column label="新增数" prop="last_sync_count" width="80" />
      <el-table-column fixed="right" label="操作" width="260">
        <template #default="{ row }">
          <el-button size="small" @click="handleTest(row)">测试</el-button>
          <el-button
            :type="row.is_active ? 'warning' : 'success'"
            size="small"
            @click="handleToggleEnable(row)"
          >
            {{ row.is_active ? '禁用' : '启用' }}
          </el-button>
          <el-button size="small" type="primary" @click="handleSync(row)">
            同步
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="mt-4 flex justify-end">
      <el-pagination
        :current-page="page"
        :page-size="pageSize"
        :total="total"
        layout="total, prev, pager, next"
        @current-change="handlePageChange"
      />
    </div>
  </div>
</template>