From 5fe8fc788f32602630f6a5cc39861d4b1f144459 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Sun, 24 Nov 2019 13:51:24 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E8=B7=AF=E5=BE=84=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/FileManager/Navigator.js | 20 +++++++++++--------- src/component/Login/LoginForm.js | 6 +++--- src/middleware/Api.js | 2 +- src/middleware/Init.js | 8 +++++++- src/untils/index.js | 8 +++++++- src/untils/page.js | 4 ++-- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/component/FileManager/Navigator.js b/src/component/FileManager/Navigator.js index 11350b2..30d389c 100644 --- a/src/component/FileManager/Navigator.js +++ b/src/component/FileManager/Navigator.js @@ -26,8 +26,8 @@ import { openCreateFolderDialog, openShareDialog, } from "../../actions/index" -import axios from 'axios' -import {setCookie,setGetParameter} from "../../untils/index" +import API from '../../middleware/Api' +import {setCookie,setGetParameter,fixUrlHash} from "../../untils/index" import { withStyles, @@ -157,11 +157,13 @@ class NavigatorCompoment extends Component { super(props); this.element = React.createRef(); } + componentDidMount = ()=>{ this.renderPath(); + // 后退操作时重新导航 window.onpopstate = (event)=>{ - var url = new URL(window.location.href); + var url = new URL(fixUrlHash(window.location.href)); var c = url.searchParams.get("path"); if(c!==null&&c!==this.props.path){ this.props.navigateToPath(c); @@ -174,15 +176,15 @@ class NavigatorCompoment extends Component { folders:path!==null?path.substr(1).split("/"):this.props.path.substr(1).split("/"), }); var newPath = path!==null?path:this.props.path; - // var apiURL = this.keywords===null?window.apiURL.listFile:'/File/SearchFile'; - var apiURL = '/File/SearchFile'; + var apiURL = this.keywords===null?'/directory':'/File/SearchFile'; newPath = this.keywords===null?newPath:this.keywords; - axios.post(apiURL, { - action: 'list', - path: newPath + API.get(apiURL, { + params: { + path: newPath, + } }) .then( (response)=> { - this.props.updateFileList(response.data.result); + this.props.updateFileList(response.data); this.props.setNavigatorLoadingStatus(false); let pathTemp = (path!==null?path.substr(1).split("/"):this.props.path.substr(1).split("/")).join(","); setCookie("path_tmp",encodeURIComponent(pathTemp),1); diff --git a/src/component/Login/LoginForm.js b/src/component/Login/LoginForm.js index 37a050c..56941d6 100644 --- a/src/component/Login/LoginForm.js +++ b/src/component/Login/LoginForm.js @@ -92,7 +92,7 @@ function LoginForm (){ const classes = useStyles(); const refreshCaptcha = ()=>{ - API.get("/Captcha").then((response) =>{ + API.get("/captcha").then((response) =>{ setCaptchaData(response.data) }).catch((error)=> { ToggleSnackbar("top", "right", "无法加载验证码:" + error.message, "error"); @@ -107,7 +107,7 @@ function LoginForm (){ const login = e=>{ e.preventDefault(); setLoading(true); - API.post('/User/Session',{ + API.post('/user/session',{ userName:email, Password:pwd, captchaCode:captcha, @@ -126,7 +126,7 @@ function LoginForm (){ // }else{ setLoading(false) Auth.authenticate(response.data); - history.push('/Home'); + history.push('/home'); ToggleSnackbar("top","right","登录成功","success"); // } }) diff --git a/src/middleware/Api.js b/src/middleware/Api.js index e281d22..15a0d88 100644 --- a/src/middleware/Api.js +++ b/src/middleware/Api.js @@ -1,7 +1,7 @@ import axios from "axios"; const instance = axios.create({ - baseURL: "http://127.0.0.1:5000/Api/V3", + baseURL: "http://127.0.0.1:5000/api/v3", withCredentials: true, crossDomain: true, }); diff --git a/src/middleware/Init.js b/src/middleware/Init.js index aa11529..ed590c4 100644 --- a/src/middleware/Init.js +++ b/src/middleware/Init.js @@ -1,15 +1,21 @@ import { setSiteConfig, toggleSnackbar } from "../actions/index" +import { fixUrlHash } from "../untils/index" import API from "./Api" export var InitSiteConfig = (rawStore) => { + // 从缓存获取默认配置 let configCache = JSON.parse(localStorage.getItem('siteConfigCache')); if (configCache != null) { rawStore.siteConfig = configCache } + // 检查是否有path参数 + var url = new URL(fixUrlHash(window.location.href)); + var c = url.searchParams.get("path"); + rawStore.navigator.path = c===null?"/":c; return rawStore } export async function UpdateSiteConfig(store) { - API.get("/Site/Config").then(function(response) { + API.get("/site/config").then(function(response) { let themes = JSON.parse(response.data.themes); response.data.theme = themes[response.data.defaultTheme] store.dispatch(setSiteConfig(response.data)); diff --git a/src/untils/index.js b/src/untils/index.js index 6c8ea85..67d9d05 100644 --- a/src/untils/index.js +++ b/src/untils/index.js @@ -6,6 +6,12 @@ export const sizeToString = (bytes) => { return (bytes / Math.pow(k, i)).toFixed(1) + ' ' + sizes[i]; } +export const fixUrlHash = (path)=> { + var relativePath = path.split('#') + var url = new URL('http://example.com/' + relativePath[1]); + return url.toString(); + } + export const setCookie = (name,value,days)=>{ if (days) { var date = new Date(); @@ -17,7 +23,7 @@ export const setCookie = (name,value,days)=>{ export const setGetParameter = (paramName, paramValue) =>{ var url = window.location.href; var hash = window.location.hash; - url = url.replace(hash, ''); + if (url.indexOf(paramName + "=") >= 0) { var prefix = url.substring(0, url.indexOf(paramName)); diff --git a/src/untils/page.js b/src/untils/page.js index b29f327..363e18b 100644 --- a/src/untils/page.js +++ b/src/untils/page.js @@ -1,10 +1,10 @@ const statusHelper = { isHomePage(path){ - return path == "/Home" + return path == "/home" }, isSharePage(path){ - return path == "/Share" + return path == "/share" }, isMobile(){ return window.innerWidth < 600;