add locale request

yhy
Dawn_Ocean 2024-03-08 21:24:08 +08:00
parent 1907f1e967
commit 00977db512
5 changed files with 36045 additions and 36024 deletions

View File

@ -29,7 +29,7 @@ export default {
success: true, success: true,
data: { data: {
token: 'token_test', token: 'token_test',
lang: 'zn_CN', lang: 'en_US',
}, },
}, },
'POST /user/locale/update': { 'POST /user/locale/update': {

2
package-lock.json generated
View File

@ -33,7 +33,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@tarojs/cli": "3.6.24", "@tarojs/cli": "3.6.24",
"@tarojs/plugin-mock": "^0.0.9", "@tarojs/plugin-mock": "^0.0.9",
"@tarojs/plugin-platform-h5": "^3.6.24", "@tarojs/plugin-platform-h5": "3.6.24",
"@tarojs/taro-loader": "3.6.24", "@tarojs/taro-loader": "3.6.24",
"@tarojs/test-utils-react": "^0.1.1", "@tarojs/test-utils-react": "^0.1.1",
"@tarojs/webpack5-runner": "3.6.24", "@tarojs/webpack5-runner": "3.6.24",

View File

@ -65,7 +65,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5",
"@tarojs/cli": "3.6.24", "@tarojs/cli": "3.6.24",
"@tarojs/plugin-mock": "^0.0.9", "@tarojs/plugin-mock": "^0.0.9",
"@tarojs/plugin-platform-h5": "^3.6.24", "@tarojs/plugin-platform-h5": "3.6.24",
"@tarojs/taro-loader": "3.6.24", "@tarojs/taro-loader": "3.6.24",
"@tarojs/test-utils-react": "^0.1.1", "@tarojs/test-utils-react": "^0.1.1",
"@tarojs/webpack5-runner": "3.6.24", "@tarojs/webpack5-runner": "3.6.24",

View File

@ -1,11 +1,20 @@
import { PropsWithChildren } from 'react'; import { PropsWithChildren } from 'react';
import { useLaunch } from '@tarojs/taro'; import Taro, { useLaunch } from '@tarojs/taro';
import { getUrl } from '@/service';
import pt from '@/plain-text';
import 'taro-ui/dist/style/index.scss'; import 'taro-ui/dist/style/index.scss';
import './app.scss'; import './app.scss';
function App({ children }: PropsWithChildren<any>) { function App({ children }: PropsWithChildren<any>) {
useLaunch(() => { useLaunch(() => {
console.log('App launched.'); console.log('App launched.');
Taro.request({
url: getUrl('/user/locale/get'),
method: 'GET',
}).then(res => {
console.log(res.data);
pt.setLang(res.data.data.lang);
});
}); });
// children 是将要会渲染的页面 // children 是将要会渲染的页面

View File

@ -1,6 +1,7 @@
import { AtList, AtListItem } from 'taro-ui'; import { AtList, AtListItem } from 'taro-ui';
import { Component, ReactNode } from 'react'; import { Component, ReactNode } from 'react';
import { View, Picker, Image, Text } from '@tarojs/components'; import { View, Picker, Image, Text } from '@tarojs/components';
import { getUrl } from '@/service';
import Taro from '@tarojs/taro'; import Taro from '@tarojs/taro';
import type CustomTabBar from '@/custom-tab-bar'; import type CustomTabBar from '@/custom-tab-bar';
import PageFooter from '@/components/PageFooter/PageFooter'; import PageFooter from '@/components/PageFooter/PageFooter';
@ -35,7 +36,18 @@ export default class UserPage extends Component {
this.setState({ this.setState({
selectorChecked: this.state.selector[e.detail.value], selectorChecked: this.state.selector[e.detail.value],
}); });
pt.setLang(this.showLangDict[this.state.selector[e.detail.value]]); let currentLang = this.showLangDict[this.state.selector[e.detail.value]];
pt.setLang(currentLang);
Taro.request({
url: getUrl('/user/locale/update'),
method: 'POST',
data: {
token: 'token_test',
lang: currentLang,
},
}).then(res => {
console.log(res.data);
});
Taro.reLaunch({ Taro.reLaunch({
url: '/pages/user/user', url: '/pages/user/user',
}); });