@@ -247,30 +247,6 @@ export default {
247
247
isDragging: false ,
248
248
lastClientX: 0 ,
249
249
scrollLeft: 0 ,
250
- taskColors: {
251
- colorList: [
252
- ' #409EFF' , // 蓝色
253
- ' #67C23A' , // 绿色
254
- ' #E6A23C' , // 黄色
255
- ' #F56C6C' , // 红色
256
- ' #626aef' , // 靛蓝
257
- ' #6f7ad3' , // 紫色
258
- ' #5cb87a' , // 浅绿
259
- ' #ff9f7f' // 橙色
260
- ]
261
- },
262
- standardColors: [
263
- ' #409EFF' , // 蓝色
264
- ' #67C23A' , // 绿色
265
- ' #E6A23C' , // 黄色
266
- ' #F56C6C' , // 红色
267
- ' #909399' , // 灰色
268
- ' #626aef' , // 靛蓝
269
- ' #6f7ad3' , // 紫色
270
- ' #1989fa' , // 浅蓝
271
- ' #5cb87a' , // 浅绿
272
- ' #ff9f7f' // 橙色
273
- ],
274
250
timerInterval: null ,
275
251
formattedTimeBlocks: {},
276
252
editDialogVisible: false ,
@@ -385,7 +361,29 @@ export default {
385
361
return ` ${ hours .toString ().padStart (2 , ' 0' )} :${ minutes .toString ().padStart (2 , ' 0' )} :${ seconds .toString ().padStart (2 , ' 0' )} ` ;
386
362
},
387
363
getRandomColor () {
388
- return this .taskColors .colorList [Math .floor (Math .random () * this .taskColors .colorList .length )];
364
+ // 生成随机的 H (0-360), S (50-100), V (50-100)
365
+ let h = Math .floor (Math .random () * 361 );
366
+ let s = Math .floor (Math .random () * 51 ) + 45 ;
367
+ // 75~95
368
+ let v = Math .floor (Math .random () * 21 ) + 75 ;
369
+
370
+ // 将 HSV 转换为 RGB
371
+ let rgb = this .hsvToRgb (h, s, v);
372
+
373
+ // 返回 RGB 颜色值
374
+ return ` rgb(${ rgb .r } , ${ rgb .g } , ${ rgb .b } )` ;
375
+ },
376
+
377
+ hsvToRgb (h , s , v ) {
378
+ s /= 100 ;
379
+ v /= 100 ;
380
+ let k = (n ) => (n + h / 60 ) % 6 ;
381
+ let f = (n ) => v - v * s * Math .max (Math .min (k (n), 4 - k (n), 1 ), 0 );
382
+ return {
383
+ r: Math .round (f (5 ) * 255 ),
384
+ g: Math .round (f (3 ) * 255 ),
385
+ b: Math .round (f (1 ) * 255 )
386
+ };
389
387
},
390
388
startTimer (taskId ) {
391
389
const task = this .tasks .find (t => t .id === taskId);
@@ -402,24 +400,21 @@ export default {
402
400
stopTimer (taskId ) {
403
401
const task = this .tasks .find (t => t .id === taskId);
404
402
const description = this .taskDescriptions [taskId]? .trim ();
405
-
406
403
if (task) {
407
404
const timer = task .timers .find (t => t .end === null );
408
405
if (timer) {
409
- timer .end = new Date ();
410
- timer .description = description;
411
- timer .color = this .getRandomColor (); // 结束时分配固定颜色
412
-
413
406
const duration = (timer .end - timer .start ) / 1000 ; // Duration in seconds
414
407
if (duration < 10 ) {
415
408
ElMessage .warning (' 时间不足10秒,计时已丢弃' );
409
+ task .timers = task .timers .filter (t => t !== timer); // Remove the timer
416
410
this .saveToStorage (); // 保存到本地存储以保持计时信息
417
411
} else {
418
412
if (! description) {
419
413
ElMessage .error (' 请先填写任务说明再结束计时' );
420
- task .timers = task .timers .filter (t => t !== timer); // Remove the timer
421
414
return ;
422
415
}
416
+ timer .end = new Date ();
417
+ timer .description = description;
423
418
ElMessage .success (' 计时已结束' );
424
419
this .saveToStorage (); // 保存到本地存储以保持颜色信息
425
420
// Only auto-export if enabled
0 commit comments