- 从cmsWebsiteField接口中删除configWebsiteField方法 - 删除useConfig自定义Hook及其引用 - 更新about页面,去除对config对象和useConfig的使用 - 修正invite模块请求URL,统一加上/api前缀
38 lines
1017 B
TypeScript
38 lines
1017 B
TypeScript
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<Config | null>(null);
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
const [error, setError] = useState<Error | null>(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 };
|
|
}; |