@cpzxrobot/sdk 1.2.53 → 1.2.54
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/dist/index.js +33 -25
- package/index.ts +34 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -415,25 +415,29 @@ class Cpzxrobot {
|
|
|
415
415
|
}
|
|
416
416
|
this.resolveReady(this.axios);
|
|
417
417
|
});
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
//
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
418
|
+
if (!Cpzxrobot.factorySelectorLoaded) {
|
|
419
|
+
Cpzxrobot.factorySelectorLoaded = true;
|
|
420
|
+
//@ts-ignore
|
|
421
|
+
Promise.resolve().then(() => __importStar(require('https://webc.cpzxrobot.com/webc/factory-selector.js'))).then(() => {
|
|
422
|
+
//insert cpzxrobot_factory_selector into body
|
|
423
|
+
const div = document.createElement('cpzxrobot-factory-selector');
|
|
424
|
+
div.setAttribute('selector-style', 'float-button');
|
|
425
|
+
document.body.appendChild(div);
|
|
426
|
+
//register onUnitChanged and onFactoryChanged on div
|
|
427
|
+
div.addEventListener('unitChanged', function (e) {
|
|
428
|
+
// @ts-ignore
|
|
429
|
+
window._notifyUnitChanged(e.detail);
|
|
430
|
+
});
|
|
431
|
+
div.addEventListener('factoryChanged', function (e) {
|
|
432
|
+
// @ts-ignore
|
|
433
|
+
window._notifyFactoryChanged(e.detail);
|
|
434
|
+
});
|
|
435
|
+
})
|
|
436
|
+
.catch(err => {
|
|
437
|
+
console.error('Failed to load factory-selector module:', err);
|
|
438
|
+
Cpzxrobot.factorySelectorLoaded = false;
|
|
432
439
|
});
|
|
433
|
-
}
|
|
434
|
-
.catch(err => {
|
|
435
|
-
console.error('Failed to load factory-selector module:', err);
|
|
436
|
-
});
|
|
440
|
+
}
|
|
437
441
|
return;
|
|
438
442
|
}
|
|
439
443
|
else {
|
|
@@ -507,7 +511,7 @@ class Cpzxrobot {
|
|
|
507
511
|
}
|
|
508
512
|
}
|
|
509
513
|
exports.Cpzxrobot = Cpzxrobot;
|
|
510
|
-
|
|
514
|
+
Cpzxrobot.factorySelectorLoaded = false;
|
|
511
515
|
function default_1(args = {
|
|
512
516
|
devAuth: "",
|
|
513
517
|
appCode: "",
|
|
@@ -523,15 +527,19 @@ function default_1(args = {
|
|
|
523
527
|
name: "",
|
|
524
528
|
},
|
|
525
529
|
}) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
530
|
+
// @ts-ignore
|
|
531
|
+
var instance = window.single_cpzxrobot_instance;
|
|
532
|
+
if (!instance) {
|
|
533
|
+
instance = new Cpzxrobot(args.appCode);
|
|
534
|
+
// @ts-ignore
|
|
535
|
+
window.single_cpzxrobot_instance = instance;
|
|
536
|
+
instance.setAuth(args.devAuth, args.baseURL);
|
|
529
537
|
if (args.selectedFarm) {
|
|
530
|
-
|
|
538
|
+
instance.user.selectedFarm = args.selectedFarm;
|
|
531
539
|
}
|
|
532
540
|
if (args.selectedUnit) {
|
|
533
|
-
|
|
541
|
+
instance.user.selectedUnit = args.selectedUnit;
|
|
534
542
|
}
|
|
535
543
|
}
|
|
536
|
-
return
|
|
544
|
+
return instance;
|
|
537
545
|
}
|
package/index.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { QuotationGateway } from "./quotation_gateway";
|
|
|
24
24
|
import { AiGateway } from "./ai_gateway";
|
|
25
25
|
|
|
26
26
|
export class Cpzxrobot {
|
|
27
|
+
private static factorySelectorLoaded = false;
|
|
27
28
|
device: DeviceGateway;
|
|
28
29
|
pigfarm: PigfarmGateway = new PigfarmGateway(this);
|
|
29
30
|
chickenfarm: ChickenFarmGateway = new ChickenFarmGateway(this);
|
|
@@ -443,26 +444,30 @@ export class Cpzxrobot {
|
|
|
443
444
|
}
|
|
444
445
|
this.resolveReady(this.axios);
|
|
445
446
|
});
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
//
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
447
|
+
if (!Cpzxrobot.factorySelectorLoaded) {
|
|
448
|
+
Cpzxrobot.factorySelectorLoaded = true;
|
|
449
|
+
//@ts-ignore
|
|
450
|
+
import('https://webc.cpzxrobot.com/webc/factory-selector.js')
|
|
451
|
+
.then(() => {
|
|
452
|
+
//insert cpzxrobot_factory_selector into body
|
|
453
|
+
const div = document.createElement('cpzxrobot-factory-selector');
|
|
454
|
+
div.setAttribute('selector-style', 'float-button');
|
|
455
|
+
document.body.appendChild(div);
|
|
456
|
+
//register onUnitChanged and onFactoryChanged on div
|
|
457
|
+
div.addEventListener('unitChanged', function (e) {
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
window._notifyUnitChanged(e.detail);
|
|
460
|
+
});
|
|
461
|
+
div.addEventListener('factoryChanged', function (e) {
|
|
462
|
+
// @ts-ignore
|
|
463
|
+
window._notifyFactoryChanged(e.detail);
|
|
464
|
+
});
|
|
465
|
+
})
|
|
466
|
+
.catch(err => {
|
|
467
|
+
console.error('Failed to load factory-selector module:', err);
|
|
468
|
+
Cpzxrobot.factorySelectorLoaded = false;
|
|
461
469
|
});
|
|
462
|
-
|
|
463
|
-
.catch(err => {
|
|
464
|
-
console.error('Failed to load factory-selector module:', err);
|
|
465
|
-
});
|
|
470
|
+
}
|
|
466
471
|
return;
|
|
467
472
|
} else {
|
|
468
473
|
//if url has access_token and app_code, use it
|
|
@@ -533,8 +538,6 @@ export class Cpzxrobot {
|
|
|
533
538
|
}
|
|
534
539
|
}
|
|
535
540
|
|
|
536
|
-
let _instance!: Cpzxrobot;
|
|
537
|
-
|
|
538
541
|
export default function (
|
|
539
542
|
args: {
|
|
540
543
|
devAuth: string;
|
|
@@ -558,17 +561,21 @@ export default function (
|
|
|
558
561
|
},
|
|
559
562
|
}
|
|
560
563
|
): Cpzxrobot {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
+
// @ts-ignore
|
|
565
|
+
var instance = window.single_cpzxrobot_instance;
|
|
566
|
+
if (!instance) {
|
|
567
|
+
instance = new Cpzxrobot(args.appCode);
|
|
568
|
+
// @ts-ignore
|
|
569
|
+
window.single_cpzxrobot_instance = instance;
|
|
570
|
+
instance.setAuth(args.devAuth, args.baseURL);
|
|
564
571
|
if (args.selectedFarm) {
|
|
565
|
-
|
|
572
|
+
instance.user.selectedFarm = args.selectedFarm;
|
|
566
573
|
}
|
|
567
574
|
if (args.selectedUnit) {
|
|
568
|
-
|
|
575
|
+
instance.user.selectedUnit = args.selectedUnit;
|
|
569
576
|
}
|
|
570
577
|
}
|
|
571
|
-
return
|
|
578
|
+
return instance;
|
|
572
579
|
}
|
|
573
580
|
|
|
574
581
|
export { type ElectricMeterRate };
|