fnHeader.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="header">
  3. <div class="title">
  4. <img class="logo" src="@/assets/images/common/logo.png" alt="" />
  5. <span>{{headerName||"飞鸟智慧巡园平台"}}</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. filterable
  11. v-model="farmVal"
  12. placeholder="我的关注农场"
  13. style="width: 189px"
  14. popper-class="focus-farm-select"
  15. @change="toggleFarm"
  16. >
  17. <el-option v-for="item in options" :key="item.organId" :label="item.name" :value="item.organId" />
  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. import { convertPointToArray } from "@/utils/index";
  40. import eventBus from "@/api/eventBus";
  41. const router = useRouter();
  42. const props = defineProps({
  43. showDate: {
  44. type: Boolean,
  45. defalut: false,
  46. },
  47. hideSwitch: {
  48. type: Boolean,
  49. defalut: false,
  50. },
  51. hideShadow: {
  52. type: Boolean,
  53. defalut: false,
  54. },
  55. autoGo: {
  56. type: Boolean,
  57. default: true,
  58. },
  59. headerName: {
  60. type: String,
  61. default: "",
  62. },
  63. });
  64. const farmVal = ref(sessionStorage.getItem("farmId")*1 || "");
  65. const toggleFarm = (val) => {
  66. sessionStorage.setItem("farmId", farmVal.value);
  67. const curGarden = options.value.filter(item =>item.organId === val)
  68. sessionStorage.setItem("point", curGarden[0].wkt);
  69. eventBus.emit('garden:organId',val)
  70. router.push({ name: "Home" });
  71. };
  72. function getCurrentFormattedTime(type) {
  73. const now = new Date();
  74. const year = now.getFullYear();
  75. const month = String(now.getMonth() + 1).padStart(2, "0"); // Months are zero based
  76. const day = String(now.getDate()).padStart(2, "0");
  77. const hours = String(now.getHours()).padStart(2, "0");
  78. const minutes = String(now.getMinutes()).padStart(2, "0");
  79. const seconds = String(now.getSeconds()).padStart(2, "0");
  80. if (type === "date") {
  81. return `${year}.${month}.${day}`;
  82. } else {
  83. return `${hours}:${minutes}:${seconds}`;
  84. }
  85. }
  86. function getCurrentDayOfWeek() {
  87. const now = new Date();
  88. const dayOfWeek = now.getDay();
  89. const daysOfWeek = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
  90. return daysOfWeek[dayOfWeek];
  91. }
  92. const options = ref([]);
  93. const userInfo = JSON.parse(sessionStorage.getItem("userinfo"));
  94. const getGardenList = () => {
  95. const location = convertPointToArray(userInfo.location);
  96. const params = {
  97. userId: userInfo.userId,
  98. show3dFarm: true,
  99. location: "113.746646,22.970229",
  100. };
  101. console.log('userInfo', userInfo);
  102. if(userInfo.userName === "游客"){
  103. options.value = [{name: "柏桥村",organId:80865, wkt: "POINT(111.010804321 21.7759452836)"}]
  104. }else if(userInfo.userName === "LBY"){
  105. options.value = [{name: "荔枝博览园",organId:766, wkt: "POINT(113.61702297075017 23.584863449735067)"}]
  106. }else{
  107. if(userInfo.userName !== "13797066447"){
  108. VE_API.home.userGarden(params).then((res) => {
  109. options.value = []
  110. for(let item of res.data){
  111. options.value.push({name: item.name,organId:item.id, wkt: item.pointWkt})
  112. }
  113. farmVal.value = options.value[0].organId
  114. if(props.autoGo){
  115. toggleFarm(options.value[0].organId)
  116. }
  117. })
  118. }else{
  119. params["vip"] = 1
  120. VE_API.home.userGarden(params).then((res) => {
  121. let resData = []
  122. for(let item of res.data){
  123. resData.push({name: item.name,organId:item.id, wkt: item.pointWkt})
  124. }
  125. options.value = resData
  126. });
  127. }
  128. }
  129. };
  130. const time = ref("");
  131. const timer = ref(null);
  132. onMounted(() => {
  133. // getGardenList();
  134. timer.value = setInterval(() => {
  135. time.value = getCurrentFormattedTime(new Date());
  136. }, 1000);
  137. });
  138. onUnmounted(() => {
  139. timer.value = null;
  140. });
  141. </script>
  142. <style lang="scss" scoped>
  143. .header {
  144. width: 100%;
  145. height: 74px;
  146. display: flex;
  147. justify-content: space-between;
  148. box-sizing: border-box;
  149. pointer-events: all;
  150. position: relative;
  151. .title {
  152. width: 100%;
  153. height: 100%;
  154. font-size: 24px;
  155. letter-spacing: 2px;
  156. padding-left: 20px;
  157. display: flex;
  158. align-items: center;
  159. box-sizing: border-box;
  160. background: url("@/assets/images/common/header-bg.png") no-repeat center center / 100% 100%;
  161. background-size: 100% 100%;
  162. background-position: left center;
  163. .logo {
  164. width: 23px;
  165. height: 26px;
  166. }
  167. .logo-icon {
  168. width: 33px;
  169. height: 12px;
  170. }
  171. span {
  172. margin: 0 5px;
  173. cursor: pointer;
  174. font-family: "PangMenZhengDao";
  175. }
  176. }
  177. .focus-farm {
  178. position: absolute;
  179. right: 192px;
  180. top: 23px;
  181. ::v-deep {
  182. .el-select__wrapper {
  183. background: rgba(255, 212, 137, 0.2);
  184. box-shadow: 0 0 0 1px rgba(255, 212, 137, 0.3) inset;
  185. height: 50px;
  186. line-height: 50px;
  187. .el-select__caret {
  188. color: #ffd489;
  189. }
  190. }
  191. .el-select__placeholder {
  192. color: #f7be5a;
  193. font-size: 20px;
  194. font-family: "PangMenZhengDao";
  195. text-align: center;
  196. }
  197. .el-select__input {
  198. color: #f7be5a;
  199. }
  200. }
  201. }
  202. .date {
  203. display: flex;
  204. align-items: center;
  205. position: absolute;
  206. right: 30px;
  207. top: 24px;
  208. .time {
  209. margin-left: 14px;
  210. line-height: 18px;
  211. div {
  212. font-family: "PangMenZhengDao";
  213. letter-spacing: 1px;
  214. font-size: 16px;
  215. }
  216. span {
  217. font-size: 11px;
  218. font-family: "SOURCEHANTIFINE";
  219. }
  220. }
  221. }
  222. }
  223. // 阴影样式
  224. .page-bg {
  225. position: fixed;
  226. z-index: -1;
  227. }
  228. .bg-top {
  229. top: 0;
  230. width: 100%;
  231. height: 200px;
  232. background: linear-gradient(0deg, rgba(0, 21, 31, 0), #00151f);
  233. }
  234. .bg-right {
  235. right: 0;
  236. width: 600px;
  237. height: 100%;
  238. background: linear-gradient(90deg, rgba(0, 21, 31, 0), rgb(0, 21, 31, 0.7));
  239. }
  240. .bg-bottom {
  241. bottom: 0;
  242. width: 100%;
  243. height: 200px;
  244. background: linear-gradient(180deg, rgba(0, 21, 31, 0), rgb(0, 21, 31, 0.7));
  245. }
  246. .bg-left {
  247. left: 0;
  248. width: 600px;
  249. height: 100%;
  250. background: linear-gradient(270deg, rgba(0, 21, 31, 0), rgb(0, 21, 31, 0.7));
  251. }
  252. </style>
  253. <style lang="less">
  254. .focus-farm-select {
  255. &.el-popper.is-light {
  256. background: #232323;
  257. border-color: rgba(255, 212, 137, 0.3);
  258. box-shadow: 0px 0px 12px rgba(255, 212, 137, 0.3);
  259. .el-select-dropdown__item {
  260. background: none;
  261. color: rgba(255, 212, 137, 0.6);
  262. }
  263. .el-select-dropdown__item.is-selected {
  264. background: rgba(255, 212, 137, 0.2);
  265. color: #ffd489;
  266. }
  267. }
  268. &.el-popper.is-light .el-popper__arrow:before {
  269. background: #232323;
  270. border-color: rgba(255, 212, 137, 0.3);
  271. }
  272. }
  273. </style>