index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. function loadMainDartJs() {
  2. console.log(new Date());
  3. if (scriptLoaded) {
  4. return;
  5. }
  6. //hideSplash();
  7. scriptLoaded = true;
  8. var scriptTag = document.createElement("script");
  9. scriptTag.src = "main.dart.js?v=" + serviceWorkerVersion;
  10. scriptTag.type = "application/javascript";
  11. document.body.append(scriptTag);
  12. }
  13. ///外部通知
  14. function externalNotification(a, b) {
  15. window.invokeJs(a, b);
  16. }
  17. ///打印pdf
  18. function printPdfByBase64(base64) {
  19. printJS({
  20. printable: base64,
  21. type: 'pdf',
  22. base64: true
  23. })
  24. }
  25. function closeWindow(windowType) {
  26. var shell = window["FisShellApi"];
  27. if (shell) {
  28. shell.closeWindow(windowType);
  29. }
  30. }
  31. function getLanguageCode(callback) {
  32. var shell = window["FisShellApi"];
  33. if (shell) {
  34. var request = shell.getLanguageCode();
  35. request.then((v) =>
  36. callback(v)
  37. );
  38. }
  39. }
  40. function closeSlaveWindow() {
  41. var shell = window["FisShellApi"];
  42. if (shell) {
  43. shell.closeSlaveWindow();
  44. }
  45. }
  46. function beginWindowDrag(name) {
  47. var shell = window["FisShellApi"];
  48. if (shell) {
  49. shell.beginWindowDrag(name);
  50. }
  51. }
  52. function endWindowDrag(name) {
  53. var shell = window["FisShellApi"];
  54. if (shell) {
  55. shell.endWindowDrag(name);
  56. }
  57. }
  58. function closeWindow(name) {
  59. var shell = window["FisShellApi"];
  60. if (shell) {
  61. shell.closeWindow(name);
  62. }
  63. }
  64. function maximizeWindow(name) {
  65. var shell = window["FisShellApi"];
  66. if (shell) {
  67. shell.maximizeWindow(name);
  68. }
  69. }
  70. function minimizeWindow(name) {
  71. var shell = window["FisShellApi"];
  72. if (shell) {
  73. shell.minimizeWindow(name);
  74. }
  75. }
  76. function hideSplash() {
  77. console.log("onhide splash")
  78. var splash = document.getElementsByClassName("splash")[0];
  79. setTimeout(function () {
  80. splash.style.zIndex = 0;
  81. });
  82. var loading = document.getElementsByClassName("full-screen-center")[0];
  83. setTimeout(function () {
  84. loading.style.zIndex = 0;
  85. });
  86. }
  87. window.addEventListener("flutter-first-frame", function () {
  88. console.log("flutter-first-frame");
  89. hideSplash();
  90. });
  91. function loadService() {
  92. if ("serviceWorker" in navigator) {
  93. // Service workers are supported. Use them.
  94. window.addEventListener("load", function () {
  95. // Wait for registration to finish before dropping the <script> tag.
  96. // Otherwise, the browser will load the script multiple times,
  97. // potentially different versions.
  98. var serviceWorkerUrl =
  99. "flutter_service_worker.js?v=" + serviceWorkerVersion;
  100. navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
  101. function waitForActivation(serviceWorker) {
  102. serviceWorker.addEventListener("statechange", () => {
  103. if (serviceWorker.state == "activated") {
  104. console.log("Installed new service worker.");
  105. loadMainDartJs();
  106. }
  107. });
  108. }
  109. if (!reg.active && (reg.installing || reg.waiting)) {
  110. // No active web worker and we have installed or are installing
  111. // one for the first time. Simply wait for it to activate.
  112. waitForActivation(reg.installing || reg.waiting);
  113. } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
  114. // When the app updates the serviceWorkerVersion changes, so we
  115. // need to ask the service worker to update.
  116. console.log("New service worker available.");
  117. reg.update().then((data) => {
  118. var worker = data.installing || data.waiting || data.active;
  119. waitForActivation(worker);
  120. });
  121. // waitForActivation(reg.installing);
  122. } else {
  123. // Existing service worker is still good.
  124. console.log("Loading app from service worker.");
  125. loadMainDartJs();
  126. }
  127. });
  128. // If service worker doesn't succeed in a reasonable amount of time,
  129. // fallback to plaint <script> tag.
  130. setTimeout(() => {
  131. if (!scriptLoaded) {
  132. console.warn(
  133. "Failed to load app from service worker. Falling back to plain <script> tag."
  134. );
  135. loadMainDartJs();
  136. }
  137. }, 4000);
  138. });
  139. } else {
  140. // Service workers not supported. Just drop the <script> tag.
  141. loadMainDartJs();
  142. }
  143. }