hiddenDangerStatisticsEcharts.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <div class="hiddenDangerStatisticsEcharts">
  3. <div class="title-button-box">
  4. <p :class="hdLevel==1?'check-p':''" @click="titleButtonClick(1)">一级指标</p>
  5. <p :class="hdLevel==2?'check-p':''" @click="titleButtonClick(2)">二级指标</p>
  6. <p :class="hdLevel==3?'check-p':''" @click="titleButtonClick(3)">三级指标</p>
  7. </div>
  8. <p v-if="nullType" style="line-height:100px;text-align: center;color:#999;">暂无数据</p>
  9. <div class="hiddenDangerStatisticsEcharts-box" id="hiddenDangerStatisticsEcharts-box">
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import echarts from 'echarts'
  15. import { hiddenCountByType, collegCheckHiddenCountByType,isSCollege } from '@/api/safetyCheck/index'
  16. export default {
  17. name: 'hiddenDangerStatisticsEcharts',
  18. data(){
  19. return{
  20. hdLevel:1,
  21. userFlg:true,
  22. nullType:false,
  23. }
  24. },
  25. created(){
  26. },
  27. mounted(){
  28. this.isSCollege();
  29. },
  30. methods:{
  31. isSCollege(){
  32. isSCollege().then(response => {
  33. this.$set(this,'userFlg',response.data.userFlg);
  34. if(this.userFlg){
  35. this.departmentEcharts();
  36. }else{
  37. this.schoolEcharts();
  38. }
  39. })
  40. },
  41. titleButtonClick(type){
  42. if(this.hdLevel != type){
  43. this.$set(this,'hdLevel',type);
  44. if(this.userFlg){
  45. this.departmentEcharts();
  46. }else{
  47. this.schoolEcharts();
  48. }
  49. }
  50. },
  51. //校级
  52. schoolEcharts(){
  53. hiddenCountByType({hdLevel:this.hdLevel}).then(response => {
  54. let myChart = this.$echarts.init(document.getElementById('hiddenDangerStatisticsEcharts-box'));
  55. let data = [];
  56. if(!response.rows[0]){
  57. this.$set(this,'nullType',true);
  58. return
  59. }else{
  60. this.$set(this,'nullType',false);
  61. }
  62. for(let i=0;i<response.rows.length;i++){
  63. // substring
  64. console.log(response.rows[i].collegeName.length)
  65. let obj = {
  66. name:response.rows[i].collegeName.length>8?response.rows[i].collegeName.substring(0,8)+'..':response.rows[i].collegeName,
  67. nameText:response.rows[i].collegeName,
  68. value:response.rows[i].sumTotal,
  69. }
  70. data.push(obj);
  71. }
  72. let option = {
  73. legend: {
  74. show:false,
  75. },
  76. tooltip: {
  77. confine: true,
  78. trigger: 'item',
  79. // formatter: '{b} : {c}'
  80. formatter: params => {
  81. console.log('params',params)
  82. return `${params.data.nameText} 隐患:${params.data.value} 占比:${params.percent}%`
  83. },
  84. },
  85. series: [
  86. {
  87. avoidLabelOverlap: false,
  88. type: 'pie',
  89. left:20,
  90. right:20,
  91. roseType: 'area', // 玫瑰图
  92. center: ['50%', '50%'],
  93. radius: ['0%', '40%'],
  94. label: {
  95. normal: {
  96. formatter: '{b}\n隐患{c}\t占比{d}%',
  97. textStyle: {
  98. fontSize: 12,
  99. color:'#333'
  100. },
  101. padding: [0, -110, 26, -110],
  102. }
  103. },
  104. labelLine: {
  105. normal: {
  106. length: 30,
  107. length2: 110,
  108. }
  109. },
  110. data: data,
  111. itemStyle: {
  112. normal: {
  113. color: function (colors) {
  114. var colorList = ['#0183FA', '#A069FF', '#80C459', '#FFA200', '#39DBED', '#FF2A00', '#009DFF', '#41BE26', '#2758E0', '#FFE019', '#FF5E86'];
  115. return colorList[colors.dataIndex];
  116. }
  117. },
  118. }
  119. }
  120. ]
  121. };
  122. myChart.setOption(option);
  123. });
  124. },
  125. //院系
  126. departmentEcharts(){
  127. collegCheckHiddenCountByType({hdLevel:this.hdLevel}).then(response => {
  128. let myChart = this.$echarts.init(document.getElementById('hiddenDangerStatisticsEcharts-box'));
  129. let data = {
  130. name:[],
  131. nameText:[],
  132. text:[],
  133. num: [],
  134. }
  135. if(!response.rows[0]){
  136. this.$set(this,'nullType',true);
  137. return
  138. }else{
  139. this.$set(this,'nullType',false);
  140. }
  141. response.rows.sort(this.compare('sumTotal', true))
  142. for(let i=0;i<response.rows.length;i++){
  143. data.name.push(response.rows[i].subjectName.length>8?response.rows[i].subjectName.substring(0,8)+'..':response.rows[i].subjectName)
  144. data.nameText.push(response.rows[i].subjectName)
  145. data.text.push(response.rows[i].hazardCheckName)
  146. data.num.push(response.rows[i].sumTotal)
  147. }
  148. let option = {
  149. grid: {
  150. left: '30%',
  151. top: '8%',
  152. right: '15%',
  153. bottom: '15%',
  154. },
  155. tooltip: {
  156. trigger: 'axis',
  157. formatter: params => {
  158. return data.nameText[params[0].dataIndex] +' 隐患:'+ data.num[params[0].dataIndex]
  159. // return `${params.data.nameText} 隐患:${params.data.value} 占比:${params.percent}%`
  160. },
  161. backgroundColor: 'rgba(0, 0, 0, 0.6)', // 提示框背景色
  162. borderColor: '#05050F', // 提示框边框色
  163. textStyle: {
  164. color: '#fff', // 提示框文本颜色
  165. },
  166. axisPointer: {
  167. type: 'none',
  168. },
  169. },
  170. legend: {
  171. show:false,
  172. },
  173. xAxis: {
  174. type: 'value',
  175. position: "bottom",
  176. splitLine: {
  177. show: false,
  178. },
  179. axisTick: {
  180. show: false,
  181. },
  182. axisLabel: {
  183. textStyle: {
  184. color: '#333',
  185. fontSize: 12,
  186. },
  187. },
  188. axisLine: {
  189. show: true,
  190. lineStyle: {
  191. color: 'rgba(216,216,216,1)',
  192. },
  193. },
  194. },
  195. yAxis: {
  196. type: 'category',
  197. splitLine: {
  198. show: false,
  199. },
  200. axisTick: {
  201. show: false,
  202. },
  203. data: data.name,
  204. axisLabel: {
  205. textStyle: {
  206. color: '#333',
  207. fontSize: 12,
  208. },
  209. },
  210. axisLine: {
  211. lineStyle: {
  212. color: 'rgba(216,216,216,1)',
  213. },
  214. },
  215. },
  216. series: [
  217. {
  218. name: '隐患',
  219. type: 'bar',
  220. data: data.num,
  221. itemStyle: {
  222. emphasis: {
  223. barBorderRadius: [0, 20, 20, 0],
  224. },
  225. normal: {
  226. barBorderRadius: [0, 20, 20, 0],
  227. color: new echarts.graphic.LinearGradient(0, 0, 1, 0,
  228. [
  229. {
  230. offset: 0,
  231. color: 'rgba(246,111,0,0.1)', // 0% 处的颜色
  232. },
  233. {
  234. offset: 1,
  235. color: 'rgba(246,111,0,1)', // 100% 处的颜色
  236. },
  237. ],
  238. false
  239. ),
  240. },
  241. },
  242. label: {
  243. normal: {
  244. show: true,
  245. formatter: params => {
  246. return '隐患'+params.data
  247. },
  248. position: 'insideRight',
  249. offset: [40, 1.5],
  250. textStyle: {
  251. color: '#333',
  252. fontSize: 12,
  253. },
  254. },
  255. },
  256. },
  257. ],
  258. barCategoryGap: '60%',
  259. };
  260. myChart.setOption(option);
  261. })
  262. },
  263. compare (attr,rev) {
  264. // console.log(attr, rev)
  265. if(rev == undefined){
  266. rev = 1;
  267. }else{
  268. rev = (rev) ? 1 : -1;
  269. }
  270. return (a,b) => {
  271. a = a[attr];
  272. b = b[attr];
  273. if(a < b){
  274. return rev * -1;
  275. }
  276. if(a > b){
  277. return rev * 1;
  278. }
  279. return 0;
  280. }
  281. },
  282. }
  283. }
  284. </script>
  285. <style scoped lang="scss">
  286. .hiddenDangerStatisticsEcharts{
  287. height:483px;
  288. .title-button-box{
  289. display: flex;
  290. border:1px solid #0183fa;
  291. width:300px;
  292. margin:32px 71px 0;
  293. p{
  294. width:100px;
  295. line-height:30px;
  296. text-align: center;
  297. color:#0183fa;
  298. cursor: pointer;
  299. }
  300. p:nth-child(2){
  301. border-left:1px solid #0183fa;
  302. border-right:1px solid #0183fa;
  303. }
  304. .check-p{
  305. background-color: #0183fa;
  306. color:#fff;
  307. }
  308. }
  309. .hiddenDangerStatisticsEcharts-box{
  310. height:420px;
  311. }
  312. }
  313. </style>