|
|
@@ -0,0 +1,266 @@
|
|
|
+<!--
|
|
|
+ * @Author: your name
|
|
|
+ * @Date: 2024-11-01 10:14:11
|
|
|
+ * @LastEditTime: 2024-11-04 16:57:16
|
|
|
+ * @LastEditors: bogon
|
|
|
+ * @Description: In User Settings Edit
|
|
|
+ * @FilePath: /performance-test/src/views/performance/components/custonAsCom/dragChart/components/chartsContent.vue
|
|
|
+-->
|
|
|
+<template>
|
|
|
+ <div class="chartContiner">
|
|
|
+ <vue-ruler-tool
|
|
|
+ :height="500"
|
|
|
+ :zoom="1"
|
|
|
+ :unit="10"
|
|
|
+ :scale="1"
|
|
|
+ :precision="0"
|
|
|
+ :rulerColor="'#00aaff'"
|
|
|
+ :bgColor="'#ffffff'"
|
|
|
+ :cornerColor="'#333'"
|
|
|
+ :guidelineColor="'#f00'"
|
|
|
+ :cornerSize="10"
|
|
|
+ :scrollLeft="0"
|
|
|
+ :scrollTop="0"
|
|
|
+ @onRulerScroll="handleScroll"
|
|
|
+ >
|
|
|
+ <div class="canvas-wrapper" ref="canvas">
|
|
|
+ <template v-if="IsCanvasPrepared">
|
|
|
+ <vue-draggable-resizable
|
|
|
+ v-for="(item, index) in currentChartList"
|
|
|
+ :key="item.id"
|
|
|
+ :w="item.width"
|
|
|
+ :h="item.height"
|
|
|
+ :x="item.x"
|
|
|
+ :y="item.y"
|
|
|
+ :snap="true"
|
|
|
+ :is-conflict-check="false"
|
|
|
+ :parent="true"
|
|
|
+ @dragging="onDrag"
|
|
|
+ @resizing="onResize"
|
|
|
+ @activated="onClickChart(item, index)"
|
|
|
+ @deactivated="onMoveout(index)"
|
|
|
+ >
|
|
|
+ <chart
|
|
|
+ :height="item.height"
|
|
|
+ :width="item.width"
|
|
|
+ :option="item.option"
|
|
|
+ />
|
|
|
+ <div class="info">
|
|
|
+ <div>x轴:{{ item.x }} 高度:{{ item.height }}</div>
|
|
|
+ <div>y轴:{{ item.y }} 宽度:{{ item.width }}</div>
|
|
|
+ <el-button
|
|
|
+ class="icon-wrapper"
|
|
|
+ size="mini"
|
|
|
+ type="danger"
|
|
|
+ plain
|
|
|
+ @click="deleteTheChart(index)"
|
|
|
+ icon="el-icon-delete"
|
|
|
+ ></el-button>
|
|
|
+ </div>
|
|
|
+ </vue-draggable-resizable>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+ </vue-ruler-tool>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import { mapState, mapMutations } from "vuex";
|
|
|
+import Chart from "./chart/index";
|
|
|
+import ChartClass from "@/assets/js/class/chart.js";
|
|
|
+import { SCALE } from "@/assets/js/constants/config.js";
|
|
|
+const OTHER_CONFIG = ["background", "theme"];
|
|
|
+const _ = require("lodash");
|
|
|
+export default {
|
|
|
+ components: {
|
|
|
+ Chart,
|
|
|
+ },
|
|
|
+ props: {
|
|
|
+ addChartType: {
|
|
|
+ type: String,
|
|
|
+ default: "",
|
|
|
+ },
|
|
|
+ config: {
|
|
|
+ type: String,
|
|
|
+ default: "",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ fileId: +this.$route.params.id,
|
|
|
+ IsCanvasPrepared: false,
|
|
|
+ chartIndex: 0,
|
|
|
+ screenHeight: 0,
|
|
|
+ screenWidth: 0,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {},
|
|
|
+ watch: {
|
|
|
+ addChartType(type) {
|
|
|
+ if (type !== "") {
|
|
|
+ !OTHER_CONFIG.includes(type) && this.appendChart(type);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ config(val) {
|
|
|
+ this.handleImportConfig(val);
|
|
|
+ },
|
|
|
+ // background(val) {
|
|
|
+ // this.changeBg(val);
|
|
|
+ // },
|
|
|
+ // isFullSize(val) {
|
|
|
+ // this.handleFullScreen();
|
|
|
+ // },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState("dragChart", {
|
|
|
+ currentChartList: "currentChartList",
|
|
|
+ curChart: "curEdit",
|
|
|
+ }),
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.getScrollSize();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...mapMutations("dragChart", [
|
|
|
+ "scaleScreen",
|
|
|
+ "setCurrentChartList",
|
|
|
+ "addChart",
|
|
|
+ "updateChart",
|
|
|
+ "deleteChart",
|
|
|
+ "setCurEdit",
|
|
|
+ "recordOriginChartList",
|
|
|
+ "restoreOriginChartList",
|
|
|
+ ]),
|
|
|
+ // ruler-tool 组件标尺滚动事件
|
|
|
+ handleScroll({ scrollLeft, scrollTop }) {
|
|
|
+ console.log("标尺滚动:", scrollLeft, scrollTop);
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @description 响应图表缩放
|
|
|
+ * @params {Array} 左上角(x,y)坐标,选中图形宽高
|
|
|
+ */
|
|
|
+ onResize(x, y, width, height) {
|
|
|
+ this.updateChart({
|
|
|
+ index: this.chartIndex,
|
|
|
+ x,
|
|
|
+ y,
|
|
|
+ height,
|
|
|
+ width,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @description 响应图表拖拽
|
|
|
+ * @params {Array} 图形左上角(x,y)坐标
|
|
|
+ */
|
|
|
+ onDrag(x, y) {
|
|
|
+ this.updateChart({
|
|
|
+ index: this.chartIndex,
|
|
|
+ x,
|
|
|
+ y,
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ onClickChart(item, index) {
|
|
|
+ this.setCurEdit(item);
|
|
|
+ this.chartIndex = index;
|
|
|
+ const nodes = document.getElementsByClassName("info");
|
|
|
+ nodes[index].style.opacity = 1;
|
|
|
+ },
|
|
|
+
|
|
|
+ onMoveout(index) {
|
|
|
+ const nodes = document.getElementsByClassName("info");
|
|
|
+ nodes[index].style.opacity = 0;
|
|
|
+ },
|
|
|
+ appendChart(type) {
|
|
|
+ const config = require(`@/assets/js/constants/echarts-config/${type}.js`);
|
|
|
+ this.addChart(
|
|
|
+ new ChartClass({
|
|
|
+ option: config.option,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 响应图表删除
|
|
|
+ * @params {Number} 序号
|
|
|
+ */
|
|
|
+ deleteTheChart(index) {
|
|
|
+ this.$confirm("是否删除改图表?", "提示", {
|
|
|
+ confirmButtonText: "确定",
|
|
|
+ cancelButtonText: "取消",
|
|
|
+ type: "warning",
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ this.deleteChart(index);
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: "删除成功!",
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
+ },
|
|
|
+
|
|
|
+ handleImportConfig(option) {
|
|
|
+ this.addChart(
|
|
|
+ new ChartClass({
|
|
|
+ option: new Function("return " + option)() /* eslint-disable-line */,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @description 修改画布元素宽高为屏幕大小
|
|
|
+ */
|
|
|
+ getScrollSize() {
|
|
|
+ this.screenHeight = window.screen.height;
|
|
|
+ this.screenWidth = document.body.clientWidth;
|
|
|
+ this.$refs.canvas.style.setProperty(
|
|
|
+ "--canvasHeight",
|
|
|
+ `${this.screenHeight / SCALE}px`
|
|
|
+ );
|
|
|
+ this.$refs.canvas.style.setProperty(
|
|
|
+ "--canvasWidth",
|
|
|
+ `${this.screenWidth / SCALE}px`
|
|
|
+ );
|
|
|
+ this.IsCanvasPrepared = true;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description 百分比转为像素值
|
|
|
+ */
|
|
|
+ calPercent(value, type) {
|
|
|
+ return type === "x"
|
|
|
+ ? value / this.screenWidth
|
|
|
+ : value / this.screenHeight;
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped lang="scss">
|
|
|
+.chartContiner {
|
|
|
+ // background-color: #fff;
|
|
|
+ flex: 1;
|
|
|
+ height: 100%;
|
|
|
+ width: 1800px;
|
|
|
+ overflow: scroll;
|
|
|
+ ::v-deep .vue-ruler-wrapper {
|
|
|
+ // width: 100% !important;
|
|
|
+ }
|
|
|
+ .canvas-wrapper {
|
|
|
+ position: relative;
|
|
|
+ width: var(--canvasWidth);
|
|
|
+ height: var(--canvasHeight);
|
|
|
+ background: #fff;
|
|
|
+ border-radius: 10px;
|
|
|
+ box-shadow: 0 0 0 10px #d6dce0;
|
|
|
+ outline: 10px solid #d6dce0;
|
|
|
+ outline-offset: 0px;
|
|
|
+ .info {
|
|
|
+ opacity: 0;
|
|
|
+ .icon-wrapper {
|
|
|
+ position: absolute;
|
|
|
+ bottom: -35px;
|
|
|
+ right: 5px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|