Skip to content

Commit 1e741de

Browse files
author
w-xuefeng
committed
feat: add pagesMap to init
1 parent ec06644 commit 1e741de

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

src/config/page.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
const pages = [
22
{
3-
title: '首页',
3+
title: '过度页',
4+
name: 'default',
45
path: 'index/index'
56
},
67
{
78
title: '登录页',
9+
name: 'login',
810
path: 'login/index'
911
},
1012
{
1113
title: '手势解锁',
14+
name: 'gestureunlock',
1215
path: 'gestureunlock/index'
1316
},
1417
{
1518
title: '底部导航',
19+
name: 'bottomframe',
1620
path: 'bottomframe/index'
17-
}
21+
},
22+
// {
23+
// title: '首页',
24+
// name: 'home',
25+
// path: 'home/index'
26+
// },
1827
];
1928

2029
module.exports = pages

src/plugins/init.vue.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue';
22
import ReadyPlugin from './ready.plugin';
3+
const pages = require('@/config/page');
34

45
Vue.config.productionTip = false;
56

@@ -17,9 +18,64 @@ Object.defineProperty(Vue.prototype, '$api', {
1718
}
1819
});
1920

21+
function getPageMap() {
22+
return pages.reduce((rst, page) => {
23+
rst[page.name] = {
24+
...page,
25+
htmlPath: page.path.replace(/\/(\w)/, (match, $1) =>
26+
$1.toLocaleLowerCase()
27+
)
28+
};
29+
return rst;
30+
}, {});
31+
}
32+
33+
Vue.prototype.$pageMap = {
34+
pages: getPageMap()
35+
};
36+
37+
Vue.prototype.$n2p = function(name) {
38+
if (getPageMap()[name]) {
39+
return getPageMap()[name].htmlPath;
40+
} else {
41+
return undefined;
42+
}
43+
};
44+
45+
function bindKeyBackExitApp() {
46+
if (typeof api !== 'undefined') {
47+
window.api.addEventListener(
48+
{
49+
name: 'keyback'
50+
},
51+
function() {
52+
window.api.toast({
53+
msg: '再按一次返回键退出' + window.api.appName,
54+
duration: 2000,
55+
location: 'bottom'
56+
});
57+
window.api.addEventListener(
58+
{
59+
name: 'keyback'
60+
},
61+
function() {
62+
window.api.closeWidget({ silent: true });
63+
}
64+
);
65+
setTimeout(() => {
66+
bindKeyBackExitApp();
67+
}, 3000);
68+
}
69+
);
70+
}
71+
}
72+
73+
Vue.prototype.$bindKeyBackExitApp = bindKeyBackExitApp;
74+
2075
var _openw = null;
2176
Vue.prototype.$page = {
2277
open(url, { pageParam, animation, winOpts } = {}) {
78+
console.log('s', _openw);
2379
if (_openw) {
2480
return;
2581
}
@@ -38,13 +94,27 @@ Vue.prototype.$page = {
3894
...(winOpts || {})
3995
};
4096
api.openWin(params);
97+
console.log('e', _openw);
4198
},
4299
close() {
43100
if (!window.api) {
44101
window.history.back();
45102
return;
46103
}
47104
window.api.closeWin();
105+
},
106+
closeToWin({ url, animation }) {
107+
url = url.endsWith('.html') ? url : url + '.html';
108+
if (typeof api !== 'undefined') {
109+
const name = `win_${url}`;
110+
if (animation) {
111+
api.closeToWin({ name, animation });
112+
} else {
113+
api.closeToWin({ name });
114+
}
115+
} else {
116+
window.location.href = url;
117+
}
48118
}
49119
};
50120

0 commit comments

Comments
 (0)