diff --git a/.workbuddy/expert-history.json b/.workbuddy/expert-history.json new file mode 100644 index 0000000..af0c8c5 --- /dev/null +++ b/.workbuddy/expert-history.json @@ -0,0 +1,17 @@ +{ + "version": 2, + "sessions": { + "22fe5580026e4f249cf9bb33390baa6a": [ + { + "expertId": "SeniorDeveloper", + "name": "Will", + "profession": "高级开发工程师", + "avatarUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/avatars/02-Engineering/SeniorDeveloper/SeniorDeveloper.png", + "promptUrl": "https://acc-1258344699.cos.accelerate.myqcloud.com/workbuddy/experts/experts/02-Engineering/SeniorDeveloper/SeniorDeveloper_zh.md", + "usedAt": 1775908159660, + "industryId": "all" + } + ] + }, + "lastUpdated": 1775908297489 +} \ No newline at end of file diff --git a/src/hooks/useConfig.ts b/src/hooks/useConfig.ts new file mode 100644 index 0000000..83cd67c --- /dev/null +++ b/src/hooks/useConfig.ts @@ -0,0 +1,38 @@ +import { useEffect, useState } from 'react'; +import Taro from '@tarojs/taro'; + +// Config 类型定义 +interface Config { + tel?: string; + workDay?: string; + theme?: string; + [key: string]: any; +} + +/** + * 自定义Hook用于获取和管理网站配置数据 + * @returns {Object} 包含配置数据和加载状态的对象 + */ +export const useConfig = () => { + const [config, setConfig] = useState(null); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + useEffect(() => { + // 从本地存储读取配置 + const storedConfig = Taro.getStorageSync('config'); + if (storedConfig) { + setConfig(storedConfig); + } + }, []); + + const refetch = () => { + // 不再调用接口,仅返回本地存储的配置 + const storedConfig = Taro.getStorageSync('config') || {}; + setConfig(storedConfig); + setLoading(false); + return Promise.resolve(storedConfig); + }; + + return { config, loading, error, refetch }; +}; \ No newline at end of file