fnHeader.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="header">
  3. <div class="title">
  4. <img class="logo" src="@/assets/images/common/logo.png" alt="" />
  5. <span>飞鸟智慧巡园平台</span>
  6. <img class="logo-icon" src="@/assets/images/common/logo-icon.png" alt="" />
  7. </div>
  8. <div class="focus-farm" v-show="!hideSwitch">
  9. <el-select
  10. v-model="farmVal"
  11. placeholder="我的关注农场"
  12. style="width: 189px"
  13. popper-class="focus-farm-select"
  14. @change="toggleFarm"
  15. >
  16. <!-- <el-option label="我的关注农场" :value="0" /> -->
  17. <el-option label="荔博园" :value="1" />
  18. <el-option label="井冈红糯基地" :value="2" />
  19. </el-select>
  20. </div>
  21. <div class="date" v-show="showDate">
  22. <el-icon size="25"><MoreFilled /></el-icon>
  23. <div class="time">
  24. <div>{{time}}</div>
  25. <span>{{getCurrentFormattedTime('date')}} {{getCurrentDayOfWeek()}}</span>
  26. </div>
  27. </div>
  28. </div>
  29. <!-- 四个方向的阴影 -->
  30. <div class="page-shadow" v-show="!hideShadow">
  31. <div class="page-bg bg-top"></div>
  32. <div class="page-bg bg-right"></div>
  33. <div class="page-bg bg-bottom"></div>
  34. <div class="page-bg bg-left"></div>
  35. </div>
  36. </template>
  37. <script setup>
  38. import { onMounted, onUnmounted, ref } from "vue";
  39. import { useRouter } from "vue-router";
  40. const router = useRouter();
  41. const props = defineProps({
  42. showDate:{
  43. type:Boolean,
  44. defalut:false
  45. },
  46. hideSwitch:{
  47. type:Boolean,
  48. defalut:false
  49. },
  50. hideShadow: {
  51. type:Boolean,
  52. defalut:false
  53. }
  54. })
  55. const farmVal = ref(sessionStorage.getItem('farmId')*1 || '')
  56. const toggleFarm = (val) => {
  57. sessionStorage.setItem('farmId',farmVal.value)
  58. router.push({ name: "Home" });
  59. };
  60. function getCurrentFormattedTime(type) {
  61. const now = new Date();
  62. const year = now.getFullYear();
  63. const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero based
  64. const day = String(now.getDate()).padStart(2, '0');
  65. const hours = String(now.getHours()).padStart(2, '0');
  66. const minutes = String(now.getMinutes()).padStart(2, '0');
  67. const seconds = String(now.getSeconds()).padStart(2, '0');
  68. if(type==='date'){
  69. return `${year}.${month}.${day}`;
  70. }else{
  71. return `${hours}:${minutes}:${seconds}`;
  72. }
  73. }
  74. function getCurrentDayOfWeek() {
  75. const now = new Date();
  76. const dayOfWeek = now.getDay();
  77. const daysOfWeek = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
  78. return daysOfWeek[dayOfWeek];
  79. }
  80. function formatTimeToHHmmss(date) {
  81. const hours = String(date.getHours()).padStart(2, '0');
  82. const minutes = String(date.getMinutes()).padStart(2, '0');
  83. const seconds = String(date.getSeconds()).padStart(2, '0');
  84. return `${hours}.${minutes}.${seconds}`;
  85. }
  86. const time = ref("21:05:46")
  87. const timer = ref(null)
  88. onMounted(()=>{
  89. timer.value = setInterval(()=>{
  90. time.value = getCurrentFormattedTime(new Date())
  91. },1000)
  92. })
  93. onUnmounted(()=>{
  94. timer.value = null
  95. })
  96. </script>
  97. <style lang="scss" scoped>
  98. .header {
  99. width: 100%;
  100. height: 74px;
  101. display: flex;
  102. justify-content: space-between;
  103. box-sizing: border-box;
  104. pointer-events: all;
  105. position: relative;
  106. .title {
  107. width: 100%;
  108. height: 100%;
  109. font-size: 24px;
  110. letter-spacing: 2px;
  111. padding-left: 20px;
  112. display: flex;
  113. align-items: center;
  114. box-sizing: border-box;
  115. background: url("@/assets/images/common/header-bg.png") no-repeat center
  116. center / 100% 100%;
  117. .logo{
  118. width: 23px;
  119. height: 26px;
  120. }
  121. .logo-icon{
  122. width: 33px;
  123. height: 12px;
  124. }
  125. span {
  126. margin: 0 5px;
  127. font-family: "PangMenZhengDao";
  128. }
  129. }
  130. .focus-farm {
  131. position: absolute;
  132. right: 192px;
  133. top: 23px;
  134. ::v-deep {
  135. .el-select__wrapper {
  136. background: rgba(255, 212, 137, 0.2);
  137. box-shadow: 0 0 0 1px rgba(255, 212, 137, 0.3) inset;
  138. height: 50px;
  139. line-height: 50px;
  140. .el-select__caret {
  141. color: #ffd489;
  142. }
  143. }
  144. .el-select__placeholder {
  145. color: #f7be5a;
  146. font-size: 20px;
  147. font-family: "PangMenZhengDao";
  148. text-align: center;
  149. }
  150. }
  151. }
  152. .date {
  153. display: flex;
  154. align-items: center;
  155. position: absolute;
  156. right: 30px;
  157. top: 24px;
  158. .time{
  159. margin-left: 14px;
  160. line-height: 18px;
  161. div{
  162. font-family: "PangMenZhengDao";
  163. letter-spacing: 1px;
  164. font-size: 16px;
  165. }
  166. span{
  167. font-size: 11px;
  168. font-family: 'SOURCEHANTIFINE';
  169. }
  170. }
  171. }
  172. }
  173. // 阴影样式
  174. .page-bg{
  175. position: fixed;
  176. z-index: -1;
  177. }
  178. .bg-top{
  179. top: 0;
  180. width: 100%;
  181. height: 200px;
  182. background: linear-gradient( 0deg, rgba(0, 21, 31,0), #00151f);
  183. }
  184. .bg-right{
  185. right: 0;
  186. width: 600px;
  187. height: 100%;
  188. background: linear-gradient( 90deg, rgba(0, 21, 31,0), rgb(0, 21, 31,0.7));
  189. }
  190. .bg-bottom{
  191. bottom: 0;
  192. width: 100%;
  193. height: 200px;
  194. background: linear-gradient( 180deg, rgba(0, 21, 31,0), rgb(0, 21, 31,0.7));
  195. }
  196. .bg-left{
  197. left: 0;
  198. width: 600px;
  199. height: 100%;
  200. background: linear-gradient( 270deg, rgba(0, 21, 31,0), rgb(0, 21, 31,0.7));
  201. }
  202. </style>
  203. <style lang="less">
  204. .focus-farm-select {
  205. &.el-popper.is-light {
  206. background: #232323;
  207. border-color: rgba(255, 212, 137, 0.3);
  208. box-shadow: 0px 0px 12px rgba(255, 212, 137, 0.3);
  209. .el-select-dropdown__item {
  210. background: none;
  211. color: rgba(255, 212, 137, 0.6);
  212. }
  213. .el-select-dropdown__item.is-selected {
  214. background: rgba(255, 212, 137, 0.2);
  215. color: #ffd489;
  216. }
  217. }
  218. &.el-popper.is-light .el-popper__arrow:before {
  219. background: #232323;
  220. border-color: rgba(255, 212, 137, 0.3);
  221. }
  222. }
  223. </style>