Download apps/web-naive/src/views/source/index.vue from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 9.42 kB
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/apps/web-naive/src/views/source/index.vue
- Command line
-
hf download hf://spaces/binhugg3/admin/apps/web-naive/src/views/source/index.vue
-
curl -L -o index.vue https://huggingface.co/spaces/binhugg3/admin/resolve/main/apps/web-naive/src/views/source/index.vue
9.42 kB
| <script lang="ts" setup> | |
| import { h, onMounted, ref } from 'vue'; | |
| import { Page } from '@vben/common-ui'; | |
| import { | |
| NButton, | |
| NCard, | |
| NDataTable, | |
| NForm, | |
| NFormItem, | |
| NInput, | |
| NInputNumber, | |
| NModal, | |
| NPopconfirm, | |
| NSpace, | |
| NSwitch, | |
| NTag, | |
| NText, | |
| useMessage, | |
| } from 'naive-ui'; | |
| import type { | |
| SourceCreateParams, | |
| SourceItem, | |
| SourceUpdateParams, | |
| } from '#/api'; | |
| import { | |
| createSourceApi, | |
| deleteSourceApi, | |
| getSourceListApi, | |
| testSourceApi, | |
| toggleSourceEnableApi, | |
| triggerHealthCheckApi, | |
| updateSourceApi, | |
| } from '#/api'; | |
| defineOptions({ name: 'SourceIndex' }); | |
| const message = useMessage(); | |
| // โโ ๅ่กจ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const loading = ref(false); | |
| const list = ref<SourceItem[]>([]); | |
| const total = ref(0); | |
| const page = ref(1); | |
| const pageSize = ref(20); | |
| async function fetchList() { | |
| loading.value = true; | |
| try { | |
| const res = await getSourceListApi({ page: page.value, page_size: pageSize.value }); | |
| list.value = res.list; | |
| total.value = res.total; | |
| } finally { | |
| loading.value = false; | |
| } | |
| } | |
| onMounted(fetchList); | |
| // โโ ๆฐๅข / ็ผ่พ Modal โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const modalVisible = ref(false); | |
| const modalTitle = ref('ๆฐๅข่ตๆบ็ซ'); | |
| const editingId = ref<null | number>(null); | |
| const saving = ref(false); | |
| const formDefault = (): SourceCreateParams => ({ | |
| name: '', | |
| code: '', | |
| base_url: '', | |
| site_url: '', | |
| play_from_m3u8: '', | |
| play_from_yun: '', | |
| parse_url: '', | |
| sync_interval: 60, | |
| sort_order: 0, | |
| remark: '', | |
| }); | |
| const form = ref(formDefault()); | |
| function openCreate() { | |
| editingId.value = null; | |
| form.value = formDefault(); | |
| modalTitle.value = 'ๆฐๅข่ตๆบ็ซ'; | |
| modalVisible.value = true; | |
| } | |
| function openEdit(row: SourceItem) { | |
| editingId.value = row.id; | |
| form.value = { | |
| name: row.name, | |
| code: row.code, | |
| base_url: row.base_url, | |
| site_url: row.site_url ?? '', | |
| play_from_m3u8: row.play_from_m3u8 ?? '', | |
| play_from_yun: row.play_from_yun ?? '', | |
| parse_url: row.parse_url ?? '', | |
| sync_interval: row.sync_interval, | |
| sort_order: row.sort_order, | |
| remark: row.remark ?? '', | |
| }; | |
| modalTitle.value = '็ผ่พ่ตๆบ็ซ'; | |
| modalVisible.value = true; | |
| } | |
| async function handleSave() { | |
| if (!form.value.name || !form.value.code || !form.value.base_url) { | |
| message.warning('ๅ็งฐใ็ผ็ ใAPIๅฐๅไธบๅฟ ๅกซ้กน'); | |
| return; | |
| } | |
| saving.value = true; | |
| try { | |
| if (editingId.value) { | |
| const payload: SourceUpdateParams = { ...form.value }; | |
| delete (payload as any).code; | |
| await updateSourceApi(editingId.value, payload); | |
| message.success('ๆดๆฐๆๅ'); | |
| } else { | |
| await createSourceApi(form.value); | |
| message.success('ๅๅปบๆๅ'); | |
| } | |
| modalVisible.value = false; | |
| await fetchList(); | |
| } finally { | |
| saving.value = false; | |
| } | |
| } | |
| // โโ ๅ ้ค โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| async function handleDelete(id: number) { | |
| await deleteSourceApi(id); | |
| message.success('ๅ ้คๆๅ'); | |
| await fetchList(); | |
| } | |
| // โโ ๅฏ็จ/็ฆ็จ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| async function handleToggle(row: SourceItem) { | |
| const res = await toggleSourceEnableApi(row.id); | |
| row.is_active = res.is_active; | |
| message.success(res.is_active ? 'ๅทฒๅฏ็จ' : 'ๅทฒ็ฆ็จ'); | |
| } | |
| // โโ ่ฟ้ๆงๆต่ฏ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const testingId = ref<null | number>(null); | |
| async function handleTest(row: SourceItem) { | |
| testingId.value = row.id; | |
| try { | |
| const res: any = await testSourceApi(row.id); | |
| if (res.status === 'ok') { | |
| message.success(`่ฟ้ๆๅ๏ผๅ ฑ ${res.total} ๆก๏ผ${res.category_count} ไธชๅ็ฑป`); | |
| } else { | |
| message.error(`่ฟ้ๅคฑ่ดฅ๏ผ${res.error}`); | |
| } | |
| } finally { | |
| testingId.value = null; | |
| } | |
| } | |
| // โโ ๅฅๅบทๆฃๆฅ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const healthChecking = ref(false); | |
| async function handleHealthCheck() { | |
| healthChecking.value = true; | |
| try { | |
| const res: any = await triggerHealthCheckApi(); | |
| message.success(`ๅฅๅบทๆฃๆฅๅฎๆ๏ผ${res.healthy}/${res.total} ๆญฃๅธธ`); | |
| await fetchList(); | |
| } finally { | |
| healthChecking.value = false; | |
| } | |
| } | |
| // โโ ่กจๆ ผๅ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| const columns = [ | |
| { key: 'id', title: 'ID', width: 60 }, | |
| { key: 'name', title: 'ๅ็งฐ', width: 120 }, | |
| { key: 'code', title: '็ผ็ ', width: 100 }, | |
| { | |
| key: 'base_url', | |
| title: 'APIๅฐๅ', | |
| ellipsis: { tooltip: true }, | |
| }, | |
| { | |
| key: 'is_active', | |
| title: '็ถๆ', | |
| width: 80, | |
| render: (row: SourceItem) => | |
| h(NSwitch, { | |
| value: row.is_active, | |
| onUpdateValue: () => handleToggle(row), | |
| }), | |
| }, | |
| { | |
| key: 'last_sync_status', | |
| title: 'ไธๆฌกๅๆญฅ', | |
| width: 100, | |
| render: (row: SourceItem) => { | |
| const map: Record<string, 'success' | 'error' | 'warning' | 'default'> = { | |
| success: 'success', | |
| failed: 'error', | |
| running: 'warning', | |
| }; | |
| const type = map[row.last_sync_status ?? ''] ?? 'default'; | |
| return h(NTag, { type, size: 'small' }, { default: () => row.last_sync_status ?? 'ๆชๅๆญฅ' }); | |
| }, | |
| }, | |
| { key: 'last_sync_count', title: 'ๅๆญฅๆฐ', width: 80 }, | |
| { key: 'sort_order', title: 'ๆๅบ', width: 70 }, | |
| { | |
| key: 'actions', | |
| title: 'ๆไฝ', | |
| width: 220, | |
| render: (row: SourceItem) => | |
| h(NSpace, { size: 'small' }, { | |
| default: () => [ | |
| h(NButton, { size: 'small', onClick: () => openEdit(row) }, { default: () => '็ผ่พ' }), | |
| h( | |
| NButton, | |
| { | |
| size: 'small', | |
| loading: testingId.value === row.id, | |
| onClick: () => handleTest(row), | |
| }, | |
| { default: () => 'ๆต่ฏ' }, | |
| ), | |
| h( | |
| NPopconfirm, | |
| { onPositiveClick: () => handleDelete(row.id) }, | |
| { | |
| trigger: () => | |
| h(NButton, { size: 'small', type: 'error' }, { default: () => 'ๅ ้ค' }), | |
| default: () => '็กฎ่ฎคๅ ้ค่ฏฅ่ตๆบ็ซ๏ผ', | |
| }, | |
| ), | |
| ], | |
| }), | |
| }, | |
| ]; | |
| </script> | |
| <template> | |
| <Page title="่ตๆบ็ซ็ฎก็"> | |
| <NCard> | |
| <template #header-extra> | |
| <NSpace> | |
| <NButton | |
| :loading="healthChecking" | |
| @click="handleHealthCheck" | |
| > | |
| ๅฅๅบทๆฃๆฅ | |
| </NButton> | |
| <NButton type="primary" @click="openCreate">ๆฐๅข่ตๆบ็ซ</NButton> | |
| </NSpace> | |
| </template> | |
| <NDataTable | |
| :columns="columns" | |
| :data="list" | |
| :loading="loading" | |
| :pagination="{ | |
| page, | |
| pageSize, | |
| itemCount: total, | |
| onChange: (p: number) => { page = p; fetchList(); }, | |
| }" | |
| scroll-x="900" | |
| /> | |
| </NCard> | |
| <!-- ๆฐๅข/็ผ่พ Modal --> | |
| <NModal | |
| v-model:show="modalVisible" | |
| :title="modalTitle" | |
| preset="card" | |
| style="width: 600px" | |
| > | |
| <NForm label-placement="left" label-width="100"> | |
| <NFormItem label="ๅ็งฐ" required> | |
| <NInput v-model:value="form.name" placeholder="่ตๆบ็ซๅ็งฐ" /> | |
| </NFormItem> | |
| <NFormItem label="็ผ็ " required> | |
| <NInput | |
| v-model:value="form.code" | |
| :disabled="!!editingId" | |
| placeholder="ๅฏไธๆ ่ฏ๏ผๅญๆฏ/ๆฐๅญ/ไธๅ็บฟ" | |
| /> | |
| </NFormItem> | |
| <NFormItem label="APIๅฐๅ" required> | |
| <NInput v-model:value="form.base_url" placeholder="่นๆCMS API ๆ นๅฐๅ" /> | |
| </NFormItem> | |
| <NFormItem label="็ซ็นๅฐๅ"> | |
| <NInput v-model:value="form.site_url" placeholder="ๅฏ้" /> | |
| </NFormItem> | |
| <NFormItem label="M3U8ๆฅๆบ"> | |
| <NInput v-model:value="form.play_from_m3u8" placeholder="play_from ๅญๆฎตๅผ" /> | |
| </NFormItem> | |
| <NFormItem label="ไบๆญๆฅๆบ"> | |
| <NInput v-model:value="form.play_from_yun" placeholder="play_from ๅญๆฎตๅผ" /> | |
| </NFormItem> | |
| <NFormItem label="่งฃๆๅฐๅ"> | |
| <NInput v-model:value="form.parse_url" placeholder="ๅค้พ่ง้ข่งฃๆURL" /> | |
| </NFormItem> | |
| <NFormItem label="ๅๆญฅ้ด้(ๅ)"> | |
| <NInputNumber v-model:value="form.sync_interval" :min="1" :max="10080" /> | |
| </NFormItem> | |
| <NFormItem label="ๆๅบ"> | |
| <NInputNumber v-model:value="form.sort_order" :min="0" /> | |
| </NFormItem> | |
| <NFormItem label="ๅคๆณจ"> | |
| <NInput v-model:value="form.remark" type="textarea" :rows="2" /> | |
| </NFormItem> | |
| </NForm> | |
| <template #footer> | |
| <NSpace justify="end"> | |
| <NButton @click="modalVisible = false">ๅๆถ</NButton> | |
| <NButton type="primary" :loading="saving" @click="handleSave">ไฟๅญ</NButton> | |
| </NSpace> | |
| </template> | |
| </NModal> | |
| </Page> | |
| </template> | |