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,
|
};
|
}
|