1 | import {trigger} from "../lib/event";
|
2 | const Light = require("../lib/core");
|
3 | import {parse2query,resolvePath} from "../lib/utils"
|
4 | module.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,"");
|
21 | data.screenShot=data.screenShot.replace(/\s+/g,"");
|
22 | trigger("screenshot",data.screenShot)
|
23 | };
|
24 |
|
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 |
|
40 | window.LightJSBridge.call('native.back', { number: number }, null);
|
41 | },
|
42 | navigateTo(path,params,options){
|
43 |
|
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 |
|
61 | location.href = path.url.indexOf('?')>-1 ? `${path.url}&${parse2query(params)}` : `${path.url}?${parse2query(params)}`;
|
62 | }
|
63 |
|
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 |