index.js 1.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
import { createUniInstance } from './uni';

function getWebviewStyle () {
  return {
    titleNView: {
      autoBackButton: true,
      titleText: 'titleText'
    }
  }
}
class Router {
  constructor (routes, plus) {
    this.routes = routes;
    this.plus = plus;
    this.id = 0;

    this.aniShow = plus.os.name === 'Android' ? 'slide-in-right' : 'pop-in';
    this.aniClose = 'pop-out';
    this.aniDuration = 300;
  }

  push ({
    type,
    path
  } = {}) {
    this.plus.webview.open(
      '',
      String(this.id++),
      getWebviewStyle(),
      this.aniShow,
      this.aniDuration,
      () => {
        console.log('show.callback');
      });
  }

  replace ({
    type,
    path
  } = {}) {

  }

  go (delta) {

  }
fxy060608's avatar
fxy060608 已提交
47
}
fxy060608's avatar
fxy060608 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

let appCtx;

function getApp () {
  return appCtx
}

function registerApp (appVm, routes, plus) {
  appCtx = appVm;
  appCtx.$router = new Router(routes, plus);
}

const pageVms = [];

function getCurrentPages () {
  return pageVms
}

const __uniConfig = Object.create(null);
const __uniRoutes = [];

function createInstanceContext ({
  weex,
  WeexPlus
}) {
  const plus = new WeexPlus(weex);
  return {
    __uniConfig,
    __uniRoutes,
    __registerApp (appVm, {
      uniConfig,
      uniRoutes
    }) {
      Object.assign(__uniConfig, uniConfig);
      uniRoutes.forEach(route => __uniRoutes.push(route));
      registerApp(appVm, __uniRoutes, plus);
    },
    uni: createUniInstance(plus),
    getApp,
    getCurrentPages
  }
}

export { createInstanceContext };