添加 h5

This commit is contained in:
saplf
2019-09-07 14:39:03 +08:00
parent 71a3719bcf
commit 49fe983181
9 changed files with 507 additions and 13 deletions

75
src/utils/h5plus.ts Normal file
View File

@@ -0,0 +1,75 @@
import { dispatch, getState } from './utils';
import { routerRedux } from 'dva';
const plus = window.plus;
const isApp = () => typeof plus !== 'undefined';
const barcodeId = 'barcode'
const scan = () => {
if (!isApp()) return Promise.resolve('');
return new Promise<string>(resolve => {
const { barcode, webview } = plus;
const bc = barcode.create(barcodeId, [barcode.QR], {
position: 'absolute',
left: '0px',
top: '100px',
width: '100%',
height: '500px',
});
bc.onmarked = (_, code) => {
resolve(code);
bc.close();
};
bc.onerror = () => {
resolve('');
bc.close();
}
webview.currentWebview().append(bc);
bc.start();
});
}
const firstPaths = [
'/check',
'/home/estate',
'/home/fund',
'/home/market',
'/home/profile',
];
const backButtonHandler = () => {
const barcode = plus.barcode.getBarcodeById(barcodeId);
if (barcode) {
barcode.close();
return;
}
const { pathname } = getState().router.location;
if (firstPaths.includes(pathname)) {
plus.runtime.quit();
} else {
dispatch(routerRedux.goBack());
}
};
const init = () => {
if (!isApp()) return;
plus.key.addEventListener('backbutton', backButtonHandler);
}
const destory = () => {
if (!isApp()) return;
plus.key.removeEventListener('backbutton', backButtonHandler);
}
export {
init,
isApp,
scan,
destory,
};
export default {
init,
isApp,
scan,
destory,
};

View File

@@ -20,7 +20,7 @@ const errorMap = {
};
const baseURL = 'https://server.fiv.tacever.org/v1';
// const baseURL = '//yapi.faronear.org/mock/20/v1';
// const baseURL = 'http://yapi.faronear.org/mock/20/v1';
const instance = axios.create({
baseURL,
});
@@ -57,7 +57,8 @@ async function filter<T>(
} else {
instance.defaults.headers = _.omit(instance.defaults.headers, 'token');
}
const { status, data } = await (instance[method] as (...args: any[]) => Promise<AxiosResponse<AppResp>>)(...args);
const { status, data } =
await (instance[method] as (...args: any[]) => Promise<AxiosResponse<AppResp>>)(...args);
replaceId(data);
ret = {
ok: status >= 200 && status < 300 && data && data.code === 0,

View File

@@ -10,6 +10,8 @@ interface Action {
const dispatch = (action: Action) => window.g_app._store.dispatch(action);
export { isDev, dispatch };
const getState = () => window.g_app._store.getState();
export default { isDev, dispatch };
export { isDev, dispatch, getState };
export default { isDev, dispatch, getState };