app-service.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. if (typeof Promise !== "undefined" && !Promise.prototype.finally) {
  2. Promise.prototype.finally = function(callback) {
  3. const promise = this.constructor;
  4. return this.then(
  5. (value) => promise.resolve(callback()).then(() => value),
  6. (reason) => promise.resolve(callback()).then(() => {
  7. throw reason;
  8. })
  9. );
  10. };
  11. }
  12. ;
  13. if (typeof uni !== "undefined" && uni && uni.requireGlobal) {
  14. const global = uni.requireGlobal();
  15. ArrayBuffer = global.ArrayBuffer;
  16. Int8Array = global.Int8Array;
  17. Uint8Array = global.Uint8Array;
  18. Uint8ClampedArray = global.Uint8ClampedArray;
  19. Int16Array = global.Int16Array;
  20. Uint16Array = global.Uint16Array;
  21. Int32Array = global.Int32Array;
  22. Uint32Array = global.Uint32Array;
  23. Float32Array = global.Float32Array;
  24. Float64Array = global.Float64Array;
  25. BigInt64Array = global.BigInt64Array;
  26. BigUint64Array = global.BigUint64Array;
  27. }
  28. ;
  29. if (uni.restoreGlobal) {
  30. uni.restoreGlobal(Vue, weex, plus, setTimeout, clearTimeout, setInterval, clearInterval);
  31. }
  32. (function(vue) {
  33. "use strict";
  34. function formatAppLog(type, filename, ...args) {
  35. if (uni.__log__) {
  36. uni.__log__(type, filename, ...args);
  37. } else {
  38. console[type].apply(console, [...args, filename]);
  39. }
  40. }
  41. const _export_sfc = (sfc, props) => {
  42. const target = sfc.__vccOpts || sfc;
  43. for (const [key, val] of props) {
  44. target[key] = val;
  45. }
  46. return target;
  47. };
  48. var wv;
  49. const _sfc_main$1 = {
  50. data() {
  51. return {
  52. title: "sanfan",
  53. // url: 'http://139.9.102.170:10012/#/',
  54. url: "http://121.37.194.75:20011/#/",
  55. src: "",
  56. wv: null,
  57. canBack: false,
  58. top: 0,
  59. //webview 头部高度
  60. height: 0,
  61. //webview 高度
  62. kbHeight: 0
  63. //键盘高度
  64. };
  65. },
  66. onBackPress() {
  67. if (wv && this.canBack) {
  68. wv.back();
  69. return true;
  70. }
  71. return false;
  72. },
  73. onReady() {
  74. var self = this;
  75. var currentWebview = this.$scope.$getAppWebview();
  76. setTimeout(function() {
  77. wv = currentWebview.children()[0];
  78. wv.addEventListener(
  79. "progressChanged",
  80. function(e) {
  81. wv.canBack(function(e2) {
  82. self.canBack = e2.canBack;
  83. });
  84. },
  85. false
  86. );
  87. }, 500);
  88. },
  89. onLoad() {
  90. uni.getSystemInfo({
  91. //成功获取的回调函数,返回值为系统信息
  92. success: (sysinfo) => {
  93. this.height = sysinfo.windowHeight;
  94. },
  95. complete: () => {
  96. }
  97. });
  98. let info = uni.getSystemInfoSync();
  99. this.top = info.statusBarHeight;
  100. var currentWebview = this.$scope.$getAppWebview();
  101. setTimeout(() => {
  102. this.wv = currentWebview.children()[0];
  103. this.wv.setStyle({
  104. //设置web-view距离顶部的距离以及自己的高度,单位为px
  105. top: this.top,
  106. //此处是距离顶部的高度,应该是你页面的头部
  107. // bottom: 0, //防止输入框被软键盘遮挡
  108. height: this.height - this.top,
  109. //webview的高度
  110. scalable: false
  111. //webview的页面是否可以缩放,双指放大缩小
  112. });
  113. }, 1e3);
  114. uni.onKeyboardHeightChange((obj) => {
  115. let _sysInfo = uni.getSystemInfoSync();
  116. let _heightDiff = _sysInfo.screenHeight - _sysInfo.windowHeight;
  117. let _diff = obj.height - _heightDiff;
  118. this.kbHeight = (_diff > 0 ? _diff : 0) - 2;
  119. this.wv.setStyle({
  120. top: this.top,
  121. // webview的高度动态修改为减去键盘高度后的
  122. height: this.height - this.kbHeight,
  123. // bottom: 0,
  124. scalable: false
  125. });
  126. });
  127. uni.onWindowResize((res) => {
  128. if (res.size.windowHeight < this.height) {
  129. setTimeout(() => {
  130. this.wv.setStyle({
  131. top: this.top,
  132. // webview的高度动态修改为减去键盘高度后的
  133. height: this.height - this.kbHeight,
  134. // bottom: 0,
  135. scalable: false
  136. });
  137. }, 50);
  138. } else {
  139. setTimeout(() => {
  140. this.wv.setStyle({
  141. top: this.top,
  142. // 这里可以根据自己情况微调
  143. height: this.height - this.top,
  144. bottom: 0
  145. });
  146. }, 50);
  147. }
  148. });
  149. uni.$on("connectStatusChange", (connectStatus) => {
  150. if (connectStatus) {
  151. jpushModule.getRegistrationID((result) => {
  152. formatAppLog("log", "at pages/index/index.vue:138", result, "注册ID.....");
  153. this.wv.evalJS(`getVueMessage(${JSON.stringify(result.registerID)})`);
  154. });
  155. }
  156. });
  157. },
  158. onUnload() {
  159. uni.$off("connectStatusChange");
  160. },
  161. methods: {
  162. messageData(e) {
  163. const data = e.detail.data;
  164. if (data[0].type == "file") {
  165. let url = data[0].url;
  166. uni.downloadFile({
  167. url,
  168. // 文件的下载链接
  169. success: function(res) {
  170. if (res.statusCode === 200) {
  171. uni.openDocument({
  172. filePath: res.tempFilePath,
  173. success: function(res2) {
  174. },
  175. fail: function(error) {
  176. }
  177. });
  178. }
  179. },
  180. fail: function(error) {
  181. }
  182. });
  183. } else if (data[0].type == "scanCode") {
  184. uni.scanCode({
  185. success: (res) => {
  186. this.wv.evalJS(`getVueMessage(${JSON.stringify(res.result)} , ${data[0].scanType})`);
  187. }
  188. });
  189. }
  190. }
  191. }
  192. };
  193. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  194. return vue.openBlock(), vue.createElementBlock("view", { class: "content" }, [
  195. vue.createElementVNode("view", { class: "status_bar" }, [
  196. vue.createCommentVNode(" 这里是状态栏 ")
  197. ]),
  198. vue.createElementVNode("web-view", {
  199. src: $data.url,
  200. fullscreen: false,
  201. onMessage: _cache[0] || (_cache[0] = (...args) => $options.messageData && $options.messageData(...args))
  202. }, null, 40, ["src"])
  203. ]);
  204. }
  205. const PagesIndexIndex = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render], ["__file", "D:/uni-fans-mobile/pages/index/index.vue"]]);
  206. __definePage("pages/index/index", PagesIndexIndex);
  207. const _sfc_main = {
  208. onLaunch: function() {
  209. formatAppLog("log", "at App.vue:4", "onLaunch");
  210. },
  211. onShow: function() {
  212. formatAppLog("log", "at App.vue:7", "App Show");
  213. },
  214. onHide: function() {
  215. formatAppLog("log", "at App.vue:10", "App Hide");
  216. }
  217. };
  218. const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "D:/uni-fans-mobile/App.vue"]]);
  219. function createApp() {
  220. const app = vue.createVueApp(App);
  221. return {
  222. app
  223. };
  224. }
  225. const { app: __app__, Vuex: __Vuex__, Pinia: __Pinia__ } = createApp();
  226. uni.Vuex = __Vuex__;
  227. uni.Pinia = __Pinia__;
  228. __app__.provide("__globalStyles", __uniConfig.styles);
  229. __app__._component.mpType = "app";
  230. __app__._component.render = () => {
  231. };
  232. __app__.mount("#app");
  233. })(Vue);