This commit is contained in:
saplf
2019-09-08 13:03:43 +08:00
parent b004908af9
commit 5351afaae3
25 changed files with 263 additions and 14 deletions

View File

@@ -1,15 +1,17 @@
import { dispatch, getState } from './utils';
import { routerRedux } from 'dva';
const plus = window.plus;
const isApp = () => typeof plus !== 'undefined';
const isApp = () => {
const r = typeof window.plus !== 'undefined';
// console.log(r);
return r;
};
const barcodeId = 'barcode'
const scan = () => {
if (!isApp()) return Promise.resolve('');
return new Promise<string>(resolve => {
const { barcode, webview } = plus;
const { barcode, webview } = window.plus;
const bc = barcode.create(barcodeId, [barcode.QR], {
position: 'absolute',
left: '0px',
@@ -38,42 +40,48 @@ const firstPaths = [
'/home/profile',
];
const backButtonHandler = () => {
const barcode = plus.barcode.getBarcodeById(barcodeId);
const barcode = window.plus.barcode.getBarcodeById(barcodeId);
if (barcode) {
barcode.close();
return;
}
const { pathname } = getState().router.location;
if (firstPaths.includes(pathname)) {
plus.runtime.quit();
window.plus.runtime.quit();
} else {
dispatch(routerRedux.goBack());
}
};
const init = () => {
if (!isApp()) return;
plus.key.addEventListener('backbutton', backButtonHandler);
window.plus.key.addEventListener('backbutton', backButtonHandler);
};
const destory = () => {
if (!isApp()) return;
plus.key.removeEventListener('backbutton', backButtonHandler);
window.plus.key.removeEventListener('backbutton', backButtonHandler);
};
const share = (content: string) => {
if (!isApp()) return;
plus.share.sendWithSystem({
window.plus.share.sendWithSystem({
type: 'text',
content,
}, () => { });
};
const restart = () => {
if (!isApp()) return;
window.plus.runtime.restart();
}
export {
init,
isApp,
scan,
share,
destory,
restart,
};
export default {
@@ -82,4 +90,5 @@ export default {
scan,
share,
destory,
restart,
};

View File

@@ -46,3 +46,7 @@ export function fromLangToText(lang: string) {
export function encryptPwd(pwd: string): string {
return md5(pwd);
}
export function displayPhone(phone: string): string {
return `1******${_.takeRight(phone, 4).join('')}`;
}