navigation.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <div class="navigation yes-events">
  3. <el-select class="select" v-model="areaId" size="large" @change="changeSelect" popper-class="focus-farm-select">
  4. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id" />
  5. </el-select>
  6. <div class="tabs" v-if="list.length">
  7. <template v-for="(item, index) in list" :key="index">
  8. <div
  9. class="tab-item"
  10. @click="handleHomeTab(item)"
  11. :class="{ active: active === item.name }"
  12. >
  13. {{ item.name }}
  14. </div>
  15. <el-checkbox-group
  16. v-show="item.monitorItems && item.name == active"
  17. class="checkbox-group"
  18. v-model="checkedChildren"
  19. @change="handleCheckedChange"
  20. :min="1"
  21. >
  22. <el-checkbox v-for="ele in item.monitorItems" :key="ele.id" :label="ele.indicatorName" :value="ele.id">
  23. {{ ele.indicatorName }}
  24. </el-checkbox>
  25. </el-checkbox-group>
  26. </template>
  27. </div>
  28. <!-- 对比 -->
  29. <el-checkbox-group
  30. class="checkbox-group compare-btn"
  31. v-model="checkedCompareChildren"
  32. @change="handleCompareChange"
  33. >
  34. <el-checkbox label="指标对比" value="1">
  35. 指标对比
  36. </el-checkbox>
  37. </el-checkbox-group>
  38. <div class="compare-tips" v-show="checkedCompareChildren.length && !checkedCompareChildren.includes('2')">
  39. <span>提示:</span>请在底图上点选 <span>两棵树</span>,才可以进行对比
  40. </div>
  41. </div>
  42. </template>
  43. <script setup>
  44. import { useRouter } from "vue-router";
  45. import { onMounted, onUnmounted, ref, computed } from "vue";
  46. import { useStore } from "vuex";
  47. import eventBus from "@/api/eventBus";
  48. const router = useRouter();
  49. const store = useStore();
  50. const areaId = ref("");
  51. const options = ref([]);
  52. eventBus.off('garden:organId', gardenOrganId)
  53. eventBus.on('garden:organId',gardenOrganId)
  54. const organId = ref()
  55. function gardenOrganId(farmId){
  56. organId.value = farmId
  57. getListByFarmId()
  58. VE_API.region.list({farmId}).then(res =>{
  59. options.value = res.data
  60. options.value.unshift({
  61. id:0,
  62. name:'全部区域'
  63. })
  64. areaId.value = res.data[0].id
  65. eventBus.emit('area:id',{areaId:areaId.value,farmId})
  66. sessionStorage.setItem('regionId',areaId.value)
  67. })
  68. }
  69. const changeSelect = (e) =>{
  70. eventBus.emit('area:id',{areaId:areaId.value,farmId:organId.value})
  71. sessionStorage.setItem('regionId',e)
  72. eventBus.emit('handleTab',)
  73. active.value = "果园总览"
  74. }
  75. const getListByFarmId = () =>{
  76. VE_API.home.listByFarmId({farmId:organId.value}).then(res =>{
  77. list.value = res.data || []
  78. monitorData.value = res.data[0].monitorItems || []
  79. })
  80. }
  81. onMounted(()=>{
  82. gardenOrganId(sessionStorage.getItem('farmId')*1)
  83. eventBus.on('handleActive',handleActive)
  84. eventBus.on('quitCompare', handleQuitCompare)
  85. })
  86. const mainMenuArr = computed(() => store.state.home.mainMenu);
  87. onUnmounted(()=>{
  88. eventBus.off('handleActive',handleActive)
  89. eventBus.off('quitCompare', handleQuitCompare)
  90. })
  91. const emit = defineEmits(["handleTab","updateLegend"])
  92. const checkedChildren = ref([]);
  93. const childrenData = ref([]);
  94. const handleCheckedChange = (e) => {
  95. if(e.length){
  96. const monitorIndicatorId = [e[e.length -1]][0]
  97. const legendConfig = monitorData.value.filter(item => item.id === monitorIndicatorId)
  98. VE_API.home.queryWorkCodeSampleParams({monitorIndicatorId,farmId:organId.value,regionId:areaId.value || null}).then(res =>{
  99. // 解析legendConfig
  100. const parsedLegendConfig = JSON.parse(legendConfig[0].legendConfig)
  101. // 根据接口返回的val字段匹配range区间
  102. let matchedData = matchDataByVal(res.data, parsedLegendConfig)
  103. emit('updateLegend',matchedData,parsedLegendConfig)
  104. })
  105. }
  106. };
  107. // 根据val字段匹配range区间的函数
  108. const matchDataByVal = (sampleData, legendConfig) => {
  109. if (!sampleData || !legendConfig) {
  110. return []
  111. }
  112. // 检查不同的数据结构可能性
  113. let legendList = null;
  114. if (legendConfig.legendList) {
  115. legendList = legendConfig.legendList;
  116. } else if (Array.isArray(legendConfig)) {
  117. legendList = legendConfig;
  118. } else if (legendConfig.list) {
  119. legendList = [legendConfig];
  120. }
  121. if (!legendList) {
  122. return []
  123. }
  124. const matchedResults = []
  125. // 遍历样本数据
  126. sampleData.forEach((sample) => {
  127. const sampleVal = sample.val || sample.value || sample.data
  128. if (sampleVal === undefined || sampleVal === null) {
  129. return;
  130. }
  131. // 遍历legend配置中的每个分类
  132. legendList.forEach((legendItem) => {
  133. // 获取list数组
  134. const itemList = legendItem.list || legendItem.items || [legendItem];
  135. // 遍历每个分类下的具体项
  136. itemList.forEach((configItem) => {
  137. // 检查val是否在range区间内
  138. if (configItem.range && Array.isArray(configItem.range) && configItem.range.length === 2) {
  139. const [min, max] = configItem.range
  140. if (sampleVal >= min && sampleVal < max) {
  141. matchedResults.push({
  142. ...sample, // 保留原始样本数据
  143. key: legendItem.key || legendItem.name || 'unknown',
  144. color: configItem.color,
  145. label: configItem.label,
  146. name: configItem.name,
  147. })
  148. }
  149. }
  150. })
  151. })
  152. })
  153. return matchedResults
  154. }
  155. function handleActive({name,key}){
  156. childrenData.value = []
  157. const menuItem = mainMenuArr.value.find(item =>item.name===key)
  158. active.value = menuItem.name;
  159. childrenData.value = menuItem.btnGroup
  160. checkedChildren.value = [name]
  161. emit('handleTab',{name:menuItem.name,id:active.value,isUpdate:true,params:name, legend: menuItem?.legend, colorObj: menuItem?.colorObj})
  162. }
  163. const active = ref("果园总览");
  164. const monitorData = ref([]);
  165. const handleHomeTab = ({ id, name , monitorItems}) => {
  166. active.value = name;
  167. childrenData.value = []
  168. monitorData.value = monitorItems || []
  169. checkedChildren.value = [] // 清空选中的值
  170. emit('handleTab',{name,id, legend: menuItem?.legend, colorObj: menuItem?.colorObj})
  171. // eventBus.emit("changePointType", {legend: menuItem?.legend, colorObj: menuItem?.colorObj})
  172. eventBus.emit('handleTab',name)
  173. };
  174. const list = ref([]);
  175. // 对比
  176. const checkedCompareChildren = ref([]);
  177. function handleCompareChange(v) {
  178. if(v == 2){
  179. eventBus.emit("showGspgjdfbt", v == 2)
  180. return
  181. }
  182. eventBus.emit("showGspgjdfbt", false)
  183. eventBus.emit("compareTree", checkedCompareChildren.value.length > 0 ? true : false)
  184. }
  185. // 退出对比
  186. function handleQuitCompare() {
  187. checkedCompareChildren.value = []
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .navigation {
  192. position: fixed;
  193. top: 34px;
  194. left: calc(50% - 70px);
  195. // left: 50%;
  196. transform: translateX(-50%);
  197. width: calc(100% - 430px * 2);
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. .select{
  202. // width: 120px;
  203. width: 166px;
  204. height: 50px;
  205. margin-right: 21px;
  206. ::v-deep{
  207. .el-select__wrapper{
  208. height: 100%;
  209. background: rgba(0, 0, 0, 0.3);
  210. box-shadow: 0 0 0 1px #F7BE5A;
  211. border-radius: 2px;
  212. text-align: center;
  213. }
  214. .el-select__placeholder{
  215. color: #F7BE5A;
  216. font-size: 20px;
  217. font-family: "PangMenZhengDao";
  218. }
  219. .el-select__caret{
  220. color: #F7BE5A;
  221. font-size: 20px;
  222. }
  223. }
  224. }
  225. .tabs {
  226. background: rgba(35, 35, 35, 0.8);
  227. border: 1px solid #555555;
  228. padding: 8px;
  229. border-radius: 8px;
  230. display: flex;
  231. justify-content: center;
  232. .tab-item {
  233. font-size: 16px;
  234. color: rgba(255, 255, 255, 0.8);
  235. padding: 7px 12px 9px 12px;
  236. font-family: "PangMenZhengDao";
  237. cursor: pointer;
  238. &.active {
  239. background: #ffd489;
  240. color: #1d1d1d;
  241. border-radius: 4px;
  242. }
  243. }
  244. .tab-item + .tab-item {
  245. margin-left: 25px;
  246. }
  247. }
  248. .tabs + .tabs {
  249. margin-left: 12px;
  250. }
  251. .checkbox-group {
  252. position: absolute;
  253. top: 65px;
  254. right: 36px;
  255. background: rgba(35, 35, 35, 0.8);
  256. border-radius: 8px;
  257. border: 1px solid #555555;
  258. padding: 10px 20px;
  259. display: flex;
  260. flex-direction: column;
  261. &.compare-btn {
  262. right: 40px;
  263. top: 0px;
  264. }
  265. ::v-deep {
  266. .el-checkbox {
  267. margin-right: 0;
  268. }
  269. .el-checkbox__input.is-checked + .el-checkbox__label {
  270. color: #ffd489;
  271. }
  272. .el-checkbox__input.is-checked .el-checkbox__inner {
  273. background-color: #ffd489;
  274. border-color: #ffd489;
  275. &::after {
  276. border-color: #1d1d1d;
  277. }
  278. }
  279. .el-checkbox__label {
  280. color: #fff;
  281. }
  282. }
  283. }
  284. .compare-tips {
  285. position: absolute;
  286. top: 96px;
  287. left: 50%;
  288. transform: translateX(-50%);
  289. background: rgba(4, 3, 0, 0.6);
  290. width: max-content;
  291. border-radius: 40px;
  292. padding: 6px 34px;
  293. font-family: 'PangMenZhengDao';
  294. font-size: 20px;
  295. span {
  296. color: #F3C11D;
  297. }
  298. }
  299. .btn {
  300. width: 80px;
  301. height: 30px;
  302. text-align: center;
  303. line-height: 28px;
  304. border-radius: 5px;
  305. cursor: pointer;
  306. background: rgba(255, 255, 255, 0.5);
  307. }
  308. }
  309. </style>