refactor(api): 移除未使用的配置接口及相关Hook
- 从cmsWebsiteField接口中删除configWebsiteField方法 - 删除useConfig自定义Hook及其引用 - 更新about页面,去除对config对象和useConfig的使用 - 修正invite模块请求URL,统一加上/api前缀
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import type { ApiResult, PageResult } from '@/api';
|
import type { ApiResult, PageResult } from '@/api';
|
||||||
import type {CmsWebsiteField, CmsWebsiteFieldParam, Config} from './model';
|
import type {CmsWebsiteField, CmsWebsiteFieldParam} from './model';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询应用参数
|
* 分页查询应用参数
|
||||||
@@ -112,18 +112,3 @@ export async function undeleteWebsiteField(id?: number) {
|
|||||||
}
|
}
|
||||||
return Promise.reject(new Error(res.message));
|
return Promise.reject(new Error(res.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询项目参数列表
|
|
||||||
*/
|
|
||||||
export async function configWebsiteField(params?: CmsWebsiteFieldParam) {
|
|
||||||
const res = await request.get<ApiResult<Config>>(
|
|
||||||
'/cms/cms-website-field/config',
|
|
||||||
params
|
|
||||||
);
|
|
||||||
if (res.code === 0 && res.data) {
|
|
||||||
return res.data;
|
|
||||||
}
|
|
||||||
return Promise.reject(new Error(res.message));
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
import { useEffect, useState } from 'react';
|
|
||||||
import Taro from '@tarojs/taro';
|
|
||||||
import { configWebsiteField } from '@/api/cms/cmsWebsiteField';
|
|
||||||
import { Config } from '@/api/cms/cmsWebsiteField/model';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自定义Hook用于获取和管理网站配置数据
|
|
||||||
* @returns {Object} 包含配置数据和加载状态的对象
|
|
||||||
*/
|
|
||||||
export const useConfig = () => {
|
|
||||||
const [config, setConfig] = useState<Config | null>(null);
|
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
|
||||||
const [error, setError] = useState<Error | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchConfig = async () => {
|
|
||||||
try {
|
|
||||||
setLoading(true);
|
|
||||||
const data = await configWebsiteField();
|
|
||||||
setConfig(data);
|
|
||||||
Taro.setStorageSync('config', data);
|
|
||||||
|
|
||||||
// 设置主题
|
|
||||||
if (data.theme && !Taro.getStorageSync('user_theme')) {
|
|
||||||
Taro.setStorageSync('user_theme', data.theme);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err : new Error('获取配置失败'));
|
|
||||||
console.error('获取网站配置失败:', err);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchConfig();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return { config, loading, error, refetch: () => {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
configWebsiteField().then(data => {
|
|
||||||
setConfig(data);
|
|
||||||
Taro.setStorageSync('config', data);
|
|
||||||
setLoading(false);
|
|
||||||
}).catch(err => {
|
|
||||||
setError(err instanceof Error ? err : new Error('获取配置失败'));
|
|
||||||
setLoading(false);
|
|
||||||
});
|
|
||||||
}};
|
|
||||||
};
|
|
||||||
@@ -79,11 +79,11 @@ const InvitePage: React.FC = () => {
|
|||||||
const fetchInviteInfo = async (inviteToken: string) => {
|
const fetchInviteInfo = async (inviteToken: string) => {
|
||||||
try {
|
try {
|
||||||
console.log('开始获取邀请信息, token:', inviteToken);
|
console.log('开始获取邀请信息, token:', inviteToken);
|
||||||
console.log('请求URL:', `${SERVER_API_URL}/api/_app/developer/invite/info?token=${encodeURIComponent(inviteToken)}`);
|
console.log('请求URL:', `${INVITE_API_URL}/api/developer/invite/info?token=${encodeURIComponent(inviteToken)}`);
|
||||||
console.log('请求头:', { 'content-type': 'application/json', TenantId });
|
console.log('请求头:', { 'content-type': 'application/json', TenantId });
|
||||||
|
|
||||||
const res = await Taro.request({
|
const res = await Taro.request({
|
||||||
url: `${INVITE_API_URL}/developer/invite/info?token=${encodeURIComponent(inviteToken)}`,
|
url: `${INVITE_API_URL}/api/developer/invite/info?token=${encodeURIComponent(inviteToken)}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
header: {
|
header: {
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
@@ -142,7 +142,7 @@ const InvitePage: React.FC = () => {
|
|||||||
setAuthLoading(true);
|
setAuthLoading(true);
|
||||||
|
|
||||||
const res = await Taro.request({
|
const res = await Taro.request({
|
||||||
url: `${INVITE_API_URL}/developer/invite/accept`,
|
url: `${INVITE_API_URL}/api/developer/invite/accept`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
token,
|
token,
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ import {listCmsNavigation} from "@/api/cms/cmsNavigation";
|
|||||||
import {View, RichText} from '@tarojs/components'
|
import {View, RichText} from '@tarojs/components'
|
||||||
import {listCmsDesign} from "@/api/cms/cmsDesign";
|
import {listCmsDesign} from "@/api/cms/cmsDesign";
|
||||||
import {CmsDesign} from "@/api/cms/cmsDesign/model";
|
import {CmsDesign} from "@/api/cms/cmsDesign/model";
|
||||||
import { useConfig } from "@/hooks/useConfig"; // 使用新的自定义Hook
|
|
||||||
|
|
||||||
|
|
||||||
const Helper = () => {
|
const Helper = () => {
|
||||||
const [nav, setNav] = useState<CmsNavigation>()
|
const [nav, setNav] = useState<CmsNavigation>()
|
||||||
const [design, setDesign] = useState<CmsDesign>()
|
const [design, setDesign] = useState<CmsDesign>()
|
||||||
const [category, setCategory] = useState<CmsNavigation[]>([])
|
const [category, setCategory] = useState<CmsNavigation[]>([])
|
||||||
const { config } = useConfig(); // 使用新的Hook
|
|
||||||
|
|
||||||
const reload = async () => {
|
const reload = async () => {
|
||||||
const navs = await listCmsNavigation({model: 'page', parentId: 0});
|
const navs = await listCmsNavigation({model: 'page', parentId: 0});
|
||||||
@@ -81,10 +79,7 @@ const Helper = () => {
|
|||||||
>
|
>
|
||||||
</Cell>
|
</Cell>
|
||||||
))}
|
))}
|
||||||
<Cell className={'flex flex-col'}>
|
|
||||||
<span>服务热线:{config?.tel}</span>
|
|
||||||
<span>工作日:{config?.workDay}</span>
|
|
||||||
</Cell>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user