ini myapp and review rest api
This commit is contained in:
@@ -8,6 +8,7 @@ import { BaseLocalStorage, ScreenUtil } from '@devwiki/base';
|
||||
import { HomeItem, HomeItemGroup } from '../model/Home';
|
||||
import { Context } from '@kit.AbilityKit';
|
||||
import { Calculator } from '@devwiki/hmcalculate';
|
||||
import { MyApp } from '../MyApp';
|
||||
|
||||
import('./animation/LoadingPage')
|
||||
|
||||
@@ -68,8 +69,8 @@ struct Index {
|
||||
];
|
||||
|
||||
aboutToAppear(): void {
|
||||
ScreenUtil.getInstance().initScreenSize();
|
||||
BaseLocalStorage.getInstance().init(getContext(this));
|
||||
ScreenUtil.getInstance().initScreenSize(MyApp.appContext);
|
||||
BaseLocalStorage.getInstance().init(MyApp.appContext);
|
||||
}
|
||||
|
||||
onPageShow(): void {
|
||||
|
@@ -1,5 +1,8 @@
|
||||
import { Log } from '@devwiki/base/Index';
|
||||
import axios, { AxiosError, AxiosResponse } from '@ohos/axios'
|
||||
import http from '@ohos.net.http';
|
||||
|
||||
const TAG = '[RestAPIPage]'
|
||||
|
||||
@Entry({routeName: "RestAPIPage"})
|
||||
@Component
|
||||
@@ -8,29 +11,37 @@ export struct RestAPIPage {
|
||||
@State viewModel: RestAPIViewModel = new RestAPIViewModel();
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Column() {
|
||||
Flex({
|
||||
justifyContent: FlexAlign.SpaceBetween
|
||||
justifyContent: FlexAlign.Start,
|
||||
direction: FlexDirection.Column,
|
||||
alignItems: ItemAlign.Center
|
||||
}) {
|
||||
Button("Get").onClick(() =>{
|
||||
this.viewModel.getServerVersion();
|
||||
})
|
||||
Button("GetByAxios").onClick(() =>{
|
||||
this.viewModel.getServerVersionByAxios();
|
||||
}).margin({top: 20})
|
||||
|
||||
Text(this.viewModel.serverVersion).backgroundColor(Color.Blue).flexGrow(1);
|
||||
}
|
||||
}.justifyContent(FlexAlign.Start).alignItems(VerticalAlign.Center).width('80%').backgroundColor(Color.Green)
|
||||
Button("GetByHttp").onClick(() =>{
|
||||
this.viewModel.getServerVersionByHttp();
|
||||
}).margin({top: 20})
|
||||
|
||||
Text(this.viewModel.serverVersion).margin({top: 20})
|
||||
}.width('80%')
|
||||
}.width('100%')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class RestAPIViewModel {
|
||||
|
||||
readonly viewUrl: string = 'https://music.devwiki.net/rest/ping.view?v=1.16.1&c=myapp&f=json';
|
||||
serverVersion: string = '123'
|
||||
|
||||
async getServerVersion() {
|
||||
async getServerVersionByAxios() {
|
||||
this.serverVersion = ''
|
||||
await axios({
|
||||
method: "post",
|
||||
url: 'https://music.devwiki.net/rest/ping.view?v=1.16.1&c=myapp&f=json'
|
||||
url: this.viewUrl
|
||||
}).then((response: AxiosResponse) => {
|
||||
if (response.status == 200) {
|
||||
let version:string = response.data['subsonic-response']['serverVersion'];
|
||||
@@ -41,4 +52,22 @@ class RestAPIViewModel {
|
||||
Log.e(error.message);
|
||||
})
|
||||
}
|
||||
|
||||
getServerVersionByHttp() {
|
||||
this.serverVersion = ''
|
||||
let httpRequest = http.createHttp();
|
||||
let option:http.HttpRequestOptions = {
|
||||
method: http.RequestMethod.GET
|
||||
};
|
||||
httpRequest.request(this.viewUrl, option, (error, resp) =>{
|
||||
if (!error) {
|
||||
Log.i(TAG, 'request http code:' + resp.responseCode)
|
||||
let version:string = resp.result['subsonic-response']['serverVersion'];
|
||||
this.serverVersion = version;
|
||||
} else {
|
||||
Log.e(TAG, `request failed, code:${error.code}, message:${error.message}`)
|
||||
}
|
||||
httpRequest.destroy();
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,5 +1,8 @@
|
||||
import { TitleBar } from '@devwiki/common_ui';
|
||||
import { i18n } from '@kit.LocalizationKit';
|
||||
import { Log } from '@devwiki/base';
|
||||
|
||||
const TAG = '[SetLanguagePage]'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@@ -7,6 +10,13 @@ struct SetLanguagePage {
|
||||
private readonly languageGroup = "languageGroup"
|
||||
@State selectedLanguage: string = 'zh-Hans';
|
||||
|
||||
aboutToAppear(): void {
|
||||
let languages:string[] = i18n.System.getSystemLanguages();
|
||||
languages.forEach((value, index) => {
|
||||
Log.i(TAG, `${index.toString()}:${value}`)
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
TitleBar({
|
||||
|
Reference in New Issue
Block a user