refactor user and app service
This commit is contained in:
+3
-16
@@ -1,26 +1,13 @@
|
||||
import { PropsWithChildren } from 'react';
|
||||
import Taro, { useLaunch } from '@tarojs/taro';
|
||||
import { getUrl } from '@/service';
|
||||
import pt from '@/plain-text';
|
||||
import { useLaunch } from '@tarojs/taro';
|
||||
import 'taro-ui/dist/style/index.scss';
|
||||
import './app.scss';
|
||||
import { getLocaleData } from './service/localeData';
|
||||
|
||||
function App({ children }: PropsWithChildren<any>) {
|
||||
useLaunch(() => {
|
||||
console.log('App launched.');
|
||||
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',
|
||||
});
|
||||
});
|
||||
getLocaleData();
|
||||
});
|
||||
|
||||
// children 是将要会渲染的页面
|
||||
|
||||
+2
-11
@@ -1,7 +1,6 @@
|
||||
import { AtList, AtListItem, AtToast } from 'taro-ui';
|
||||
import { Component, ReactNode } from 'react';
|
||||
import { View, Picker, Image, Text } from '@tarojs/components';
|
||||
import { getUrl } from '@/service';
|
||||
import Taro from '@tarojs/taro';
|
||||
import type CustomTabBar from '@/custom-tab-bar';
|
||||
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 wechatUser from '@/wechat';
|
||||
import logo from '@/assets/images/UserPage/logo.png';
|
||||
import { setLocaleData } from '@/service/localeData';
|
||||
import './user.scss';
|
||||
|
||||
const listLangInterval = 20;
|
||||
@@ -70,16 +70,7 @@ export default class UserPage extends Component {
|
||||
});
|
||||
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);
|
||||
});
|
||||
setLocaleData(currentLang);
|
||||
Taro.reLaunch({
|
||||
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',
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user