refactor user and app service
parent
9c6cbd91ff
commit
eaa22dcaa5
19
src/app.ts
19
src/app.ts
|
|
@ -1,26 +1,13 @@
|
||||||
import { PropsWithChildren } from 'react';
|
import { PropsWithChildren } from 'react';
|
||||||
import Taro, { useLaunch } from '@tarojs/taro';
|
import { 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';
|
||||||
|
import { getLocaleData } from './service/localeData';
|
||||||
|
|
||||||
function App({ children }: PropsWithChildren<any>) {
|
function App({ children }: PropsWithChildren<any>) {
|
||||||
useLaunch(() => {
|
useLaunch(() => {
|
||||||
console.log('App launched.');
|
console.log('App launched.');
|
||||||
Taro.request({
|
getLocaleData();
|
||||||
url: getUrl('/user/locale/get'),
|
|
||||||
method: 'GET',
|
|
||||||
data: {
|
|
||||||
token: 'token_test',
|
|
||||||
},
|
|
||||||
}).then(res => {
|
|
||||||
console.log(res.data);
|
|
||||||
pt.setLang(res.data.data.lang);
|
|
||||||
Taro.reLaunch({
|
|
||||||
url: '/pages/index/index',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// children 是将要会渲染的页面
|
// children 是将要会渲染的页面
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { AtList, AtListItem, AtToast } from 'taro-ui';
|
import { AtList, AtListItem, AtToast } 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';
|
||||||
|
|
@ -9,6 +8,7 @@ import aboutIcon from '@/assets/icons/AboutPage/about.svg';
|
||||||
import pt, { Lang } from '@/plain-text';
|
import pt, { Lang } from '@/plain-text';
|
||||||
import wechatUser from '@/wechat';
|
import wechatUser from '@/wechat';
|
||||||
import logo from '@/assets/images/UserPage/logo.png';
|
import logo from '@/assets/images/UserPage/logo.png';
|
||||||
|
import { setLocaleData } from '@/service/localeData';
|
||||||
import './user.scss';
|
import './user.scss';
|
||||||
|
|
||||||
const listLangInterval = 20;
|
const listLangInterval = 20;
|
||||||
|
|
@ -70,16 +70,7 @@ export default class UserPage extends Component {
|
||||||
});
|
});
|
||||||
let currentLang = this.showLangDict[this.state.selector[e.detail.value]];
|
let currentLang = this.showLangDict[this.state.selector[e.detail.value]];
|
||||||
pt.setLang(currentLang);
|
pt.setLang(currentLang);
|
||||||
Taro.request({
|
setLocaleData(currentLang);
|
||||||
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',
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
import Taro from '@tarojs/taro';
|
||||||
|
import pt, { Lang } from '@/plain-text';
|
||||||
|
import { getUrl } from '.';
|
||||||
|
|
||||||
|
export function setLocaleData(lang: Lang) {
|
||||||
|
Taro.request({
|
||||||
|
url: getUrl('/user/locale/update'),
|
||||||
|
method: 'POST',
|
||||||
|
data: {
|
||||||
|
token: 'token_test',
|
||||||
|
lang: lang,
|
||||||
|
},
|
||||||
|
}).then(res => {
|
||||||
|
console.log(res.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLocaleData() {
|
||||||
|
Taro.request({
|
||||||
|
url: getUrl('/user/locale/get'),
|
||||||
|
method: 'GET',
|
||||||
|
data: {
|
||||||
|
token: 'token_test',
|
||||||
|
},
|
||||||
|
}).then(res => {
|
||||||
|
console.log(res.data);
|
||||||
|
pt.setLang(res.data.data.lang);
|
||||||
|
Taro.reLaunch({
|
||||||
|
url: '/pages/index/index',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue