feat: 界面调整
This commit is contained in:
@@ -1,69 +1,65 @@
|
||||
/** @format */
|
||||
|
||||
import { action, makeObservable, observable } from "mobx";
|
||||
import { isHydrated, makePersistable } from "mobx-persist-store";
|
||||
import { handleLocalforage } from "@/utils/localforage";
|
||||
|
||||
export class useFileStore {
|
||||
filePath: [any] = [
|
||||
{
|
||||
title: "/ root",
|
||||
},
|
||||
];
|
||||
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
filePath: observable,
|
||||
setFilePath: action,
|
||||
getFilePath: action,
|
||||
clearFilePath: action,
|
||||
getFilePathSecondLast: action,
|
||||
isHydrated: action,
|
||||
});
|
||||
makePersistable(
|
||||
this,
|
||||
{
|
||||
// 在构造函数内使用 makePersistable
|
||||
name: "file", // 保存的name,用于在storage中的名称标识,只要不和storage中其他名称重复就可以
|
||||
properties: ["filePath"], // 要保存的字段,这些字段会被保存在name对应的storage中,注意:不写在这里面的字段将不会被保存,刷新页面也将丢失:get字段例外。get数据会在数据返回后再自动计算
|
||||
storage: handleLocalforage, // 保存的位置:可以是localStorage,sessionstorage
|
||||
removeOnExpiration: true, //如果 expireIn 具有值且已过期,则在调用 getItem 时将自动删除存储中的数据。默认值为 true。
|
||||
stringify: false, //如果为 true,则数据在传递给 setItem 之前将是 JSON.stringify。默认值为 true。
|
||||
expireIn: 2592000000, // 一个以毫秒为单位的值,用于确定 getItem 何时不应检索存储中的数据。默认情况下永不过期。
|
||||
debugMode: false, // 如果为 true,将为多个 mobx-persist-store 项调用 console.info。默认值为 false。
|
||||
},
|
||||
{
|
||||
delay: 0, // 允许您设置一个 delay 选项来限制 write 函数的调用次数。默认情况下没有延迟。
|
||||
fireImmediately: false, // 确定是应立即保留存储数据,还是等到存储中的属性发生更改。 false 默认情况下。
|
||||
},
|
||||
).then(
|
||||
action(() => {
|
||||
// persist 完成的回调,在这里可以执行一些拿到数据后需要执行的操作,如果在页面上要判断是否完成persist,使用 isHydrated
|
||||
// console.log(persistStore)
|
||||
}),
|
||||
);
|
||||
}
|
||||
// 获取文件路径
|
||||
getFilePath() {
|
||||
return this.filePath ? this.filePath : [];
|
||||
}
|
||||
// 设置文件路径
|
||||
setFilePath(path: any) {
|
||||
this.filePath.push(path);
|
||||
}
|
||||
// 删除文件路径最后一个
|
||||
clearFilePath() {
|
||||
if (this.filePath.length === 1) {
|
||||
return;
|
||||
}
|
||||
this.filePath.pop();
|
||||
}
|
||||
// 获取文件路径倒数第二个
|
||||
getFilePathSecondLast() {
|
||||
return this.filePath.slice(0, -1).pop();
|
||||
}
|
||||
|
||||
isHydrated() {
|
||||
return isHydrated(this);
|
||||
}
|
||||
}
|
||||
/** @format */
|
||||
|
||||
import { action, makeObservable, observable } from "mobx";
|
||||
import { isHydrated, makePersistable } from "mobx-persist-store";
|
||||
import { handleLocalforage } from "@/utils/localforage";
|
||||
|
||||
export class useFileStore {
|
||||
filePath: [any] = ["/root"];
|
||||
|
||||
constructor() {
|
||||
makeObservable(this, {
|
||||
filePath: observable,
|
||||
setFilePath: action,
|
||||
getFilePath: action,
|
||||
clearFilePath: action,
|
||||
getFilePathSecondLast: action,
|
||||
isHydrated: action,
|
||||
});
|
||||
makePersistable(
|
||||
this,
|
||||
{
|
||||
// 在构造函数内使用 makePersistable
|
||||
name: "file", // 保存的name,用于在storage中的名称标识,只要不和storage中其他名称重复就可以
|
||||
properties: ["filePath"], // 要保存的字段,这些字段会被保存在name对应的storage中,注意:不写在这里面的字段将不会被保存,刷新页面也将丢失:get字段例外。get数据会在数据返回后再自动计算
|
||||
storage: handleLocalforage, // 保存的位置:可以是localStorage,sessionstorage
|
||||
removeOnExpiration: true, //如果 expireIn 具有值且已过期,则在调用 getItem 时将自动删除存储中的数据。默认值为 true。
|
||||
stringify: false, //如果为 true,则数据在传递给 setItem 之前将是 JSON.stringify。默认值为 true。
|
||||
expireIn: 2592000000, // 一个以毫秒为单位的值,用于确定 getItem 何时不应检索存储中的数据。默认情况下永不过期。
|
||||
debugMode: false, // 如果为 true,将为多个 mobx-persist-store 项调用 console.info。默认值为 false。
|
||||
},
|
||||
{
|
||||
delay: 0, // 允许您设置一个 delay 选项来限制 write 函数的调用次数。默认情况下没有延迟。
|
||||
fireImmediately: false, // 确定是应立即保留存储数据,还是等到存储中的属性发生更改。 false 默认情况下。
|
||||
},
|
||||
).then(
|
||||
action(() => {
|
||||
// persist 完成的回调,在这里可以执行一些拿到数据后需要执行的操作,如果在页面上要判断是否完成persist,使用 isHydrated
|
||||
// console.log(persistStore)
|
||||
}),
|
||||
);
|
||||
}
|
||||
// 获取文件路径
|
||||
getFilePath() {
|
||||
return this.filePath ? this.filePath : [];
|
||||
}
|
||||
// 设置文件路径
|
||||
setFilePath(path: any) {
|
||||
this.filePath.push(path);
|
||||
}
|
||||
// 删除文件路径最后一个
|
||||
clearFilePath() {
|
||||
if (this.filePath.length === 1) {
|
||||
return;
|
||||
}
|
||||
this.filePath.pop();
|
||||
}
|
||||
// 获取文件路径倒数第二个
|
||||
getFilePathSecondLast() {
|
||||
return this.filePath.slice(0, -1).pop();
|
||||
}
|
||||
|
||||
isHydrated() {
|
||||
return isHydrated(this);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user