This commit is contained in:
oneao committed 2026-03-18 17:29:39 +08:00
1 parent 68f08d921a
commit 3656d05f62
97 files changed
+17495

No files matched your search

@@ -0,0 +1,22 @@
const fleetCounts = reactive({
diaodu: {
todo: 0,
finished: 0,
total: 0,
},
})
const driverCounts = reactive({
jindu: {
todo: 0,
finished: 0,
total: 0,
},
})
export function useCounts() {
return {
fleetCounts,
driverCounts,
}
}
@@ -0,0 +1,16 @@
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
const store = createPinia()
store.use(
createPersistedState({
storage: {
getItem: uni.getStorageSync,
setItem: uni.setStorageSync,
},
}),
)
export default store
export * from './user'
@@ -0,0 +1,62 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
const initState: IUserInfo = {
token: '',
orgid: '',
userid: '',
}
export const useUserStore = defineStore(
'user',
() => {
const userInfo = ref<IUserInfo>({ ...initState })
const setUserInfo = (val: IUserInfo) => {
userInfo.value = val
}
const reset = () => {
userInfo.value.token = ''
}
const isLogined = computed(
() => !!(userInfo.value.token && userInfo.value.orgid && userInfo.value.userid),
)
function requireLogin(): boolean {
if (!isLogined.value) {
uni.showToast({
title: '请先登录',
icon: 'none',
})
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const path = currentPage?.route ? `/${currentPage.route}` : ''
if (!path || path !== '/pages-sub/login/index') {
setTimeout(() => {
uni.reLaunch({
url: '/pages-sub/login/index',
})
}, 500)
}
return false
}
return true
}
return {
userInfo,
setUserInfo,
reset,
isLogined,
requireLogin,
}
},
{
persist: true,
},
)