index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <fs-page>
  3. <fs-crud ref="crudRef" v-bind="crudBinding">
  4. <template #header-top>
  5. <div id="myEcharts" v-show="isEcharts" v-resize-ob="handleResize" :style="{width: '100%', height: '300px'}"></div>
  6. </template>
  7. </fs-crud>
  8. </fs-page>
  9. </template>
  10. <script lang="ts" setup name="loginLog">
  11. import { ref, onMounted } from 'vue';
  12. import { useFs } from '@fast-crud/fast-crud';
  13. import { createCrudOptions } from './crud';
  14. import * as echarts from "echarts";
  15. const isEcharts = ref(true)
  16. const { crudBinding, crudRef, crudExpose } = useFs({ createCrudOptions,isEcharts,initChart });
  17. const myEcharts = echarts
  18. function initChart() {
  19. let chart = myEcharts.init(document.getElementById("myEcharts"), "purple-passion");
  20. // 在这里请求API,例如:
  21. /***
  22. * request({url:'xxxx'}).then(res=>{
  23. * // 把chart.setOption写在这里面
  24. *
  25. * })
  26. *
  27. */
  28. chart.setOption({
  29. title: {
  30. text: "2021年各月份销售量(单位:件)",
  31. left: "center",
  32. },
  33. xAxis: {
  34. type: "category",
  35. data: [
  36. "一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"
  37. ]
  38. },
  39. tooltip: {
  40. trigger: "axis"
  41. },
  42. yAxis: {
  43. type: "value"
  44. },
  45. series: [
  46. {
  47. data: [
  48. 606, 542, 985, 687, 501, 787, 339, 706, 383, 684, 669, 737
  49. ],
  50. type: "line",
  51. smooth: true,
  52. itemStyle: {
  53. normal: {
  54. label: {
  55. show: true,
  56. position: "top",
  57. formatter: "{c}"
  58. }
  59. }
  60. }
  61. }
  62. ]
  63. });
  64. window.onresize = function () {
  65. chart.resize();
  66. };
  67. }
  68. function handleResize(size) {
  69. // console.log(size)
  70. }
  71. // 页面打开后获取列表数据
  72. onMounted(() => {
  73. crudExpose.doRefresh();
  74. initChart()
  75. });
  76. </script>