mirror of
https://github.com/PlayEdu/frontend.git
synced 2025-12-23 18:59:44 +08:00
added: api
This commit is contained in:
55
src/utils/index.ts
Normal file
55
src/utils/index.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import moment from "moment";
|
||||
|
||||
export function getToken(): string {
|
||||
return window.localStorage.getItem("playedu-backend-token") || "";
|
||||
}
|
||||
|
||||
export function setToken(token: string) {
|
||||
window.localStorage.setItem("playedu-backend-token", token);
|
||||
}
|
||||
|
||||
export function clearToken() {
|
||||
window.localStorage.removeItem("playedu-backend-token");
|
||||
}
|
||||
|
||||
export function dateFormat(dateStr: string) {
|
||||
return moment(dateStr).format("YYYY-MM-DD HH:mm");
|
||||
}
|
||||
|
||||
export function generateUUID(): string {
|
||||
let guid = "";
|
||||
for (let i = 1; i <= 32; i++) {
|
||||
let n = Math.floor(Math.random() * 16.0).toString(16);
|
||||
guid += n;
|
||||
if (i === 8 || i === 12 || i === 16 || i === 20) guid += "-";
|
||||
}
|
||||
return guid;
|
||||
}
|
||||
|
||||
export function transformBase64ToBlob(
|
||||
base64: string,
|
||||
mime: string,
|
||||
filename: string
|
||||
): File {
|
||||
const arr = base64.split(",");
|
||||
const bstr = atob(arr[1]);
|
||||
let n = bstr.length;
|
||||
const u8arr = new Uint8Array(n);
|
||||
while (n--) {
|
||||
u8arr[n] = bstr.charCodeAt(n);
|
||||
}
|
||||
return new File([u8arr], filename, { type: mime });
|
||||
}
|
||||
|
||||
export function getHost() {
|
||||
return window.location.protocol + "//" + window.location.host + "/";
|
||||
}
|
||||
|
||||
export function inStrArray(array: string[], value: string): boolean {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (array[i] === value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user