fix: updatge config

This commit is contained in:
熊潇 2025-03-10 15:26:46 +08:00
parent 7f82e37ea2
commit 0bc4d054d9
4 changed files with 23 additions and 10 deletions

View File

@ -5,7 +5,7 @@ import { Link2, SquareArrowOutUpRight } from 'lucide-react';
import { useConfigStore } from '@/store/config';
export const PackageManager = () => {
const { shopPackages, installedPackages, getInstalledPackages, getShopPackages, uninstallPackage, installPackage } = usePackageStore();
const { pageApi } = useConfigStore();
const { pageApi, pageStoreApi } = useConfigStore();
useEffect(() => {
getInstalledPackages();
getShopPackages();
@ -70,7 +70,7 @@ export const PackageManager = () => {
}
};
const handleOpenWindow = (pkg: Package) => {
const baseUrl = 'https://kevisual.silkyai.cn';
const baseUrl = pageStoreApi || 'https://kevisual.silkyai.cn';
const path = `/${pkg.user}/${pkg.key}`;
window.open(`${baseUrl}${path}`, '_blank');
};

View File

@ -12,6 +12,8 @@ const Enter: React.FC = () => {
if (config.pageApi) {
const pageApi = document.getElementById('pageApi') as HTMLInputElement;
pageApi.value = config.pageApi;
const loadURL = document.getElementById('loadURL') as HTMLInputElement;
loadURL.value = config.loadURL || '/web/note/';
}
}, [config]);
const createParticles = () => {
@ -47,7 +49,8 @@ const Enter: React.FC = () => {
};
const onSave = () => {
const pageApi = document.getElementById('pageApi') as HTMLInputElement;
saveConfig(pageApi.value);
const loadURL = document.getElementById('loadURL') as HTMLInputElement;
saveConfig({ pageApi: pageApi.value, loadURL: loadURL.value });
};
return (
<div className='h-full w-full p-4 pt-10'>
@ -76,6 +79,10 @@ const Enter: React.FC = () => {
<label htmlFor='pageApi'>Page Enter Api</label>
<input type='text' id='pageApi' placeholder='Enter page api configuration' />
</div>
<div className='form-group'>
<label htmlFor='loadURL'>Page Index</label>
<input type='text' id='loadURL' placeholder='首页,例如: /web/note/' />
</div>
<button type='submit' id='save-button' onClick={onSave}>
<svg

View File

@ -9,6 +9,8 @@ type ConfigStore = {
saveConfig: (config: any) => Promise<void>;
pageApi: string;
setPageApi: (pageApi: string) => void;
pageStoreApi: string;
setPageStoreApi: (pageStoreApi: string) => void;
};
export const useConfigStore = create<ConfigStore>((set) => ({
@ -20,23 +22,25 @@ export const useConfigStore = create<ConfigStore>((set) => ({
});
if (res.code === 200) {
console.log(res.data);
set({ config: res.data, pageApi: res.data?.pageApi || '' });
set({ config: res.data, pageApi: res.data?.pageApi || '', pageStoreApi: res.data?.pageStoreApi || '' });
} else {
toast.error(res.message || '获取配置失败');
}
},
pageApi: '',
setPageApi: (pageApi) => set({ pageApi }),
saveConfig: async (config) => {
console.log(config);
if (!config) {
pageStoreApi: '',
setPageStoreApi: (pageStoreApi) => set({ pageStoreApi }),
saveConfig: async ({ pageApi, loadURL }) => {
console.log(pageApi, loadURL);
if (!pageApi) {
toast.error('配置不能为空');
return;
}
const res = await client.post({
path: 'config',
key: 'set',
data: { pageApi: config },
data: { pageApi, loadURL },
});
if (res.code === 200) {
toast.success('保存配置成功');

View File

@ -38,12 +38,14 @@ export default defineConfig({
host: '0.0.0.0',
proxy: {
'/api': {
target: 'http://localhost:4005',
// target: 'http://localhost:4005',
target: 'https://kevisual.xiongxiao.me',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api'),
},
'/api/router': {
target: 'ws://localhost:4005',
// target: 'ws://localhost:4005',
target: 'wss://kevisual.xiongxiao.me',
changeOrigin: true,
ws: true,
rewriteWsOrigin: true,