ch3chi-commons-vue 0.1.11 → 0.1.12

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.
@@ -0,0 +1,126 @@
1
+ import { AxiosProgressEvent, RawAxiosResponseHeaders } from 'axios';
2
+ /**
3
+ * ApiEndpoint 定義 API 端點的結構
4
+ */
5
+ export interface ApiEndpoint {
6
+ path: string;
7
+ method: string;
8
+ isAuthenticated?: boolean;
9
+ errorMessageMap?: Record<number, string>;
10
+ noSpinner?: boolean;
11
+ headers?: Record<string, string>;
12
+ }
13
+ /**
14
+ * ApiRequest 定義 API 請求的結構
15
+ */
16
+ export declare class ApiRequest {
17
+ endpointKey: string;
18
+ headers?: Record<string, string>;
19
+ pathParam?: Record<string, any>;
20
+ queryParam?: Record<string, any>;
21
+ postBody?: Record<string, any> | FormData;
22
+ isDownloadMode?: boolean;
23
+ downloadFileName?: string;
24
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
25
+ constructor(data: ApiRequest);
26
+ }
27
+ /**
28
+ * ApiResponse 定義 API 回應的結構
29
+ */
30
+ export declare class ApiResponse {
31
+ httpStatus: number;
32
+ code: number;
33
+ message?: string;
34
+ data?: any;
35
+ nativeError?: any;
36
+ paging?: Record<string, any>;
37
+ blobData?: Blob;
38
+ headers?: RawAxiosResponseHeaders;
39
+ constructor(data?: Partial<ApiResponse>);
40
+ isOk(): boolean;
41
+ }
42
+ /**
43
+ * ApiRejectError 定義 API 呼叫失敗時的自訂錯誤
44
+ * 此物件給 ApiService.call 呼叫後,並且回傳 Promise.reject() 使用
45
+ */
46
+ export declare class ApiRejectError extends Error {
47
+ response: ApiResponse;
48
+ type?: string;
49
+ constructor(response: ApiResponse);
50
+ notFound(): this;
51
+ }
52
+ /**
53
+ * ApiService 提供呼叫後端 API 的功能
54
+ */
55
+ export declare class ApiService {
56
+ private static _apiEndpoints;
57
+ private static _customHeaders;
58
+ private static _customErrorMessageMap;
59
+ constructor();
60
+ /**
61
+ * 靜態方法,配置 ApiService
62
+ * 為方便管理,建議在專案啟動時呼叫此方法註冊所有端點
63
+ * 可以配置
64
+ * - endpoints: 預設註冊的 API 端點
65
+ * - customHeaders: 全域自訂標頭
66
+ * - customErrorMessageMap: 全域自訂錯誤訊息對應
67
+ * @param config
68
+ */
69
+ static configure(config: {
70
+ endpoints: Record<string, ApiEndpoint>;
71
+ customHeaders?: Record<string, string>;
72
+ customErrorMessageMap?: Record<number, string>;
73
+ }): void;
74
+ /**
75
+ * 靜態方法,新增單一 API 端點
76
+ * @param key
77
+ * @param endpoint
78
+ */
79
+ static addEndpoints(key: string, endpoint: ApiEndpoint): void;
80
+ /**
81
+ * 靜態方法,方便直接呼叫 API
82
+ * @param request
83
+ */
84
+ static call(request: ApiRequest): Promise<ApiResponse>;
85
+ /**
86
+ * 靜態方法,方便直接下載檔案
87
+ * @param request
88
+ */
89
+ static download(request: ApiRequest): Promise<void>;
90
+ /**
91
+ * 取得指定的 API 端點資訊
92
+ * @param endpointKey
93
+ */
94
+ getEndpoint(endpointKey: string): ApiEndpoint | undefined;
95
+ /**
96
+ * 取得完整的 API URL
97
+ * @param endpointKey
98
+ */
99
+ getFullUrl(endpointKey: string): string | undefined;
100
+ /**
101
+ * 組合完整的 API URL
102
+ * @param endpoint
103
+ */
104
+ makeBaseUrl(endpoint: ApiEndpoint): string | undefined;
105
+ /**
106
+ * 呼叫 API
107
+ * @param request
108
+ */
109
+ callApi(request: ApiRequest): Promise<ApiResponse>;
110
+ /**
111
+ * 下載檔案
112
+ * @param request
113
+ */
114
+ downloadFile(request: ApiRequest): Promise<void>;
115
+ /**
116
+ * 決定下載檔案名稱
117
+ * @param request
118
+ * @param response
119
+ */
120
+ resolveExportFileName(request: ApiRequest, response: ApiResponse): string;
121
+ /**
122
+ * 解碼 RFC 2047 編碼的字串
123
+ * @param str RFC 2047 編碼的字串
124
+ */
125
+ decodeRfc2047(str: string): string;
126
+ }
@@ -0,0 +1,57 @@
1
+ import { CMenuItem, MenuItem } from '../model/CMenuItem';
2
+ /**
3
+ * 提供選單項目的參數介面
4
+ */
5
+ type ProvideMenuByPermissionParams = {
6
+ roleCode: string;
7
+ permissions: string[];
8
+ picker?: (roleCode: string) => MenuItem[];
9
+ };
10
+ /**
11
+ * AuthorizationService 類別負責處理權限相關的邏輯
12
+ */
13
+ export declare class AuthorizationService {
14
+ /**
15
+ * 角色權限映射表
16
+ * 定義角色對應多個權限項目
17
+ * @private
18
+ */
19
+ private static _rolePermissionMap;
20
+ /**
21
+ * 選單定義映射表
22
+ * 定義不同角色對應的選單結構
23
+ * @private
24
+ */
25
+ private static _menuDefineMap;
26
+ /**
27
+ * 設定角色權限映射
28
+ * @param map 角色權限映射物件
29
+ */
30
+ static set rolePermissionMap(map: Record<string, string[]>);
31
+ /**
32
+ * 設定選單定義映射
33
+ * @param map
34
+ */
35
+ static set menuDefineMap(map: Record<string, MenuItem[]>);
36
+ /**
37
+ * 配置角色與權限關係,以及選單定義映射
38
+ * @param config 配置物件
39
+ */
40
+ static configure(config: {
41
+ rolePermissionMap?: Record<string, string[]>;
42
+ menuDefineMap: Record<string, MenuItem[]>;
43
+ }): void;
44
+ /**
45
+ * 檢查角色列表是否包含所需的權限
46
+ * @param roleCodes
47
+ * @param requiredPermission
48
+ */
49
+ static hasPermissionByRole(roleCodes: string[], requiredPermission: string): boolean;
50
+ /**
51
+ * 根據角色列表提供選單項目
52
+ * @param roleCode 角色代碼
53
+ * @param permissions 權限列表
54
+ */
55
+ static provideMenuByPermission(param: ProvideMenuByPermissionParams): CMenuItem[];
56
+ }
57
+ export {};
@@ -0,0 +1,17 @@
1
+ import { CAlertModalData } from './CAlertDefine';
2
+ type __VLS_Props = {
3
+ id?: string;
4
+ };
5
+ declare function show(data?: CAlertModalData): void;
6
+ declare function hide(): void;
7
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {
8
+ show: typeof show;
9
+ hide: typeof hide;
10
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
11
+ "c.modal.ok": (...args: any[]) => void;
12
+ "c.modal.cancel": (...args: any[]) => void;
13
+ }, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
14
+ "onC.modal.ok"?: ((...args: any[]) => any) | undefined;
15
+ "onC.modal.cancel"?: ((...args: any[]) => any) | undefined;
16
+ }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
17
+ export default _default;
@@ -0,0 +1,12 @@
1
+ export interface CAlertModalData {
2
+ title?: string;
3
+ content?: string;
4
+ onCancel?: () => void;
5
+ onOk?: () => void;
6
+ }
7
+ export declare enum CAlertModalType {
8
+ Error = "error",// 警告類型
9
+ Alert = "alert",// 警告類型
10
+ Confirm = "confirm",// 確認類型
11
+ Info = "info"
12
+ }
@@ -0,0 +1,6 @@
1
+ import { CAlertModalData } from '../components/CAlertDefine';
2
+ declare function addToast(data: CAlertModalData): void;
3
+ declare const _default: import('vue').DefineComponent<{}, {
4
+ addToast: typeof addToast;
5
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
6
+ export default _default;
@@ -0,0 +1,10 @@
1
+ type __VLS_Props = {
2
+ show?: boolean;
3
+ };
4
+ declare function showSpinner(): void;
5
+ declare function hide(): void;
6
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {
7
+ show: typeof showSpinner;
8
+ hide: typeof hide;
9
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
10
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import { ComputedRef } from 'vue';
2
+ type __VLS_Props = {
3
+ align?: 'left' | 'center' | 'right';
4
+ rowData: Record<string, any>;
5
+ cancelable?: boolean;
6
+ disableComputed?: ComputedRef<boolean>;
7
+ readMode?: boolean;
8
+ };
9
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
10
+ "update:checked": (...args: any[]) => void;
11
+ }, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
12
+ "onUpdate:checked"?: ((...args: any[]) => any) | undefined;
13
+ }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
14
+ export default _default;
@@ -0,0 +1,10 @@
1
+ type __VLS_Props = {
2
+ rowData: Record<string, any>;
3
+ dataName: string;
4
+ };
5
+ declare const _default: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
6
+ "update:textInput": (...args: any[]) => void;
7
+ }, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
8
+ "onUpdate:textInput"?: ((...args: any[]) => any) | undefined;
9
+ }>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLInputElement>;
10
+ export default _default;
@@ -0,0 +1,125 @@
1
+ import { VNode } from 'vue';
2
+ /**
3
+ * CTableColumnType 定義了表格欄位的類型
4
+ * - RowNumber: 行號類型
5
+ * - Text: 文字類型
6
+ * - Date: 日期類型
7
+ * - DateTime: 日期時間類型
8
+ * - Action: 操作類型
9
+ */
10
+ export declare enum CTableColumnType {
11
+ RowNumber = "rowNumber",// 行號類型
12
+ Text = "text",// 文字類型
13
+ TextInput = "textInput",// 文字輸入類型(可手動切換?)
14
+ Date = "date",// 日期類型
15
+ DateRange = "dateRange",// 日期範圍類型
16
+ DateTime = "datetime",// 日期時間類型
17
+ Action = "action",// 操作類型
18
+ Checkbox = "checkbox"
19
+ }
20
+ /**
21
+ * CTableColumnActionType 定義了表格欄位的操作類型
22
+ */
23
+ export declare enum CTableColumnActionType {
24
+ Edit = "edit",// 編輯操作
25
+ Delete = "delete",// 刪除操作
26
+ Review = "review",// 審核操作
27
+ Vote = "vote",// 投票操作
28
+ Check = "check"
29
+ }
30
+ /**
31
+ * CTableColumnActionParam 定義了表格欄位操作的參數
32
+ */
33
+ export interface CTableColumnActionParam {
34
+ actionType: CTableColumnActionType;
35
+ rowData: Record<string, any>;
36
+ event?: Event;
37
+ }
38
+ export interface CTableColumnActionMeta {
39
+ actionType: CTableColumnActionType;
40
+ text?: string;
41
+ cls?: string;
42
+ icon?: string;
43
+ onClick?: (p: CTableColumnActionParam) => void;
44
+ emit?: (event: string, ...args: any[]) => void;
45
+ }
46
+ /**
47
+ * CTableColumnDefine 定義了表格欄位的屬性和行為
48
+ */
49
+ export interface CTableColumnDefine {
50
+ id?: string;
51
+ type: CTableColumnType;
52
+ idName?: string;
53
+ dataName?: string;
54
+ dataNameList?: string[];
55
+ text: string;
56
+ defaultText?: string;
57
+ width?: string;
58
+ align?: 'left' | 'center' | 'right';
59
+ dataAlign?: 'left' | 'center' | 'right';
60
+ formatPattern?: string;
61
+ actionList?: CTableColumnActionMeta[];
62
+ customRender?: (rowData: Record<string, any>) => string | HTMLElement | VNode;
63
+ useHtml?: boolean;
64
+ useVNode?: boolean;
65
+ vNodeAttrs?: Record<string, any>;
66
+ }
67
+ /**
68
+ * CTableColumn 類別定義了表格欄位的屬性和行為
69
+ */
70
+ export declare class CTableColumn implements CTableColumnDefine {
71
+ id?: string;
72
+ type: CTableColumnType;
73
+ idName?: string;
74
+ dataName?: string;
75
+ dataNameList?: string[];
76
+ text: string;
77
+ defaultText?: string;
78
+ width?: string;
79
+ align?: 'left' | 'center' | 'right';
80
+ dataAlign?: 'left' | 'center' | 'right';
81
+ formatPattern?: string;
82
+ actionList?: CTableColumnActionMeta[];
83
+ defaultRender?: (rowData: Record<string, any>) => string | HTMLElement | VNode;
84
+ customRender?: (rowData: Record<string, any>) => string | HTMLElement | VNode;
85
+ useHtml: boolean;
86
+ useVNode: boolean;
87
+ vNodeAttrs?: Record<string, any>;
88
+ constructor(define: CTableColumnDefine);
89
+ static defaultIconMap: Record<CTableColumnActionType, string>;
90
+ static defaultBtnClassMap: Record<CTableColumnActionType, string>;
91
+ static configure(config: {
92
+ iconMap?: Partial<Record<CTableColumnActionType, string>>;
93
+ btnClassMap?: Partial<Record<CTableColumnActionType, string>>;
94
+ }): void;
95
+ /**
96
+ * 渲染欄位內容
97
+ * @param rowData 當前行的數據
98
+ */
99
+ render(rowData: Record<string, any>): string | HTMLElement | VNode;
100
+ /**
101
+ * 生成 th 的 class 名稱
102
+ */
103
+ thClass(): string;
104
+ /**
105
+ * 生成 td 的 class 名稱
106
+ */
107
+ tdClass(): string;
108
+ /**
109
+ * 處理欄位操作
110
+ * @private
111
+ */
112
+ private handleAction;
113
+ /**
114
+ * 生成默認渲染函數
115
+ * @private
116
+ */
117
+ private makeDefaultRender;
118
+ /**
119
+ * 根據操作類型生成按鈕的樣式和文字
120
+ * @param actionType 操作類型
121
+ * @returns {cls: string, text: string} 按鈕的樣式和文字
122
+ * @private
123
+ */
124
+ private buildActionButtonMeta;
125
+ }
@@ -2,5 +2,9 @@ import { Directive } from 'vue';
2
2
  /**
3
3
  * v-date-formatter 指令
4
4
  * 解析 ref<Date> 並格式化為文字,根據元素型態輸出
5
+ * 可以透過 attribute data-date-format 指定日期格式,預設為 'YYYY-MM-DD'
6
+ * 使用方式:
7
+ * <input type="text" v-date-formatter="dateRef" data-date-format="YYYY/MM/DD" />
8
+ * <span v-date-formatter="dateRef" data-date-format="DD-MM-YYYY"></span>
5
9
  */
6
10
  export declare const vdDateFormatter: Directive;
@@ -1,2 +1,9 @@
1
1
  import { Directive } from 'vue';
2
+ /**
3
+ * v-cf-turnstile 指令
4
+ * 用於在表單中嵌入 Cloudflare Turnstile 驗證碼
5
+ * 使用方式:
6
+ * <div v-cf-turnstile="fieldContext"></div>
7
+ * 其中 fieldContext 為 vee-validate 的 FieldContext,用於接收驗證碼 token
8
+ */
2
9
  export declare const CFTurnstileDirective: Directive;