vue-quokit 0.1.8 → 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.
Files changed (2) hide show
  1. package/dist/index.d.ts +284 -0
  2. package/package.json +5 -3
@@ -0,0 +1,284 @@
1
+ import type { Ref, ComputedRef, Reactive } from 'vue';
2
+
3
+ /* ---------- 数据结构 ---------- */
4
+
5
+ export interface ColumnDef {
6
+ field: string;
7
+ title: string;
8
+ editor: 'INPUT' | 'NUMBER' | 'SELECT' | 'TEXTAREA' | 'DATE' | 'CHECKBOX' | 'AUTO_SEQ' | 'AUTO_CALC' | string;
9
+ width: number;
10
+ dict?: string[];
11
+ formula?: string;
12
+ merge_on_group?: boolean;
13
+ dictStr?: string;
14
+ [key: string]: any;
15
+ }
16
+
17
+ export interface GroupRules {
18
+ merge_field?: string;
19
+ show_detail_subtotal?: boolean;
20
+ }
21
+
22
+ export interface SectionCell {
23
+ type: 'text' | 'image' | 'field' | 'separator';
24
+ text?: string;
25
+ field?: string;
26
+ width?: string | number;
27
+ align?: 'left' | 'center' | 'right';
28
+ bold?: boolean;
29
+ italic?: boolean;
30
+ fontSize?: number;
31
+ color?: string;
32
+ border?: { top: string; bottom: string; left: string; right: string };
33
+ colspan?: number;
34
+ rowspan?: number;
35
+ [key: string]: any;
36
+ }
37
+
38
+ export interface SectionRow {
39
+ cells: SectionCell[];
40
+ [key: string]: any;
41
+ }
42
+
43
+ export interface SummaryField {
44
+ field: string;
45
+ label: string;
46
+ type: 'MANUAL_INPUT' | 'AUTO_CALC' | 'AUTO_SUM' | string;
47
+ default?: any;
48
+ formula?: string;
49
+ [key: string]: any;
50
+ }
51
+
52
+ export interface QuokitTemplateData {
53
+ columns: ColumnDef[];
54
+ group_rules?: GroupRules | null;
55
+ header_sections?: SectionRow[];
56
+ footer_sections?: SectionRow[];
57
+ summary_fields?: SummaryField[];
58
+ }
59
+
60
+ export interface QuokitDataModel {
61
+ headerData?: Record<string, any>;
62
+ rows?: Record<string, any>[];
63
+ footerData?: Record<string, any>;
64
+ }
65
+
66
+ /* ---------- 全局配置 ---------- */
67
+
68
+ export interface TemplateColConfig {
69
+ key: string;
70
+ label: string;
71
+ width: number;
72
+ }
73
+
74
+ export interface TemplateColsConfig {
75
+ layout: 'auto' | 'fixed';
76
+ minWidth: number;
77
+ columns: TemplateColConfig[];
78
+ }
79
+
80
+ export interface QuokitUserConfig {
81
+ templateCols?: Partial<TemplateColsConfig> & {
82
+ columns?: TemplateColConfig[];
83
+ };
84
+ [key: string]: any;
85
+ }
86
+
87
+ export function setConfig(userConfig: QuokitUserConfig): void;
88
+ export function getConfig(): QuokitUserConfig;
89
+ export function resetConfig(): void;
90
+
91
+ /* ---------- Composables ---------- */
92
+
93
+ export interface UseColumnsReturn {
94
+ columns: Ref<ColumnDef[]>;
95
+ groupRules: Ref<Required<GroupRules>>;
96
+ tpl: ComputedRef<{ columns: ColumnDef[]; group_rules: GroupRules | null }>;
97
+ setColumns(raw: ColumnDef[]): void;
98
+ setGroupRules(raw: GroupRules): void;
99
+ }
100
+
101
+ export function useColumns(
102
+ initialColumns?: ColumnDef[],
103
+ initialGroupRules?: GroupRules
104
+ ): UseColumnsReturn;
105
+
106
+ export interface UseSectionsReturn {
107
+ sections: Ref<SectionRow[]>;
108
+ setSections(raw: SectionRow[]): void;
109
+ toTpl(): SectionRow[];
110
+ }
111
+
112
+ export function useSections(
113
+ initialSections?: SectionRow[]
114
+ ): UseSectionsReturn;
115
+
116
+ export interface UseSummaryReturn {
117
+ fields: Ref<SummaryField[]>;
118
+ tpl: ComputedRef<SummaryField[]>;
119
+ setFields(raw: SummaryField[]): void;
120
+ toTpl(): SummaryField[];
121
+ }
122
+
123
+ export function useSummary(initialFields?: SummaryField[]): UseSummaryReturn;
124
+
125
+ export interface PreviewDialogConfig {
126
+ title?: string;
127
+ excel?: boolean;
128
+ print?: boolean;
129
+ json?: boolean;
130
+ [key: string]: any;
131
+ }
132
+
133
+ export interface UsePreviewReturn {
134
+ open: Ref<boolean>;
135
+ current: Reactive<{
136
+ tpl: QuokitTemplateData | null;
137
+ data: QuokitDataModel | null;
138
+ config: Required<PreviewDialogConfig>;
139
+ }>;
140
+ openPreview(tpl: QuokitTemplateData, data: QuokitDataModel, config?: PreviewDialogConfig): void;
141
+ closePreview(): void;
142
+ }
143
+
144
+ export function usePreview(): UsePreviewReturn;
145
+
146
+ export function openPreview(
147
+ tpl: QuokitTemplateData,
148
+ data: QuokitDataModel,
149
+ config?: PreviewDialogConfig
150
+ ): void;
151
+
152
+ export function openTemplatePreview(
153
+ tpl: QuokitTemplateData,
154
+ config?: { title?: string }
155
+ ): void;
156
+
157
+ /* ---------- Vue 组件 ---------- */
158
+
159
+ type Comp<P = {}, X = {}> = {
160
+ __name?: string;
161
+ __props?: P;
162
+ new (): X;
163
+ };
164
+
165
+ /**
166
+ * 报价单模板设计器(整体容器,5 个 tab)
167
+ *
168
+ * @example
169
+ * ```vue
170
+ * <script setup lang="ts">
171
+ * import { ref } from 'vue';
172
+ * import { QuokitTemplate, type QuokitTemplateData } from 'vue-quokit';
173
+ *
174
+ * const tpl = ref<QuokitTemplateData>({ columns: [], group_rules: null });
175
+ * const designerRef = ref<InstanceType<typeof QuokitTemplate> | null>(null);
176
+ *
177
+ * function handleSave() {
178
+ * const json = designerRef.value?.getTemplateJSON();
179
+ * console.log(json);
180
+ * }
181
+ * </script>
182
+ *
183
+ * <template>
184
+ * <QuokitTemplate ref="designerRef" v-model:tpl="tpl" />
185
+ * </template>
186
+ * ```
187
+ */
188
+ export declare const QuokitTemplate: Comp<
189
+ { tpl?: QuokitTemplateData; breakpoint?: number },
190
+ {
191
+ /** 取当前设计器里的完整模板 JSON */
192
+ getTemplateJSON(): QuokitTemplateData;
193
+ /** 弹出帮助对话框 */
194
+ showHelp(): void;
195
+ }
196
+ >;
197
+
198
+ /**
199
+ * 报价单数据填写器
200
+ *
201
+ * @example
202
+ * ```vue
203
+ * <script setup lang="ts">
204
+ * import { ref } from 'vue';
205
+ * import { QuokitData, type QuokitTemplateData } from 'vue-quokit';
206
+ *
207
+ * const tpl = ref<QuokitTemplateData>({ columns: [], group_rules: null });
208
+ * const data = ref<Record<string, any>[]>([]);
209
+ * </script>
210
+ *
211
+ * <template>
212
+ * <QuokitData :tpl="tpl" v-model:data="data" />
213
+ * </template>
214
+ * ```
215
+ */
216
+ export declare const QuokitData: Comp<{
217
+ tpl: QuokitTemplateData;
218
+ data?: Record<string, any>[];
219
+ }>;
220
+
221
+ /**
222
+ * 报价单预览 / 导出 / 打印
223
+ *
224
+ * @example
225
+ * ```vue
226
+ * <script setup lang="ts">
227
+ * import { ref } from 'vue';
228
+ * import { QuokitSheet, type QuokitTemplateData } from 'vue-quokit';
229
+ *
230
+ * const tpl = ref<QuokitTemplateData>({ columns: [], group_rules: null });
231
+ * const data = ref<Record<string, any>[]>([]);
232
+ * const sheetRef = ref<InstanceType<typeof QuokitSheet> | null>(null);
233
+ *
234
+ * function doExport() {
235
+ * sheetRef.value?.exportExcel();
236
+ * }
237
+ * function doPrint() {
238
+ * sheetRef.value?.print();
239
+ * }
240
+ * </script>
241
+ *
242
+ * <template>
243
+ * <QuokitSheet ref="sheetRef" :tpl="tpl" :data="data" />
244
+ * </template>
245
+ * ```
246
+ */
247
+ export declare const QuokitSheet: Comp<
248
+ { tpl: QuokitTemplateData; data?: QuokitDataModel; placeholder?: string },
249
+ {
250
+ /** 导出 Excel。撑长模式下会自动加高行高。 */
251
+ exportExcel(expandRowHeight?: boolean): Promise<void>;
252
+ /** 打印报价单。竖版时 width 设为 800。 */
253
+ print(vertical?: boolean): void;
254
+ }
255
+ >;
256
+
257
+ /**
258
+ * 报价单总体预览对话框(含导出/打印/JSON查看按钮)
259
+ *
260
+ * 通常不需要直接使用,而是通过 `openPreview()` 或 `usePreview()` 来触发。
261
+ *
262
+ * @example
263
+ * ```vue
264
+ * <script setup lang="ts">
265
+ * import { ref } from 'vue';
266
+ * import { QuokitPreview, type QuokitTemplateData } from 'vue-quokit';
267
+ *
268
+ * const tpl = ref<QuokitTemplateData>({ columns: [], group_rules: null });
269
+ * const data = ref({ headerData: {}, rows: [], footerData: {} });
270
+ * const visible = ref(true);
271
+ * </script>
272
+ *
273
+ * <template>
274
+ * <QuokitPreview v-if="visible" :tpl="tpl" :data="data" :config="{ title: '我的报价单' }" @close="visible = false" />
275
+ * </template>
276
+ * ```
277
+ */
278
+ export declare const QuokitPreview: Comp<
279
+ {
280
+ tpl: QuokitTemplateData;
281
+ data?: QuokitDataModel;
282
+ config?: PreviewDialogConfig;
283
+ }
284
+ >;
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "vue-quokit",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
7
8
  "exports": {
8
9
  ".": {
9
10
  "import": "./dist/index.mjs",
10
- "require": "./dist/index.cjs"
11
+ "require": "./dist/index.cjs",
12
+ "types": "./dist/index.d.ts"
11
13
  }
12
14
  },
13
15
  "files": [
@@ -30,4 +32,4 @@
30
32
  "vite-plugin-css-injected-by-js": "^5.0.2",
31
33
  "vue": "^3.4.21"
32
34
  }
33
- }
35
+ }