Quellcode durchsuchen

feat(stores): 添加渠道列表数据源

- 新增 channel store用于管理渠道列表数据
- 实现了获取渠道列表的功能,包括数据加载状态管理
- 使用 Pinia 和 Vue 的 ref 功能创建响应式数据
wui vor 6 Monaten
Ursprung
Commit
784c93e8fd
1 geänderte Dateien mit 28 neuen und 0 gelöschten Zeilen
  1. 28 0
      src/stores/channel.js

+ 28 - 0
src/stores/channel.js

@@ -0,0 +1,28 @@
+import { defineStore } from 'pinia'
+import { ref } from 'vue'
+import { http } from '@/plugins/http'
+
+export const useChannelStore = defineStore('channel', () => {
+    const channelOptions = ref([])
+    const loading = ref(false)
+
+    async function fetchChannelOptions() {
+        if (channelOptions.value.length > 0) return
+        
+        loading.value = true
+        try {
+            const response = await http.post('/ocrChannel/names')
+            channelOptions.value = response.data || []
+        } catch (error) {
+            console.error('获取渠道列表失败:', error)
+        } finally {
+            loading.value = false
+        }
+    }
+
+    return {
+        channelOptions,
+        loading,
+        fetchChannelOptions
+    }
+})