chartCard.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <div class="card-item">
  3. <div class="top" v-if="options.series&&isHaveButton">
  4. <div class="title text_twoLine">
  5. <span>{{cardTitle}}</span>
  6. </div>
  7. <div style="flex-shrink: 0">
  8. <template v-if="isHaveEdbHandle">
  9. <el-dropdown
  10. v-if="isEdbAdd"
  11. split-button
  12. type="primary"
  13. @click="updateEdbHandle(entryType)"
  14. @command="edbCommandHandle"
  15. >
  16. 更新指标
  17. <el-dropdown-menu slot="dropdown">
  18. <el-dropdown-item :command="{entryType,scence:'saveOther'}">指标另存为</el-dropdown-item>
  19. </el-dropdown-menu>
  20. </el-dropdown>
  21. <el-button type="primary" v-else @click="saveEdb(entryType)">保存指标</el-button>
  22. </template>
  23. <el-dropdown
  24. v-if="isChartAdd"
  25. split-button
  26. type="primary"
  27. @click="updateChartHandle(entryType)"
  28. @command="chartCommandHandle"
  29. >
  30. 更新
  31. <el-dropdown-menu slot="dropdown" v-if="isHaveSaveOtherHandle">
  32. <el-dropdown-item :command="{entryType,scence:'saveOther'}">另存为</el-dropdown-item>
  33. </el-dropdown-menu>
  34. </el-dropdown>
  35. <el-button type="primary" @click="saveChart(entryType)" v-else>保存</el-button>
  36. </div>
  37. </div>
  38. <div class="chartWrapper">
  39. <div class="title text_twoLine">
  40. <span v-if="$route.path==='/fittingEquationChartEditor'">{{chartInfo.ChartName}}</span>
  41. </div>
  42. <Chart
  43. v-if="options.series"
  44. :options="options"
  45. :index="String(entryType)"
  46. :ref="`chartRef${entryType}`"
  47. height="350"
  48. />
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import { chartSetMixin } from '@/views/dataEntry_manage/mixins/chartPublic';
  54. import { dataBaseInterface } from '@/api/api.js';
  55. import chartRelevanceApi,{statisticFeatureInterface} from '@/api/modules/chartRelevanceApi.js';
  56. import Chart from '@/views/dataEntry_manage/components/chart';
  57. export default {
  58. components: { Chart },
  59. mixins: [chartSetMixin],
  60. computed: {
  61. isHaveButton() {
  62. let routes = ['/relevancechartEditor','/statisticFeatureChartEditor']
  63. return routes.includes(this.$route.path)
  64. },
  65. cardTitle() {
  66. let title='';
  67. if(this.$route.path==='/relevancechartEditor') {
  68. title = [3,4].includes(this.entryType) ? `滚动相关性${this.entryType-2}` : this.entryType===1 ? this.chartInfo.ChartName : ''
  69. }else if(this.$route.path==='/statisticFeatureChartEditor') {
  70. title = this.chartInfo.ChartName
  71. }
  72. return title
  73. },
  74. isHaveEdbHandle() { //有指标操作的区域
  75. //相关性 3,4区域可保存指标 统计图 2,3区域
  76. return (([3,4].includes(this.entryType)&&this.$route.path==='/relevancechartEditor')
  77. || ([2,3].includes(this.entryType)&&this.$route.path==='/statisticFeatureChartEditor'))
  78. },
  79. isHaveSaveOtherHandle() {//有图表另存的区域
  80. //相关性 1,2区域有另存 统计图 4个区域都有另存
  81. return (([1,2].includes(this.entryType) && this.$route.path==='/relevancechartEditor')
  82. || (this.$route.path==='/statisticFeatureChartEditor'))
  83. }
  84. },
  85. watch: {
  86. data(nval) {
  87. this.setRenderChartData(nval)
  88. }
  89. },
  90. props: {
  91. entryType: { //位置 1 2 3 4
  92. required: true,
  93. type:Number
  94. },
  95. data: {
  96. type:Object
  97. },
  98. isChartAdd: {
  99. type:Boolean,
  100. default: false
  101. },
  102. isEdbAdd: {
  103. type:Boolean,
  104. default: false
  105. },
  106. settings: {
  107. type: Object
  108. }
  109. },
  110. data() {
  111. return {
  112. chartInfo: {}
  113. }
  114. },
  115. methods: {
  116. //设置图依赖数据
  117. setRenderChartData(data) {
  118. console.log(data)
  119. switch(data.ChartInfo.Source) {//1曲线
  120. case 1:
  121. this.chartInfo = data.ChartInfo;
  122. this.setDefaultChart(data.EdbInfoList);
  123. break
  124. case 3: //3相关性
  125. this.chartInfo = data.ChartInfo;
  126. this.relevanceChartData={
  127. ChartInfo:data.ChartInfo,
  128. EdbInfoList:data.EdbInfoList,
  129. XEdbIdValue:data.XEdbIdValue || data.XDateTimeValue,
  130. CorrelationChartInfo:data.CorrelationChartInfo,
  131. YDataList:[
  132. {
  133. Value:data.YDataList[0].Value,
  134. Color:'#00f',
  135. Name:data.ChartInfo.ChartName,
  136. NameEn:''
  137. }
  138. ]
  139. }
  140. this.tableData=data.EdbInfoList||[]
  141. this.initRelevanceChartData()
  142. break
  143. case 4: //4滚动相关性
  144. this.relevanceChartData = {
  145. ChartInfo:data.ChartInfo,
  146. CorrelationChartInfo: data.CorrelationChartInfo
  147. }
  148. this.chartInfo = data.ChartInfo;
  149. this.setDefaultChart([data.DataResp]);
  150. break
  151. case 6: //弹性系数
  152. this.initFittingEquation(data);
  153. break
  154. case 7: //7标准差 8百分比
  155. case 8:
  156. this.chartInfo = data.ChartInfo;
  157. this.setDefaultChart([data.DataResp]);
  158. break
  159. case 9: //频率分布
  160. this.chartInfo = data.ChartInfo;
  161. this.tableData=data.EdbInfoList||[]
  162. this.statisticFrequencyData = data.DataResp;
  163. this.setStatisticFrequency();
  164. break
  165. }
  166. },
  167. /* 拟合方程曲线 */
  168. initFittingEquation(data) {
  169. const { ChartInfo,EdbInfo } = data;
  170. this.chartInfo = ChartInfo;
  171. this.setDefaultChart([EdbInfo]);
  172. },
  173. // 指标下拉菜单
  174. edbCommandHandle({entryType,scence}) {
  175. const typeMap = {
  176. 'saveOther': this.saveEdb
  177. }
  178. typeMap[scence](entryType,scence)
  179. },
  180. //图表下拉菜单
  181. chartCommandHandle({entryType,scence}) {
  182. const typeMap = {
  183. 'saveOther': this.saveChart
  184. }
  185. typeMap[scence](entryType,scence)
  186. },
  187. /* 保存指标入库 */
  188. saveEdb(type,scence='') {
  189. this.$emit('saveEdb',{type,chartData: this.chartInfo,scence})
  190. },
  191. /* 保存图表 另存为图表 */
  192. saveChart(type,scence='') {
  193. this.$emit('saveChart',{type,chartData: this.chartInfo,scence})
  194. },
  195. /* 设置图表封面图片 */
  196. setChartImage(entryType,id) {
  197. let otherOptions = this.chartInfo.Source===3 ? {
  198. chart: {
  199. width:340,
  200. height:230,
  201. },
  202. xAxis:[{
  203. ...this.options.xAxis,
  204. offset: -65,
  205. }]//这里记得要写成你渲染的图的配置项一样的 单独就配置一个offset无效
  206. } : {
  207. chart: {
  208. width:340,
  209. height:230,
  210. }
  211. }
  212. let svg = this.$refs[`chartRef${entryType}`].chart.getSVG(otherOptions);
  213. let form = new FormData();
  214. form.append('Img', svg);
  215. this.setImageHandle(form,id);
  216. },
  217. async setImageHandle(form,id) {
  218. let { Data } = await dataBaseInterface.uploadImgSvg(form);
  219. await dataBaseInterface.setChartImage({
  220. ChartInfoId: id,
  221. ImageUrl: Data.ResourceUrl,
  222. });
  223. },
  224. /* 更新图表 */
  225. async updateChartHandle(entryType) {
  226. //统计图的2 3 4对应source8 9 10但其实图表source又是7 8 9 别问为什么这样搞问后端 我也乱的一批
  227. const sourceMap = {
  228. 1: 1,
  229. 2: 8,
  230. 3: 9,
  231. 4: 10
  232. }
  233. let Source;
  234. if(this.$route.path==='/relevancechartEditor') {
  235. Source = entryType;
  236. }else if(this.$route.path==='/statisticFeatureChartEditor') {
  237. Source = sourceMap[entryType]
  238. }
  239. let params = {
  240. Source,
  241. IsSaveAs: false,
  242. ...this.settings
  243. }
  244. let res = null;
  245. if(this.$route.path==='/relevancechartEditor') {
  246. res = await chartRelevanceApi.saveChart(params)
  247. }else if(this.$route.path==='/statisticFeatureChartEditor') {
  248. res = await statisticFeatureInterface.saveChart(params);
  249. }
  250. if(res.Ret !== 200) return
  251. this.$message.success('更新成功');
  252. },
  253. /* 更新指标 */
  254. async updateEdbHandle(entryType) {
  255. //统计图的2 3 4对应source8 9 10但其实图表source又是7 8 9 别问为什么这样搞问后端 我也乱的一批
  256. const sourceMap = {
  257. 1: 1,
  258. 2: 8,
  259. 3: 9,
  260. 4: 10
  261. }
  262. let Source;
  263. if(this.$route.path==='/relevancechartEditor') {
  264. Source = entryType;
  265. }else if(this.$route.path==='/statisticFeatureChartEditor') {
  266. Source = sourceMap[entryType]
  267. }
  268. let params = {
  269. Source,
  270. IsSaveAs: false,
  271. ...this.settings
  272. }
  273. let res = null;
  274. if(this.$route.path==='/relevancechartEditor') {
  275. res = await chartRelevanceApi.saveEdb(params)
  276. }else if(this.$route.path==='/statisticFeatureChartEditor') {
  277. res = await statisticFeatureInterface.saveEdb(params);
  278. }
  279. if(res.Ret !== 200) return
  280. this.$message.success('更新成功');
  281. }
  282. },
  283. mounted() {
  284. this.setRenderChartData(this.data);
  285. }
  286. }
  287. </script>
  288. <style lang="scss" scoped>
  289. </style>