feat: 添加pinia状态管理库和Tabbar组件

- 添加pinia状态管理库和Tabbar组件
- 引入axios和fant-axios-adapter
- 在main.ts中使用pinia和persist插件
- 在App.vue中修改标题
- 在useUser.ts中添加logout方法
- 添加persist.ts文件
- 修改page-wrapper.vue和TabBar.vue中的代码
- 修改index.vue和login.vue中的代码
This commit is contained in:
2024-09-19 00:13:56 +08:00
parent cf77c72dfe
commit ceb9636b42
13 changed files with 806 additions and 139 deletions

17
src/stores/persist.ts Normal file
View File

@ -0,0 +1,17 @@
import type { PiniaPluginContext } from "pinia";
import { deepClone } from "wot-design-uni/components/common/util";
export function persist({ store }: PiniaPluginContext) {
// 暂存State
let persistState = deepClone(store.$state);
// 从缓存中读取
const storageState = uni.getStorageSync(store.$id);
if (storageState) {
persistState = storageState;
}
store.$state = persistState;
store.$subscribe(() => {
// 在存储变化的时候将store缓存
uni.setStorageSync(store.$id, deepClone(store.$state));
});
}

View File

@ -3,9 +3,17 @@ import { defineStore } from "pinia";
import { ref } from "vue";
export const useUser = defineStore("user", () => {
const token = ref<string | null>(null);
const userinfo = ref<User | null>(null);
function logout() {
token.value = null
userinfo.value = null
}
return {
token,
userinfo,
logout,
};
});