fnHeader.vue 6.8 KB

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