ch3chi-commons-vue 0.1.7 → 0.1.10
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.
- package/README.md +68 -29
- package/package.json +19 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Commons Vue Library
|
|
2
2
|
|
|
3
|
-
這是一個 Vue
|
|
3
|
+
這是一個 Vue 公用元件/函式庫。
|
|
4
4
|
|
|
5
5
|
## 安裝
|
|
6
6
|
|
|
@@ -10,40 +10,79 @@ npm install commons-vue
|
|
|
10
10
|
|
|
11
11
|
## 使用方式
|
|
12
12
|
|
|
13
|
-
###
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
### APIService 範例
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { ApiService, ApiRequest } from 'commons-vue';
|
|
17
|
+
|
|
18
|
+
// 註冊多個 API 端點
|
|
19
|
+
ApiService.registerEndpoints({
|
|
20
|
+
getUser: { path: '/user/{id}', method: 'GET' },
|
|
21
|
+
createUser: { path: '/user', method: 'POST' }
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// 新增單一 API 端點
|
|
25
|
+
ApiService.addEndpoints('deleteUser', { path: '/user/{id}', method: 'DELETE' });
|
|
26
|
+
|
|
27
|
+
// 呼叫 API
|
|
28
|
+
const req = new ApiRequest({
|
|
29
|
+
endpointKey: 'getUser',
|
|
30
|
+
pathParam: { id: 123 }
|
|
31
|
+
});
|
|
32
|
+
ApiService.call(req).then(resp => {
|
|
33
|
+
if (resp.isOk()) {
|
|
34
|
+
console.log('取得使用者資料:', resp.data);
|
|
35
|
+
} else {
|
|
36
|
+
console.error('API 錯誤:', resp.message);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 下載檔案
|
|
41
|
+
const downloadReq = new ApiRequest({
|
|
42
|
+
endpointKey: 'exportUser',
|
|
43
|
+
queryParam: { id: 123 },
|
|
44
|
+
downloadFileName: 'user_123.xlsx'
|
|
45
|
+
});
|
|
46
|
+
ApiService.download(downloadReq).then(() => {
|
|
47
|
+
console.log('檔案下載完成');
|
|
48
|
+
}).catch(err => {
|
|
49
|
+
console.error('下載失敗:', err);
|
|
50
|
+
});
|
|
24
51
|
```
|
|
25
52
|
|
|
26
|
-
###
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
### AuthorizationService 範例
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { AuthorizationService, CMenuItem, MenuItem } from 'commons-vue';
|
|
57
|
+
|
|
58
|
+
// 設定角色權限映射
|
|
59
|
+
AuthorizationService.rolePermissionMap = {
|
|
60
|
+
admin: ['user.read', 'user.write', 'menu.view'],
|
|
61
|
+
user: ['user.read', 'menu.view']
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// 設定選單定義映射
|
|
65
|
+
AuthorizationService.menuDefineMap = {
|
|
66
|
+
default: [
|
|
67
|
+
{ title: '使用者管理', permission: 'user.read' },
|
|
68
|
+
{ title: '系統設定', permission: 'user.write' }
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// 檢查角色是否有某權限
|
|
73
|
+
const hasWrite = AuthorizationService.hasPermissionByRole(['user'], 'user.write');
|
|
74
|
+
console.log('user 是否有寫入權限:', hasWrite);
|
|
75
|
+
|
|
76
|
+
// 取得符合權限的選單
|
|
77
|
+
const menu = AuthorizationService.provideMenuByPermission({
|
|
78
|
+
roleCode: 'user',
|
|
79
|
+
permissions: ['user.read', 'menu.view']
|
|
80
|
+
});
|
|
81
|
+
console.log('使用者可見選單:', menu);
|
|
36
82
|
```
|
|
37
83
|
|
|
38
|
-
### 工具函式範例
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
import { someUtil } from 'commons-vue';
|
|
42
84
|
|
|
43
|
-
const output = someUtil(input);
|
|
44
|
-
```
|
|
45
85
|
|
|
46
86
|
## 文件
|
|
47
87
|
|
|
48
88
|
請參考 src/ 目錄下的程式碼與註解,或補充詳細 API 文件。
|
|
49
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ch3chi-commons-vue",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,27 +21,45 @@
|
|
|
21
21
|
"build": "tsc"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
+
"@fortawesome/fontawesome-svg-core": ">=7.1.0",
|
|
25
|
+
"@fortawesome/free-solid-svg-icons": ">=7.1.0",
|
|
26
|
+
"@fortawesome/vue-fontawesome": ">=3.1.2",
|
|
27
|
+
"axios": ">=1.13.2",
|
|
24
28
|
"bootstrap": "^5.3.7",
|
|
25
29
|
"dayjs": ">=1.11.13",
|
|
30
|
+
"flatpickr": ">=4.6.13",
|
|
26
31
|
"lodash": ">=4.17.21",
|
|
32
|
+
"mime-types": ">=3.0.1",
|
|
27
33
|
"uuid": ">=11.1.0",
|
|
34
|
+
"uuidv4": ">=6.2.13",
|
|
28
35
|
"vee-validate": ">=4.15.1",
|
|
29
36
|
"vue": "^3.5.18",
|
|
30
37
|
"yup": ">=1.7.1"
|
|
31
38
|
},
|
|
32
39
|
"devDependencies": {
|
|
40
|
+
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
|
41
|
+
"@fortawesome/free-solid-svg-icons": "^7.1.0",
|
|
42
|
+
"@fortawesome/vue-fontawesome": "^3.1.2",
|
|
43
|
+
"@tinymce/tinymce-vue": "^6.3.0",
|
|
33
44
|
"@types/bootstrap": "^5.2.10",
|
|
34
45
|
"@types/lodash": "^4.17.20",
|
|
46
|
+
"@types/mime-types": "^3.0.1",
|
|
35
47
|
"@types/node": "^24.10.0",
|
|
48
|
+
"axios": "^1.13.2",
|
|
36
49
|
"bootstrap": "^5.3.7",
|
|
37
50
|
"dayjs": "^1.11.13",
|
|
51
|
+
"flatpickr": "^4.6.13",
|
|
38
52
|
"lodash": "^4.17.21",
|
|
53
|
+
"mime-types": "^3.0.1",
|
|
54
|
+
"pinia": "^3.0.4",
|
|
39
55
|
"typescript": "^5.9.3",
|
|
40
56
|
"uuid": "^11.1.0",
|
|
57
|
+
"uuidv4": "^6.2.13",
|
|
41
58
|
"vee-validate": "^4.15.1",
|
|
42
59
|
"vite": "^7.2.1",
|
|
43
60
|
"vite-plugin-dts": "^4.5.4",
|
|
44
61
|
"vue": "^3.5.23",
|
|
62
|
+
"vue-router": "^4.6.3",
|
|
45
63
|
"yup": "^1.7.1"
|
|
46
64
|
},
|
|
47
65
|
"prepublishOnly": [
|