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';
import useButtonPadding from '@/hooks/useButtonPadding';
import FeedbackItem from './components/FeedbackItem/FeedbackItem';
import { formatDate } from '@/utils/time';
import useSystemInfo from '@/hooks/useSystemInfo';
import { compareVersion } from '@/utils/version';
function Feedback() {
useShareAppMessage(shareHandle);
......@@ -68,15 +70,21 @@ function Feedback() {
}
};
const [scrollTop, setScrollTop] = useState(0);
const systemInfo = useSystemInfo();
useEffect(() => {
wx.onKeyboardHeightChange(res => {
console.log(res.height);
if (res.height) {
setShowKeyboard(true);
} else {
setShowKeyboard(false);
}
});
if (compareVersion(systemInfo.SDKVersion, '2.7.0')) {
wx.onKeyboardHeightChange(res => {
console.log(res.height);
if (res.height) {
setShowKeyboard(true);
} else {
setShowKeyboard(false);
}
});
} else {
console.log('in focus');
}
}, []);
useEffect(() => {
Taro.createSelectorQuery()
......
......@@ -8,6 +8,7 @@ import { connect } from '@tarojs/redux';
import { updateUserInfo, UserState } from '../../store/rootReducers/userinfo';
import { appLogin } from '../../api/customer';
import { shareHandle } from '@/common/shareMethod';
import useSystemInfo from '@/hooks/useSystemInfo';
type PageDispatchProps = {
updateUserInfo: (e: UserState | { token: string }) => void;
......@@ -97,6 +98,7 @@ class Index extends Component {
render() {
const { errorText } = this.state;
useSystemInfo();
return <View className='Index'>{errorText}</View>;
}
}
......
......@@ -5,6 +5,7 @@ import ShowerReducer from '@/pages/Shower/store';
import serviceList from './rootReducers/service';
import orderState from './rootReducers/orderState';
import showerState from './rootReducers/shower';
import systemInfo from './rootReducers/systemInfo';
export default combineReducers({
userinfo,
......@@ -13,4 +14,5 @@ export default combineReducers({
serviceList,
orderState,
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 { Customer } from '../../types/Customer/Customer';
import { Customer, CustomerSex } from '../../types/Customer/Customer';
export type UserState = StoreState<Customer & { code: string }>;
......@@ -14,7 +14,7 @@ export const INITIAL_STATE = {
customerId: 0,
customerName: '',
customerPhone: '',
customerSex: '',
customerSex: CustomerSex.boy,
customerType: '',
email: '',
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