softleader-nuxt-core 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- /**
2
- * 核心邏輯模組入口 (Centralized Logic Modules Entry)
3
- * 提供專案規範中要求的核心 Composable。
4
- */
5
- export function useModules() {
6
- return {
7
- /** 分頁管理 */
8
- usePagination,
9
- /** API 請求 */
10
- useApi,
11
- /** 檔案下載 */
12
- useFileDownload,
13
- /** 檔案上傳 */
14
- useFileUpload,
15
- /** 資料驗證 */
16
- useValidation
17
- }
18
- }
1
+ /**
2
+ * 核心邏輯模組入口 (Centralized Logic Modules Entry)
3
+ * 提供專案規範中要求的核心 Composable。
4
+ */
5
+ export function useModules() {
6
+ return {
7
+ /** 分頁管理 */
8
+ usePagination,
9
+ /** API 請求 */
10
+ useApi,
11
+ /** 檔案下載 */
12
+ useFileDownload,
13
+ /** 檔案上傳 */
14
+ useFileUpload,
15
+ /** 資料驗證 */
16
+ useValidation
17
+ }
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "softleader-nuxt-core",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Nuxt 3 Core Layer - 可重用的基礎架構",
5
5
  "type": "module",
6
6
  "files": [
@@ -19,6 +19,7 @@
19
19
  "utils",
20
20
  "stores",
21
21
  "types",
22
+ "repositories",
22
23
  "bin",
23
24
  "schemas",
24
25
  "nuxt.config.ts",
@@ -0,0 +1,18 @@
1
+ import user from './modules/user'
2
+ import auth from './modules/auth'
3
+
4
+ /**
5
+ * Repository Index (資料層)
6
+ *
7
+ * 職責:
8
+ * 1. 自動掃描 modules 資料夾下的所有檔案
9
+ * 2. 將它們打包成一個大物件匯出
10
+ * 3. 不依賴 Nuxt,純粹的資料定義
11
+ */
12
+
13
+ const repositories = {
14
+ user,
15
+ auth
16
+ }
17
+
18
+ export default repositories
@@ -0,0 +1,29 @@
1
+ import type { UseFetchOptions } from 'nuxt/app'
2
+
3
+ // 定義 Client,指向 /auth (假設後端路由是 /api/auth)
4
+ const api = useClient('/auth')
5
+
6
+ export default {
7
+ /**
8
+ * 使用者登入
9
+ * @param credentials { username, password }
10
+ * @param options
11
+ */
12
+ login(credentials: any, options: UseFetchOptions<any> = {}) {
13
+ return api.post('/login', credentials, options)
14
+ },
15
+
16
+ /**
17
+ * 使用者登出 (如果有的話)
18
+ */
19
+ logout() {
20
+ return api.post('/logout')
21
+ },
22
+
23
+ /**
24
+ * 取得當前使用者資訊 (Session/Me)
25
+ */
26
+ getProfile() {
27
+ return api.get('/me')
28
+ }
29
+ }
@@ -0,0 +1,100 @@
1
+ import type { UseFetchOptions } from 'nuxt/app'
2
+ import type { UserListResponse } from '../../types/api'
3
+
4
+ type MaybeRef<T> = T | Ref<T>
5
+
6
+ interface UserQueryParams {
7
+ page?: MaybeRef<number>
8
+ itemsPerPage?: MaybeRef<number>
9
+ q?: MaybeRef<string>
10
+ }
11
+
12
+ // 1. 定義 Client
13
+ const api = useClient('/users')
14
+
15
+ export default {
16
+ /**
17
+ * 取得使用者列表
18
+ * @param params - 查詢參數 (如分頁、搜尋關鍵字)
19
+ * @param options - 其他 Fetch 選項
20
+ * @returns List of users
21
+ */
22
+ getUsers(params: UserQueryParams = {}, options: UseFetchOptions<UserListResponse> = {}) {
23
+ return api.get<UserListResponse>('/', {
24
+ query: params,
25
+ ...options
26
+ })
27
+ },
28
+
29
+ /**
30
+ * 根據 ID 取得單一使用者
31
+ * @param id - 使用者 ID
32
+ * @returns User detail
33
+ */
34
+ getUserById(id: MaybeRef<number>) {
35
+ return api.get<any>(`/${unref(id)}`)
36
+ },
37
+
38
+ /**
39
+ * [範例] 建立使用者
40
+ * @param userData - 使用者資料物件
41
+ * @returns Created user data
42
+ */
43
+ createUser(userData: any) {
44
+ return api.post('/', userData)
45
+ },
46
+
47
+ /**
48
+ * [範例] 搜尋使用者
49
+ * @param keyword - 搜尋關鍵字
50
+ * @returns Search results
51
+ */
52
+ searchUsers(keyword: Ref<string>) {
53
+ return api.get('/search', {
54
+ query: { q: keyword },
55
+ watch: [keyword]
56
+ })
57
+ },
58
+
59
+ /**
60
+ * [範例] 更新使用者
61
+ * @param id - 使用者 ID
62
+ * @param userData - 更新的使用者資料
63
+ * @returns Updated user data
64
+ */
65
+ updateUser(id: number, userData: any) {
66
+ return api.put(`/${id}`, userData)
67
+ },
68
+
69
+ /**
70
+ * [範例] 刪除使用者
71
+ * @param id - 使用者 ID
72
+ * @returns Deletion result
73
+ */
74
+ deleteUser(id: number) {
75
+ return api.delete(`/${id}`)
76
+ },
77
+
78
+ /**
79
+ * [範例] 取得大量資料 (延遲載入)
80
+ * @returns Heavy data report
81
+ */
82
+ getHeavyData() {
83
+ // 注意:這裡是 /heavy-report,因為 api base 是 /users
84
+ // 假設 heavy-report 也是在 /users 下,否則需另外處理
85
+ // 原始碼是 useApi('/heavy-report'),這可能不在 /users 下
86
+ // 為了安全,這裡假設它是獨立的
87
+ // 如果是獨立的,應該用 useApi 或另外一個 useClient
88
+ // 這裡我判斷它可能是 /users/heavy-report 的筆誤,或者真的是 root level
89
+ // 為了保持功能,我這裡用 root client 處理 (假設它不是 users/*)
90
+ // 但原檔放在 user.ts 卻叫 /heavy-report 有點怪
91
+ // 我先維持原路徑:/heavy-report (不接在 /users 後面)
92
+
93
+ // 這裡特別展示:如何在 policy 模式下呼叫「外面」的 API
94
+ // 方法 1: 使用 useApi
95
+ // return useApi('/heavy-report', { lazy: true })
96
+
97
+ // 方法 2 (如果它其實是 user 報表):
98
+ return useApi('/heavy-report', { lazy: true })
99
+ }
100
+ }
@@ -1,24 +1,24 @@
1
- import { execSync } from 'child_process'
2
-
3
- /**
4
- * 自動化發布腳本
5
- * 用法:
6
- * npm run release (預設 patch: 1.1.0 -> 1.1.1)
7
- * npm run release minor (1.1.0 -> 1.2.0)
8
- * npm run release major (1.1.0 -> 2.0.0)
9
- */
10
-
11
- const type = process.argv[2] || 'patch'
12
-
13
- try {
14
- console.log(`\n\x1b[36m[Release] Step 1: Bumping version (${type})...\x1b[0m`)
15
- execSync(`npm version ${type} --no-git-tag-version`, { stdio: 'inherit' })
16
-
17
- console.log(`\n\x1b[36m[Release] Step 2: Publishing to npm...\x1b[0m`)
18
- execSync('npm publish', { stdio: 'inherit' })
19
-
20
- console.log('\n\x1b[32m[Release] Successfully published! 🎉\x1b[0m\n')
21
- } catch (error) {
22
- console.error('\n\x1b[31m[Release] Failed to publish:\x1b[0m', error.message)
23
- process.exit(1)
24
- }
1
+ import { execSync } from 'child_process'
2
+
3
+ /**
4
+ * 自動化發布腳本
5
+ * 用法:
6
+ * npm run release (預設 patch: 1.1.0 -> 1.1.1)
7
+ * npm run release minor (1.1.0 -> 1.2.0)
8
+ * npm run release major (1.1.0 -> 2.0.0)
9
+ */
10
+
11
+ const type = process.argv[2] || 'patch'
12
+
13
+ try {
14
+ console.log(`\n\x1b[36m[Release] Step 1: Bumping version (${type})...\x1b[0m`)
15
+ execSync(`npm version ${type} --no-git-tag-version`, { stdio: 'inherit' })
16
+
17
+ console.log(`\n\x1b[36m[Release] Step 2: Publishing to npm...\x1b[0m`)
18
+ execSync('npm publish', { stdio: 'inherit' })
19
+
20
+ console.log('\n\x1b[32m[Release] Successfully published! 🎉\x1b[0m\n')
21
+ } catch (error) {
22
+ console.error('\n\x1b[31m[Release] Failed to publish:\x1b[0m', error.message)
23
+ process.exit(1)
24
+ }