Selaa lähdekoodia

chore(hooks): 添加获取字典数据和控制视图显示的函数

wangcong 3 kuukautta sitten
vanhempi
sitoutus
7ca0c6c271
2 muutettua tiedostoa jossa 44 lisäystä ja 0 poistoa
  1. 25 0
      src/hooks/dict-data.ts
  2. 19 0
      src/hooks/view-visible.ts

+ 25 - 0
src/hooks/dict-data.ts

@@ -0,0 +1,25 @@
+import { ref } from 'vue';
+
+import { getDictTypeData } from '@/api';
+
+import type { DictCode } from '@/constants';
+import type { DictValue } from '@/types';
+
+export const useDictData = (dictCode: DictCode) => {
+  const dictData = ref<DictValue[]>([]);
+
+  const getDictData = async () => {
+    const data = await getDictTypeData({
+      dictCode,
+    });
+
+    if (data.length) {
+      dictData.value = data[0].dictTypeDataList;
+    }
+  };
+
+  return {
+    dictData,
+    getDictData,
+  };
+};

+ 19 - 0
src/hooks/view-visible.ts

@@ -0,0 +1,19 @@
+import { ref } from 'vue';
+
+export const useViewVisible = () => {
+  const visible = ref(false);
+
+  const showView = () => {
+    visible.value = true;
+  };
+
+  const hideView = () => {
+    visible.value = false;
+  };
+
+  return {
+    visible,
+    showView,
+    hideView,
+  };
+};