Add NavBar.

This commit is contained in:
Yang Luo
2020-10-20 22:37:38 +08:00
parent bb06e55d8d
commit 88fd1fda47
11 changed files with 551 additions and 37 deletions

79
web/src/Setting.js Normal file
View File

@ -0,0 +1,79 @@
// Copyright 2020 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {message} from "antd";
import React from "react";
import {isMobile as isMobileDevice} from "react-device-detect";
export let ServerUrl = '';
export function initServerUrl() {
const hostname = window.location.hostname;
if (hostname === 'localhost') {
ServerUrl = `http://${hostname}:10000`;
}
}
export function parseJson(s) {
if (s === "") {
return null;
} else {
return JSON.parse(s);
}
}
export function goToLink(link) {
window.location.href = link;
}
export function showMessage(type, text) {
if (type === "") {
return;
} else if (type === "success") {
message.success(text);
} else if (type === "error") {
message.error(text);
}
}
export function isMobile() {
// return getIsMobileView();
return isMobileDevice;
}
export function getShortName(s) {
return s.split('/').slice(-1)[0];
}
function getRandomInt(s) {
let hash = 0;
if (s.length !== 0) {
for (let i = 0; i < s.length; i ++) {
let char = s.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
}
return hash;
}
export function getAvatarColor(s) {
const colorList = ['#f56a00', '#7265e6', '#ffbf00', '#00a2ae'];
let random = getRandomInt(s);
if (random < 0) {
random = -random;
}
return colorList[random % 4];
}