Bchfxtj.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <div>
  3. <Title title="异常预警">
  4. <template v-slot:title-slot>
  5. </template>
  6. </Title>
  7. <div class="tabs yse-events">
  8. <div class="lbtn"><div class="text" :key="btnIndex" :class="getActive(1)" @click="change(1)">病害</div></div>
  9. <div class="rbtn"><div class="text" :key="btnIndex" :class="getActive(2)" @click="change(2)">虫害</div></div>
  10. </div>
  11. <div class="sumArea">
  12. <div class="left"></div>
  13. <template v-if="btnIndex == 1">
  14. <div class="content">
  15. <div class="label">预计发生病害面积</div>
  16. <div><font class="val">6
  17. </font><font class="unit">亩</font></div>
  18. </div>
  19. </template>
  20. <template v-if="btnIndex == 2">
  21. <div class="content">
  22. <div class="label">预计发生虫害面积</div>
  23. <div><font class="val">10
  24. </font><font class="unit">亩</font></div>
  25. </div>
  26. </template>
  27. <div class="right"></div>
  28. </div>
  29. <div ref="chartDom" class="content-box yse-events"></div>
  30. </div>
  31. </template>
  32. <script setup>
  33. import {onMounted, ref} from "vue";
  34. import * as echarts from 'echarts';
  35. import Title from "../../../components/title";
  36. let chartDom = ref(null);
  37. let myChart = null;
  38. const btnIndex = ref(null);
  39. function getActive(index){
  40. return btnIndex.value == index ? "active" : "";
  41. }
  42. function change(index) {
  43. btnIndex.value = index;
  44. switch (index) {
  45. case 1:
  46. bhInit();
  47. break;
  48. case 2:
  49. chInit();
  50. break;
  51. }
  52. }
  53. onMounted(async () => {
  54. myChart = echarts.init(chartDom.value);
  55. change(1)
  56. })
  57. const options = {
  58. tooltip: {
  59. trigger: 'item',
  60. formatter:function(obj){
  61. let {value,unit,per,name} = obj.data;
  62. return value +" "+ unit + "<br/>"+per + "%<br/>"+name;
  63. },
  64. },
  65. legend: {
  66. orient:"vertical",
  67. top: '50%',
  68. right: '0%',
  69. textStyle:{
  70. color: "#fff",
  71. },
  72. formatter:function(name){
  73. let data = options.series[0].data;
  74. let obj = data.find((item)=> item.name == name)
  75. return obj.name+" "+obj.value + " " + obj.unit + " | "+ obj.per + "%";
  76. },
  77. },
  78. series: [
  79. {
  80. center:['30%','50%'],
  81. name: 'Access From',
  82. type: 'pie',
  83. radius: ['50', '70'],
  84. avoidLabelOverlap: false,
  85. itemStyle: {
  86. borderColor: '#00000010',
  87. borderRadius:3,
  88. borderWidth: 2
  89. },
  90. label: {
  91. show: false,
  92. position: 'center'
  93. },
  94. data: []
  95. },
  96. {
  97. center:['30%','50%'],
  98. name: 'Access From',
  99. type: 'pie',
  100. radius: ['30', '40'],
  101. avoidLabelOverlap: false,
  102. itemStyle: {
  103. color:"#847e7e",
  104. borderColor: '#00000010',
  105. borderRadius:3,
  106. borderWidth: 2
  107. },
  108. label: {
  109. formatter:function(obj){
  110. let {per,name} = obj.data;
  111. return per + "%\n"+name;
  112. },
  113. show: true,
  114. position: 'center'
  115. },
  116. data: []
  117. }
  118. ]
  119. };
  120. function bhInit() {
  121. options.series[0]["name"] = "病害"
  122. options.series[1]["name"] = "病害"
  123. options.series[0].data = [
  124. {
  125. name: "无病害",
  126. value: 24,
  127. unit: "亩",
  128. per: "75",
  129. itemStyle: {
  130. color: "#1FEBD4",
  131. }
  132. },
  133. {
  134. name: '有病害',
  135. value: 6,
  136. unit: "亩",
  137. per: "25",
  138. itemStyle: {
  139. color: "#9DEA4B",
  140. }
  141. },
  142. ];
  143. options.series[1].data = [];
  144. for(let item of options.series[0].data){
  145. options.series[1].data.push({...item,itemStyle:{color:"#3C3F41"}})
  146. }
  147. myChart.clear();
  148. options && myChart.setOption(options);
  149. }
  150. function chInit() {
  151. options.series[0]["name"] = "虫害"
  152. options.series[1]["name"] = "虫害"
  153. options.series[0].data = [
  154. {
  155. name: "有虫害",
  156. value: 10,
  157. unit: "亩",
  158. per: "62",
  159. itemStyle:{
  160. color: "#77ec5d",
  161. }
  162. },
  163. {
  164. name: '无虫害',
  165. value: 20,
  166. unit: "亩",
  167. per: "19",
  168. itemStyle:{
  169. color: "#FFA75C",
  170. }
  171. },
  172. ];
  173. options.series[1].data = [];
  174. for(let item of options.series[0].data){
  175. options.series[1].data.push({...item,itemStyle:{color:"#3C3F41"}})
  176. }
  177. myChart.clear();
  178. options && myChart.setOption(options);
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .tabs{
  183. position: absolute;
  184. top:25%;
  185. width:100%;
  186. z-index: 3;
  187. display: flex;
  188. flex-direction: row;
  189. justify-content: center;
  190. align-items: center;
  191. .text{
  192. text-align: center;
  193. width: 88px;
  194. height: 38px;
  195. line-height: 38px;
  196. font-size: 14px;
  197. font-family: PingFangSC-Regular, PingFang SC;
  198. font-weight: 400;
  199. color: #B4FFFB;
  200. }
  201. .lbtn{
  202. cursor: pointer;
  203. background-image: url(@/assets/img/left_btn.png);
  204. background-repeat: no-repeat;
  205. background-size: 100% 100%;
  206. width: 88px;
  207. height: 38px;
  208. .active{
  209. width: 88px;
  210. height: 38px;
  211. background-image: url(@/assets/img/left_btn_active.png);
  212. background-repeat: no-repeat;
  213. background-size: 100% 100%;
  214. }
  215. }
  216. .btn{
  217. cursor: pointer;
  218. background-image: url(@/assets/img/center_btn.png);
  219. background-repeat: no-repeat;
  220. background-size: 100% 100%;
  221. width: 88px;
  222. height: 38px;
  223. .active{
  224. width: 88px;
  225. height: 36px;
  226. background: rgba(3,44,57,0.8);
  227. box-shadow: inset 0px 0px 20px 4px rgba(0,255,240,0.5);
  228. border-radius: 0px 0px 0px 0px;
  229. border: 1px solid #51E9F0;
  230. }
  231. }
  232. .rbtn{
  233. background-image: url(@/assets/img/right_btn.png);
  234. background-repeat: no-repeat;
  235. background-size: 100% 100%;
  236. width: 88px;
  237. height: 38px;
  238. cursor: pointer;
  239. .active{
  240. width: 88px;
  241. height: 38px;
  242. background-image: url(@/assets/img/right_btn_active.png);
  243. background-repeat: no-repeat;
  244. background-size: 100% 100%;
  245. }
  246. }
  247. }
  248. .sumArea{
  249. position: absolute;
  250. top:50%;
  251. right: 0;
  252. width:40%;
  253. z-index: 3;
  254. display: flex;
  255. flex-direction: row;
  256. justify-content: flex-start;
  257. align-items: center;
  258. color: #F4F4F4;
  259. .left{
  260. width: 8px;
  261. height: 52px;
  262. border: 1px solid #00FFF0;
  263. border-right: none;
  264. }
  265. .right{
  266. width: 8px;
  267. height: 52px;
  268. border: 1px solid #00FFF0;
  269. border-left: none;
  270. }
  271. .content{
  272. flex-grow:1;
  273. display: flex;
  274. flex-direction: column;
  275. justify-content: center;
  276. align-items: center;
  277. .label{
  278. height: 20px;
  279. font-size: 14px;
  280. font-family: PingFangSC-Medium, PingFang SC;
  281. font-weight: 500;
  282. color: #B4FFFB;
  283. line-height: 20px;
  284. text-align: center;
  285. }
  286. .val{
  287. text-align: left;
  288. color: #D0C249;font-size: 18px;font-weight: bold
  289. }
  290. }
  291. }
  292. .content-box{
  293. position: absolute;
  294. width: 100%;
  295. height: calc(80% - 48px - 10px);
  296. bottom: 0px;
  297. }
  298. </style>