fnHeader.vue 7.1 KB

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