ts-glitter 20.7.8 → 20.7.9

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 (30) hide show
  1. package/lowcode/Entry.js +1 -1
  2. package/lowcode/Entry.ts +1 -1
  3. package/lowcode/cms-plugin/POS-setting.js +1 -0
  4. package/lowcode/cms-plugin/POS-setting.ts +1 -0
  5. package/lowcode/cms-plugin/cms-router.js +5 -0
  6. package/lowcode/cms-plugin/cms-router.ts +5 -0
  7. package/lowcode/cms-plugin/pos-config-setting.js +591 -0
  8. package/lowcode/cms-plugin/pos-config-setting.ts +681 -0
  9. package/lowcode/cms-plugin/pos-pages/imin-module.js +176 -59
  10. package/lowcode/cms-plugin/pos-pages/imin-module.ts +708 -568
  11. package/lowcode/cms-plugin/pos-pages/payment-page.js +47 -16
  12. package/lowcode/cms-plugin/pos-pages/payment-page.ts +55 -16
  13. package/lowcode/glitterBundle/dialog/ShareDialog.js +3 -0
  14. package/lowcode/glitterBundle/dialog/ShareDialog.ts +5 -0
  15. package/lowcode/glitterBundle/dialog/dialog.js +5 -1
  16. package/lowcode/glitterBundle/dialog/dialog.ts +4 -1
  17. package/lowcode/jspage/function-page/setting_editor.js +8 -0
  18. package/lowcode/jspage/function-page/setting_editor.ts +8 -0
  19. package/lowcode/public-components/terms-related/index.js +1 -1
  20. package/lowcode/public-components/terms-related/index.ts +1 -1
  21. package/package.json +1 -1
  22. package/src/api-public/services/order-event.js +1 -1
  23. package/src/api-public/services/order-event.js.map +1 -1
  24. package/src/api-public/services/order-event.ts +1 -1
  25. package/src/api-public/services/user.js +9 -8
  26. package/src/api-public/services/user.js.map +1 -1
  27. package/src/api-public/services/user.ts +13 -13
  28. package/src/services/template.js +1 -0
  29. package/src/services/template.js.map +1 -1
  30. package/src/services/template.ts +1 -0
@@ -1,608 +1,748 @@
1
1
  //Imin機台的功能
2
2
  import { PayConfig } from './pay-config.js';
3
3
  import { PaymentPage } from './payment-page.js';
4
+ import { ApiShop } from '../../glitter-base/route/shopping.js';
5
+ import { Glitter } from '../../glitterBundle/Glitter.js';
4
6
 
5
7
  export class IminModule {
6
- public static init() {
7
- return new Promise((resolve, reject) => {
8
- (window as any).glitter.addMtScript(
9
- [
10
- 'https://oss-sg.imin.sg/web/iMinPartner/js/imin-printer.min.js',
11
- 'https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js',
12
- (window as any).glitter.root_path + 'jslib/qrcode-d.js',
13
- ],()=>{
14
- resolve(true)
15
- },()=>{
16
- resolve(false)
17
- })
18
- })
19
- }
20
- //列印發票
21
- public static async printInvoice(invoice: any, orderID: string, staff_title: string) {
22
- await IminModule.init()
23
- if ( (window.parent as any).glitter.share.PayConfig.posType === 'SUNMI') {
24
- IminModule.printInvoiceSunMi(invoice, orderID, staff_title);
25
- return;
8
+ public static init() {
9
+ return new Promise((resolve, reject) => {
10
+ (window as any).glitter.addMtScript(
11
+ [
12
+ 'https://oss-sg.imin.sg/web/iMinPartner/js/imin-printer.min.js',
13
+ 'https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js',
14
+ (window as any).glitter.root_path + 'jslib/qrcode-d.js',
15
+ ],
16
+ () => {
17
+ resolve(true);
18
+ },
19
+ () => {
20
+ resolve(false);
26
21
  }
27
- const IminPrintInstance: any = (window as any).IminPrintInstance;
22
+ );
23
+ });
24
+ }
28
25
 
29
- function generateBarcodeBase64(barcodeString: any) {
30
- const canvas = document.createElement('canvas');
31
- // 使用 JsBarcode 將條碼字串渲染到 canvas
32
- //@ts-ignore
33
- JsBarcode(canvas, barcodeString, {
34
- format: 'CODE128', // 條碼格式,可根據需求更換
35
- lineColor: '#000000', // 條碼顏色
36
- width: 2, // 條碼寬度
37
- height: 50, // 條碼高度
38
- displayValue: false, // 是否顯示條碼值
39
- });
26
+ //列印發票
27
+ public static async printInvoice(invoice: any, orderID: string, staff_title: string) {
28
+ await IminModule.init();
29
+ if ((window.parent as any).glitter.share.PayConfig.posType === 'SUNMI') {
30
+ IminModule.printInvoiceSunMi(invoice, orderID, staff_title);
31
+ return;
32
+ }
33
+ const IminPrintInstance: any = (window as any).IminPrintInstance;
40
34
 
41
- // canvas 轉換為 base64 圖片
42
- const base64String = canvas.toDataURL('image/png');
43
- console.log('Base64 Barcode:', base64String);
35
+ function generateBarcodeBase64(barcodeString: any) {
36
+ const canvas = document.createElement('canvas');
37
+ // 使用 JsBarcode 將條碼字串渲染到 canvas
38
+ //@ts-ignore
39
+ JsBarcode(canvas, barcodeString, {
40
+ format: 'CODE128', // 條碼格式,可根據需求更換
41
+ lineColor: '#000000', // 條碼顏色
42
+ width: 2, // 條碼寬度
43
+ height: 50, // 條碼高度
44
+ displayValue: false, // 是否顯示條碼值
45
+ });
44
46
 
45
- return base64String;
46
- }
47
+ // 將 canvas 轉換為 base64 圖片
48
+ const base64String = canvas.toDataURL('image/png');
49
+ console.log('Base64 Barcode:', base64String);
47
50
 
48
- //列印公司名稱
49
- await IminPrintInstance.setAlignment(1);
50
- await IminPrintInstance.setTextSize(50);
51
- await IminPrintInstance.setTextStyle(1);
52
- await IminPrintInstance.printText(PayConfig.pos_config.shop_name);
53
- await IminPrintInstance.printAndFeedPaper(20);
54
- //列印電子發票證明聯
55
- await IminPrintInstance.setAlignment(1);
56
- await IminPrintInstance.setTextSize(40);
57
- await IminPrintInstance.setTextStyle(0);
58
- await IminPrintInstance.printText('電子發票證明聯');
59
- await IminPrintInstance.printAndFeedPaper(5);
60
- //列印電子發票證明聯
61
- await IminPrintInstance.setAlignment(1);
62
- await IminPrintInstance.setTextSize(50);
63
- await IminPrintInstance.setTextStyle(0);
64
- await IminPrintInstance.printText(invoice.date);
65
- //列印電子發票號碼
66
- await IminPrintInstance.setAlignment(1);
67
- await IminPrintInstance.setTextSize(50);
68
- await IminPrintInstance.setTextStyle(0);
69
- await IminPrintInstance.printText(invoice.invoice_code);
70
- //列印日期
71
- await IminPrintInstance.printAndFeedPaper(5);
72
- await IminPrintInstance.setAlignment(0);
73
- await IminPrintInstance.setTextSize(24);
74
- await IminPrintInstance.setTextStyle(0);
75
- await IminPrintInstance.printText(invoice.create_date);
76
- //列印日期和總計
77
- await IminPrintInstance.printAndFeedPaper(5);
78
- await IminPrintInstance.setAlignment(0);
79
- await IminPrintInstance.setTextSize(24);
80
- await IminPrintInstance.setTextStyle(0);
81
- await IminPrintInstance.printText(`${invoice.random_code} ${invoice.total}`);
82
- //賣方與買方
51
+ return base64String;
52
+ }
53
+
54
+ //列印公司名稱
55
+ await IminPrintInstance.setAlignment(1);
56
+ await IminPrintInstance.setTextSize(50);
57
+ await IminPrintInstance.setTextStyle(1);
58
+ await IminPrintInstance.printText(PayConfig.pos_config.shop_name);
59
+ await IminPrintInstance.printAndFeedPaper(20);
60
+ //列印電子發票證明聯
61
+ await IminPrintInstance.setAlignment(1);
62
+ await IminPrintInstance.setTextSize(40);
63
+ await IminPrintInstance.setTextStyle(0);
64
+ await IminPrintInstance.printText('電子發票證明聯');
65
+ await IminPrintInstance.printAndFeedPaper(5);
66
+ //列印電子發票證明聯
67
+ await IminPrintInstance.setAlignment(1);
68
+ await IminPrintInstance.setTextSize(50);
69
+ await IminPrintInstance.setTextStyle(0);
70
+ await IminPrintInstance.printText(invoice.date);
71
+ //列印電子發票號碼
72
+ await IminPrintInstance.setAlignment(1);
73
+ await IminPrintInstance.setTextSize(50);
74
+ await IminPrintInstance.setTextStyle(0);
75
+ await IminPrintInstance.printText(invoice.invoice_code);
76
+ //列印日期
77
+ await IminPrintInstance.printAndFeedPaper(5);
78
+ await IminPrintInstance.setAlignment(0);
79
+ await IminPrintInstance.setTextSize(24);
80
+ await IminPrintInstance.setTextStyle(0);
81
+ await IminPrintInstance.printText(invoice.create_date);
82
+ //列印日期和總計
83
+ await IminPrintInstance.printAndFeedPaper(5);
84
+ await IminPrintInstance.setAlignment(0);
85
+ await IminPrintInstance.setTextSize(24);
86
+ await IminPrintInstance.setTextStyle(0);
87
+ await IminPrintInstance.printText(`${invoice.random_code} ${invoice.total}`);
88
+ //賣方與買方
89
+ await IminPrintInstance.printAndFeedPaper(5);
90
+ await IminPrintInstance.setAlignment(0);
91
+ await IminPrintInstance.setTextSize(24);
92
+ await IminPrintInstance.setTextStyle(0);
93
+ await IminPrintInstance.printText(`${invoice.sale_gui} ${invoice.buy_gui}`);
94
+ //列印條碼
95
+ await IminPrintInstance.printAndFeedPaper(5);
96
+ IminPrintInstance.printSingleBitmap(generateBarcodeBase64(invoice.bar_code));
97
+ setTimeout(async () => {
98
+ await IminPrintInstance.printAndFeedPaper(5);
99
+ await IminPrintInstance.setQrCodeSize(2);
100
+ await IminPrintInstance.setDoubleQRSize(4);
101
+ await IminPrintInstance.setDoubleQR1MarginLeft(10);
102
+ await IminPrintInstance.setDoubleQR2MarginLeft(520);
103
+ const ba = (new Blob([invoice.qrcode_0]).size - new Blob([invoice.qrcode_1]).size) * 1.1;
104
+ for (let a = 0; a <= ba; a++) {
105
+ invoice.qrcode_1 += '*';
106
+ }
107
+ await IminPrintInstance.printDoubleQR([invoice.qrcode_0, invoice.qrcode_1]);
108
+ await IminPrintInstance.printAndFeedPaper(100);
109
+ //列印交易明細
110
+ await IminPrintInstance.printAndFeedPaper(5);
111
+ await IminPrintInstance.setAlignment(1);
112
+ await IminPrintInstance.setTextSize(40);
113
+ await IminPrintInstance.setTextStyle(0);
114
+ await IminPrintInstance.printText('交易明細');
115
+ //列印日期
116
+ await IminPrintInstance.printAndFeedPaper(10);
117
+ await IminPrintInstance.setAlignment(0);
118
+ await IminPrintInstance.setTextSize(24);
119
+ await IminPrintInstance.setTextStyle(0);
120
+ await IminPrintInstance.printText('時間:' + invoice.create_date);
121
+ //營業人統編
122
+ await IminPrintInstance.printAndFeedPaper(5);
123
+ await IminPrintInstance.setAlignment(0);
124
+ await IminPrintInstance.setTextSize(24);
125
+ await IminPrintInstance.setTextStyle(0);
126
+ await IminPrintInstance.printText('營業人統編:' + invoice.sale_gui.replace('賣方 ', ''));
127
+ //訂單號碼
128
+ await IminPrintInstance.printAndFeedPaper(5);
129
+ await IminPrintInstance.setAlignment(0);
130
+ await IminPrintInstance.setTextSize(24);
131
+ await IminPrintInstance.setTextStyle(0);
132
+ await IminPrintInstance.printText('訂單編號:' + orderID);
133
+ //訂單號碼
134
+ await IminPrintInstance.printAndFeedPaper(5);
135
+ await IminPrintInstance.setAlignment(0);
136
+ await IminPrintInstance.setTextSize(24);
137
+ await IminPrintInstance.setTextStyle(0);
138
+ await IminPrintInstance.printText('發票號碼:' + invoice.invoice_code);
139
+ //員工
140
+ await IminPrintInstance.printAndFeedPaper(5);
141
+ await IminPrintInstance.setAlignment(0);
142
+ await IminPrintInstance.setTextSize(24);
143
+ await IminPrintInstance.setTextStyle(0);
144
+ await IminPrintInstance.printText('員工:' + staff_title);
145
+ //分隔線
146
+ await IminPrintInstance.printAndFeedPaper(30);
147
+ await IminPrintInstance.printText('品名 單價*數量 金額 ');
148
+ const pay_what = PaymentPage.stripHtmlTags(invoice.pay_detail);
149
+ for (let a = 0; a < pay_what.length; a++) {
83
150
  await IminPrintInstance.printAndFeedPaper(5);
84
- await IminPrintInstance.setAlignment(0);
151
+ await IminPrintInstance.setAlignment(a % 3);
85
152
  await IminPrintInstance.setTextSize(24);
86
153
  await IminPrintInstance.setTextStyle(0);
87
- await IminPrintInstance.printText(`${invoice.sale_gui} ${invoice.buy_gui}`);
88
- //列印條碼
89
- await IminPrintInstance.printAndFeedPaper(5);
90
- IminPrintInstance.printSingleBitmap(generateBarcodeBase64(invoice.bar_code));
91
- setTimeout(async () => {
92
- await IminPrintInstance.printAndFeedPaper(5);
93
- await IminPrintInstance.setQrCodeSize(2);
94
- await IminPrintInstance.setDoubleQRSize(4);
95
- await IminPrintInstance.setDoubleQR1MarginLeft(10);
96
- await IminPrintInstance.setDoubleQR2MarginLeft(520);
97
- const ba = (new Blob([invoice.qrcode_0]).size - (new Blob([invoice.qrcode_1]).size)) * 1.1;
98
- for (let a = 0; a <= ba; a++) {
99
- invoice.qrcode_1 += '*';
100
- }
101
- await IminPrintInstance.printDoubleQR([invoice.qrcode_0, invoice.qrcode_1]);
102
- await IminPrintInstance.printAndFeedPaper(100);
103
- //列印交易明細
104
- await IminPrintInstance.printAndFeedPaper(5);
105
- await IminPrintInstance.setAlignment(1);
106
- await IminPrintInstance.setTextSize(40);
107
- await IminPrintInstance.setTextStyle(0);
108
- await IminPrintInstance.printText('交易明細');
109
- //列印日期
110
- await IminPrintInstance.printAndFeedPaper(10);
111
- await IminPrintInstance.setAlignment(0);
112
- await IminPrintInstance.setTextSize(24);
113
- await IminPrintInstance.setTextStyle(0);
114
- await IminPrintInstance.printText('時間:' + invoice.create_date);
115
- //營業人統編
116
- await IminPrintInstance.printAndFeedPaper(5);
117
- await IminPrintInstance.setAlignment(0);
118
- await IminPrintInstance.setTextSize(24);
119
- await IminPrintInstance.setTextStyle(0);
120
- await IminPrintInstance.printText('營業人統編:' + invoice.sale_gui.replace('賣方 ', ''));
121
- //訂單號碼
122
- await IminPrintInstance.printAndFeedPaper(5);
123
- await IminPrintInstance.setAlignment(0);
124
- await IminPrintInstance.setTextSize(24);
125
- await IminPrintInstance.setTextStyle(0);
126
- await IminPrintInstance.printText('訂單編號:' + orderID);
127
- //訂單號碼
128
- await IminPrintInstance.printAndFeedPaper(5);
129
- await IminPrintInstance.setAlignment(0);
130
- await IminPrintInstance.setTextSize(24);
131
- await IminPrintInstance.setTextStyle(0);
132
- await IminPrintInstance.printText('發票號碼:' + invoice.invoice_code);
133
- //員工
134
- await IminPrintInstance.printAndFeedPaper(5);
135
- await IminPrintInstance.setAlignment(0);
136
- await IminPrintInstance.setTextSize(24);
137
- await IminPrintInstance.setTextStyle(0);
138
- await IminPrintInstance.printText('員工:' + staff_title);
139
- //分隔線
140
- await IminPrintInstance.printAndFeedPaper(30);
141
- await IminPrintInstance.printText('品名 單價*數量 金額 ');
142
- const pay_what = PaymentPage.stripHtmlTags(invoice.pay_detail);
143
- for (let a = 0; a < pay_what.length; a++) {
144
- await IminPrintInstance.printAndFeedPaper(5);
145
- await IminPrintInstance.setAlignment(a % 3);
146
- await IminPrintInstance.setTextSize(24);
147
- await IminPrintInstance.setTextStyle(0);
148
- await IminPrintInstance.printText(pay_what[a]);
149
- }
150
- await IminPrintInstance.setAlignment(0);
151
- let tempDiv = document.createElement('div');
152
- // 设置其内容为给定的HTML字符串
153
- tempDiv.innerHTML = invoice.pay_detail_footer;
154
- const text = `${tempDiv.querySelector('.invoice-detail-sum')!!.children[0].textContent}
154
+ await IminPrintInstance.printText(pay_what[a]);
155
+ }
156
+ await IminPrintInstance.setAlignment(0);
157
+ let tempDiv = document.createElement('div');
158
+ // 设置其内容为给定的HTML字符串
159
+ tempDiv.innerHTML = invoice.pay_detail_footer;
160
+ const text = `${tempDiv.querySelector('.invoice-detail-sum')!!.children[0].textContent}
155
161
  ${tempDiv.querySelector('.invoice-detail-sum')!!.children[1].textContent}
156
162
  ${tempDiv.querySelector('.invoice-detail-sum')!!.children[2].textContent!.replace(/ /g, '')}`;
157
- await IminPrintInstance.printText(text);
158
- await IminPrintInstance.printAndFeedPaper(100);
159
- }, 1000);
160
- }
163
+ await IminPrintInstance.printText(text);
164
+ await IminPrintInstance.printAndFeedPaper(100);
165
+ }, 1000);
166
+ }
161
167
 
162
- //SUMI的發票列印
163
- public static async printInvoiceSunMi(invoice: any, orderID: string, staff_title: string) {
164
- const glitter = (window as any).glitter;
168
+ //SUMI的發票列印
169
+ public static async printInvoiceSunMi(invoice: any, orderID: string, staff_title: string) {
170
+ const glitter = (window as any).glitter;
165
171
 
166
- async function mergeQRCodes(code: string[]) {
167
- return new Promise(async (resolve, reject) => {
168
- let size = 190; // QR Code 尺寸
169
- let gap = 15; // 間距
172
+ async function mergeQRCodes(code: string[]) {
173
+ return new Promise(async (resolve, reject) => {
174
+ let size = 190; // QR Code 尺寸
175
+ let gap = 15; // 間距
170
176
 
171
- let qr1 = await generateQRCode(code[0], size);
172
- let qr2 = await generateQRCode(code[1], size);
177
+ let qr1 = await generateQRCode(code[0], size);
178
+ let qr2 = await generateQRCode(code[1], size);
173
179
 
174
- let canvas = document.createElement('canvas');
175
- let ctx: any = canvas.getContext('2d');
180
+ let canvas = document.createElement('canvas');
181
+ let ctx: any = canvas.getContext('2d');
176
182
 
177
- let img1: any = new Image();
178
- let img2: any = new Image();
183
+ let img1: any = new Image();
184
+ let img2: any = new Image();
179
185
 
180
- img1.src = qr1;
181
- img2.src = qr2;
186
+ img1.src = qr1;
187
+ img2.src = qr2;
182
188
 
183
- img1.onload = () => {
184
- img2.onload = () => {
185
- canvas.width = size * 2 + gap;
186
- canvas.height = size;
187
- ctx.fillStyle = 'white';
188
- ctx.fillRect(0, 0, canvas.width, canvas.height);
189
- ctx.drawImage(img1, 0, 0, size, size);
190
- ctx.drawImage(img2, size + gap, 0, size, size);
191
- resolve(canvas.toDataURL('image/png').split('base64,')[1]);
189
+ img1.onload = () => {
190
+ img2.onload = () => {
191
+ canvas.width = size * 2 + gap;
192
+ canvas.height = size;
193
+ ctx.fillStyle = 'white';
194
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
195
+ ctx.drawImage(img1, 0, 0, size, size);
196
+ ctx.drawImage(img2, size + gap, 0, size, size);
197
+ resolve(canvas.toDataURL('image/png').split('base64,')[1]);
192
198
 
193
- console.log(`two-qrcode=>`, canvas.toDataURL('image/png'));
194
- };
195
- };
196
- });
197
- }
199
+ console.log(`two-qrcode=>`, canvas.toDataURL('image/png'));
200
+ };
201
+ };
202
+ });
203
+ }
198
204
 
199
- function generateQRCode(text: string, size: number) {
200
- return new Promise((resolve) => {
201
- try {
202
- const div = document.createElement('div');
203
- //@ts-ignore
204
- var qrcode_R = new QRCode(div, {
205
- text: text,
206
- width: 50,
207
- height: 50,
208
- colorDark: "#000000",
209
- colorLight: "#ffffff",
210
- //@ts-ignore
211
- correctLevel: QRCode.CorrectLevel.M
212
- });
213
- // 等待 QR Code 生成完畢
214
- setTimeout(() => {
215
- resolve(div.querySelector('canvas')!!.toDataURL('image/png'));
216
- }, 200); // 延遲等待 QRCode 完成渲染
217
- }catch (e) {
218
- console.log('qr生成失敗')
219
- console.log('qr生成失敗',e)
220
- }
221
- });
205
+ function generateQRCode(text: string, size: number) {
206
+ return new Promise(resolve => {
207
+ try {
208
+ const div = document.createElement('div');
209
+ //@ts-ignore
210
+ var qrcode_R = new QRCode(div, {
211
+ text: text,
212
+ width: 50,
213
+ height: 50,
214
+ colorDark: '#000000',
215
+ colorLight: '#ffffff',
216
+ //@ts-ignore
217
+ correctLevel: QRCode.CorrectLevel.M,
218
+ });
219
+ // 等待 QR Code 生成完畢
220
+ setTimeout(() => {
221
+ resolve(div.querySelector('canvas')!!.toDataURL('image/png'));
222
+ }, 200); // 延遲等待 QRCode 完成渲染
223
+ } catch (e) {
224
+ console.log('qr生成失敗');
225
+ console.log('qr生成失敗', e);
222
226
  }
223
- mergeQRCodes([invoice.qrcode_0, invoice.qrcode_1]).then((res) => {
224
- console.log(`two-qrcode=>`, res);
225
- glitter.runJsInterFace('start-print', {
226
- 'command-list': [
227
- {
228
- key: 'print-text', data: {
229
- style: 'bold',
230
- text: PayConfig.pos_config.shop_name,
231
- font_size: 50,
232
- align: 1,
233
- },
234
- },
235
- {
236
- key: 'print-space', data: {
237
- space: 20,
238
- },
239
- },
240
- {
241
- key: 'print-text', data: {
242
- style: 'normal',
243
- text: '電子發票證明聯',
244
- font_size: 40,
245
- align: 1,
246
- },
247
- },
248
- {
249
- key: 'print-text', data: {
250
- style: 'normal',
251
- text: invoice.date,
252
- font_size: 50,
253
- align: 1,
254
- },
255
- },
256
- {
257
- key: 'print-text', data: {
258
- style: 'normal',
259
- text: invoice.invoice_code,
260
- font_size: 50,
261
- align: 1,
262
- },
263
- },
264
- {
265
- key: 'print-space', data: {
266
- space: 10,
267
- },
268
- },
269
- {
270
- key: 'print-text', data: {
271
- style: 'normal',
272
- text: invoice.create_date,
273
- font_size: 24,
274
- align: 0,
275
- },
276
- },
277
- {
278
- key: 'print-space', data: {
279
- space: 5,
280
- },
281
- },
282
- {
283
- key: 'print-text', data: {
284
- style: 'normal',
285
- text: `${invoice.random_code} ${invoice.total}`,
286
- font_size: 24,
287
- align: 0,
288
- },
289
- },
290
- {
291
- key: 'print-space', data: {
292
- space: 5,
293
- },
294
- },
295
- {
296
- key: 'print-text', data: {
297
- style: 'normal',
298
- text: `${invoice.sale_gui} ${invoice.buy_gui}`,
299
- font_size: 24,
300
- align: 0,
301
- },
302
- },
303
- {
304
- key: 'print-space', data: {
305
- space: 15,
306
- },
307
- },
308
- {
309
- key: 'barcode', data: {
310
- text: invoice.bar_code,
311
- height: 50,
312
- width: 384,
313
- },
314
- },
315
- {
316
- key: 'print-space', data: {
317
- space: 15,
318
- },
319
- },
320
- {
321
- key: 'print-bitmap', data: {
322
- base64: res,
323
- height: 150,
324
- width: 350,
325
- },
326
- },
327
- {
328
- key: 'print-space', data: {
329
- space: 100,
330
- },
331
- },
332
- {
333
- key: 'print-text', data: {
334
- style: 'normal',
335
- text: '交易明細',
336
- font_size: 40,
337
- align: 1,
338
- },
339
- },
340
- {
341
- key: 'print-space', data: {
342
- space: 5,
343
- },
344
- },
345
- {
346
- key: 'print-text', data: {
347
- style: 'normal',
348
- text: '時間:' + invoice.create_date,
349
- font_size: 24,
350
- align: 0,
351
- },
352
- },
353
- {
354
- key: 'print-space', data: {
355
- space: 5,
356
- },
357
- },
358
- {
359
- key: 'print-text', data: {
360
- style: 'normal',
361
- text: '營業人統編:' + invoice.sale_gui.replace('賣方 ', ''),
362
- font_size: 24,
363
- align: 0,
364
- },
365
- },
366
- {
367
- key: 'print-space', data: {
368
- space: 5,
369
- },
370
- },
371
- {
372
- key: 'print-text', data: {
373
- style: 'normal',
374
- text: '訂單編號:' + orderID,
375
- font_size: 24,
376
- align: 0,
377
- },
378
- },
379
- {
380
- key: 'print-space', data: {
381
- space: 5,
382
- },
383
- },
384
- {
385
- key: 'print-text', data: {
386
- style: 'normal',
387
- text: '發票號碼:' + invoice.invoice_code,
388
- font_size: 24,
389
- align: 0,
390
- },
391
- },
392
- {
393
- key: 'print-space', data: {
394
- space: 5,
395
- },
396
- },
397
- {
398
- key: 'print-text', data: {
399
- style: 'normal',
400
- text: '員工:' + staff_title,
401
- font_size: 24,
402
- align: 0,
403
- },
404
- },
405
- {
406
- key: 'print-space', data: {
407
- space: 20,
408
- },
409
- },
410
- {
411
- key: 'print-text', data: {
412
- style: 'normal',
413
- text: '品名 單價*數量 金額',
414
- font_size: 24,
415
- align: 0,
416
- },
417
- },
418
- ...(() => {
419
- let b: any = [];
420
- const pay_what = PaymentPage.stripHtmlTags(invoice.pay_detail);
421
- for (let a = 0; a < pay_what.length; a++) {
422
- b.push({
423
- key: 'print-text', data: {
424
- style: 'normal',
425
- text: pay_what[a],
426
- font_size: 24,
427
- align: a % 3,
428
- },
429
- });
430
- // await IminPrintInstance.printAndFeedPaper(5);
431
- // await IminPrintInstance.setAlignment(a % 3);
432
- // await IminPrintInstance.setTextSize(24);
433
- // await IminPrintInstance.setTextStyle(0);
434
- // await IminPrintInstance.printText(pay_what[a]);
435
- }
436
- return b;
437
- })(),
438
- {
439
- key: 'print-space', data: {
440
- space: 5,
441
- },
442
- },
443
- ...(() => {
444
- const c: any = [];
445
- let tempDiv = document.createElement('div');
446
- // 设置其内容为给定的HTML字符串
447
- tempDiv.innerHTML = invoice.pay_detail_footer;
448
- c.push({
449
- key: 'print-text', data: {
450
- style: 'normal',
451
- text: tempDiv.querySelector('.invoice-detail-sum')!!.children[0].textContent,
452
- font_size: 24,
453
- align: 0,
454
- },
455
- });
456
- c.push({
457
- key: 'print-space', data: {
458
- space: 5,
459
- },
460
- });
461
- c.push({
462
- key: 'print-text', data: {
463
- style: 'normal',
464
- text: tempDiv.querySelector('.invoice-detail-sum')!!.children[1].textContent,
465
- font_size: 24,
466
- align: 0,
467
- },
468
- });
469
- c.push({
470
- key: 'print-space', data: {
471
- space: 20,
472
- },
473
- });
474
- c.push({
475
- key: 'print-text', data: {
476
- style: 'normal',
477
- text: tempDiv.querySelector('.invoice-detail-sum')!!.children[2].textContent,
478
- font_size: 24,
479
- align: 0,
480
- },
481
- });
482
- return c;
483
- })(),
484
- {
485
- key: 'print-space', data: {
486
- space: 150,
487
- },
488
- },
489
- ],
490
- }, () => {
227
+ });
228
+ }
491
229
 
492
- }, {});
230
+ mergeQRCodes([invoice.qrcode_0, invoice.qrcode_1]).then(res => {
231
+ console.log(`two-qrcode=>`, res);
232
+ glitter.runJsInterFace(
233
+ 'start-print',
234
+ {
235
+ 'command-list': [
236
+ {
237
+ key: 'print-text',
238
+ data: {
239
+ style: 'bold',
240
+ text: PayConfig.pos_config.shop_name,
241
+ font_size: 50,
242
+ align: 1,
243
+ },
244
+ },
245
+ {
246
+ key: 'print-space',
247
+ data: {
248
+ space: 20,
249
+ },
250
+ },
251
+ {
252
+ key: 'print-text',
253
+ data: {
254
+ style: 'normal',
255
+ text: '電子發票證明聯',
256
+ font_size: 40,
257
+ align: 1,
258
+ },
259
+ },
260
+ {
261
+ key: 'print-text',
262
+ data: {
263
+ style: 'normal',
264
+ text: invoice.date,
265
+ font_size: 50,
266
+ align: 1,
267
+ },
268
+ },
269
+ {
270
+ key: 'print-text',
271
+ data: {
272
+ style: 'normal',
273
+ text: invoice.invoice_code,
274
+ font_size: 50,
275
+ align: 1,
276
+ },
277
+ },
278
+ {
279
+ key: 'print-space',
280
+ data: {
281
+ space: 10,
282
+ },
283
+ },
284
+ {
285
+ key: 'print-text',
286
+ data: {
287
+ style: 'normal',
288
+ text: invoice.create_date,
289
+ font_size: 24,
290
+ align: 0,
291
+ },
292
+ },
293
+ {
294
+ key: 'print-space',
295
+ data: {
296
+ space: 5,
297
+ },
298
+ },
299
+ {
300
+ key: 'print-text',
301
+ data: {
302
+ style: 'normal',
303
+ text: `${invoice.random_code} ${invoice.total}`,
304
+ font_size: 24,
305
+ align: 0,
306
+ },
307
+ },
308
+ {
309
+ key: 'print-space',
310
+ data: {
311
+ space: 5,
312
+ },
313
+ },
314
+ {
315
+ key: 'print-text',
316
+ data: {
317
+ style: 'normal',
318
+ text: `${invoice.sale_gui} ${invoice.buy_gui}`,
319
+ font_size: 24,
320
+ align: 0,
321
+ },
322
+ },
323
+ {
324
+ key: 'print-space',
325
+ data: {
326
+ space: 15,
327
+ },
328
+ },
329
+ {
330
+ key: 'barcode',
331
+ data: {
332
+ text: invoice.bar_code,
333
+ height: 50,
334
+ width: 384,
335
+ },
336
+ },
337
+ {
338
+ key: 'print-space',
339
+ data: {
340
+ space: 15,
341
+ },
342
+ },
343
+ {
344
+ key: 'print-bitmap',
345
+ data: {
346
+ base64: res,
347
+ height: 150,
348
+ width: 350,
349
+ },
350
+ },
351
+ {
352
+ key: 'print-space',
353
+ data: {
354
+ space: 100,
355
+ },
356
+ },
357
+ {
358
+ key: 'print-text',
359
+ data: {
360
+ style: 'normal',
361
+ text: '交易明細',
362
+ font_size: 40,
363
+ align: 1,
364
+ },
365
+ },
366
+ {
367
+ key: 'print-space',
368
+ data: {
369
+ space: 5,
370
+ },
371
+ },
372
+ {
373
+ key: 'print-text',
374
+ data: {
375
+ style: 'normal',
376
+ text: '時間:' + invoice.create_date,
377
+ font_size: 24,
378
+ align: 0,
379
+ },
380
+ },
381
+ {
382
+ key: 'print-space',
383
+ data: {
384
+ space: 5,
385
+ },
386
+ },
387
+ {
388
+ key: 'print-text',
389
+ data: {
390
+ style: 'normal',
391
+ text: '營業人統編:' + invoice.sale_gui.replace('賣方 ', ''),
392
+ font_size: 24,
393
+ align: 0,
394
+ },
395
+ },
396
+ {
397
+ key: 'print-space',
398
+ data: {
399
+ space: 5,
400
+ },
401
+ },
402
+ {
403
+ key: 'print-text',
404
+ data: {
405
+ style: 'normal',
406
+ text: '訂單編號:' + orderID,
407
+ font_size: 24,
408
+ align: 0,
409
+ },
410
+ },
411
+ {
412
+ key: 'print-space',
413
+ data: {
414
+ space: 5,
415
+ },
416
+ },
417
+ {
418
+ key: 'print-text',
419
+ data: {
420
+ style: 'normal',
421
+ text: '發票號碼:' + invoice.invoice_code,
422
+ font_size: 24,
423
+ align: 0,
424
+ },
425
+ },
426
+ {
427
+ key: 'print-space',
428
+ data: {
429
+ space: 5,
430
+ },
431
+ },
432
+ {
433
+ key: 'print-text',
434
+ data: {
435
+ style: 'normal',
436
+ text: '員工:' + staff_title,
437
+ font_size: 24,
438
+ align: 0,
439
+ },
440
+ },
441
+ {
442
+ key: 'print-space',
443
+ data: {
444
+ space: 20,
445
+ },
446
+ },
447
+ {
448
+ key: 'print-text',
449
+ data: {
450
+ style: 'normal',
451
+ text: '品名 單價*數量 金額',
452
+ font_size: 24,
453
+ align: 0,
454
+ },
455
+ },
456
+ ...(() => {
457
+ let b: any = [];
458
+ const pay_what = PaymentPage.stripHtmlTags(invoice.pay_detail);
459
+ for (let a = 0; a < pay_what.length; a++) {
460
+ b.push({
461
+ key: 'print-text',
462
+ data: {
463
+ style: 'normal',
464
+ text: pay_what[a],
465
+ font_size: 24,
466
+ align: a % 3,
467
+ },
468
+ });
469
+ // await IminPrintInstance.printAndFeedPaper(5);
470
+ // await IminPrintInstance.setAlignment(a % 3);
471
+ // await IminPrintInstance.setTextSize(24);
472
+ // await IminPrintInstance.setTextStyle(0);
473
+ // await IminPrintInstance.printText(pay_what[a]);
474
+ }
475
+ return b;
476
+ })(),
477
+ {
478
+ key: 'print-space',
479
+ data: {
480
+ space: 5,
481
+ },
482
+ },
483
+ ...(() => {
484
+ const c: any = [];
485
+ let tempDiv = document.createElement('div');
486
+ // 设置其内容为给定的HTML字符串
487
+ tempDiv.innerHTML = invoice.pay_detail_footer;
488
+ c.push({
489
+ key: 'print-text',
490
+ data: {
491
+ style: 'normal',
492
+ text: tempDiv.querySelector('.invoice-detail-sum')!!.children[0].textContent,
493
+ font_size: 24,
494
+ align: 0,
495
+ },
496
+ });
497
+ c.push({
498
+ key: 'print-space',
499
+ data: {
500
+ space: 5,
501
+ },
502
+ });
503
+ c.push({
504
+ key: 'print-text',
505
+ data: {
506
+ style: 'normal',
507
+ text: tempDiv.querySelector('.invoice-detail-sum')!!.children[1].textContent,
508
+ font_size: 24,
509
+ align: 0,
510
+ },
511
+ });
512
+ c.push({
513
+ key: 'print-space',
514
+ data: {
515
+ space: 20,
516
+ },
517
+ });
518
+ c.push({
519
+ key: 'print-text',
520
+ data: {
521
+ style: 'normal',
522
+ text: tempDiv.querySelector('.invoice-detail-sum')!!.children[2].textContent,
523
+ font_size: 24,
524
+ align: 0,
525
+ },
526
+ });
527
+ return c;
528
+ })(),
529
+ {
530
+ key: 'print-space',
531
+ data: {
532
+ space: 150,
533
+ },
534
+ },
535
+ ],
536
+ },
537
+ () => {},
538
+ {}
539
+ );
540
+ });
541
+ }
493
542
 
543
+ public static async printCodeSumi(code: string) {
544
+ const glitter = (window as any).glitter;
545
+ glitter.runJsInterFace(
546
+ 'start-print',
547
+ {
548
+ 'command-list': [
549
+ {
550
+ key: 'barcode',
551
+ data: {
552
+ text: code,
553
+ height: 50,
554
+ width: 384,
555
+ },
556
+ },
557
+ {
558
+ key: 'print-space',
559
+ data: {
560
+ space: 150,
561
+ },
562
+ },
563
+ ],
564
+ },
565
+ () => {},
566
+ {}
567
+ );
568
+ }
494
569
 
495
- });
496
- }
570
+ public static async printQrCodeSumi(code: string) {
571
+ const glitter = (window as any).glitter;
572
+ glitter.addMtScript(
573
+ [
574
+ 'https://oss-sg.imin.sg/web/iMinPartner/js/imin-printer.min.js',
575
+ 'https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js',
576
+ glitter.root_path + 'jslib/qrcode-d.js',
577
+ ],
578
+ () => {
579
+ function generateQRCode(text: string, size: number) {
580
+ return new Promise(resolve => {
581
+ try {
582
+ const div = document.createElement('div');
583
+ //@ts-ignore
584
+ var qrcode_R = new QRCode(div, {
585
+ text: text,
586
+ width: 100,
587
+ height: 100,
588
+ colorDark: '#000000',
589
+ colorLight: '#ffffff',
590
+ //@ts-ignore
591
+ correctLevel: QRCode.CorrectLevel.M,
592
+ });
593
+ // 等待 QR Code 生成完畢
594
+ setTimeout(() => {
595
+ resolve(div.querySelector('canvas')!!.toDataURL('image/png'));
596
+ }, 200); // 延遲等待 QRCode 完成渲染
597
+ } catch (e) {
598
+ console.log('qr生成失敗');
599
+ console.log('qr生成失敗', e);
600
+ }
601
+ });
602
+ }
497
603
 
498
- public static async printCodeSumi(code: string) {
499
- const glitter = (window as any).glitter;
500
- glitter.runJsInterFace('start-print', {
501
- 'command-list': [
604
+ generateQRCode(code, 185).then((res: any) => {
605
+ console.log(`two-qrcode=>`, res);
606
+ glitter.runJsInterFace(
607
+ 'start-print',
608
+ {
609
+ 'command-list': [
502
610
  {
503
- key: 'barcode', data: {
504
- text: code,
505
- height: 50,
506
- width: 384,
507
- },
611
+ key: 'print-bitmap',
612
+ data: {
613
+ base64: res.split('base64,')[1],
614
+ height: 185,
615
+ width: 185,
616
+ },
508
617
  },
509
618
  {
510
- key: 'print-space', data: {
511
- space: 150,
512
- },
619
+ key: 'print-space',
620
+ data: {
621
+ space: 150,
622
+ },
513
623
  },
514
- ],
515
- }, () => {
516
-
517
- }, {});
518
- }
519
-
520
- public static async printQrCodeSumi(code: string) {
521
- const glitter = (window as any).glitter;
522
- glitter.addMtScript(
523
- [
524
- 'https://oss-sg.imin.sg/web/iMinPartner/js/imin-printer.min.js',
525
- 'https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js',
526
- glitter.root_path + 'jslib/qrcode-d.js',
527
- ],
528
- () => {
529
-
530
- function generateQRCode(text: string, size: number) {
531
- return new Promise((resolve) => {
532
- try {
533
- const div = document.createElement('div');
534
- //@ts-ignore
535
- var qrcode_R = new QRCode(div, {
536
- text: text,
537
- width: 100,
538
- height: 100,
539
- colorDark: "#000000",
540
- colorLight: "#ffffff",
541
- //@ts-ignore
542
- correctLevel: QRCode.CorrectLevel.M
543
- });
544
- // 等待 QR Code 生成完畢
545
- setTimeout(() => {
546
-
547
- resolve(div.querySelector('canvas')!!.toDataURL('image/png'));
548
- }, 200); // 延遲等待 QRCode 完成渲染
549
- }catch (e) {
550
- console.log('qr生成失敗')
551
- console.log('qr生成失敗',e)
552
- }
553
- });
554
- }
624
+ ],
625
+ },
626
+ () => {},
627
+ {}
628
+ );
629
+ });
630
+ },
631
+ () => {}
632
+ );
633
+ }
555
634
 
556
- generateQRCode(code, 185).then((res: any) => {
557
- console.log(`two-qrcode=>`, res);
558
- glitter.runJsInterFace('start-print', {
559
- 'command-list': [
560
- {
561
- key: 'print-bitmap', data: {
562
- base64: res.split('base64,')[1],
563
- height: 185,
564
- width: 185,
565
- },
566
- },
567
- {
568
- key: 'print-space', data: {
569
- space: 150,
570
- },
571
- },
572
- ],
573
- }, () => {
635
+ //列印QRCODE
636
+ public static async printCode(code: string) {
637
+ const IminPrintInstance: any = (window.parent as any).IminPrintInstance;
574
638
 
575
- }, {});
576
- });
577
- },
578
- () => {
579
- },
580
- );
639
+ function generateBarcodeBase64(barcodeString: any) {
640
+ const canvas = (window.parent as any).document.createElement('canvas');
641
+ // 使用 JsBarcode 將條碼字串渲染到 canvas
642
+ //@ts-ignore
643
+ (window.parent as any).JsBarcode(canvas, barcodeString, {
644
+ format: 'CODE128', // 條碼格式,可根據需求更換
645
+ lineColor: '#000000', // 條碼顏色
646
+ width: 2, // 條碼寬度
647
+ height: 50, // 條碼高度
648
+ displayValue: false, // 是否顯示條碼值
649
+ });
650
+ // 將 canvas 轉換為 base64 圖片
651
+ const base64String = canvas.toDataURL('image/png');
652
+ console.log('Base64 Barcode:', base64String);
653
+ return base64String;
581
654
  }
582
655
 
656
+ IminPrintInstance.printSingleBitmap(generateBarcodeBase64(code));
657
+ await IminPrintInstance.printAndFeedPaper(70);
658
+ }
583
659
 
584
- //列印QRCODE
585
- public static async printCode(code: string) {
586
- const IminPrintInstance: any = (window.parent as any).IminPrintInstance;
587
-
588
- function generateBarcodeBase64(barcodeString: any) {
589
- const canvas = (window.parent as any).document.createElement('canvas');
590
- // 使用 JsBarcode 將條碼字串渲染到 canvas
591
- //@ts-ignore
592
- (window.parent as any).JsBarcode(canvas, barcodeString, {
593
- format: 'CODE128', // 條碼格式,可根據需求更換
594
- lineColor: '#000000', // 條碼顏色
595
- width: 2, // 條碼寬度
596
- height: 50, // 條碼高度
597
- displayValue: false, // 是否顯示條碼值
598
- });
599
- // canvas 轉換為 base64 圖片
600
- const base64String = canvas.toDataURL('image/png');
601
- console.log('Base64 Barcode:', base64String);
602
- return base64String;
603
- }
660
+ public static async printTransactionDetails(orderID: string, invoice?: any, staff_title?: string) {
661
+ await IminModule.init();
662
+ const IminPrintInstance: any = (window as any).IminPrintInstance;
663
+ const od = (
664
+ await ApiShop.getOrder({
665
+ limit: 1,
666
+ page: 0,
667
+ data_from: 'user',
668
+ search: orderID,
669
+ searchType: 'cart_token',
670
+ })
671
+ ).response.data[0];
672
+ console.log(`order_data==>`, od);
673
+ if ((window.parent as any).glitter.share.PayConfig.posType === 'SUNMI') {
674
+ } else {
675
+ async function nextLine24(align: number) {
676
+ await IminPrintInstance.printAndFeedPaper(5);
677
+ await IminPrintInstance.setAlignment(align);
678
+ await IminPrintInstance.setTextSize(24);
679
+ await IminPrintInstance.setTextStyle(0);
680
+ }
681
+ //列印公司名稱
682
+ await IminPrintInstance.setAlignment(1);
683
+ await IminPrintInstance.setTextSize(50);
684
+ await IminPrintInstance.setTextStyle(1);
685
+ await IminPrintInstance.printText(PayConfig.pos_config.shop_name);
686
+ await IminPrintInstance.printAndFeedPaper(20);
687
+ //列印交易明細
688
+ await IminPrintInstance.printAndFeedPaper(5);
689
+ await IminPrintInstance.setAlignment(1);
690
+ await IminPrintInstance.setTextSize(40);
691
+ await IminPrintInstance.setTextStyle(0);
692
+ if(PayConfig.pos_config.pos_support_finction.includes("order_sort")){
693
+ await IminPrintInstance.printText(`取餐號碼 : ${od.orderData.user_info.shipment_number}`);
694
+ }else{
695
+ await IminPrintInstance.printText('交易明細');
696
+ }
604
697
 
605
- IminPrintInstance.printSingleBitmap(generateBarcodeBase64(code));
606
- await IminPrintInstance.printAndFeedPaper(70);
698
+ //列印日期
699
+ await IminPrintInstance.printAndFeedPaper(5);
700
+ await nextLine24(0);
701
+ await IminPrintInstance.printText(
702
+ '時間:' + Glitter.glitter.ut.dateFormat(new Date(od.created_time), 'yyyy-MM-dd hh:mm:ss')
703
+ );
704
+ //營業人統編
705
+ if (invoice) {
706
+ await nextLine24(0);
707
+ await IminPrintInstance.printText('營業人統編:' + invoice.sale_gui.replace('賣方 ', ''));
708
+ }
709
+ //訂單號碼
710
+ await nextLine24(0);
711
+ await IminPrintInstance.printText('訂單編號:' + orderID);
712
+ //發票號碼
713
+ if (invoice) {
714
+ await nextLine24(0);
715
+ await IminPrintInstance.printText('發票號碼:' + invoice.invoice_code);
716
+ }
717
+ //員工
718
+ await nextLine24(0);
719
+ await IminPrintInstance.printText('員工:' + staff_title);
720
+ //分隔線
721
+ await IminPrintInstance.printAndFeedPaper(30);
722
+ await IminPrintInstance.printText('品名 單價*數量 金額 ');
723
+ for (const b of od.orderData.lineItems) {
724
+ //品名
725
+ await nextLine24(0);
726
+ await IminPrintInstance.printText(b.title);
727
+ //單價*數量
728
+ await nextLine24(1);
729
+ await IminPrintInstance.printText(`${b.sale_price.toLocaleString()} * ${b.count}`);
730
+ //金額
731
+ await nextLine24(2);
732
+ await IminPrintInstance.printText(b.sale_price);
733
+ }
734
+ await nextLine24(0);
735
+ await IminPrintInstance.printText(`折扣 ${od.orderData.discount.toLocaleString()}`);
736
+ await nextLine24(0);
737
+ await IminPrintInstance.printText(`合計 ${od.orderData.lineItems.length} 項`);
738
+ await nextLine24(0);
739
+ await IminPrintInstance.printText(`總計 $${od.total.toLocaleString()}`);
740
+ await nextLine24(0);
741
+ if (od.orderData.user_info.note) {
742
+ await IminPrintInstance.printText(`備註`);
743
+ await IminPrintInstance.printText(od.orderData.user_info.note);
744
+ }
745
+ await IminPrintInstance.printAndFeedPaper(140);
607
746
  }
608
- }
747
+ }
748
+ }