24145419b0
後端: - AdminStatsController:總會員/教練/課程數統計 API - AdminUserController:會員與教練列表、詳情、啟用/停用、教練驗證(toggle 反轉語意) - AdminOfferController:全平台課程列表與刪除 - routes/api.php:新增 /api/admin/stats、members、providers、offers 等路由 前端(frontend/): - adminAuth store、adminAxios(第三套獨立認證) - /admin/* 路由群組 + requiresAdmin guard - AdminNavBar、AdminLayout - App.vue:isCoachPage → isBackofficePage(/coach/* 和 /admin/* 皆隱藏會員 NavBar) - LoginView、DashboardView(統計卡片) - MembersView、ProvidersView(含驗證操作)、OffersView(含刪除確認) OpenSpec: - 新增 specs:admin-auth / admin-user-management / admin-offer-management / admin-stats / admin-panel-ui - 歸檔:openspec/changes/archive/2026-05-10-admin-panel Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import adminApi from '../api/adminAxios'
|
|
|
|
export const useAdminAuthStore = defineStore('adminAuth', () => {
|
|
const user = ref(null)
|
|
const token = ref(null)
|
|
|
|
const isLoggedIn = computed(() => !!token.value)
|
|
|
|
function init() {
|
|
const savedToken = localStorage.getItem('admin_token')
|
|
const savedUser = localStorage.getItem('admin_user')
|
|
if (savedToken) {
|
|
token.value = savedToken
|
|
user.value = savedUser ? JSON.parse(savedUser) : null
|
|
}
|
|
}
|
|
|
|
function setAuth(userData, tokenValue) {
|
|
user.value = userData
|
|
token.value = tokenValue
|
|
localStorage.setItem('admin_token', tokenValue)
|
|
localStorage.setItem('admin_user', JSON.stringify(userData))
|
|
}
|
|
|
|
async function logout() {
|
|
try {
|
|
await adminApi.post('/admin/logout')
|
|
} catch {}
|
|
user.value = null
|
|
token.value = null
|
|
localStorage.removeItem('admin_token')
|
|
localStorage.removeItem('admin_user')
|
|
}
|
|
|
|
return { user, token, isLoggedIn, init, setAuth, logout }
|
|
})
|