target_progress.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import { View, Text } from '@tarojs/components'
  2. import Rings, { RingCommon, BgRing, TargetRing, CurrentDot } from "@/features/trackTimeDuration/components/Rings";
  3. import './target_progress.scss'
  4. import { MainColorType } from '@/context/themes/color';
  5. import { durationArc, startArc } from '@/utils/ring_utils';
  6. import { rpxToPx } from '@/utils/tools';
  7. export default function TargetProgress(props: {
  8. showLine?: boolean,
  9. color?: string,
  10. startTimestamp?: number,
  11. endTimerstamp?: number,
  12. canvasId?: string,
  13. showRing: boolean,
  14. icon?: any,
  15. desc?: string,
  16. //双环
  17. doubleRing?: boolean,
  18. first?: any,
  19. second?: any,
  20. onClick?: any
  21. }) {
  22. function ring() {
  23. const common: RingCommon = {
  24. useCase: 'ChooseScenario',
  25. radius: 12,
  26. lineWidth: 6,
  27. isFast: true,
  28. status: 'WAIT_FOR_START'
  29. }
  30. const bgRing: BgRing = {
  31. color: MainColorType.ringBg
  32. }
  33. const realRing = {
  34. hideBg: true,
  35. color: props.color ?? MainColorType.fast,
  36. startArc: startArc(props.startTimestamp ?? 0),
  37. durationArc: durationArc(props.startTimestamp ?? 0, props.endTimerstamp ?? 0)
  38. }
  39. return <Rings common={common} bgRing={bgRing} realRing={realRing} canvasId={props.canvasId ?? 'helloworld'} />
  40. }
  41. function ring1() {
  42. const common: RingCommon = {
  43. useCase: 'ChooseScenario',
  44. radius: 12.5,
  45. lineWidth: 5,
  46. isFast: true,
  47. status: 'WAIT_FOR_START'
  48. }
  49. const bgRing: BgRing = {
  50. color: MainColorType.ringBg
  51. }
  52. const realRing = {
  53. hideBg: true,
  54. color: MainColorType.fast,
  55. startArc: startArc(props.first.window_range.start_timestamp ?? 0),
  56. durationArc: durationArc(props.first.window_range.start_timestamp ?? 0, props.first.window_range.end_timestamp ?? 0)
  57. }
  58. return <Rings common={common} bgRing={bgRing} realRing={realRing} canvasId={props.canvasId + 'big' ?? 'helloworld'} />
  59. }
  60. function ring2() {
  61. const common: RingCommon = {
  62. useCase: 'ChooseScenario',
  63. radius: 6.5,
  64. lineWidth: 5,
  65. isFast: true,
  66. status: 'WAIT_FOR_START'
  67. }
  68. const bgRing: BgRing = {
  69. color: MainColorType.ringBg
  70. }
  71. const realRing = {
  72. hideBg: true,
  73. color: MainColorType.sleep,
  74. startArc: startArc(props.second.window_range.start_timestamp ?? 0),
  75. durationArc: durationArc(props.second.window_range.start_timestamp ?? 0, props.second.window_range.end_timestamp ?? 0)
  76. }
  77. return <Rings common={common} bgRing={bgRing} realRing={realRing} canvasId={props.canvasId + 'small' ?? 'helloworld'} />
  78. }
  79. function twoRing() {
  80. return <View style={{
  81. display: 'flex',
  82. alignItems: 'center',
  83. justifyContent: 'center',
  84. position: 'relative'
  85. }}>
  86. {
  87. ring1()
  88. }
  89. <View style={{
  90. position: 'absolute',
  91. left: 0,
  92. right: 0,
  93. top: 0,
  94. bottom: 0,
  95. display: 'flex',
  96. alignItems: 'center',
  97. justifyContent: 'center'
  98. }}>
  99. {
  100. ring2()
  101. }
  102. </View>
  103. </View>
  104. }
  105. return <View className='history_duration_bg'
  106. onClick={(e) => {
  107. if (props.onClick) {
  108. if (process.env.TARO_ENV == 'weapp') {
  109. e.stopPropagation()
  110. }
  111. props.onClick()
  112. }
  113. }}
  114. style={{ position: 'relative', marginTop: 0, marginBottom: props.showLine ? rpxToPx(7) : 0 }}>
  115. {
  116. props.showRing ? <View className='recent_ring_bg'>
  117. {
  118. props.doubleRing ? twoRing() : ring()
  119. }
  120. </View> :
  121. <View className='recent_ring_bg'>
  122. {
  123. props.icon
  124. }
  125. </View>
  126. }
  127. {
  128. props.desc && <View className='history_item_duration h32'>{props.desc}</View>
  129. }
  130. {
  131. props.doubleRing && <View className='history_item_duration h32' style={{
  132. display: 'flex',
  133. flexDirection: 'column'
  134. }}><Text className='h32'>{props.first.description}</Text><Text className='h32'>{props.second.description}</Text></View>
  135. }
  136. {/* {
  137. props.showLine && <View style={{height:rpxToPx(7),flexShrink:0}} />
  138. } */}
  139. </View>
  140. }