generated from template/vite-react-template
	fix: updatge config
This commit is contained in:
		| @@ -5,7 +5,7 @@ import { Link2, SquareArrowOutUpRight } from 'lucide-react'; | |||||||
| import { useConfigStore } from '@/store/config'; | import { useConfigStore } from '@/store/config'; | ||||||
| export const PackageManager = () => { | export const PackageManager = () => { | ||||||
|   const { shopPackages, installedPackages, getInstalledPackages, getShopPackages, uninstallPackage, installPackage } = usePackageStore(); |   const { shopPackages, installedPackages, getInstalledPackages, getShopPackages, uninstallPackage, installPackage } = usePackageStore(); | ||||||
|   const { pageApi } = useConfigStore(); |   const { pageApi, pageStoreApi } = useConfigStore(); | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     getInstalledPackages(); |     getInstalledPackages(); | ||||||
|     getShopPackages(); |     getShopPackages(); | ||||||
| @@ -70,7 +70,7 @@ export const PackageManager = () => { | |||||||
|     } |     } | ||||||
|   }; |   }; | ||||||
|   const handleOpenWindow = (pkg: Package) => { |   const handleOpenWindow = (pkg: Package) => { | ||||||
|     const baseUrl = 'https://kevisual.silkyai.cn'; |     const baseUrl = pageStoreApi || 'https://kevisual.silkyai.cn'; | ||||||
|     const path = `/${pkg.user}/${pkg.key}`; |     const path = `/${pkg.user}/${pkg.key}`; | ||||||
|     window.open(`${baseUrl}${path}`, '_blank'); |     window.open(`${baseUrl}${path}`, '_blank'); | ||||||
|   }; |   }; | ||||||
|   | |||||||
| @@ -12,6 +12,8 @@ const Enter: React.FC = () => { | |||||||
|     if (config.pageApi) { |     if (config.pageApi) { | ||||||
|       const pageApi = document.getElementById('pageApi') as HTMLInputElement; |       const pageApi = document.getElementById('pageApi') as HTMLInputElement; | ||||||
|       pageApi.value = config.pageApi; |       pageApi.value = config.pageApi; | ||||||
|  |       const loadURL = document.getElementById('loadURL') as HTMLInputElement; | ||||||
|  |       loadURL.value = config.loadURL || '/web/note/'; | ||||||
|     } |     } | ||||||
|   }, [config]); |   }, [config]); | ||||||
|   const createParticles = () => { |   const createParticles = () => { | ||||||
| @@ -47,7 +49,8 @@ const Enter: React.FC = () => { | |||||||
|   }; |   }; | ||||||
|   const onSave = () => { |   const onSave = () => { | ||||||
|     const pageApi = document.getElementById('pageApi') as HTMLInputElement; |     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 ( |   return ( | ||||||
|     <div className='h-full w-full p-4 pt-10'> |     <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> |               <label htmlFor='pageApi'>Page Enter Api</label> | ||||||
|               <input type='text' id='pageApi' placeholder='Enter page api configuration' /> |               <input type='text' id='pageApi' placeholder='Enter page api configuration' /> | ||||||
|             </div> |             </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}> |             <button type='submit' id='save-button' onClick={onSave}> | ||||||
|               <svg |               <svg | ||||||
|   | |||||||
| @@ -9,6 +9,8 @@ type ConfigStore = { | |||||||
|   saveConfig: (config: any) => Promise<void>; |   saveConfig: (config: any) => Promise<void>; | ||||||
|   pageApi: string; |   pageApi: string; | ||||||
|   setPageApi: (pageApi: string) => void; |   setPageApi: (pageApi: string) => void; | ||||||
|  |   pageStoreApi: string; | ||||||
|  |   setPageStoreApi: (pageStoreApi: string) => void; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export const useConfigStore = create<ConfigStore>((set) => ({ | export const useConfigStore = create<ConfigStore>((set) => ({ | ||||||
| @@ -20,23 +22,25 @@ export const useConfigStore = create<ConfigStore>((set) => ({ | |||||||
|     }); |     }); | ||||||
|     if (res.code === 200) { |     if (res.code === 200) { | ||||||
|       console.log(res.data); |       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 { |     } else { | ||||||
|       toast.error(res.message || '获取配置失败'); |       toast.error(res.message || '获取配置失败'); | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   pageApi: '', |   pageApi: '', | ||||||
|   setPageApi: (pageApi) => set({ pageApi }), |   setPageApi: (pageApi) => set({ pageApi }), | ||||||
|   saveConfig: async (config) => { |   pageStoreApi: '', | ||||||
|     console.log(config); |   setPageStoreApi: (pageStoreApi) => set({ pageStoreApi }), | ||||||
|     if (!config) { |   saveConfig: async ({ pageApi, loadURL }) => { | ||||||
|  |     console.log(pageApi, loadURL); | ||||||
|  |     if (!pageApi) { | ||||||
|       toast.error('配置不能为空'); |       toast.error('配置不能为空'); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     const res = await client.post({ |     const res = await client.post({ | ||||||
|       path: 'config', |       path: 'config', | ||||||
|       key: 'set', |       key: 'set', | ||||||
|       data: { pageApi: config }, |       data: { pageApi, loadURL }, | ||||||
|     }); |     }); | ||||||
|     if (res.code === 200) { |     if (res.code === 200) { | ||||||
|       toast.success('保存配置成功'); |       toast.success('保存配置成功'); | ||||||
|   | |||||||
| @@ -38,12 +38,14 @@ export default defineConfig({ | |||||||
|     host: '0.0.0.0', |     host: '0.0.0.0', | ||||||
|     proxy: { |     proxy: { | ||||||
|       '/api': { |       '/api': { | ||||||
|         target: 'http://localhost:4005', |         // target: 'http://localhost:4005', | ||||||
|  |         target: 'https://kevisual.xiongxiao.me', | ||||||
|         changeOrigin: true, |         changeOrigin: true, | ||||||
|         rewrite: (path) => path.replace(/^\/api/, '/api'), |         rewrite: (path) => path.replace(/^\/api/, '/api'), | ||||||
|       }, |       }, | ||||||
|       '/api/router': { |       '/api/router': { | ||||||
|         target: 'ws://localhost:4005', |         // target: 'ws://localhost:4005', | ||||||
|  |         target: 'wss://kevisual.xiongxiao.me', | ||||||
|         changeOrigin: true, |         changeOrigin: true, | ||||||
|         ws: true, |         ws: true, | ||||||
|         rewriteWsOrigin: true, |         rewriteWsOrigin: true, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user