Commit 88042cb9 by 姜雷

添加APP呼起页

parent 724150af
...@@ -167,3 +167,16 @@ export const switchBalanceState = ( ...@@ -167,3 +167,16 @@ export const switchBalanceState = (
url: `/app/customer/swich/balance/${entity.customerId}/${entity.isEnabled}`, url: `/app/customer/swich/balance/${entity.customerId}/${entity.isEnabled}`,
method: 'PUT', method: 'PUT',
}); });
type FetchAppLaunchCustomerParams = {
secretCode: string;
uuId: string;
serviceId: string;
timeStamp: string;
sign: string;
};
export const fetchAppLaunchCustomer = (entity: FetchAppLaunchCustomerParams) =>
customerFetch({
url: '/dcxy/wechat/anxinpay/app/jump/mini/validatelogin',
data: entity,
});
...@@ -47,6 +47,7 @@ class App extends Component { ...@@ -47,6 +47,7 @@ class App extends Component {
'pages/Password/ChangePwd', 'pages/Password/ChangePwd',
'pages/Password/ChangeHardwareAccount', 'pages/Password/ChangeHardwareAccount',
'pages/Password/ChangeTelAccount', 'pages/Password/ChangeTelAccount',
'pages/AppLaunch/AppLaunch',
], ],
window: { window: {
backgroundTextStyle: 'light', backgroundTextStyle: 'light',
......
.AppLaunch {
padding: 60px 48px;
.AppLaunch-Message {
margin-bottom: 40px;
}
}
import './AppLaunch.scss';
import { View, Button } from '@tarojs/components';
import Taro, { useEffect, useState } from '@tarojs/taro';
import { fetchAppLaunchCustomer } from '@/api/customer';
import { LogoutCode } from '@/constants';
import { useDispatch } from '@tarojs/redux';
import { updateUserInfo } from '@/store/rootReducers/userinfo';
function AppLaunch() {
const dispatch = useDispatch();
const goNextPage = (serviceId: string) => {
Taro.redirectTo({
url: `/pages/Home/Home?serviceId=${serviceId}`,
});
};
const [showBackButtonState, setShowBackButtonState] = useState(false);
const [errorMsg, setErrorMsg] = useState('');
useEffect(() => {
console.log('AppLaunch', this.$router.params);
let entity = this.$router.params;
Taro.showLoading();
const { uuId, serviceId } = entity;
if (uuId && serviceId) {
fetchAppLaunchCustomer(entity)
.then(res => {
console.log(res);
Taro.hideLoading();
dispatch(updateUserInfo(res.data));
goNextPage(serviceId);
})
.catch(err => {
Taro.hideLoading();
let msg = err.msg || '请求失败';
Taro.showToast({
title: msg,
icon: 'none',
});
if (err.code !== LogoutCode) {
setErrorMsg(msg);
setShowBackButtonState(true);
}
});
} else {
Taro.hideLoading();
console.log('no uuid');
setErrorMsg('进入小程序参数错误');
setShowBackButtonState(true);
}
}, []);
const goBackAppError = e => {
console.log(e);
Taro.showModal({
title: '提示',
content: '呼起APP失败,请手动回到APP',
});
};
return (
<View className='AppLaunch'>
<View className='AppLaunch-Message'>{errorMsg}</View>
{showBackButtonState && (
<Button
open-type='launchApp'
app-parameter='wechat'
onError={goBackAppError}>
返回APP
</Button>
)}
</View>
);
}
export default AppLaunch;
...@@ -118,12 +118,37 @@ class Home extends Component { ...@@ -118,12 +118,37 @@ 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();
} }
componentDidShow() { componentDidShow() {
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();
...@@ -294,7 +319,8 @@ class Home extends Component { ...@@ -294,7 +319,8 @@ class Home extends Component {
{userinfo.customerName} {userinfo.customerName}
</View> </View>
<View className='Home-UserBox-tel'> <View className='Home-UserBox-tel'>
{this.formatePhone(userinfo.customerPhone)} {userinfo.customerPhone &&
this.formatePhone(userinfo.customerPhone)}
</View> </View>
<View className='Home-UserBox-addr'>{userinfo.areaName}</View> <View className='Home-UserBox-addr'>{userinfo.areaName}</View>
</View> </View>
......
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