fnHeader.vue 5.7 KB

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