Lufaneng 6 months ago
parent edd1ba0555
commit 381a58dc01

@ -362,7 +362,7 @@ export struct AutoMode {
// Deep copy // Deep copy
const t: ControlTask = this.startTask; const t: ControlTask = this.startTask;
const copy: ControlTask = 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; copy.timeType = t.timeType;
t.loops.forEach((l: TaskLoop, i: number) => { t.loops.forEach((l: TaskLoop, i: number) => {
copy.loops[i].turnOn = l.turnOn; copy.loops[i].turnOn = l.turnOn;
@ -373,7 +373,7 @@ export struct AutoMode {
else if (type === 'stop') { else if (type === 'stop') {
const t: ControlTask = this.stopTask; const t: ControlTask = this.stopTask;
const copy: ControlTask = 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; copy.timeType = t.timeType;
t.loops.forEach((l: TaskLoop, i: number) => { t.loops.forEach((l: TaskLoop, i: number) => {
copy.loops[i].turnOn = l.turnOn; copy.loops[i].turnOn = l.turnOn;
@ -384,7 +384,7 @@ export struct AutoMode {
else if (type === 'middle') { else if (type === 'middle') {
const t: ControlTask = index >= 0 ? this.middleTasks[index] : this.createEmptyTask(); const t: ControlTask = index >= 0 ? this.middleTasks[index] : this.createEmptyTask();
const copy: ControlTask = 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; copy.timeType = t.timeType;
t.loops.forEach((l: TaskLoop, i: number) => { t.loops.forEach((l: TaskLoop, i: number) => {
copy.loops[i].turnOn = l.turnOn; copy.loops[i].turnOn = l.turnOn;
@ -468,12 +468,22 @@ export struct AutoMode {
List() { List() {
ListItem() { 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) => { ForEach(this.middleTasks, (task: ControlTask, index: number) => {
ListItem() { 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() { ListItem() {
this.TaskCard('结束任务', this.stopTask, (): void => {this.openEditDialog('stop', -1);}) TaskItem({
title: '结束任务',
task: this.stopTask,
onEdit: (): void => { this.openEditDialog('stop', -1); }
})
} }
} }
.layoutWeight(1) .layoutWeight(1)
@ -533,8 +547,6 @@ export struct AutoMode {
.justifyContent(FlexAlign.Center) .justifyContent(FlexAlign.Center)
.padding(10) .padding(10)
// Dialog // Dialog
if(this.showTaskDialog) { if(this.showTaskDialog) {
Stack() { Stack() {
@ -567,21 +579,13 @@ export struct AutoMode {
if (this.editingTask.timeType === 0) { if (this.editingTask.timeType === 0) {
Text('执行时间').fontColor('#b2ebf2').margin({top: 15, bottom: 5}).alignSelf(ItemAlign.Start).fontSize(14) Text('执行时间').fontColor('#b2ebf2').margin({top: 15, bottom: 5}).alignSelf(ItemAlign.Start).fontSize(14)
Row() { 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) .width(120).height(40)
.backgroundColor('#333').fontColor('#fff') .backgroundColor('#333').fontColor('#fff')
.borderRadius(5) .borderRadius(5)
.onChange((val: string) => { .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) { if (val.length === 5) {
const today = new Date(); this.editingTask.execTime = val;
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`;
} }
}) })
@ -591,13 +595,9 @@ export struct AutoMode {
TimePickerDialog.show({ TimePickerDialog.show({
useMilitaryTime: true, useMilitaryTime: true,
onAccept: (value: TimePickerResult) => { 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 h = String(value.hour).padStart(2, '0');
const min = String(value.minute).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) { } catch(e) {
@ -685,26 +685,37 @@ export struct AutoMode {
} }
} }
} }
}
@Component
struct TaskItem {
@Prop title: string;
@ObjectLink task: ControlTask;
onEdit: () => void = () => {};
@Prop isDeletable: boolean = false;
onDelete: () => void = () => {};
@Builder build() {
TaskCard(title: string, task: ControlTask, onEdit: () => void, isDeletable: boolean = false, onDelete?: () => void) {
Column() { Column() {
Row() { Row() {
Text(title).fontColor('#22fdc8').fontWeight(FontWeight.Bold) Text(this.title).fontColor('#22fdc8').fontWeight(FontWeight.Bold)
Blank() Blank()
Column() { Column() {
Text(task.timeType === 0 ? '定时时间' : '经纬度时间') Text(this.task.timeType === 0 ? '定时时间' : '经纬度时间')
.fontSize(10) .fontSize(10)
.fontColor('#aaa') .fontColor('#aaa')
.alignSelf(ItemAlign.End) .alignSelf(ItemAlign.End)
Text(task.execTime) Text((this.task.execTime.includes(' ') ? this.task.execTime.split(' ')[1] : this.task.execTime).substring(0, 5))
.fontColor('#fff') .fontColor('#fff')
.alignSelf(ItemAlign.End) .alignSelf(ItemAlign.End)
.onAppear(() => {
console.info(`TaskItem: ${this.title} time=${this.task.execTime}`);
})
} }
}.width('100%').margin({ bottom: 5 }) }.width('100%').margin({ bottom: 5 })
Row() { Row() {
ForEach(task.loops, (loop: TaskLoop) => { ForEach(this.task.loops, (loop: TaskLoop) => {
if (loop.turnOn) { if (loop.turnOn) {
Text(`${loop.index+1}`).fontSize(10).fontColor('#22fdc8').margin({right: 2}) Text(`${loop.index+1}`).fontSize(10).fontColor('#22fdc8').margin({right: 2})
} }
@ -712,9 +723,9 @@ export struct AutoMode {
}.width('100%') }.width('100%')
Row() { Row() {
Button('编辑').fontSize(10).height(24).onClick(onEdit) Button('编辑').fontSize(10).height(24).onClick(this.onEdit)
if (isDeletable && onDelete) { if (this.isDeletable && this.onDelete) {
Button('删除').fontSize(10).height(24).backgroundColor('red').margin({left: 10}).onClick(onDelete) Button('删除').fontSize(10).height(24).backgroundColor('red').margin({left: 10}).onClick(this.onDelete)
} }
}.width('100%').justifyContent(FlexAlign.End).margin({ top: 5 }) }.width('100%').justifyContent(FlexAlign.End).margin({ top: 5 })
} }

Loading…
Cancel
Save