|
|
@@ -4852,7 +4852,6 @@ export struct LocalMusic {
|
|
|
//倒计时关闭音乐,退出App功能实现。
|
|
|
@State selectedMinutes: number = 0 // 0表示未开启
|
|
|
@State remainingSeconds: number = 0
|
|
|
- @State isCustomSuccess: boolean = false //设置自定义成功
|
|
|
// 预设时间选项
|
|
|
private presetTimes: number[] = [0, 5, 15, 30, 45, 60, -1]
|
|
|
|
|
|
@@ -4887,7 +4886,7 @@ export struct LocalMusic {
|
|
|
.margin({ top: 2 });
|
|
|
|
|
|
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) {
|
|
|
- ForEach(this.presetTimes, (minutes: number) => {
|
|
|
+ ForEach(this.presetTimes, (minutes: number, index: number) => {
|
|
|
// 单行时间选项容器
|
|
|
Row() {
|
|
|
// 文字描述区域
|
|
|
@@ -4898,20 +4897,49 @@ export struct LocalMusic {
|
|
|
.textAlign(TextAlign.Start)
|
|
|
.layoutWeight(1); // 占据剩余空间
|
|
|
|
|
|
- // 复选框区域
|
|
|
- Checkbox()
|
|
|
- .select(minutes === this.selectedMinutes ? true : minutes === -1 ? this.isCustomSuccess : false)// 绑定选中状态
|
|
|
- .selectedColor(this.themeColor)// 主题色
|
|
|
- .shape(CheckBoxShape.CIRCLE)
|
|
|
- .size({ width: 24, height: 24 })
|
|
|
- .margin({ left: 20 })
|
|
|
+ // 复选框样式的选择器
|
|
|
+ Row() {
|
|
|
+ if (minutes === this.selectedMinutes) {
|
|
|
+ // 选中状态 - 带勾号的圆形复选框
|
|
|
+ Row() {
|
|
|
+ // 使用系统内置的勾号图标
|
|
|
+ Image($r('sys.media.ohos_ic_public_ok'))
|
|
|
+ .width(14)
|
|
|
+ .height(14)
|
|
|
+ .fillColor(Color.White)
|
|
|
+ }
|
|
|
+ .width(24)
|
|
|
+ .height(24)
|
|
|
+ .borderRadius(12)
|
|
|
+ .backgroundColor(this.themeColor)
|
|
|
+ .justifyContent(FlexAlign.Center)
|
|
|
+ .alignItems(VerticalAlign.Center)
|
|
|
+ } else {
|
|
|
+ // 未选中状态的圆形边框
|
|
|
+ Row()
|
|
|
+ .width(24)
|
|
|
+ .height(24)
|
|
|
+ .borderRadius(12)
|
|
|
+ .border({
|
|
|
+ width: 2,
|
|
|
+ color: $r('app.color.text_color'),
|
|
|
+ style: BorderStyle.Solid
|
|
|
+ })
|
|
|
+ .backgroundColor(Color.Transparent)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .width(24)
|
|
|
+ .height(24)
|
|
|
+ .margin({ left: 20 })
|
|
|
+ .justifyContent(FlexAlign.Center)
|
|
|
+ .alignItems(VerticalAlign.Center)
|
|
|
}
|
|
|
.width('100%')
|
|
|
.padding(10)
|
|
|
.backgroundColor(minutes === this.selectedMinutes ?$r('app.color.timeColor_bg') :$r('app.color.bottom_control_background')) // 选中背景高亮
|
|
|
.borderRadius(12)
|
|
|
.margin({ bottom: 6 })
|
|
|
- .onClick(() => this.handleSelect(minutes)); // 确保点击触发选择
|
|
|
+ .onClick(() => this.handleSelect(minutes)); // 点击整行触发选择
|
|
|
});
|
|
|
}
|
|
|
.width('100%')
|
|
|
@@ -4942,15 +4970,15 @@ export struct LocalMusic {
|
|
|
},
|
|
|
onAction: (action, dialogId, content) => {
|
|
|
if (action == DialogAction.TWO) {
|
|
|
- this.handleTimeSelect(Number(content)); // 改为调用统一方法
|
|
|
- this.isCustomSuccess = true
|
|
|
- ToastUtil.showToast("设置成功," + this.selectedMinutes + "分钟后定时关闭");
|
|
|
-
|
|
|
+ const customMinutes = Number(content);
|
|
|
+ if (customMinutes > 0) {
|
|
|
+ this.handleTimeSelect(customMinutes); // 设置自定义时间
|
|
|
+ ToastUtil.showToast("设置成功," + customMinutes + "分钟后定时关闭");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- this.isCustomSuccess = false
|
|
|
this.handleTimeSelect(minutes); // 统一调用选择处理方法
|
|
|
}
|
|
|
}
|
|
|
@@ -5017,7 +5045,6 @@ export struct LocalMusic {
|
|
|
private handleTimeout() {
|
|
|
// 执行播放器关闭逻辑
|
|
|
this.selectedMinutes = 0;
|
|
|
- this.isCustomSuccess = false;
|
|
|
ToastUtil.showToast(" 定时关闭已完成");
|
|
|
this.stop(); // 假设存在的播放器实例
|
|
|
//退出APP
|