1
0

chartManage.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="图表名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入图表名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="创建用户ID" prop="userId">
  13. <el-input
  14. v-model="queryParams.userId"
  15. placeholder="请输入创建用户ID"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" size="mini" @click="handleQuery">
  22. <template #icon>
  23. <el-icon><Search /></el-icon>
  24. </template>
  25. <template #default>
  26. 搜索
  27. </template>
  28. </el-button>
  29. <el-button size="mini" @click="resetQuery">
  30. <template #icon>
  31. <el-icon><RefreshRight /></el-icon>
  32. </template>
  33. <template #default>
  34. 重置
  35. </template>
  36. </el-button>
  37. </el-form-item>
  38. </el-form>
  39. <el-table v-loading="loading" :data="chartList" @selection-change="handleSelectionChange">
  40. <el-table-column type="selection" width="55" align="center" />
  41. <el-table-column label="图表ID" align="center" prop="id" />
  42. <el-table-column label="图表名称" align="center" prop="name" />
  43. <el-table-column label="分析目标" align="center" prop="analysisTarget" />
  44. <el-table-column label="图标类型" align="center" prop="chartType" />
  45. <!--<el-table-column label="生成的分析结论" align="center" prop="analysisConclusion" />-->
  46. <el-table-column label="创建用户ID" align="center" prop="userId" />
  47. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  48. <template #default="scope">
  49. <el-button
  50. type="primary"
  51. size="mini"
  52. @click="handleUpdate(scope.row)"
  53. >
  54. <template #icon>
  55. <el-icon><TrendCharts /></el-icon>
  56. </template>
  57. 详情
  58. </el-button>
  59. <el-popconfirm
  60. confirm-button-text="确定"
  61. cancel-button-text="取消"
  62. :icon="InfoFilled"
  63. icon-color="#626AEF"
  64. title="确定删除这个分析的图表结果吗"
  65. @confirm="handleDelete(scope.row)"
  66. @cancel="cancelEvent"
  67. >
  68. <template #reference>
  69. <el-button type="danger">
  70. <template #icon>
  71. <el-icon><Remove /></el-icon>
  72. </template>
  73. <template #default>
  74. 删除
  75. </template>
  76. </el-button>
  77. </template>
  78. </el-popconfirm>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <!-- 分页 -->
  83. <el-pagination
  84. v-show="total>0"
  85. v-model:current-page="queryParams.pageNum"
  86. v-model:page-size="queryParams.pageSize"
  87. :page-sizes="[10, 15, 30]"
  88. layout="total, sizes, prev, pager, next, jumper"
  89. :total="total"
  90. @size-change="getList"
  91. @current-change="getList"
  92. />
  93. <!-- 显示图表和结论详情的对话框 -->
  94. <el-dialog v-model="open" width="60%" center append-to-body>
  95. <template #header>数据分析详情</template>
  96. <template #default>
  97. <el-row>
  98. <el-col :span="12">
  99. <el-card>
  100. <template #header>数据图表</template>
  101. <template #default>
  102. <div ref="chart" style="height:50vh"/>
  103. </template>
  104. </el-card>
  105. </el-col>
  106. <el-col :span="12">
  107. <el-card>
  108. <template #header>分析结论</template>
  109. <template #default>
  110. <div style="height:50vh">
  111. <el-text type="primary" size="large" style="margin-top: 20px">
  112. {{analysisConclusion}}
  113. </el-text>
  114. </div>
  115. </template>
  116. </el-card>
  117. </el-col>
  118. </el-row>
  119. </template>
  120. <template #footer class="dialog-footer">
  121. </template>
  122. </el-dialog>
  123. </div>
  124. </template>
  125. <script>
  126. import { listChart, delChart } from "@/common/api/chart";
  127. import {ElMessage} from "element-plus";
  128. import * as echarts from 'echarts';
  129. export default {
  130. name: "Chart",
  131. data() {
  132. return {
  133. // 遮罩层
  134. loading: true,
  135. // 选中数组
  136. ids: [],
  137. // 非单个禁用
  138. single: true,
  139. // 非多个禁用
  140. multiple: true,
  141. // 显示搜索条件
  142. showSearch: true,
  143. // 总条数
  144. total: 0,
  145. // 图表管理表格数据
  146. chartList: [],
  147. // 是否显示弹出层
  148. open: false,
  149. // 查询参数
  150. queryParams: {
  151. pageNum: 1,
  152. pageSize: 10,
  153. name: null,
  154. analysisTarget: null,
  155. chartType: null,
  156. userId: null,
  157. },
  158. //图表的配置对象
  159. option:{
  160. xAxis: {
  161. type: 'category',
  162. data: ['2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],
  163. boundaryGap: true,
  164. axisLabel:{
  165. interval:0,
  166. rotate : 50
  167. },
  168. },
  169. yAxis: {
  170. type: 'value'
  171. },
  172. series: [{
  173. name:'增长人数',
  174. type:'line',
  175. data:[34.0, 34.0, 3.0, 3.0, 43.0, 34.0, 43.0, 34.0, 34.0, 12.0, 12.0, 12.0, 12.0, 32.0, 12.0, 32.0, 32.0, 32.0, 32.0],
  176. markPoint: {
  177. data: [
  178. {type: 'max', name: '最大值'},
  179. {type: 'min', name: '最小值'}
  180. ]
  181. },
  182. markLine: {data: [
  183. {type: 'average', name: '平均值'}
  184. ]},
  185. smooth: true
  186. }]
  187. },
  188. analysisConclusion:'',
  189. chart:undefined
  190. };
  191. },
  192. created() {
  193. this.getList();
  194. },
  195. methods: {
  196. /** 查询图表管理列表 */
  197. getList() {
  198. this.loading = true;
  199. listChart(this.queryParams).then(response => {
  200. this.chartList = response.data.records;
  201. this.total = response.data.total;
  202. this.loading = false;
  203. });
  204. },
  205. // 取消按钮
  206. cancel() {
  207. this.open = false;
  208. this.reset();
  209. },
  210. // 表单重置
  211. reset() {
  212. this.form = {
  213. id: null,
  214. name: null,
  215. analysisTarget: null,
  216. chartData: null,
  217. chartType: null,
  218. generatedChartData: null,
  219. analysisConclusion: null,
  220. userId: null,
  221. createdTime: null,
  222. updatedTime: null,
  223. deleteFlag: null
  224. };
  225. // this.resetForm("form");
  226. },
  227. /** 搜索按钮操作 */
  228. handleQuery() {
  229. this.queryParams.pageNum = 1;
  230. this.getList();
  231. },
  232. /** 重置按钮操作 */
  233. resetQuery() {
  234. // this.resetForm("queryForm");
  235. this.handleQuery();
  236. },
  237. // 多选框选中数据
  238. handleSelectionChange(selection) {
  239. this.ids = selection.map(item => item.id)
  240. this.single = selection.length!==1
  241. this.multiple = !selection.length
  242. },
  243. /** 修改按钮操作 */
  244. handleUpdate(row) {
  245. this.reset();
  246. this.analysisConclusion = row.analysisConclusion;
  247. let generatedChartData = row.generatedChartData;
  248. let optionJson = eval("(" +generatedChartData+ ")");
  249. //返回格式不稳定,有可能会多封装一层option,需要判断一下
  250. if (optionJson.option === undefined || optionJson.option === null){
  251. this.option = optionJson;
  252. }else{
  253. this.option = optionJson.option;
  254. }
  255. this.open = true;
  256. this.refreshChart();
  257. },
  258. /** 删除按钮操作 */
  259. handleDelete(row) {
  260. const ids = row.id || this.ids;
  261. delChart(ids).then(res => {
  262. if (res.code === 200) {
  263. ElMessage({
  264. message: '删除成功',
  265. type: 'success'
  266. })
  267. }else {
  268. ElMessage({
  269. message: res.msg,
  270. type: 'error'
  271. })
  272. }
  273. this.getList();
  274. }).error(err => {
  275. ElMessage({
  276. message: 'err',
  277. type: 'error'
  278. })
  279. });
  280. // this.$modal.confirm('是否确认删除图表管理编号为"' + ids + '"的数据项?').then(function() {
  281. // return delChart(ids);
  282. // }).then(() => {
  283. // this.getList();
  284. // this.$modal.msgSuccess("删除成功");
  285. // }).catch(() => {});
  286. },
  287. //更新图表
  288. refreshChart(){
  289. setTimeout(()=>{
  290. if (this.chart === undefined){
  291. this.chart = echarts.init(this.$refs.chart);
  292. }
  293. this.chart.clear();
  294. setTimeout(()=>{
  295. this.chart.setOption(this.option);
  296. },500)
  297. },500);
  298. }
  299. }
  300. };
  301. </script>