Files
violin-home/src/store/modules/customer.ts
T
simple321vip 4da6832b44 feat: R1 重构对称迁移 + 升级依赖 + 配置文件分离
- 命名重构:tenant → customer(对齐后端 R1 重构)
  - Tenant → Customer / tenant_id → customerId
  - tenantStore → customerStore / getTenant/setTenant → getCustomer/setCustomer
  - cookie key tenant → customer, HTTP header tenantId → customerId
- 后端契约更新:AuthResponse 加 sub 字段
- 接口 URL 修复:/auth/oidc/callback → /api/v1/auth/oidc/callback
- 依赖升级:vue 3.5 / element-plus 2.8 / vite 5 / typescript 5.6 / sass 1.79
- 删 node-sass / scss / sass-loader / moment / mock/index.ts
- 配置文件拆分:.env.development / .env.production / .env.example
- 删除冗余 view/auth/auth/callback.vue 副本
- .gitignore 增加 dist / .opencode / tmp
- 新增 AGENT.md 与后端风格对齐
2026-06-22 08:02:21 +08:00

56 lines
1.4 KiB
TypeScript

import { defineStore, acceptHMRUpdate } from 'pinia'
import { authorize } from '../../api/user'
import { getToken, setToken, resetToken, setCustomer, getCustomer } from '../../utils/auth'
import { Customer } from '../../entity/index'
import { ref } from 'vue'
export const customerStore = defineStore('customer', () => {
const customer = ref({
account: '',
token: '',
id: '',
headerImg: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
})
const login = async (customer: Customer, token: string) => {
try {
await authorize({
customerId: customer.customerId, token: token
})
setToken(token)
setCustomer(customer)
} catch {
Promise.resolve("authorize error")
}
}
const logout = async () => {
customer.value.account = ''
customer.value.token = ''
customer.value.id = ''
resetToken()
window.location.reload()
}
const reflush = async () => {
if (getToken()) {
const customerStorage = <Customer>(JSON.parse(getCustomer() as string))
const token = <string>getToken()
customer.value.account = customerStorage.account
customer.value.token = token
customer.value.id = customerStorage.customerId
}
}
return {
customer,
login,
logout,
reflush
}
})
if (import.meta.hot) {
import.meta.hot.accept(acceptHMRUpdate(customerStore, import.meta.hot))
}