diff --git a/entry/src/main/ets/pages/components/AutoMode.ets b/entry/src/main/ets/pages/components/AutoMode.ets index b393713..64255c4 100644 --- a/entry/src/main/ets/pages/components/AutoMode.ets +++ b/entry/src/main/ets/pages/components/AutoMode.ets @@ -362,7 +362,7 @@ export struct AutoMode { // Deep copy const t: ControlTask = this.startTask; const copy: ControlTask = this.createEmptyTask(); - copy.execTime = t.execTime; + copy.execTime = (t.execTime.includes(' ') ? t.execTime.split(' ')[1] : t.execTime).substring(0, 5); copy.timeType = t.timeType; t.loops.forEach((l: TaskLoop, i: number) => { copy.loops[i].turnOn = l.turnOn; @@ -373,7 +373,7 @@ export struct AutoMode { else if (type === 'stop') { const t: ControlTask = this.stopTask; const copy: ControlTask = this.createEmptyTask(); - copy.execTime = t.execTime; + copy.execTime = (t.execTime.includes(' ') ? t.execTime.split(' ')[1] : t.execTime).substring(0, 5); copy.timeType = t.timeType; t.loops.forEach((l: TaskLoop, i: number) => { copy.loops[i].turnOn = l.turnOn; @@ -384,7 +384,7 @@ export struct AutoMode { else if (type === 'middle') { const t: ControlTask = index >= 0 ? this.middleTasks[index] : this.createEmptyTask(); const copy: ControlTask = this.createEmptyTask(); - copy.execTime = t.execTime; + copy.execTime = (t.execTime.includes(' ') ? t.execTime.split(' ')[1] : t.execTime).substring(0, 5); copy.timeType = t.timeType; t.loops.forEach((l: TaskLoop, i: number) => { copy.loops[i].turnOn = l.turnOn; @@ -468,12 +468,22 @@ export struct AutoMode { List() { ListItem() { - this.TaskCard('开始任务', this.startTask, (): void => {this.openEditDialog('start', -1);}) + TaskItem({ + title: '开始任务', + task: this.startTask, + onEdit: (): void => { this.openEditDialog('start', -1); } + }) } ForEach(this.middleTasks, (task: ControlTask, index: number) => { ListItem() { - this.TaskCard(`中间任务 ${index+1}`, task, (): void => {this.openEditDialog('middle', index);}, true, (): void => {this.deleteMiddleTask(index);}) + TaskItem({ + title: `中间任务 ${index+1}`, + task: task, + onEdit: (): void => { this.openEditDialog('middle', index); }, + isDeletable: true, + onDelete: (): void => { this.deleteMiddleTask(index); } + }) } }) @@ -487,7 +497,11 @@ export struct AutoMode { } ListItem() { - this.TaskCard('结束任务', this.stopTask, (): void => {this.openEditDialog('stop', -1);}) + TaskItem({ + title: '结束任务', + task: this.stopTask, + onEdit: (): void => { this.openEditDialog('stop', -1); } + }) } } .layoutWeight(1) @@ -533,8 +547,6 @@ export struct AutoMode { .justifyContent(FlexAlign.Center) .padding(10) - - // Dialog if(this.showTaskDialog) { Stack() { @@ -567,21 +579,13 @@ export struct AutoMode { if (this.editingTask.timeType === 0) { Text('执行时间').fontColor('#b2ebf2').margin({top: 15, bottom: 5}).alignSelf(ItemAlign.Start).fontSize(14) Row() { - TextInput({ text: this.editingTask.execTime.split(' ')[1] ? this.editingTask.execTime.split(' ')[1].substring(0,5) : '00:00' }) + TextInput({ text: this.editingTask.execTime.includes(' ') ? this.editingTask.execTime.split(' ')[1].substring(0,5) : this.editingTask.execTime }) .width(120).height(40) .backgroundColor('#333').fontColor('#fff') .borderRadius(5) .onChange((val: string) => { - // Simple validation/update. better to use TimePicker but native TimePicker takes much space. - // Assume user types HH:mm. we append to today's date prefix on save or keep full string. - // Reference Vue: uses picker. Here let's just use text input for simplicity or check if we can use TimePickerDialog - // For now update logic: if (val.length === 5) { - const today = new Date(); - const y = today.getFullYear(); - const m = String(today.getMonth() + 1).padStart(2, '0'); - const d = String(today.getDate()).padStart(2, '0'); - this.editingTask.execTime = `${y}-${m}-${d} ${val}:00`; + this.editingTask.execTime = val; } }) @@ -591,13 +595,9 @@ export struct AutoMode { TimePickerDialog.show({ useMilitaryTime: true, onAccept: (value: TimePickerResult) => { - const today = new Date(); - const y = today.getFullYear(); - const m = String(today.getMonth() + 1).padStart(2, '0'); - const d = String(today.getDate()).padStart(2, '0'); const h = String(value.hour).padStart(2, '0'); const min = String(value.minute).padStart(2, '0'); - this.editingTask.execTime = `${y}-${m}-${d} ${h}:${min}:00`; + this.editingTask.execTime = `${h}:${min}`; } }) } catch(e) { @@ -683,28 +683,39 @@ export struct AutoMode { .width('100%').height('100%') .zIndex(1000) } + } } } - @Builder - TaskCard(title: string, task: ControlTask, onEdit: () => void, isDeletable: boolean = false, onDelete?: () => void) { +@Component +struct TaskItem { + @Prop title: string; + @ObjectLink task: ControlTask; + onEdit: () => void = () => {}; + @Prop isDeletable: boolean = false; + onDelete: () => void = () => {}; + + build() { Column() { Row() { - Text(title).fontColor('#22fdc8').fontWeight(FontWeight.Bold) + Text(this.title).fontColor('#22fdc8').fontWeight(FontWeight.Bold) Blank() Column() { - Text(task.timeType === 0 ? '定时时间' : '经纬度时间') + Text(this.task.timeType === 0 ? '定时时间' : '经纬度时间') .fontSize(10) .fontColor('#aaa') .alignSelf(ItemAlign.End) - Text(task.execTime) + Text((this.task.execTime.includes(' ') ? this.task.execTime.split(' ')[1] : this.task.execTime).substring(0, 5)) .fontColor('#fff') .alignSelf(ItemAlign.End) + .onAppear(() => { + console.info(`TaskItem: ${this.title} time=${this.task.execTime}`); + }) } }.width('100%').margin({ bottom: 5 }) Row() { - ForEach(task.loops, (loop: TaskLoop) => { + ForEach(this.task.loops, (loop: TaskLoop) => { if (loop.turnOn) { Text(`${loop.index+1}`).fontSize(10).fontColor('#22fdc8').margin({right: 2}) } @@ -712,10 +723,10 @@ export struct AutoMode { }.width('100%') Row() { - Button('编辑').fontSize(10).height(24).onClick(onEdit) - if (isDeletable && onDelete) { - Button('删除').fontSize(10).height(24).backgroundColor('red').margin({left: 10}).onClick(onDelete) - } + Button('编辑').fontSize(10).height(24).onClick(this.onEdit) + if (this.isDeletable && this.onDelete) { + Button('删除').fontSize(10).height(24).backgroundColor('red').margin({left: 10}).onClick(this.onDelete) + } }.width('100%').justifyContent(FlexAlign.End).margin({ top: 5 }) } .backgroundColor('rgba(20, 38, 81, 0.95)')