UNPKG

3.15 kBJavaScriptView Raw
1import {trigger} from "../lib/event";
2const Light = require("../lib/core");
3import {parse2query,resolvePath} from "../lib/utils"
4module.exports = {
5 init(){
6 document.addEventListener("deviceready", function () {
7 window.LightJSBridge.onPageAppear = function(){
8 trigger("viewappear")
9 };
10 window.LightJSBridge.onPageDisappear = function(){
11 trigger("viewdisappear")
12 };
13 window.LightJSBridge.AppWillEnterForeground = function(){
14 trigger("appappear")
15 };
16 window.LightJSBridge.AppDidEnterBackground = function(){
17 trigger("appdisappear")
18 };
19 window.LightJSBridge.onScreenShot = function(data){
20 data.screenShot=data.screenShot.replace(/\r\n/g,""); // 231663 native 插件新增支持jsn环境的监听屏幕截图配置,图片显示错误问题修复
21 data.screenShot=data.screenShot.replace(/\s+/g,"");
22 trigger("screenshot",data.screenShot)
23 };
24 //154941 light框架支持Light.on("viewback")
25 window.LightJSBridge.pageShouldBack = function(data){
26 return trigger("viewback",{
27 sync:true
28 })
29 };
30 })
31 },
32 start(router,options){
33 const app = new Light.Vue({
34 el : options.el|| "#main",
35 router
36 });
37 },
38 navigateBack(number){
39 // number = number > window.history.length ? window.history.length : number;
40 window.LightJSBridge.call('native.back', { number: number }, null);
41 },
42 navigateTo(path,params,options){
43 //166093【框架】优化light.navigate路由跳转时无入参的路由
44 let distURL = resolvePath(path.url, params);
45 if(path.type === "jsnative"){
46 location.href = `gmu://jsnative?startPage=${encodeURIComponent(distURL)}&${parse2query(options)}`
47 }
48 if(path.type === "web"){
49 if(options.replace===false||path.url.indexOf("vhost.light.com")>-1){
50 location.href = `gmu://web?startPage=${encodeURIComponent(distURL)}&${parse2query(options)}`
51 }else{
52 if(options.history!==false){
53 location.href= resolvePath(path.url, params);
54 }else{
55 location.replace(resolvePath(path.url, params));
56 }
57 }
58 }
59 if(path.type === "native"){
60 //231597支持打开gmu://web?startPage=xxx(H5)
61 location.href = path.url.indexOf('?')>-1 ? `${path.url}&${parse2query(params)}` : `${path.url}?${parse2query(params)}`;
62 }
63 //167515 小程序olight模块支持navigate跳转区分lightweb和miniapp
64 if(path.type === "lightweb") {
65 path.type = options.miniappContainer || path.type;
66 location.href = `gmu://${path.type}?startPage=${encodeURIComponent(distURL)}&${parse2query(options)}`
67 }
68 },
69 getCurrentFile(){
70 return location.href.split(/([#])/)[0];
71 },
72 ajax:require("./pure").ajax
73};
\No newline at end of file