Feat: 路径导航

This commit is contained in:
HFO4 2019-11-24 13:51:24 +08:00
parent 341a70e7c8
commit 5fe8fc788f
6 changed files with 31 additions and 17 deletions

View File

@ -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);

View File

@ -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");
// }
})

View File

@ -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,
});

View File

@ -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));

View File

@ -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));

View File

@ -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;