timeLine.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="time-line-wrap">
  3. <div class="play" @click="handleChange">
  4. <img
  5. class="icon"
  6. :src="`/src/assets/images/home/${isCounting ? 'transparent-pause-icon.png' : 'transparent-play-icon.png'}`"
  7. alt=""
  8. />
  9. </div>
  10. <div class="line">
  11. <div class="active-line" :style="{ width: widthTotal()}"></div>
  12. <div :class="['dot-item', {'cur-category':active===index},{'not-special':active===index&&!item.special&&listType!=='mentalState'}]" v-for="(item, index) in timeArr" :key="index">
  13. <span v-show="listType==='mentalState'" :class="['name']">{{ item.nodeName}}</span>
  14. <div :class="['dot', {'big-dot': item.bigDot}]" :style="{marginLeft:marginLeftValue(index)}"></div>
  15. <div v-show="item.farmworkName&&active===index" :class="{'ns':active===index}">{{item.farmworkName}}</div>
  16. <span>{{ item.date }}</span>
  17. <template v-if="listType!=='mentalState'&&active===index&&!isBtnActive">
  18. <span class="position">{{ item.jieqi }}</span>
  19. <span :class="['name name-1',{'color':item.bigDot}]">{{ item.nodeName}}</span>
  20. </template>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import { ref, onDeactivated, onMounted} from "vue";
  27. import { useStore } from "vuex";
  28. // import eventBus from "@/api/eventBus";
  29. const store = useStore();
  30. const total = ref(0)
  31. const widthTotal = () =>{
  32. let num
  33. num = isCompute.value?((active.value/(timeArr.value.length - 1)) * 100) + total.value : widthNum.value
  34. // if(listType.value==='mentalState'){
  35. if(num>=100 && listType.value==='mentalState'){
  36. // const arr = [5,24,37,50,68,82,95]
  37. num = 93
  38. // num = arr[active.value]
  39. }
  40. if(num>=100 && listType.value==='cataclysm'){
  41. num = 101
  42. }
  43. return num + '%'
  44. }
  45. const marginLeftValue = (index) =>{
  46. let num = 7.5
  47. if(listType.value === 'mentalState'){
  48. num = 12
  49. }
  50. return num + 'px'
  51. }
  52. const active = ref(0);
  53. const isCounting = ref(false);
  54. const timeArr = ref([])
  55. const organId = ref(null)
  56. onMounted(() => {
  57. getTimeList()
  58. })
  59. const isUpdate = () =>{
  60. if(listType.value==='cataclysm'){
  61. if(timeArr.value[active.value -1]?.phenologyName!==timeArr.value[active.value].phenologyName){
  62. isBtnActive.value = false
  63. }
  64. }
  65. }
  66. const widthNum = ref(0)
  67. const curIndex = ref(0)
  68. const isCompute = ref(false)
  69. const listType = ref('mentalState')//mentalState:灵境时间轴,cataclysm:灾变时间轴
  70. // nodeType 节点类型 0:大发育期,1:小发育期,2:节气
  71. // nodeStatus 节点状态(0-过去;1-现在;2-未来)
  72. const getTimeList = () =>{
  73. widthNum.value = 3
  74. total.value = 0
  75. isCompute.value = false
  76. restActive()
  77. timeArr.value = [
  78. {
  79. "farmworkName": "",
  80. "nodeDate": "2025-01-07",
  81. "nodeName": "花芽萌动期",
  82. "date":"01.07",
  83. "nodeStatus": 0
  84. },
  85. {
  86. "farmworkName": "",
  87. "nodeDate": "2025-01-19",
  88. "date":"01.09",
  89. "nodeName": "花蕾抽出期",
  90. "nodeStatus": 2
  91. },
  92. {
  93. "farmworkName": "",
  94. "nodeDate": "2025-02-02",
  95. "nodeName": "花穗伸长期",
  96. "date":"01.10",
  97. "nodeStatus": 2
  98. }
  99. ]
  100. // VE_API.farm.getTimeLine({farmId:organId.value}).then(({code,data}) =>{
  101. // if(code===0){
  102. // curIndex.value = 0
  103. // active.value = curIndex.value
  104. // timeArr.value = data.map((item,index) =>{
  105. // return {
  106. // ...item,
  107. // bigDot:index===0?true:false,
  108. // curCategory:item.nodeStatus===1,
  109. // smallDot:index==1||index==2||index==4||index==5,
  110. // date:item.nodeDate.slice(5,7) + '.' + item.nodeDate.slice(8,10)
  111. // }
  112. // })
  113. // eventBus.emit("timeLine:changeTime",{...data[0],isFirst:true})
  114. // }
  115. // })
  116. }
  117. const incrementInterval = 7000; // 默认间隔5秒
  118. const specialIncrementInterval = 7000; // 特殊间隔7秒
  119. const timer = ref(null);
  120. const incrementCount = (type) => {
  121. isCompute.value = true
  122. if (active.value === timeArr.value.length - 1) {
  123. isCompute.value = false
  124. active.value = 0;
  125. isUpdate()
  126. } else {
  127. if(type!=='original'){
  128. active.value += 1;
  129. isUpdate()
  130. }
  131. timeArr.value[active.value].show = true
  132. }
  133. let time = incrementInterval;
  134. if (active.value === 0 || active.value === timeArr.value.length - 1) {
  135. time = specialIncrementInterval;
  136. }
  137. timer.value = setTimeout(() => {
  138. if (isCounting.value) incrementCount();
  139. }, time);
  140. };
  141. const timerId = ref(null);
  142. const isBtnActive = ref(true)
  143. const handleChange = () => {
  144. clearTime()
  145. if (active.value === 0 || active.value === timeArr.value.length - 1) {
  146. timerId.value = setTimeout(() => {
  147. if (isCounting.value) incrementCount();
  148. }, specialIncrementInterval);
  149. } else {
  150. incrementCount('original');
  151. }
  152. isCounting.value = !isCounting.value;
  153. };
  154. onDeactivated(() => {
  155. clearTime();
  156. });
  157. //清除定时器
  158. const clearTime = () => {
  159. if (timerId.value) {
  160. clearTimeout(timerId.value);
  161. }
  162. if (timer.value) {
  163. clearTimeout(timer.value);
  164. }
  165. };
  166. const restActive = () => {
  167. clearTime();
  168. active.value = curIndex.value;
  169. isCounting.value = false;
  170. };
  171. </script>
  172. <style lang="scss" scoped>
  173. .time-line-wrap {
  174. width: 100%;
  175. height: 100%;
  176. border-radius: 8px 8px 36px 36px;
  177. background: rgba(35, 35, 35, 0.6);
  178. display: flex;
  179. align-items: center;
  180. box-sizing: border-box;
  181. padding: 10px 15px;
  182. border: 1px solid rgba(255,255,255,0.4);
  183. .play {
  184. display: flex;
  185. align-items: center;
  186. margin-right: 30px;
  187. cursor: pointer;
  188. .icon {
  189. width: 48px;
  190. height: 48px;
  191. }
  192. }
  193. .line {
  194. background: linear-gradient(30deg, #fff 0% , #2C2C2C 100%);
  195. border-radius: 2px;
  196. width: 80%;
  197. height: 2px;
  198. display: flex;
  199. justify-content: space-between;
  200. position: relative;
  201. z-index: 2;
  202. .active-line {
  203. background: linear-gradient(30deg, #eccd9b 0% ,#F3C11D 100%,);
  204. position: absolute;
  205. top: 0;
  206. left: 0;
  207. height: 2px;
  208. z-index: 1;
  209. }
  210. .dot-item {
  211. color: rgba(255,255,255,0.3);
  212. font-size: 16px;
  213. position: relative;
  214. z-index: 2;
  215. .dot {
  216. width: 10px;
  217. height: 10px;
  218. background: #E6E6E6;
  219. border-radius: 50%;
  220. margin: -4px 0 6px 14px;
  221. position: relative;
  222. &::after{
  223. content: '';
  224. position: absolute;
  225. top: -2px;
  226. left: -2px;
  227. width: 4px;
  228. height: 4px;
  229. border-radius: 50%;
  230. border: 2px solid rgba(255,255,255,0.2);
  231. }
  232. }
  233. .ns{
  234. position: absolute;
  235. top: -45px;
  236. left: -10px;
  237. width: 56px;
  238. height: 20px;
  239. color: #fff;
  240. text-align: center;
  241. line-height: 20px;
  242. border-radius: 5px;
  243. background: linear-gradient(180deg,#F3C11D 0%,#715803 100%);
  244. &::before{
  245. content: '';
  246. position: absolute;
  247. top: 20px;
  248. left: calc(50% - 8px);
  249. border-left: 6px solid transparent;
  250. border-right: 6px solid transparent;
  251. border-top: 6px solid #715803;
  252. }
  253. }
  254. span {
  255. margin-left: -3px;
  256. letter-spacing: 0.5px;
  257. }
  258. .position{
  259. position: absolute;
  260. width: 22px;
  261. left: -4px;
  262. top: 6px;
  263. }
  264. .color{
  265. color: #D7C690;
  266. }
  267. .big-dot {
  268. width: 6px;
  269. height: 6px;
  270. margin: -2px 0 5px 14px;
  271. position: relative;
  272. &::after{
  273. content: '';
  274. position: absolute;
  275. top: -2px;
  276. left: -2px;
  277. width: 6px;
  278. height: 6px;
  279. border-radius: 50%;
  280. border: 2px solid rgba(255,255,255,0.2);
  281. }
  282. }
  283. .name{
  284. position: absolute;
  285. top: -30px;
  286. left: -25px;
  287. width: 85px;
  288. text-align: center;
  289. }
  290. .name-1{
  291. left: -27px;
  292. }
  293. &.cur-category{
  294. color: #F3C11D;
  295. .color{
  296. color: #F3C11D;
  297. }
  298. .dot{
  299. background: #f3c11d;
  300. &::after{
  301. border: 2px solid rgba(243,193,29,0.2);
  302. }
  303. }
  304. }
  305. &.not-special{
  306. color: #D7C690;
  307. .color{
  308. color: #D7C690;
  309. }
  310. .dot{
  311. background: #D7C690;
  312. &::after{
  313. border: 2px solid rgba(215, 198, 144,0.2);
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. </style>