From 9e975eee3ebe9cc133435ca3fb2dbf8458efc748 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 11 八月 2025 18:10:11 +0800
Subject: [PATCH] fix: 修改登录

---
 packages/hooks/area.ts |   51 ++++++++++++++++++++++++---------------------------
 1 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/packages/hooks/area.ts b/packages/hooks/area.ts
index 684ce2c..7cca58c 100644
--- a/packages/hooks/area.ts
+++ b/packages/hooks/area.ts
@@ -1,6 +1,6 @@
 import { flattenAreaTree, formatAreaListToTree } from '@12333/utils';
 import { useQuery, useQueryClient } from '@tanstack/vue-query';
-import { computed, onMounted, onUnmounted, ref } from 'vue';
+import { computed, MaybeRef, onMounted, onUnmounted, ref, unref } from 'vue';
 import { AreaType, CategoryCode } from '@12333/constants';
 import Taro, { EventChannel } from '@tarojs/taro';
 import { useDictionaryDataSelect } from './dic';
@@ -9,16 +9,9 @@
 export function useArea() {
   const queryClient = useQueryClient();
 
-  const { dictionaryDataList } = useDictionaryDataSelect({
-    categoryCode: CategoryCode.Area,
-    staleTime: Infinity,
-    all: true,
-    maxDeep: AreaType.Area,
-  });
+  const { areaList } = useAllAreaList();
 
-  const areaList = computed(() => dictionaryDataList.value.map(convertDictionaryToAreaTreeNode));
-
-  // const areaTree = computed(() => formatAreaListToTree(areaList.value));
+  // const areaList = computed(() => dictionaryDataList.value.map(convertDictionaryToAreaTreeNode));
 
   function getAreaFromCompleteAreaList(areaCode: string) {
     return areaList.value.find((x) => x.areaCode === areaCode);
@@ -38,24 +31,16 @@
   };
 }
 
-export function useAreaTree() {
-  axios.get('https://parkmanagement.oss-cn-hangzhou.aliyuncs.com/12333/area.txt').then((res) => {
-    console.log(res);
-  });
-  const { data } = useQuery({
-    queryKey: ['area.txt'],
-    queryFn() {
-      return axios
-        .get<API.AreaTreeNode[]>(
-          'https://parkmanagement.oss-cn-hangzhou.aliyuncs.com/12333/area.txt'
-        )
-        .then((res) => res.data);
-    },
+type UseAreaTreeOptions = {
+  maxLayer?: MaybeRef<AreaType>;
+};
 
-    placeholderData: () => [] as API.AreaTreeNode[],
-  });
+export function useAreaTree(options = {} as UseAreaTreeOptions) {
+  const { maxLayer = AreaType.Area } = options;
 
-  const areaTree = computed(() => formatAreaListToTree(data.value));
+  const { areaList } = useAllAreaList();
+
+  const areaTree = computed(() => formatAreaListToTree(areaList.value, null, unref(maxLayer)));
 
   return { areaTree: areaTree };
 }
@@ -75,7 +60,19 @@
 }
 
 export function useAllAreaList() {
-  const { areaList } = useArea();
+  const { data: areaList } = useQuery({
+    queryKey: ['area.txt'],
+    queryFn() {
+      return axios
+        .get<API.AreaTreeNode[]>(
+          'https://parkmanagement.oss-cn-hangzhou.aliyuncs.com/12333/area.txt'
+        )
+        .then((res) => res.data);
+    },
+
+    placeholderData: () => [] as API.AreaTreeNode[],
+    staleTime: Infinity,
+  });
 
   const findAreaCodeFromName = (areaName: string) => {
     const areaItem = areaList.value.find((x) => x.areaName === areaName);

--
Gitblit v1.9.1