ts-glitter 18.5.6 → 18.5.7

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/lowcode/Entry.js CHANGED
@@ -131,7 +131,7 @@ export class Entry {
131
131
  }
132
132
  window.renderClock = (_b = window.renderClock) !== null && _b !== void 0 ? _b : createClock();
133
133
  console.log(`Entry-time:`, window.renderClock.stop());
134
- glitter.share.editerVersion = 'V_18.5.6';
134
+ glitter.share.editerVersion = 'V_18.5.7';
135
135
  glitter.share.start = new Date();
136
136
  const vm = { appConfig: [] };
137
137
  window.saasConfig = {
package/lowcode/Entry.ts CHANGED
@@ -131,7 +131,7 @@ export class Entry {
131
131
  }
132
132
  (window as any).renderClock = (window as any).renderClock ?? createClock();
133
133
  console.log(`Entry-time:`, (window as any).renderClock.stop());
134
- glitter.share.editerVersion = 'V_18.5.6';
134
+ glitter.share.editerVersion = 'V_18.5.7';
135
135
  glitter.share.start = new Date();
136
136
  const vm = { appConfig: [] };
137
137
  (window as any).saasConfig = {
@@ -336,14 +336,23 @@ export class ApiPageConfig {
336
336
  const fileSizeKB = file.size / 1024;
337
337
  if (file.name.endsWith('png') || file.name.endsWith('jpg') || file.name.endsWith('jpeg')) {
338
338
  if (fileSizeKB > 500) {
339
- yield new Promise((resolve, reject) => {
339
+ const result = yield new Promise((resolve, reject) => {
340
340
  dialog.checkYesOrNot({
341
341
  text: '圖片上傳大小不得超過 500 KB,避免網頁加載速度緩慢,是否透過系統自動壓縮畫質?',
342
342
  callback: (response) => {
343
+ if (response) {
344
+ resolve(true);
345
+ }
346
+ else {
347
+ resolve(false);
348
+ }
343
349
  }
344
350
  });
345
351
  });
346
- return;
352
+ if (!result) {
353
+ dialog.dataLoading({ visible: false });
354
+ return;
355
+ }
347
356
  }
348
357
  }
349
358
  const file_id = window.glitter.getUUID();
@@ -374,6 +383,7 @@ export class ApiPageConfig {
374
383
  const img = new Image();
375
384
  img.src = URL.createObjectURL(file);
376
385
  img.onload = function () {
386
+ let quality = 0.9;
377
387
  const og_width = img.width;
378
388
  const og_height = img.height;
379
389
  const canvas = document.createElement('canvas');
@@ -397,23 +407,28 @@ export class ApiPageConfig {
397
407
  canvas.height = height;
398
408
  const ctx = canvas.getContext('2d');
399
409
  ctx.drawImage(img, 0, 0, width, height);
400
- canvas.toBlob(function (blob) {
401
- return __awaiter(this, void 0, void 0, function* () {
402
- const s3res = (yield ApiPageConfig.uploadFile(getFileName(size))).response;
403
- const res = yield BaseApi.create({
404
- url: s3res.url,
405
- type: 'put',
406
- data: blob,
407
- headers: {
408
- 'Content-Type': s3res.type,
409
- }
410
- });
411
- if (size === 1920) {
412
- links.push(s3res.fullUrl);
410
+ function tryCompression() {
411
+ canvas.toBlob((blob) => __awaiter(this, void 0, void 0, function* () {
412
+ console.log(`嘗試壓縮品質: ${quality}, 檔案大小: ${(blob.size / 1024).toFixed(2)} KB`);
413
+ if (blob.size > 500 * 1024 && quality > 0.1) {
414
+ quality -= 0.1;
415
+ tryCompression();
416
+ }
417
+ else {
418
+ const s3res = (yield ApiPageConfig.uploadFile(getFileName(size))).response;
419
+ const res = yield BaseApi.create({
420
+ url: s3res.url,
421
+ type: 'put',
422
+ data: blob,
423
+ headers: {
424
+ 'Content-Type': s3res.type,
425
+ }
426
+ });
427
+ resolve(s3res.fullUrl);
413
428
  }
414
- resolve(res.result);
415
- });
416
- }, file.type);
429
+ }), 'image/jpeg', quality);
430
+ }
431
+ tryCompression();
417
432
  };
418
433
  };
419
434
  reader.readAsDataURL(file);
@@ -422,16 +437,21 @@ export class ApiPageConfig {
422
437
  }
423
438
  let chunk_size = [150, 600, 1200, 1440, 1920];
424
439
  let chunk_count = 0;
425
- const s3res = (yield ApiPageConfig.uploadFile(getFileName('original'))).response;
426
- const res = yield BaseApi.create({
427
- url: s3res.url,
428
- type: 'put',
429
- data: file,
430
- headers: {
431
- 'Content-Type': s3res.type,
432
- }
433
- });
434
- links.push(s3res.fullUrl);
440
+ if (fileSizeKB > 500) {
441
+ links.push(yield loopSize(chunk_size[1200]));
442
+ }
443
+ else {
444
+ const s3res = (yield ApiPageConfig.uploadFile(getFileName('original'))).response;
445
+ const res = yield BaseApi.create({
446
+ url: s3res.url,
447
+ type: 'put',
448
+ data: file,
449
+ headers: {
450
+ 'Content-Type': s3res.type,
451
+ }
452
+ });
453
+ links.push(s3res.fullUrl);
454
+ }
435
455
  result = true;
436
456
  if (!result) {
437
457
  return {
@@ -405,15 +405,23 @@ export class ApiPageConfig {
405
405
  // 假設你想限制上傳檔案最大為 500 KB
406
406
  if(file.name.endsWith('png')||file.name.endsWith('jpg')||file.name.endsWith('jpeg')){
407
407
  if (fileSizeKB > 500) {
408
- await new Promise((resolve,reject)=>{
408
+ const result=await new Promise((resolve,reject)=>{
409
409
  dialog.checkYesOrNot({
410
410
  text:'圖片上傳大小不得超過 500 KB,避免網頁加載速度緩慢,是否透過系統自動壓縮畫質?',
411
411
  callback:(response)=>{
412
-
412
+ if(response){
413
+ resolve(true)
414
+ }else{
415
+ resolve(false)
416
+ }
413
417
  }
414
418
  })
415
419
  })
416
- return
420
+ if(!result){
421
+ dialog.dataLoading({visible:false})
422
+ return
423
+ }
424
+
417
425
  }
418
426
  }
419
427
 
@@ -440,13 +448,14 @@ export class ApiPageConfig {
440
448
  }
441
449
  //壓縮圖片後再上傳
442
450
  if(file.name.endsWith('png')||file.name.endsWith('jpg')||file.name.endsWith('jpeg')){
443
- async function loopSize(size:number):Promise<boolean>{
451
+ async function loopSize(size:number):Promise<string>{
444
452
  return new Promise( (resolve,reject)=>{
445
453
  const reader = new FileReader();
446
454
  reader.onload = function(e) {
447
455
  const img = new Image();
448
456
  img.src = URL.createObjectURL(file);
449
457
  img.onload = function() {
458
+ let quality=0.9
450
459
  // 获取图像宽度和高度
451
460
  const og_width = img.width;
452
461
  const og_height = img.height;
@@ -472,22 +481,28 @@ export class ApiPageConfig {
472
481
  canvas.height = height;
473
482
  const ctx:any = canvas.getContext('2d');
474
483
  ctx.drawImage(img, 0, 0, width, height);
475
- // 将调整后的图像转换为 Blob
476
- canvas.toBlob(async function(blob:any) {
477
- const s3res= (await ApiPageConfig.uploadFile(getFileName(size))).response;
478
- const res= await BaseApi.create({
479
- url: s3res.url,
480
- type: 'put',
481
- data: blob,
482
- headers: {
483
- 'Content-Type': s3res.type,
484
+ function tryCompression() {
485
+ canvas.toBlob(async (blob:any) => {
486
+ console.log(`嘗試壓縮品質: ${quality}, 檔案大小: ${(blob.size / 1024).toFixed(2)} KB`);
487
+ if (blob.size > 500 * 1024 && quality > 0.1) {
488
+ quality -= 0.1; // 逐步降低品質
489
+ tryCompression();
490
+ } else {
491
+ const s3res= (await ApiPageConfig.uploadFile(getFileName(size))).response;
492
+ const res= await BaseApi.create({
493
+ url: s3res.url,
494
+ type: 'put',
495
+ data: blob,
496
+ headers: {
497
+ 'Content-Type': s3res.type,
498
+ }
499
+ })
500
+ resolve(s3res.fullUrl)
484
501
  }
485
- })
486
- if(size===1920){
487
- links.push(s3res.fullUrl)
488
- }
489
- resolve(res.result)
490
- }, file.type);
502
+ }, 'image/jpeg', quality);
503
+ }
504
+
505
+ tryCompression();
491
506
  };
492
507
  };
493
508
  reader.readAsDataURL(file);
@@ -495,28 +510,21 @@ export class ApiPageConfig {
495
510
  }
496
511
  let chunk_size=[150,600,1200,1440,1920]
497
512
  let chunk_count=0
498
- // await new Promise((resolve, reject)=>{
499
- // // for (const size of chunk_size){
500
- // // loopSize(size).then((res:boolean)=>{
501
- // // chunk_count++
502
- // // result=res && result
503
- // // if(chunk_count===chunk_size.length){
504
- // // resolve(true)
505
- // // }
506
- // // })
507
- // // }
508
- //
509
- // })
510
- const s3res= (await ApiPageConfig.uploadFile(getFileName('original'))).response;
511
- const res= await BaseApi.create({
512
- url: s3res.url,
513
- type: 'put',
514
- data: file,
515
- headers: {
516
- 'Content-Type': s3res.type,
517
- }
518
- })
519
- links.push(s3res.fullUrl)
513
+ if(fileSizeKB>500){
514
+ links.push(await loopSize(chunk_size[1200]))
515
+ }else{
516
+ const s3res= (await ApiPageConfig.uploadFile(getFileName('original'))).response;
517
+ const res= await BaseApi.create({
518
+ url: s3res.url,
519
+ type: 'put',
520
+ data: file,
521
+ headers: {
522
+ 'Content-Type': s3res.type,
523
+ }
524
+ })
525
+ links.push(s3res.fullUrl)
526
+ }
527
+
520
528
  result=true
521
529
  if(!result){
522
530
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-glitter",
3
- "version": "18.5.6",
3
+ "version": "18.5.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {