| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import { reactive, ref } from "vue"; |
| | | import { |
| | | collectOptionSourcesFromFields, |
| | | fetchSelectOptionCaches, |
| | | resolveFieldSelectOptions, |
| | | resolveSelectDisplayLabel, |
| | | } from "./selectOptionSource.js"; |
| | | |
| | | /** 䏿卿é项ï¼äººå / é¨é¨ç¼åä¸è§£æ */ |
| | | export function useSelectOptionSources() { |
| | | const loading = ref(false); |
| | | const caches = reactive({ |
| | | users: [], |
| | | deptOptions: [], |
| | | }); |
| | | |
| | | async function ensureForFields(fields) { |
| | | const sources = collectOptionSourcesFromFields(fields); |
| | | if (!sources.length) return; |
| | | loading.value = true; |
| | | try { |
| | | const next = await fetchSelectOptionCaches(sources); |
| | | caches.users = next.users; |
| | | caches.deptOptions = next.deptOptions; |
| | | } finally { |
| | | loading.value = false; |
| | | } |
| | | } |
| | | |
| | | function getOptions(field) { |
| | | return resolveFieldSelectOptions(field, caches); |
| | | } |
| | | |
| | | function getDisplayLabel(field, val) { |
| | | return resolveSelectDisplayLabel(field, val, caches); |
| | | } |
| | | |
| | | return { |
| | | loading, |
| | | caches, |
| | | ensureForFields, |
| | | getOptions, |
| | | getDisplayLabel, |
| | | }; |
| | | } |