mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-12 12:13:46 +08:00
fix conflicts
This commit is contained in:
42
new-ui/projects/vue-admin/src/stores/auth.ts
Normal file
42
new-ui/projects/vue-admin/src/stores/auth.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { Message } from '@arco-design/web-vue'
|
||||
import { userLogin, userLogout } from '@/http/login'
|
||||
import router from '@/router'
|
||||
|
||||
export const useAuthStore = defineStore({
|
||||
id: __AUTH_KEY,
|
||||
state: () => ({ token: null } as { token: string | null }),
|
||||
actions: {
|
||||
init() {
|
||||
this.$state.token = localStorage.getItem(__AUTH_KEY);
|
||||
},
|
||||
async login(params: any) {
|
||||
try {
|
||||
const { data } = await userLogin(params)
|
||||
if (data) {
|
||||
this.$state.token = data;
|
||||
localStorage.setItem(__AUTH_KEY, data)
|
||||
Message.success('登录成功');
|
||||
router.replace({ name: 'home' })
|
||||
return Promise.resolve(data)
|
||||
}
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
},
|
||||
async logout() {
|
||||
try {
|
||||
await userLogout()
|
||||
if (this.$state.token) {
|
||||
localStorage.removeItem(__AUTH_KEY)
|
||||
this.$reset()
|
||||
}
|
||||
Message.success('退出成功');
|
||||
router.push({ name: 'Login' })
|
||||
return Promise.resolve(true)
|
||||
} catch (err) {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
12
new-ui/projects/vue-admin/src/stores/counter.ts
Normal file
12
new-ui/projects/vue-admin/src/stores/counter.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useCounterStore = defineStore('counter', () => {
|
||||
const count = ref(0)
|
||||
const doubleCount = computed(() => count.value * 2)
|
||||
function increment() {
|
||||
count.value++
|
||||
}
|
||||
|
||||
return { count, doubleCount, increment }
|
||||
})
|
||||
Reference in New Issue
Block a user