Skip to content
Snippets Groups Projects
Commit 82e7df8b authored by 沈 芳's avatar 沈 芳
Browse files

delete和done

parent ac06cd9d
No related branches found
No related tags found
No related merge requests found
......@@ -201,6 +201,46 @@ export default class webAPI {
return result
}
static async DoneSingleItem(id:number): Promise<string> {
/*
新建事项,返回string类型结果
* 1. 成功:success
* 2. 失败:error
*/
if(webAPI.token == '') {
promptAction.showToast({ message: '未登录,添加事项失败' })
return 'error'
}
let httpRequest = http.createHttp()
let result = 'error' // 默认返回 error
try {
const data = await httpRequest.request('localhost:8080/api/todolist/add', {
method: http.RequestMethod.POST,
header: {
'token': webAPI.token
},
extraData: {
"id": id,
"isDone": 'TRUE',
"userId": webAPI.userId
},
})
if (data.responseCode === 200) {
result = 'success'
} else {
result = 'error'
}
// for debug
// console.log(String(JSON.stringify(data)))
} catch (error) {
console.error('Registration API error:', error)
result = 'error'
} finally {
httpRequest.destroy()
}
return result
}
static async getDone(): Promise<number> {
/*
获取当前用户已完成的事项数目
......@@ -232,4 +272,35 @@ export default class webAPI {
return -1
}
static async DeleteSingleItem(id:number): Promise<string> {
/*
用户登录,返回string类型结果
* 1. 成功:success
* 2. 失败:failed(大概率是手机号/密码错误)
*/
let httpRequest = http.createHttp()
let result = '' // 初始值为空字符串
try {
const data = await httpRequest.request(`localhost:8080/api/todolist/update?id=${id}`, {
method: http.RequestMethod.POST,
header: {
'token': webAPI.token
}
});
if (data.responseCode === 200) {
result = 'success'
} else {
result = 'error'
}
// for debug
// console.log(String(JSON.stringify(data)))
} catch (error) {
console.error('Login API error:', error)
result = 'failed'
} finally {
httpRequest.destroy()
}
return result
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
import CommonConstants from '../public/CommonConstant'
import TodoItemModel from '../viewmodel/TodoItemModel'
import { promptAction } from '@kit.ArkUI'
import webAPI from '../public/WebAPI'
@Component
export default struct ItemDetail {
......@@ -73,117 +74,6 @@ export default struct ItemDetail {
@Builder
MainPage() {
/* Column() {
Row() {
Text('名字')
.fontSize(CommonConstants.detail_title_font_size)
.fontWeight(FontWeight.Bold)
.width(CommonConstants.detail_width)
.margin({
left: CommonConstants.detail_margin_Left
})
Text(this.content.itemName)
.fontSize(CommonConstants.detail_font_size)
.width(CommonConstants.detail_width)
.textAlign(TextAlign.Center)
}
}
.margin({
top: CommonConstants.list_margin_top
})
.width(CommonConstants.list_width)
.height(CommonConstants.name_height)
.backgroundColor($r('app.color.white'))
.borderRadius(CommonConstants.border_radius)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Start)
Column() {
Row() {
Text('描述')
.fontSize(CommonConstants.detail_title_font_size)
.fontWeight(FontWeight.Bold)
.width(CommonConstants.detail_width)
.margin({
left: CommonConstants.detail_margin_Left
})
Scroll() {
Text(this.content.itemDisc)
.fontSize(CommonConstants.detail_font_size)
.width(CommonConstants.detail_width)
.textAlign(TextAlign.Center)
}
}
}
.margin({
top: CommonConstants.list_margin_top
})
.width(CommonConstants.list_width)
.height(CommonConstants.disc_height)
.backgroundColor($r('app.color.white'))
.borderRadius(CommonConstants.border_radius)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Start)
Column() {
Row() {
Text('时间')
.fontSize(CommonConstants.detail_title_font_size)
.fontWeight(FontWeight.Bold)
.width(CommonConstants.detail_width)
.margin({
left: CommonConstants.detail_margin_Left
})
Scroll() {
Text(this.content.itemTime)
.fontSize(CommonConstants.detail_font_size)
.width(CommonConstants.detail_width)
.textAlign(TextAlign.Center)
}
}
}
.margin({
top: CommonConstants.list_margin_top
})
.width(CommonConstants.list_width)
.height(CommonConstants.time_height)
.backgroundColor($r('app.color.white'))
.borderRadius(CommonConstants.border_radius)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Start)
if(this.content.isCompleted) {
Column() {
Row() {
Text('完成时间')
.fontSize(CommonConstants.detail_title_font_size)
.fontWeight(FontWeight.Bold)
.width(CommonConstants.detail_width)
.margin({
left: CommonConstants.detail_margin_Left
})
Scroll() {
Text(this.content.completeTime)
.fontSize(CommonConstants.detail_font_size)
.width(CommonConstants.detail_width)
.textAlign(TextAlign.Center)
}
}
}
.margin({
top: CommonConstants.list_margin_top
})
.width(CommonConstants.list_width)
.height(CommonConstants.time_height)
.backgroundColor($r('app.color.white'))
.borderRadius(CommonConstants.border_radius)
.justifyContent(FlexAlign.Center)
.alignItems(HorizontalAlign.Start)
}*/
Column() {
// 名字行
Row() {
......@@ -285,11 +175,19 @@ export default struct ItemDetail {
}
private deleteItem() {
//todo:删除(还有更新)
promptAction.showToast({
message: '删除成功!'
})
private async deleteItem() {
// 删除事件
const res = await webAPI.DeleteSingleItem(this.content.id)
if(res == 'success') {
promptAction.showToast({ message: '删除成功' })
setTimeout(() => {
}, 500)
}
else {
promptAction.showToast({ message: '删除失败' })
}
this.LocalPageStack.pop({},true)
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ import CommonConstants from '../public/CommonConstant'
import TodoItemModel from '../viewmodel/TodoItemModel'
import { promptAction } from '@kit.ArkUI'
import { http } from '@kit.NetworkKit'
import webAPI from '../public/WebAPI';
interface HttpError {
message: string;
......@@ -31,7 +32,8 @@ export default struct ToDoItem {
.margin(CommonConstants.checkbox_margin)
.onClick(() => {
// this.myTask.isCompleted = !this.myTask.isCompleted
this.markComplete()
//this.markComplete()
this.DoneItem(this.myTask.id)
})
}
......@@ -115,4 +117,19 @@ export default struct ToDoItem {
// })
// }
}
private async DoneItem(id:number) {
// 完成事件
const res = await webAPI.DoneSingleItem(id)
if(res == 'success') {
promptAction.showToast({ message: '已完成此事件' })
setTimeout(() => {
}, 500)
}
else {
promptAction.showToast({ message: '完成失败' })
}
this.LocalPageStack.pop({},true)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment