More
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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('')}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user