From 53877a1023796eaabd74a479204846ae16431205 Mon Sep 17 00:00:00 2001 From: yz <221840196@smail.nju.edu.cn> Date: Fri, 17 Jan 2025 01:47:51 +0800 Subject: [PATCH] feat: user API --- entry/src/main/ets/pages/Index.ets | 2 +- entry/src/main/ets/pages/LocalPage.ets | 2 +- entry/src/main/ets/pages/LoginPage.ets | 26 ++-- entry/src/main/ets/pages/RegisterPage.ets | 3 +- .../ets/{common => public}/CommonConstant.ets | 128 +++++++++--------- entry/src/main/ets/public/WebAPI.ets | 69 ++++++++++ entry/src/main/ets/view/AddItem.ets | 2 +- entry/src/main/ets/view/ItemDetail.ets | 2 +- entry/src/main/ets/view/TodoItem.ets | 2 +- 9 files changed, 155 insertions(+), 81 deletions(-) rename entry/src/main/ets/{common => public}/CommonConstant.ets (97%) create mode 100644 entry/src/main/ets/public/WebAPI.ets diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 7e9f61f..183cf3b 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -1,5 +1,5 @@ // 棣栭〉锛氬鑸爮+瀛愰〉闈� -import CommonConstants from '../common/CommonConstant'; +import CommonConstants from '../public/CommonConstant'; import {LocalPage} from '../pages/LocalPage' import {Login} from '../pages/LoginPage' diff --git a/entry/src/main/ets/pages/LocalPage.ets b/entry/src/main/ets/pages/LocalPage.ets index 4c09e37..928616c 100644 --- a/entry/src/main/ets/pages/LocalPage.ets +++ b/entry/src/main/ets/pages/LocalPage.ets @@ -1,6 +1,6 @@ // Todolist椤甸潰 import ToDoItem from '../view/TodoItem' -import CommonConstants from '../common/CommonConstant' +import CommonConstants from '../public/CommonConstant' import TodoItemModel from '../viewmodel/TodoItemModel' import AddItem from '../view/AddItem'; diff --git a/entry/src/main/ets/pages/LoginPage.ets b/entry/src/main/ets/pages/LoginPage.ets index 1139af4..af5d1a4 100644 --- a/entry/src/main/ets/pages/LoginPage.ets +++ b/entry/src/main/ets/pages/LoginPage.ets @@ -1,6 +1,7 @@ // 鐧婚檰椤甸潰 import { router, promptAction } from '@kit.ArkUI' -import CommonConstants from '../common/CommonConstant' +import CommonConstants from '../public/CommonConstant' +import { getCurrentUser, loginAPI, registerAPI } from '../public/WebAPI'; import './RegisterPage' import Register from './RegisterPage'; @@ -20,16 +21,19 @@ export struct Login { // 鎻愪氦 handleSubmit() { - if(this.phone === '' || this.pwd === '') { - promptAction.showToast({ message: '鎵嬫満鍙锋垨瀵嗙爜涓嶈兘涓虹┖' }) - }else { - // 鐧诲綍鎺ュ彛閫昏緫... - - promptAction.showToast({ message: '鐧诲綍鎴愬姛' }) - setTimeout(() => { - router.replaceUrl({ url: 'pages/Index' }) - }, 2000) - } + // getCurrentUser() + // loginAPI("123","123") + registerAPI("yz", "123", "123") + // if(this.phone === '' || this.pwd === '') { + // promptAction.showToast({ message: '鎵嬫満鍙锋垨瀵嗙爜涓嶈兘涓虹┖' }) + // }else { + // // 鐧诲綍鎺ュ彛閫昏緫... + // + // promptAction.showToast({ message: '鐧诲綍鎴愬姛' }) + // setTimeout(() => { + // router.replaceUrl({ url: 'pages/Index' }) + // }, 2000) + // } } build() { diff --git a/entry/src/main/ets/pages/RegisterPage.ets b/entry/src/main/ets/pages/RegisterPage.ets index 1eb47f1..99296d0 100644 --- a/entry/src/main/ets/pages/RegisterPage.ets +++ b/entry/src/main/ets/pages/RegisterPage.ets @@ -1,6 +1,6 @@ // 娉ㄥ唽椤甸潰 import { router, promptAction } from '@kit.ArkUI' -import CommonConstants from '../common/CommonConstant'; +import CommonConstants from '../public/CommonConstant'; @Component export default struct Register { @@ -72,6 +72,7 @@ export default struct Register { } .height('100%') .width('100%') + .backgroundColor($r("app.color.grey")) } .hideTitleBar(true) } diff --git a/entry/src/main/ets/common/CommonConstant.ets b/entry/src/main/ets/public/CommonConstant.ets similarity index 97% rename from entry/src/main/ets/common/CommonConstant.ets rename to entry/src/main/ets/public/CommonConstant.ets index 042c7e1..71351ed 100644 --- a/entry/src/main/ets/common/CommonConstant.ets +++ b/entry/src/main/ets/public/CommonConstant.ets @@ -1,65 +1,65 @@ -// 鏍峰紡闆嗗悎 -export default class CommonConstants { - - //姣忓垪瀹藉害 - static readonly column_space = 16 - - //浜嬮」妗嗙殑瀹�/楂樺害 - static readonly list_width = '93.3%' - static readonly list_height = '64vp' - static readonly list_margin_top = '13vp' - static readonly list_margin_bottom = '64vp' - - //浜嬮」鎵撳嬀鎸夐挳 - static readonly checkbox_width = '28vp' - static readonly checkbox_margin = '20vp' - //浜嬮」鏂囧瓧 - static readonly item_font_size = '20fp' - static readonly item_font_weight = '500' - //涓嶉€忔槑搴� - static readonly opacity_default = 1 - static readonly opacity_completed = 0.4 - //鍦嗚 - static readonly border_radius = 24 - - //涓嶅甫杩斿洖鎸夐挳鐨� 鏍囬 - static readonly title1_font_size = '33fp' - static readonly title1_font_height = '33vp' - static readonly title1_width = '75%' - static readonly title1_margin_top = '24vp' - static readonly title1_margin_bottom = '12vp' - static readonly title1_margin_left = '12vp' - //鎸夐挳 - static readonly button_font_size = '20fp' //鎸夐挳鐨勬枃鏈� - static readonly button_font_size_yes = '20fp' //鎵撳嬀鎸夐挳鐨勬枃鏈� - static readonly button_size = '45fp' //鎸夐挳澶у皬 - static readonly button_margin_top = '24vp' - static readonly button_margin_bottom = '12vp' - static readonly lb_margin_left = '-270' - static readonly rb_margin_left = '5' - - //涓棿鏍囬鎵€鍗犲搴� - static readonly mid_title_col_width = '70%' - //璇︽儏 - static readonly detail_margin_Left = '30' - static readonly detail_width = '40%' - //璇︽儏妗� - static readonly name_height = '80vp' - static readonly disc_height = '200vp' - static readonly time_height = '80vp' - //璇︽儏瀛椾綋 - static readonly detail_title_font_size = '25fp' - static readonly detail_font_size = '20fp' - static readonly time_font_size = '20fp' - static readonly detail_font_weight = '500' - - //杈撳叆妗� - static readonly add_name_width = '20%' - static readonly input_container_width = '65%' - static readonly input_disc_height = '80%' - static readonly input_margin_left = '5' - - //棰滆壊 - static readonly base_blue = '#0A59F7' - +// 鏍峰紡闆嗗悎 +export default class CommonConstants { + + //姣忓垪瀹藉害 + static readonly column_space = 16 + + //浜嬮」妗嗙殑瀹�/楂樺害 + static readonly list_width = '93.3%' + static readonly list_height = '64vp' + static readonly list_margin_top = '13vp' + static readonly list_margin_bottom = '64vp' + + //浜嬮」鎵撳嬀鎸夐挳 + static readonly checkbox_width = '28vp' + static readonly checkbox_margin = '20vp' + //浜嬮」鏂囧瓧 + static readonly item_font_size = '20fp' + static readonly item_font_weight = '500' + //涓嶉€忔槑搴� + static readonly opacity_default = 1 + static readonly opacity_completed = 0.4 + //鍦嗚 + static readonly border_radius = 24 + + //涓嶅甫杩斿洖鎸夐挳鐨� 鏍囬 + static readonly title1_font_size = '33fp' + static readonly title1_font_height = '33vp' + static readonly title1_width = '75%' + static readonly title1_margin_top = '24vp' + static readonly title1_margin_bottom = '12vp' + static readonly title1_margin_left = '12vp' + //鎸夐挳 + static readonly button_font_size = '20fp' //鎸夐挳鐨勬枃鏈� + static readonly button_font_size_yes = '20fp' //鎵撳嬀鎸夐挳鐨勬枃鏈� + static readonly button_size = '45fp' //鎸夐挳澶у皬 + static readonly button_margin_top = '24vp' + static readonly button_margin_bottom = '12vp' + static readonly lb_margin_left = '-270' + static readonly rb_margin_left = '5' + + //涓棿鏍囬鎵€鍗犲搴� + static readonly mid_title_col_width = '70%' + //璇︽儏 + static readonly detail_margin_Left = '30' + static readonly detail_width = '40%' + //璇︽儏妗� + static readonly name_height = '80vp' + static readonly disc_height = '200vp' + static readonly time_height = '80vp' + //璇︽儏瀛椾綋 + static readonly detail_title_font_size = '25fp' + static readonly detail_font_size = '20fp' + static readonly time_font_size = '20fp' + static readonly detail_font_weight = '500' + + //杈撳叆妗� + static readonly add_name_width = '20%' + static readonly input_container_width = '65%' + static readonly input_disc_height = '80%' + static readonly input_margin_left = '5' + + //棰滆壊 + static readonly base_blue = '#0A59F7' + } \ No newline at end of file diff --git a/entry/src/main/ets/public/WebAPI.ets b/entry/src/main/ets/public/WebAPI.ets new file mode 100644 index 0000000..641d475 --- /dev/null +++ b/entry/src/main/ets/public/WebAPI.ets @@ -0,0 +1,69 @@ +import { http } from '@kit.NetworkKit' + +export function getCurrentUser() { + let httpRequest = http.createHttp(); + let result = '' + httpRequest.request('localhost:8080/api/users/userInfo', { + method: http.RequestMethod.GET, + }).then((data) => { + if(data.responseCode == 200) { + // return userInfo + } + else { + // error + } + // for debug + console.log(String(JSON.stringify(data))) + }).finally(() => { + httpRequest.destroy() + return result + }); +} + +export function loginAPI(phone:string, psw:string) { + let httpRequest = http.createHttp(); + let result = '' + httpRequest.request( `localhost:8080/api/users/login?phone=${phone}&password=${psw}`, { + method: http.RequestMethod.POST, + }).then((data) => { + if(data.responseCode == 200) { + result = 'success' + } + else { + // error + } + // for debug + console.log(String(JSON.stringify(data))) + }).finally(() => { + httpRequest.destroy() + return result + }); +} + +export function registerAPI(name:string, phone:string, psw:string) { + let httpRequest = http.createHttp(); + let result = '' + httpRequest.request('localhost:8080/api/users/register', { + method: http.RequestMethod.POST, + header: { + 'Content-Type': 'application/json' + }, + extraData: { + "name": name, + "phone": phone, + "password": psw + }, + }).then((data) => { + if(data.responseCode == 200) { + result = 'success' + } + else { + // error + } + // for debug + console.log(String(JSON.stringify(data))) + }).finally(() => { + httpRequest.destroy() + return result + }); +} \ No newline at end of file diff --git a/entry/src/main/ets/view/AddItem.ets b/entry/src/main/ets/view/AddItem.ets index 96d3a9d..0b48472 100644 --- a/entry/src/main/ets/view/AddItem.ets +++ b/entry/src/main/ets/view/AddItem.ets @@ -1,5 +1,5 @@ // 娣诲姞浜嬮」椤甸潰 -import CommonConstants from '../common/CommonConstant' +import CommonConstants from '../public/CommonConstant' import { http } from '@kit.NetworkKit' import { promptAction } from '@kit.ArkUI'; import DataModel from '../viewmodel/DataModel'; diff --git a/entry/src/main/ets/view/ItemDetail.ets b/entry/src/main/ets/view/ItemDetail.ets index 2ca287f..6798682 100644 --- a/entry/src/main/ets/view/ItemDetail.ets +++ b/entry/src/main/ets/view/ItemDetail.ets @@ -1,5 +1,5 @@ // 浜嬮」璇︽儏椤甸潰 -import CommonConstants from '../common/CommonConstant' +import CommonConstants from '../public/CommonConstant' import DataModel from '../viewmodel/DataModel' import TodoItemModel from '../viewmodel/TodoItemModel' import { promptAction } from '@kit.ArkUI' diff --git a/entry/src/main/ets/view/TodoItem.ets b/entry/src/main/ets/view/TodoItem.ets index 9e5c4be..a6b422a 100644 --- a/entry/src/main/ets/view/TodoItem.ets +++ b/entry/src/main/ets/view/TodoItem.ets @@ -1,5 +1,5 @@ // 鍗曚釜浜嬮」 -import CommonConstants from '../common/CommonConstant' +import CommonConstants from '../public/CommonConstant' import TodoItemModel from '../viewmodel/TodoItemModel' import { promptAction } from '@kit.ArkUI' import { http } from '@kit.NetworkKit' -- GitLab