feat(stores): add Pinia domain stores and update docs

Implement concrete Pinia stores for app UI and domain data instead of
placeholder re-exports, including seeded student records and snackbar state.

Refresh README guidance for components, plugins, and services to document the
current project structure, data flow, and usage conventions.feat(stores): add Pinia domain stores and update docs

Implement concrete Pinia stores for app UI and domain data instead of
placeholder re-exports, including seeded student records and snackbar state.

Refresh README guidance for components, plugins, and services to document the
current project structure, data flow, and usage conventions.
This commit is contained in:
skytek_xinliang
2026-05-05 11:54:19 +08:00
parent 6eab4d9744
commit b37f4363eb
23 changed files with 1531 additions and 1588 deletions
+343 -1
View File
@@ -1 +1,343 @@
export * from './stores/students'
import { defineStore } from 'pinia'
import { ref } from 'vue'
export interface StudentRecord {
id: number
studentId: string
name: string
department: string
grade: number
enrollYear: number
credits: number
advisor: string
email: string
phone: string
status: string
}
const seedStudents: StudentRecord[] = [
{
id: 1,
studentId: 'S2024001',
name: '王小明',
department: '資訊工程',
grade: 1,
enrollYear: 2024,
credits: 18,
advisor: '林育成',
email: 'ming.wang@school.edu',
phone: '02-2345-1001',
status: '在學',
},
{
id: 2,
studentId: 'S2023017',
name: '陳怡君',
department: '企業管理',
grade: 2,
enrollYear: 2023,
credits: 36,
advisor: '許雅婷',
email: 'yijun.chen@school.edu',
phone: '02-2345-1002',
status: '在學',
},
{
id: 3,
studentId: 'S2022008',
name: '林冠宇',
department: '財務金融',
grade: 3,
enrollYear: 2022,
credits: 64,
advisor: '張國華',
email: 'kuanyu.lin@school.edu',
phone: '02-2345-1003',
status: '休學',
},
{
id: 4,
studentId: 'S2021022',
name: '郭雅婷',
department: '視覺設計',
grade: 4,
enrollYear: 2021,
credits: 92,
advisor: '蔡怡芳',
email: 'yating.kuo@school.edu',
phone: '02-2345-1004',
status: '在學',
},
{
id: 5,
studentId: 'S2019013',
name: '張柏翰',
department: '應用外語',
grade: 5,
enrollYear: 2019,
credits: 28,
advisor: '吳佳玲',
email: 'bohan.chang@school.edu',
phone: '02-2345-1005',
status: '畢業',
},
{
id: 6,
studentId: 'S2024024',
name: '李詩涵',
department: '視覺設計',
grade: 1,
enrollYear: 2024,
credits: 16,
advisor: '蔡怡芳',
email: 'shihan.li@school.edu',
phone: '02-2345-1006',
status: '在學',
},
{
id: 7,
studentId: 'S2023044',
name: '黃俊豪',
department: '資訊工程',
grade: 2,
enrollYear: 2023,
credits: 40,
advisor: '林育成',
email: 'junhao.huang@school.edu',
phone: '02-2345-1007',
status: '在學',
},
{
id: 8,
studentId: 'S2022066',
name: '周佳穎',
department: '企業管理',
grade: 3,
enrollYear: 2022,
credits: 58,
advisor: '許雅婷',
email: 'jiaying.chou@school.edu',
phone: '02-2345-1008',
status: '在學',
},
{
id: 9,
studentId: 'S2021088',
name: '許景皓',
department: '財務金融',
grade: 4,
enrollYear: 2021,
credits: 88,
advisor: '張國華',
email: 'jinghao.hsu@school.edu',
phone: '02-2345-1009',
status: '在學',
},
{
id: 10,
studentId: 'S2020019',
name: '鄭婉如',
department: '應用外語',
grade: 5,
enrollYear: 2020,
credits: 22,
advisor: '吳佳玲',
email: 'wanru.cheng@school.edu',
phone: '02-2345-1010',
status: '在學',
},
{
id: 11,
studentId: 'S2024031',
name: '謝承翰',
department: '資訊工程',
grade: 1,
enrollYear: 2024,
credits: 20,
advisor: '林育成',
email: 'chenghan.hsieh@school.edu',
phone: '02-2345-1011',
status: '在學',
},
{
id: 12,
studentId: 'S2023055',
name: '邱雅雯',
department: '視覺設計',
grade: 2,
enrollYear: 2023,
credits: 34,
advisor: '蔡怡芳',
email: 'yawin.chiu@school.edu',
phone: '02-2345-1012',
status: '在學',
},
{
id: 13,
studentId: 'S2022073',
name: '何柏勳',
department: '財務金融',
grade: 3,
enrollYear: 2022,
credits: 62,
advisor: '張國華',
email: 'boxun.he@school.edu',
phone: '02-2345-1013',
status: '休學',
},
{
id: 14,
studentId: 'S2021095',
name: '鄒庭安',
department: '企業管理',
grade: 4,
enrollYear: 2021,
credits: 96,
advisor: '許雅婷',
email: 'tingan.tsou@school.edu',
phone: '02-2345-1014',
status: '在學',
},
{
id: 15,
studentId: 'S2020028',
name: '潘子涵',
department: '應用外語',
grade: 5,
enrollYear: 2020,
credits: 26,
advisor: '吳佳玲',
email: 'zihan.pan@school.edu',
phone: '02-2345-1015',
status: '畢業',
},
{
id: 16,
studentId: 'S2024042',
name: '賴昀潔',
department: '視覺設計',
grade: 1,
enrollYear: 2024,
credits: 14,
advisor: '蔡怡芳',
email: 'yunjie.lai@school.edu',
phone: '02-2345-1016',
status: '在學',
},
{
id: 17,
studentId: 'S2023068',
name: '高宇辰',
department: '資訊工程',
grade: 2,
enrollYear: 2023,
credits: 38,
advisor: '林育成',
email: 'yuchen.kao@school.edu',
phone: '02-2345-1017',
status: '在學',
},
{
id: 18,
studentId: 'S2022089',
name: '游品妤',
department: '企業管理',
grade: 3,
enrollYear: 2022,
credits: 60,
advisor: '許雅婷',
email: 'pinyu.yu@school.edu',
phone: '02-2345-1018',
status: '在學',
},
{
id: 19,
studentId: 'S2021106',
name: '羅子軒',
department: '財務金融',
grade: 4,
enrollYear: 2021,
credits: 84,
advisor: '張國華',
email: 'zixuan.lo@school.edu',
phone: '02-2345-1019',
status: '在學',
},
{
id: 20,
studentId: 'S2020036',
name: '謝佳玲',
department: '應用外語',
grade: 5,
enrollYear: 2020,
credits: 24,
advisor: '吳佳玲',
email: 'jialing.hsieh@school.edu',
phone: '02-2345-1020',
status: '畢業',
},
]
export const useStudentStore = defineStore('students', () => {
const students = ref<StudentRecord[]>([...seedStudents])
const deletedIds = ref<Set<number>>(new Set())
const addStudent = (payload: Omit<StudentRecord, 'id'>) => {
const nextId = students.value.reduce((max, item) => Math.max(max, item.id), 0) + 1
const created = { id: nextId, ...payload }
students.value.push(created)
return created.id
}
const updateStudent = (id: number, payload: Omit<StudentRecord, 'id'>) => {
const target = students.value.find((item) => item.id === id)
if (!target) return false
Object.assign(target, payload)
return true
}
const removeStudent = (id: number) => {
const before = students.value.length
students.value = students.value.filter((item) => item.id !== id)
return students.value.length !== before
}
// 標記刪除(軟刪除,還原用)
const markAsDeleted = (id: number) => {
deletedIds.value.add(id)
}
// 清除所有標記
const clearDeletedIds = () => {
deletedIds.value.clear()
}
// 提交刪除(實際刪除)
const commitDeleted = () => {
for (const id of deletedIds.value) {
removeStudent(id)
}
deletedIds.value.clear()
}
// 還原標記(取消刪除)
const restoreDeleted = () => {
deletedIds.value.clear()
}
// 檢查是否已標記刪除
const isMarkedAsDeleted = (id: number) => deletedIds.value.has(id)
return {
students,
deletedIds,
addStudent,
updateStudent,
removeStudent,
markAsDeleted,
clearDeletedIds,
commitDeleted,
restoreDeleted,
isMarkedAsDeleted,
}
})