From 54a07e948bf890af687740391b1b50a851d1da00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E9=98=B3?= <3311118881@qq.com> Date: Thu, 22 Aug 2024 15:27:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=9C=AC=E5=9C=B0=E6=B2=A1?= =?UTF-8?q?=E6=9C=89token=E5=B0=B1=E8=B7=B3=E8=BD=AC=E5=88=B0=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/RouteList/index.tsx | 8 +++++-- src/components/Sidebar/index.tsx | 7 +++--- src/pages/Setup/components/Layout/index.tsx | 25 +++++++++++++++++---- src/pages/Swiper/index.tsx | 18 +++------------ 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/components/RouteList/index.tsx b/src/components/RouteList/index.tsx index 2843f59..33b67dc 100644 --- a/src/components/RouteList/index.tsx +++ b/src/components/RouteList/index.tsx @@ -1,5 +1,6 @@ +import { useEffect, useState } from "react"; import DefaultLayout from "@/layout/DefaultLayout"; -import { Route, Routes, useLocation } from "react-router-dom"; +import { Route, Routes, useLocation, useNavigate } from "react-router-dom"; import Home from '@/pages/Dashboard'; import Create from '@/pages/Cate'; @@ -19,13 +20,13 @@ import Role from '@/pages/Role'; import PageTitle from "../PageTitle"; import Login from "@/pages/Login"; -import { useEffect, useState } from "react"; import { useUserStore } from "@/stores"; import { getRouteListAPI } from "@/api/Role"; import { Route as RouteType } from "@/types/app/route"; import NotFound from "../NotFound"; export default () => { + const navigate = useNavigate(); const store = useUserStore(); const { pathname } = useLocation(); const isLoginRoute = pathname === '/login'; @@ -57,6 +58,9 @@ export default () => { }; useEffect(() => { + // 如果没有token就跳转到登录页 + if (!store.token) return navigate("/login") + if (store.role.id) getRouteList(store.role.id) }, [store]); diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index a9dc465..ff7e492 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -1,12 +1,11 @@ import React, { useEffect, useRef, useState } from 'react'; import { NavLink, useLocation } from 'react-router-dom'; import SidebarLinkGroup from './SidebarLinkGroup'; -import { BiEditAlt, BiFolderOpen, BiHomeSmile, BiSliderAlt } from "react-icons/bi"; + +import { BiEditAlt, BiFolderOpen, BiHomeSmile, BiSliderAlt, BiShieldQuarter, BiLineChart, BiCategoryAlt, BiBug } from "react-icons/bi"; import { LuCrown } from "react-icons/lu"; -import { BiCategoryAlt, BiBug } from "react-icons/bi"; import { LiaRssSolid } from "react-icons/lia"; -import { BiLineChart } from "react-icons/bi"; -import { BiShieldQuarter } from "react-icons/bi"; + import { useUserStore } from '@/stores'; import { getRouteListAPI } from '@/api/Role' import { Route } from '@/types/app/route'; diff --git a/src/pages/Setup/components/Layout/index.tsx b/src/pages/Setup/components/Layout/index.tsx index cddefed..f42cbc0 100644 --- a/src/pages/Setup/components/Layout/index.tsx +++ b/src/pages/Setup/components/Layout/index.tsx @@ -1,13 +1,14 @@ import { useState, useEffect } from 'react'; import { notification, Divider, Input, Alert, Button, Spin } from 'antd'; -import { PictureOutlined, LoadingOutlined } from '@ant-design/icons'; +import { PictureOutlined, LoadingOutlined, CloudUploadOutlined } from '@ant-design/icons'; import { editLayoutDataAPI, getLayoutDataAPI } from '@/api/Project'; import { Layout } from '@/types/app/project'; +import FileUpload from '@/components/FileUpload'; const LayoutPage = () => { const [loading, setLoading] = useState(false); const [swiperText, setSwiperText] = useState(''); - + const [isModalOpen, setIsModalOpen] = useState(false); const [layout, setLayout] = useState({} as Layout); const onSidebar = (value: string) => { @@ -47,8 +48,13 @@ const LayoutPage = () => { return new URL(`./image/${name}.png`, import.meta.url).href } + // 文件上传 + const UploadBtn = () => ( + setIsModalOpen(true)} /> + ) + return ( -
+ <> }>

布局配置

@@ -59,6 +65,9 @@ const LayoutPage = () => { onChange={(e) => setLayout({ ...layout, swiperImage: e.target.value })} placeholder="请输入背景图地址" prefix={} + addonAfter={} + size='large' + className='customizeAntdInputAddonAfter' />
@@ -69,6 +78,7 @@ const LayoutPage = () => { value={swiperText} onChange={(e) => setSwiperText(e.target.value)} autoSize={{ minRows: 2, maxRows: 4 }} + size='large' /> @@ -101,7 +111,14 @@ const LayoutPage = () => { - + + setLayout({ ...layout, swiperImage: url })} + onCancel={() => setIsModalOpen(false)} + /> + ); }; diff --git a/src/pages/Swiper/index.tsx b/src/pages/Swiper/index.tsx index 27546a0..7d98093 100644 --- a/src/pages/Swiper/index.tsx +++ b/src/pages/Swiper/index.tsx @@ -4,7 +4,7 @@ import { getSwiperListAPI, addSwiperDataAPI, editSwiperDataAPI, delSwiperDataAPI import { Swiper } from '@/types/app/swiper'; import Title from '@/components/Title'; import { ColumnsType } from 'antd/es/table'; -import { CloudUploadOutlined } from '@ant-design/icons'; +import { CloudUploadOutlined, PictureOutlined } from '@ant-design/icons'; import FileUpload from '@/components/FileUpload'; const SwiperPage = () => { @@ -137,7 +137,7 @@ const SwiperPage = () => { - } className='customizeAntdInputAddonAfter' /> + } addonAfter={} className='customizeAntdInputAddonAfter' /> @@ -157,22 +157,10 @@ const SwiperPage = () => { - {/* setIsModelOpen(false)} - > - swiper - */} - { - form.setFieldValue("image", url) - getSwiperList() - }} + onSuccess={(url: string) => form.setFieldValue("image", url)} onCancel={() => setIsModalOpen(false)} />