diff --git a/src/App.vue b/src/App.vue index 0efa384..8535a93 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,7 +15,13 @@ - + diff --git a/src/components/news/NewsList.vue b/src/components/news/NewsList.vue index 9693619..4bfae88 100644 --- a/src/components/news/NewsList.vue +++ b/src/components/news/NewsList.vue @@ -1,17 +1,49 @@ diff --git a/src/composables/useNews.ts b/src/composables/useNews.ts index 9ce885a..603a3b7 100644 --- a/src/composables/useNews.ts +++ b/src/composables/useNews.ts @@ -1,10 +1,9 @@ -import { ref } from 'vue' +import { onMounted, ref } from 'vue' import type { NewsItem } from '../types' import { newsMock } from '../mocks/news' - -function delay(ms = 300): Promise { - return new Promise((r) => setTimeout(r, ms)) -} +import { contractConfig } from '../config/contract' +import { getFuturesNews } from '../api/baidu/news' +import { mapBaiduNewsToItems } from '../api/baidu/mapNews' export function useNews() { const data = ref(structuredClone(newsMock)) @@ -15,14 +14,19 @@ export function useNews() { loading.value = true error.value = null try { - await delay() - data.value = structuredClone(newsMock) + const list = await getFuturesNews({ code: contractConfig.code }) + data.value = mapBaiduNewsToItems(list) } catch (e) { error.value = e + console.error('[useNews] 拉取新闻失败', e) } finally { loading.value = false } } + onMounted(() => { + void refresh() + }) + return { data, loading, error, refresh } } diff --git a/src/mocks/news.ts b/src/mocks/news.ts index 68b062b..d2dad8b 100644 --- a/src/mocks/news.ts +++ b/src/mocks/news.ts @@ -1,49 +1,4 @@ import type { NewsItem } from '../types' -export const newsMock: NewsItem[] = [ - { - id: 1, - source: 'LSEG', - time: '07-16 04:07', - title: 'Precipitate Gold appoints Pelayo Troncoso and John Wenger to the Board', - summary: - 'Precipitate Gold Corp announced the appointment of Pelayo Troncoso and John Wenger as independent directors, strengthening governance ahead of exploration milestones.', - url: 'https://example.com/news/1', - }, - { - id: 2, - source: '路透', - time: '07-16 03:42', - title: '原油短线承压,美油回落关注库存数据', - summary: - '隔夜油价震荡回落,市场等待本周库存与炼厂开工率数据,短线交易者对风险偏好趋于谨慎。', - url: 'https://example.com/news/2', - }, - { - id: 3, - source: '财联社', - time: '07-15 21:18', - title: '玻璃期货日内走弱,期现基差小幅收敛', - summary: - '盘面跟随黑色系情绪回落,现货报价相对坚挺,基差有所收窄;机构提示关注沙河地区库存变化。', - url: 'https://example.com/news/3', - }, - { - id: 4, - source: 'Bloomberg', - time: '07-15 18:05', - title: 'Gold holds near highs as markets await PPI print', - summary: - 'Bullion stayed firm as traders positioned for U.S. producer price data, with real yields and dollar moves still the key drivers.', - url: 'https://example.com/news/4', - }, - { - id: 5, - source: '新华财经', - time: '07-15 15:30', - title: '碳酸锂价格波动加剧,产业链观望情绪升温', - summary: - '下游备货节奏放缓,部分贸易商报价分歧加大,锂盐市场短期或以区间震荡为主。', - url: 'https://example.com/news/5', - }, -] +/** 首屏占位;打开页面后由百度 getfuturesnews 覆盖 */ +export const newsMock: NewsItem[] = [] diff --git a/src/types/index.ts b/src/types/index.ts index 5fc964d..8504123 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -65,11 +65,12 @@ export interface QuoteData { } export interface NewsItem { - id: number + id: string | number source: string time: string title: string - summary: string + /** 接口无摘要时可不填 */ + summary?: string url?: string }