import { create } from "zustand"; import { UserService } from "@/services/userService"; export interface PickerOptionState { cities: any[]; professions: any[]; ntrpLevels: any[]; getCities: () => Promise; getProfessions: () => Promise; } export const usePickerOption = create((set) => ({ cities: [], professions: [], ntrpLevels: [ { text: "1.5", value: "1.5", }, { text: "2.0", value: "2.0", }, { text: "2.5", value: "2.5", }, { text: "3.0", value: "3.0", }, { text: "3.5", value: "3.5", }, { text: "4.0", value: "4.0", }, { text: "4.5", value: "4.5", }, { text: "4.5+", value: "4.5+", }, ], getCities: async () => { try { const res = await UserService.getCities(); set({ cities: res }); return res; } catch (e) { console.log("获取城市列表失败:", e); throw e; } }, getProfessions: async () => { try { const res = await UserService.getProfessions(); set({ professions: res }); return res; } catch (e) { console.log("获取职业失败:", e); throw e; } }, })); export const useCities = () => usePickerOption((state) => state.cities); export const useProfessions = () => usePickerOption((state) => state.professions); export const useNtrpLevels = () => usePickerOption((state) => state.ntrpLevels);