yyb
9 小时以前 769fb543015f1a90d42882a0a9f0592efa45a10e
src/views/officeProcessAutomation/ApproveManage/approve-template/useSelectOptionSources.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,45 @@
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,
  };
}