wupengfei
5 天以前 64ff795479a7667f17c1a4349bb171f546a92a0b
packages/hooks/area.ts
@@ -4,6 +4,7 @@
import { AreaType, CategoryCode } from '@12333/constants';
import Taro, { EventChannel } from '@tarojs/taro';
import { useDictionaryDataSelect } from './dic';
import axios from 'axios';
export function useArea() {
  const queryClient = useQueryClient();
@@ -17,7 +18,7 @@
  const areaList = computed(() => dictionaryDataList.value.map(convertDictionaryToAreaTreeNode));
  const areaTree = computed(() => formatAreaListToTree(areaList.value));
  // const areaTree = computed(() => formatAreaListToTree(areaList.value));
  function getAreaFromCompleteAreaList(areaCode: string) {
    return areaList.value.find((x) => x.areaCode === areaCode);
@@ -30,20 +31,41 @@
  return {
    completeAreaList: areaList,
    areaList,
    completeAreaTree: areaTree,
    provinceList: computed(() => areaList.value.filter((x) => x.layer === AreaType.Province)),
    // completeAreaTree: areaTree,
    // provinceList: computed(() => areaList.value.filter((x) => x.layer === AreaType.Province)),
    getAreaFromCompleteAreaList,
    getAreaByAreaCode,
  };
}
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);
    },
    placeholderData: () => [] as API.AreaTreeNode[],
  });
  const areaTree = computed(() => formatAreaListToTree(data.value));
  return { areaTree: areaTree };
}
function convertDictionaryToAreaTreeNode(
  item: API.SelectOptionStringGetDictionaryDataSelectQueryResultOption
) {
  return {
    children: [],
    areaCode: item.data?.code,
    parentCode: '',
    parentCode: item.data?.parentCode,
    areaName: item.label,
    layer: Number(item.data?.field4),
    quickQuery: item.data?.field2,
@@ -78,13 +100,13 @@
  };
}
export function useProvinceList() {
  const { provinceList } = useArea();
// export function useProvinceList() {
//   const { provinceList } = useArea();
  return {
    provinceList,
  };
}
//   return {
//     provinceList,
//   };
// }
export const globalEventEmitter = new Taro.Events();