Commit ac3c884d by 姜雷

添加版本低于2.7.0的键盘输入处理

parent 21a80cb8
import { useSelector, useDispatch } from '@tarojs/redux';
import Taro, { useEffect } from '@tarojs/taro';
import { updateSystemInfo } from '@/store/rootReducers/systemInfo';
const useSystemInfo = () => {
const systemInfo = useSelector(
(state: { systemInfo: Taro.getSystemInfo.Promised }) => state.systemInfo,
);
const dispatch = useDispatch();
useEffect(() => {
if (!systemInfo.SDKVersion) {
Taro.getSystemInfo().then(res => {
dispatch(updateSystemInfo(res));
});
}
}, []);
return systemInfo;
};
export default useSystemInfo;
...@@ -16,6 +16,8 @@ import { addFeedback } from '@/api/feedback'; ...@@ -16,6 +16,8 @@ import { addFeedback } from '@/api/feedback';
import useButtonPadding from '@/hooks/useButtonPadding'; import useButtonPadding from '@/hooks/useButtonPadding';
import FeedbackItem from './components/FeedbackItem/FeedbackItem'; import FeedbackItem from './components/FeedbackItem/FeedbackItem';
import { formatDate } from '@/utils/time'; import { formatDate } from '@/utils/time';
import useSystemInfo from '@/hooks/useSystemInfo';
import { compareVersion } from '@/utils/version';
function Feedback() { function Feedback() {
useShareAppMessage(shareHandle); useShareAppMessage(shareHandle);
...@@ -68,7 +70,10 @@ function Feedback() { ...@@ -68,7 +70,10 @@ function Feedback() {
} }
}; };
const [scrollTop, setScrollTop] = useState(0); const [scrollTop, setScrollTop] = useState(0);
const systemInfo = useSystemInfo();
useEffect(() => { useEffect(() => {
if (compareVersion(systemInfo.SDKVersion, '2.7.0')) {
wx.onKeyboardHeightChange(res => { wx.onKeyboardHeightChange(res => {
console.log(res.height); console.log(res.height);
if (res.height) { if (res.height) {
...@@ -77,6 +82,9 @@ function Feedback() { ...@@ -77,6 +82,9 @@ function Feedback() {
setShowKeyboard(false); setShowKeyboard(false);
} }
}); });
} else {
console.log('in focus');
}
}, []); }, []);
useEffect(() => { useEffect(() => {
Taro.createSelectorQuery() Taro.createSelectorQuery()
......
...@@ -8,6 +8,7 @@ import { connect } from '@tarojs/redux'; ...@@ -8,6 +8,7 @@ import { connect } from '@tarojs/redux';
import { updateUserInfo, UserState } from '../../store/rootReducers/userinfo'; import { updateUserInfo, UserState } from '../../store/rootReducers/userinfo';
import { appLogin } from '../../api/customer'; import { appLogin } from '../../api/customer';
import { shareHandle } from '@/common/shareMethod'; import { shareHandle } from '@/common/shareMethod';
import useSystemInfo from '@/hooks/useSystemInfo';
type PageDispatchProps = { type PageDispatchProps = {
updateUserInfo: (e: UserState | { token: string }) => void; updateUserInfo: (e: UserState | { token: string }) => void;
...@@ -97,6 +98,7 @@ class Index extends Component { ...@@ -97,6 +98,7 @@ class Index extends Component {
render() { render() {
const { errorText } = this.state; const { errorText } = this.state;
useSystemInfo();
return <View className='Index'>{errorText}</View>; return <View className='Index'>{errorText}</View>;
} }
} }
......
...@@ -5,6 +5,7 @@ import ShowerReducer from '@/pages/Shower/store'; ...@@ -5,6 +5,7 @@ import ShowerReducer from '@/pages/Shower/store';
import serviceList from './rootReducers/service'; import serviceList from './rootReducers/service';
import orderState from './rootReducers/orderState'; import orderState from './rootReducers/orderState';
import showerState from './rootReducers/shower'; import showerState from './rootReducers/shower';
import systemInfo from './rootReducers/systemInfo';
export default combineReducers({ export default combineReducers({
userinfo, userinfo,
...@@ -13,4 +14,5 @@ export default combineReducers({ ...@@ -13,4 +14,5 @@ export default combineReducers({
serviceList, serviceList,
orderState, orderState,
showerState, showerState,
systemInfo,
}); });
import Actions from '@/types/Store/Actions';
const INITIAL_STATE = {
brand: '',
model: '',
pixelRatio: '',
screenWidth: 0,
screenHeight: 0,
windowWidth: 0,
windowHeight: 0,
statusBarHeight: 0,
language: '',
version: '',
system: '',
platform: '',
fontSizeSetting: 0,
SDKVersion: '',
};
export const updateSystemInfo = (
entity: Taro.getSystemInfo.Promised,
): Actions => ({
type: 'UPDATE_SYSTEMINFO',
payload: entity,
});
export default function systemInfo(
state: Taro.getSystemInfo.Promised = INITIAL_STATE,
actions: Actions,
): Taro.getSystemInfo.Promised {
switch (actions.type) {
case 'UPDATE_SYSTEMINFO':
return {
...state,
...actions.payload,
};
default:
return state;
}
}
import Action from '../../types/Store/Actions'; import Action from '../../types/Store/Actions';
import { Customer } from '../../types/Customer/Customer'; import { Customer, CustomerSex } from '../../types/Customer/Customer';
export type UserState = StoreState<Customer & { code: string }>; export type UserState = StoreState<Customer & { code: string }>;
...@@ -14,7 +14,7 @@ export const INITIAL_STATE = { ...@@ -14,7 +14,7 @@ export const INITIAL_STATE = {
customerId: 0, customerId: 0,
customerName: '', customerName: '',
customerPhone: '', customerPhone: '',
customerSex: '', customerSex: CustomerSex.boy,
customerType: '', customerType: '',
email: '', email: '',
entranceDate: '', entranceDate: '',
......
export function compareVersion(v1: string, v2: string): boolean {
let v1Arr = v1.split('.');
let v2Arr = v2.split('.');
const len = Math.max(v1.length, v2.length);
while (v1.length < len) {
v1Arr.push('0');
}
while (v2.length < len) {
v2Arr.push('0');
}
for (let i = 0; i < len; i++) {
const num1 = parseInt(v1[i]);
const num2 = parseInt(v2[i]);
if (num1 > num2) {
return true;
} else if (num1 < num2) {
return false;
}
}
return true;
}
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