developmentCycle.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <section>
  3. <div class="control">
  4. <el-row type="flex" align="middle">
  5. <el-col :span="4" :offset="20">
  6. <el-select v-model="selectType" size="small" @change="statusChange">
  7. <el-option
  8. v-for="item in graphTypeList"
  9. :key="item.code"
  10. :label="item.label"
  11. :value="item.code"
  12. />
  13. </el-select>
  14. </el-col>
  15. </el-row>
  16. </div>
  17. <div class="chart-contain">
  18. <normal-echart v-if="echartsOption" :chart-id="id" :option="echartsOption" @onClick="toLink" />
  19. </div>
  20. </section>
  21. </template>
  22. <script>
  23. import normalEchart from '@/components/chart/normalEchart'
  24. import echarts from 'echarts'
  25. export default {
  26. components: { normalEchart },
  27. props: {
  28. id: {
  29. type: String,
  30. default: 'develop-cycle-chart',
  31. required: false
  32. },
  33. chartData: {
  34. type: Array,
  35. default: () => [],
  36. required: false
  37. },
  38. type: {
  39. type: String,
  40. default: '',
  41. required: false
  42. },
  43. graphType: {
  44. type: Number,
  45. default: 1,
  46. required: false
  47. },
  48. graphTypeList: {
  49. type: Array,
  50. default: () => [],
  51. required: false
  52. }
  53. },
  54. data() {
  55. return {
  56. echartsOption: null,
  57. selectType: this.graphType
  58. }
  59. },
  60. watch: {
  61. chartData: {
  62. handler(newV) {
  63. this.setChart()
  64. },
  65. deep: true,
  66. immediate: true
  67. },
  68. timeType: {
  69. handler(newV) {
  70. this.timeType = newV
  71. },
  72. immediate: true
  73. },
  74. graphType: {
  75. handler(newV) {
  76. this.selectType = newV
  77. },
  78. immediate: true
  79. }
  80. },
  81. methods: {
  82. statusChange(val) {
  83. this.selectType = val
  84. this.$emit('update:graphType', this.selectType)
  85. this.$emit('change')
  86. },
  87. setChart() {
  88. const target = this.graphTypeList.find(value => {
  89. return value.code === this.graphType
  90. })
  91. this.echartsOption = {
  92. grid: { left: '0%', right: '2%', bottom: '0%', top: '3%', containLabel: true },
  93. tooltip: {
  94. showDelay: 0,
  95. formatter: (params) => {
  96. if (params.componentType === 'markLine') {
  97. return `平均${target.label}:${params.value.toFixed(1)}天`
  98. } else {
  99. return `交付日期:${params.data[0]}<br/> ${target.label}:${params.data[1]}天`
  100. }
  101. },
  102. axisPointer: {
  103. show: true,
  104. type: 'cross',
  105. lineStyle: {
  106. type: 'dashed',
  107. width: 1
  108. }
  109. }
  110. },
  111. xAxis: {
  112. type: 'time'
  113. },
  114. yAxis: {
  115. type: 'value'
  116. },
  117. series: [{
  118. name: '',
  119. data: this.chartData,
  120. type: 'scatter',
  121. symbolSize: 10,
  122. markLine: {
  123. data: [{ type: 'average', name: '平均研发交付周期' }],
  124. label: {
  125. formatter: function(params) {
  126. return params.value.toFixed(1)
  127. }
  128. }
  129. },
  130. itemStyle: {
  131. shadowBlur: 10,
  132. shadowColor: 'rgba(25, 100, 150, 0.5)',
  133. shadowOffsetY: 5,
  134. color: new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{
  135. offset: 0,
  136. color: 'rgb(129, 227, 238)'
  137. }, {
  138. offset: 1,
  139. color: 'rgb(25, 183, 207)'
  140. }])
  141. }
  142. }]
  143. }
  144. },
  145. toLink(params) {
  146. if (!params.data[2]) return
  147. if (this.type === 'require') {
  148. const newTab = this.$router.resolve({ name: '需求详情', query: { id: params.data[2] }})
  149. window.open(newTab.href, '_blank')
  150. } else if (this.type === 'task') {
  151. const newTab = this.$router.resolve({ name: '任务详情', query: { id: params.data[2] }})
  152. window.open(newTab.href, '_blank')
  153. }
  154. }
  155. }
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. .chart-contain {
  160. position: relative;
  161. height: 400px;
  162. width: 84%;
  163. margin: auto;
  164. margin-top: 20px;
  165. }
  166. .control{
  167. width: 84%;
  168. margin: auto;
  169. margin-top: 20px;
  170. }
  171. </style>