From 053485b470419b5a451b73aec0dc03d12b7dde56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=91=B8=E9=B1=BC=E5=8E=BB?= <1780903673@qq.com> Date: Sat, 17 May 2025 18:50:30 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E2=9C=8F=EF=B8=8F=20=20=E4=BC=98?= =?UTF-8?q?=E7=A7=80=E6=A1=88=E4=BE=8B=E6=94=B9=E4=B8=BA=E5=8F=96=E7=BA=BF?= =?UTF-8?q?=E4=B8=8A=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/theme/composables/cases.ts | 53 +++++++++++++++++ docs/guide/cases.md | 68 +++------------------- 2 files changed, 60 insertions(+), 61 deletions(-) create mode 100644 docs/.vitepress/theme/composables/cases.ts diff --git a/docs/.vitepress/theme/composables/cases.ts b/docs/.vitepress/theme/composables/cases.ts new file mode 100644 index 00000000..2782c4db --- /dev/null +++ b/docs/.vitepress/theme/composables/cases.ts @@ -0,0 +1,53 @@ +import { ref, onMounted } from 'vue' +import axios from 'axios' + +export type CaseData = { + name: string + image: string + description?: string +} + +const data = ref([]) + +export function useCaseData() { + onMounted(async () => { + // 定义数据源URL列表,按优先级排序 + const urls = [ + 'https://sponsor.wot-design-uni.cn', + 'https://wot-sponsors.pages.dev' + ] + + // 尝试从多个数据源获取数据 + const fetchData = async () => { + for (const url of urls) { + try { + const path = '/cases.json' + const response = await axios.get(url + path, { + timeout: 5000 // 设置5秒超时 + }) + const data = response.data && response.data.data ? response.data.data : [] + return data.map(item => { + return { + name: item.name, + image: item.image ? url + item.image : '', + description: item.description + } + }) // 成功获取数据后直接返回 + } catch (error) { + console.warn(`Failed to fetch from ${url}`) + // 继续尝试下一个URL + } + } + return [] // 所有数据源都失败时返回空数组 + } + + data.value = await fetchData() + }) + + return { + data + } +} + + + diff --git a/docs/guide/cases.md b/docs/guide/cases.md index 8f32baad..3a38114a 100644 --- a/docs/guide/cases.md +++ b/docs/guide/cases.md @@ -5,70 +5,13 @@ Wot UI 已被很多公司和团队在生产环境使用,下面是一些优秀的案例:
- + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+