Commit 93073288 by 姜雷

修改APP进入逻辑以及返回按钮

parent 8ac2056b
.AppBackButton {
position: absolute;
left: 0;
bottom: 160px;
width: 140px;
height: 60px;
line-height: 60px;
font-size: 30px;
}
import { Button } from '@tarojs/components';
import Taro from '@tarojs/taro';
import useAppBackState from '@/hooks/useAppBackState';
import './AppBackButton.scss';
const AppBackButton = () => {
const isShow = useAppBackState();
const goBackAppError = e => {
console.log(e);
Taro.showModal({
title: '提示',
content: '呼起APP失败,请手动回到APP',
});
};
return isShow ? (
<Button
className='AppBackButton'
open-type='launchApp'
app-parameter='wechat'
onError={goBackAppError}>
返回
</Button>
) : null;
};
export default AppBackButton;
import Taro, { useEffect, useState } from '@tarojs/taro';
const useAppBackState = (): boolean => {
const [state, setState] = useState(false);
useEffect(() => {
let entity = Taro.getLaunchOptionsSync();
console.log(entity);
if (entity.scene === 1069 || entity.scene === 1036) {
setState(true);
}
}, []);
return state;
};
export default useAppBackState;
import { useSelector, useDispatch } from '@tarojs/redux';
import { getShowerController, ShowerUseType } from '@/api/shower';
import { updateShowerControlConfig } from '@/store/rootReducers/shower';
import { Customer } from '@/types/Customer/Customer';
import Taro, { useEffect, useState } from '@tarojs/taro';
const useShowerController = () => {
const [method, setState] = useState('');
const dispatch = useDispatch();
const userinfo = useSelector(
(state: { userinfo: Customer }) => state.userinfo,
);
useEffect(() => {
if (method) {
Taro.showLoading();
getShowerController({
campusId: userinfo.areaId,
customerId: userinfo.customerId,
})
.then(res => {
let data = res.data;
dispatch(updateShowerControlConfig(res.data));
let type =
data.useType === ShowerUseType.mix
? data.defaultType
: data.useType;
let url = '';
if (type === ShowerUseType.bluetooth) {
url = '/pages/Shower/Shower';
} else {
url = '/pages/Shower/ShowerAppointment';
}
Taro.hideLoading();
console.log(url);
if (method === 'redirectTo') {
Taro.redirectTo({ url: url });
} else {
Taro.navigateTo({ url: url });
}
})
.catch(err => {
Taro.hideLoading();
console.log('getShowerController err:', err);
Taro.showToast({
title: err.msg || '网络错误',
icon: 'none',
});
});
}
}, [method]);
return setState;
};
export default useShowerController;
...@@ -5,13 +5,36 @@ import { fetchAppLaunchCustomer } from '@/api/customer'; ...@@ -5,13 +5,36 @@ import { fetchAppLaunchCustomer } from '@/api/customer';
import { LogoutCode } from '@/constants'; import { LogoutCode } from '@/constants';
import { useDispatch } from '@tarojs/redux'; import { useDispatch } from '@tarojs/redux';
import { updateUserInfo } from '@/store/rootReducers/userinfo'; import { updateUserInfo } from '@/store/rootReducers/userinfo';
import AppBackButton from '@/components/AppBackButton/AppBackButton';
import useShowerController from '@/hooks/useShowerController';
function AppLaunch() { function AppLaunch() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const setGoMethod = useShowerController();
const goNextPage = (serviceId: string) => { const goNextPage = (serviceId: string) => {
Taro.redirectTo({ let url = '';
url: `/pages/Home/Home?serviceId=${serviceId}`, switch (serviceId) {
}); case '9':
url = '/pages/WaterDispenser/WaterDispenser';
break;
case '10':
setGoMethod('redirectTo');
return;
case '11':
case '12':
url = `/pages/BarCode/BarCode?serviceId=${serviceId}`;
break;
default:
console.log('goNextPage serviceId: ' + serviceId);
Taro.showToast({
title: '无法识别的服务',
icon: 'none',
});
break;
}
if (url) {
Taro.redirectTo({ url });
}
}; };
const [showBackButtonState, setShowBackButtonState] = useState(false); const [showBackButtonState, setShowBackButtonState] = useState(false);
const [errorMsg, setErrorMsg] = useState(''); const [errorMsg, setErrorMsg] = useState('');
...@@ -22,7 +45,10 @@ function AppLaunch() { ...@@ -22,7 +45,10 @@ function AppLaunch() {
Taro.showLoading(); Taro.showLoading();
const { uuId, serviceId } = entity; const { uuId, serviceId } = entity;
if (uuId && serviceId) { if (uuId && serviceId) {
fetchAppLaunchCustomer(entity) fetchAppLaunchCustomer({
...entity,
timeStamp: Math.floor(new Date().getTime() / 1000),
})
.then(res => { .then(res => {
console.log(res); console.log(res);
Taro.hideLoading(); Taro.hideLoading();
......
...@@ -17,6 +17,7 @@ import { shareHandle } from '@/common/shareMethod'; ...@@ -17,6 +17,7 @@ import { shareHandle } from '@/common/shareMethod';
import { PayOrderState } from '@/store/rootReducers/orderState'; import { PayOrderState } from '@/store/rootReducers/orderState';
import WaitPayOrderComponent from '@/components/WaitPayOrder/WaitPayOrder'; import WaitPayOrderComponent from '@/components/WaitPayOrder/WaitPayOrder';
import widthWaitPayOrderComponent from '@/components/WaitPayOrder/WaitPayOrder'; import widthWaitPayOrderComponent from '@/components/WaitPayOrder/WaitPayOrder';
import AppBackButton from '@/components/AppBackButton/AppBackButton';
type PageStateProps = { type PageStateProps = {
userinfo: Customer; userinfo: Customer;
...@@ -172,6 +173,7 @@ class BarCode extends Component { ...@@ -172,6 +173,7 @@ class BarCode extends Component {
return ( return (
<View className='BarCode'> <View className='BarCode'>
<AppBackButton />
<WaitPayOrderComponent /> <WaitPayOrderComponent />
<View className={payOrderState ? 'blur' : ''}> <View className={payOrderState ? 'blur' : ''}>
{showBackTag && ( {showBackTag && (
......
...@@ -118,11 +118,6 @@ class Home extends Component { ...@@ -118,11 +118,6 @@ class Home extends Component {
onShareAppMessage = shareHandle; onShareAppMessage = shareHandle;
componentWillMount() { componentWillMount() {
const { serviceId } = this.$router.params;
console.log('in componentWillMount', serviceId);
if (serviceId) {
return this.redirectFromAppLaunch(serviceId);
}
this.getInitData(); this.getInitData();
} }
...@@ -130,25 +125,6 @@ class Home extends Component { ...@@ -130,25 +125,6 @@ class Home extends Component {
this.getInitData(); this.getInitData();
} }
redirectFromAppLaunch(serviceId: string) {
switch (serviceId) {
case '9':
return this.goDispenser();
case '10':
return this.goShower();
case '11':
case '12':
return this.goBarCode(Number(serviceId));
default:
console.log('redirectFromAppLaunch serviceId: ' + serviceId);
Taro.showToast({
title: '无法识别的服务',
icon: 'none',
});
break;
}
}
getInitData() { getInitData() {
this.getServiceList(); this.getServiceList();
this.getAnn(); this.getAnn();
......
...@@ -27,6 +27,7 @@ import { updateBluetoothDevice } from './actions'; ...@@ -27,6 +27,7 @@ import { updateBluetoothDevice } from './actions';
import { ab2str, str2ab } from '@/utils/arrayBuffer'; import { ab2str, str2ab } from '@/utils/arrayBuffer';
import WaitPayOrderComponent from '@/components/WaitPayOrder/WaitPayOrder'; import WaitPayOrderComponent from '@/components/WaitPayOrder/WaitPayOrder';
import { PayOrderState } from '@/store/rootReducers/orderState'; import { PayOrderState } from '@/store/rootReducers/orderState';
import AppBackButton from '@/components/AppBackButton/AppBackButton';
enum BlueToothError { enum BlueToothError {
BlueToothNotOpen = 'BlueToothNotOpen', BlueToothNotOpen = 'BlueToothNotOpen',
...@@ -829,6 +830,7 @@ class Shower extends Component { ...@@ -829,6 +830,7 @@ class Shower extends Component {
return ( return (
<View className='Shower'> <View className='Shower'>
<AppBackButton />
<WaitPayOrderComponent /> <WaitPayOrderComponent />
{showAppoint && ( {showAppoint && (
<View className='showAppoint' onClick={this.goAppointShower}> <View className='showAppoint' onClick={this.goAppointShower}>
......
...@@ -17,6 +17,7 @@ import AppointermentEquipment from './components/AppointermentEquipment/Appointe ...@@ -17,6 +17,7 @@ import AppointermentEquipment from './components/AppointermentEquipment/Appointe
import useAppointRecordsList from './hooks/useAppointRecordsList'; import useAppointRecordsList from './hooks/useAppointRecordsList';
import useCheckAppointable from './hooks/useCheckAppointable'; import useCheckAppointable from './hooks/useCheckAppointable';
import { ShowerState } from '@/store/rootReducers/shower'; import { ShowerState } from '@/store/rootReducers/shower';
import AppBackButton from '@/components/AppBackButton/AppBackButton';
function ShowerAppointment() { function ShowerAppointment() {
const userInfo = useSelector( const userInfo = useSelector(
...@@ -199,6 +200,7 @@ function ShowerAppointment() { ...@@ -199,6 +200,7 @@ function ShowerAppointment() {
return ( return (
<View className='ShowerAppointment'> <View className='ShowerAppointment'>
<AppBackButton />
{showState == 1 && ( {showState == 1 && (
<View className='ShowerAppointment-Searchbox'> <View className='ShowerAppointment-Searchbox'>
<Input <Input
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment