echarts dialog组件(轮子)

1. 父文件引用子组件:
	<dataEcahrtsZs :zsItem="zsItem"
                   :zsVisiable="zsVisiable"
                   @zsClose="zsCloseDialog">
    </dataEcahrtsZs>
    <script>
    import dataEcahrtsZs from "../dialogs/data-echarts-zs.vue";
    export default {
    	components: {
		    dataEcahrtsZs,
		  },
		  data() {
    		return {
    			zsVisiable:false,
    			zsItem: {
        			title: "",
     			},
   			 }
    	}
    	method(){
    		zsCloseDialog(val) {
		      this.zsVisiable = false;
		    },
    	}
    }
    </script>
2. 子组件
<template>
  <el-dialog @open="initStations"
             :title="this.zsItem.title"
             @close="closeDialog"
             width=auto
             :destroy-on-close="true"
             :close-on-click-modal="false"
             :visible.sync="zsVis">
    <el-divider></el-divider>
    <el-form>
      <el-row type="flex"
              :gutter="20">
        <el-col :span="7">
          <el-form-item label="设备位置">
            <el-select v-model="location"
                       @change="initStationNames()"
                       placeholder="请选择">
              <el-option v-for="item in stations"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="7">
          <el-form-item label="设备名称">
            <el-select v-model="stationName"
                       :disabled="this.ifLocation"
                       @change="initNoiseData()"
                       :placeholder="this.SecondSelectText">
              <el-option v-for="item in stationNames"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="起止时间">
            <el-date-picker @change="initNoiseData()"
            :clearable="false"
                            v-model="time"
                            type="datetimerange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div id="funcTable"
         style="margin:24px 0 12px 0; min-height:350px; width:100%; border:1px solid #dfdfdf"></div>
  </el-dialog>
</template>

<script>
//首先初始化时间格式工具,可直接复制到js里面
Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //24小时制
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds(), //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  return fmt;
};
export default {
  name: "dataEcahrtsZs",
  props: {
    zsVisiable: Boolean,
    zsItem: Object,
  },
  data() {
    return {
      SecondSelectText: "请选择设备位置",
      ifLocation: true,
      zsVis: false,
      stations: [],
      noiseArr: [],
      arrtime: [],
      arrtime1: [],
      errorCode: "",
      newStartTime: "",
      newEndTime: "",
      stationName: "",
      location: "",
      stationNames: [],
      locations: [], //设备位置信息select数组
      isShow: true, //是否显示提示信息
      showInf: false, //是否显示导入返回信息
      importOpts: {
        uploadExcelUrl: "/xxxx",
        applicationName: "xxx",
        configId: "",
        text: "",
        rootOrgCode: "",
        rootOrgId: "",
        rootDLevelCode: "",
      },
      fileList: [],
      information: {
        success: "",
        successCount: "",
        errorId: "",
        type: "",
        errorCount: "",
        originName: "",
      },
      loading: "",
      tempId: "",
      title: "导入数据",
      dialogVisibleNoise: false,
      time: [],
      name: "",
      noiseDialog: false,
    };
  },
  beforeMount() {},
  mounted() {},
  watch: {
    zsVisiable(newValue, oldValue) {
      this.zsVis = newValue;
    },
  },
  methods: {
    closeDialog() {
      (this.location = ""), (this.stationName = ""), (this.ifLocation = true), (this.time = []), (this.SecondSelectText = "请选择设备位置");
      this.$emit("zsClose", true);
    },
    //其次,对方法进行封装
    formatTime(timeSecond) {
      var d = new Date(timeSecond); //注意timeSecond是毫秒
      return d.Format("yyyy-MM-dd hh:mm:ss");
    },

    funcTable() {
      var myChart; //全局变量
      var charts = {
        unit: "噪声 (db)",
        names: ["噪声"],
        lineX: this.arrtime,
        value: [this.arrtime1],
      };
      var lineY = [];

      for (var i = 0; i < charts.names.length; i++) {
        var x = i;
        var data = {
          name: charts.names[i],
          type: "line",
          smooth: false,
          symbolSize: 5,
          data: charts.value[i],
        };
        lineY.push(data);
      }
      lineY[0].markLine = {};
      if (myChart != null && myChart != "" && myChart != undefined) {
        myChart.dispose(); //销毁
      }
      myChart = this.$echarts.init(document.getElementById("funcTable"));
      myChart.setOption({
        color: "#039382",
        title: {
          // text: '历史数据-曲线',
          textStyle: {
            fontWeight: "normal",
            fontSize: 16,
            color: "",
          },
          left: "45%",
          top: "4%",
        },
        // backgroundColor: '',
        tooltip: {
          // color: '#039382'
          // trigger: 'axis',
        },

        legend: {
          show: false,
          top: "4%",
          data: charts.names,
          textStyle: {
            fontSize: 14,
            // color: 'F1F1F3',
          },
          right: "4%",
        },
        grid: {
          top: "10%",
          left: "4%",
          right: "4%",
          bottom: "10%",
          containLabel: true,
        },
        xAxis: {
          splitLine: {
            show: true,
            lineStyle: {
              type: "dashed",
            },
          },
          show: true,
          type: "category",
          boundaryGap: false,
          data: charts.lineX,
          axisLabel: {
            textStyle: {
              color: "",
            },
            formatter: function (params) {
              return params.split(" ")[0] + "\n" + params.split(" ")[1];
            },
          },
        },
        yAxis: {
          show: true,
          splitArea: {
            show: true,
            areaStyle: {
              color: "",
            },
          },
          name: charts.unit,
          type: "value",
          axisLabel: {
            formatter: "{value}",
            textStyle: {
              color: "",
            },
          },
          splitLine: {
            show: true,
            lineStyle: {
              type: "dashed",
            },
          },
        },
        series: lineY,
      });
    },
  },
};
</script>

<style scoped>
.map {
  width: 100%;
  height: 100%;
}
.el-main {
  width: 100%;
  height: 100%;
  padding: 0px;
}
.Grid {
  display: flex;
}
::v-deep .el-tabs__header {
  padding: 0;
  position: relative;
  margin: 0 0 4px;
}
::v-deep .el-icon-picture-outline-round:before {
  size: 20px;
  margin-right: 0.05rem;
}
::v-deep .el-dialog__body {
  background-color: white;
}
::v-deep .el-dialog .el-dialog__body {
  text-align: initial;
  padding: 15px 30px 15px 30px;
}
::v-deep .el-dialog__header {
  height: 0.1rem;
}
::v-deep .el-dialog__body .el-form {
  padding: 8px 8px 8px 8px;
}

::v-deep .el-dialog__title {
  margin: 0 0 0 15px;
  font-weight: 700;
}
.buttonGroup {
  margin-top: 16px;
  display: flex;
  justify-content: space-around;
}
.buttonItem {
  flex-grow: 0;
  /* flex: 1; */
}
.searchFormItem {
  margin-top: 8px;
  flex: 1;
}
::v-deep .el-dialog .el-dialog--center {
  width: 680px;
}
::v-deep .el-date-editor--datetimerange.el-input,
.el-date-editor--datetimerange.el-input__inner {
  width: auto;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
封装一个dialog组件可以分为以下几个步骤: 1. 设计组件API:包括输入参数和输出结果。例如,输入参数可能包括标题、内容、按钮等信息;输出结果可能包括用户的选择、关闭事件等信息。 2. 编写组件逻辑:根据设计好的API,编写组件的业务逻辑,包括渲染组件、处理用户输入等。 3. 添加样式:为组件添加必要的样式,使其能够呈现出设计好的外观。 4. 测试和调试:测试组件的功能是否符合API设计,调试组件中可能存在的问题。 5. 文档化:为组件编写文档,包括组件的使用方法、输入参数和输出结果等。 下面是一个简单的dialog组件的示例代码: ``` // Dialog组件的API interface DialogProps { title: string; content: string; onConfirm?: () => void; onCancel?: () => void; } // Dialog组件 const Dialog: React.FC<DialogProps> = ({ title, content, onConfirm, onCancel }) => { return ( <div className="dialog"> <h2>{title}</h2> <p>{content}</p> <div className="buttons"> <button onClick={onConfirm}>确认</button> <button onClick={onCancel}>取消</button> </div> </div> ); }; // 使用Dialog组件 const App: React.FC = () => { const handleConfirm = () => { console.log("确认"); }; const handleCancel = () => { console.log("取消"); }; return ( <div className="app"> <Dialog title="提示" content="确定要删除吗?" onConfirm={handleConfirm} onCancel={handleCancel} /> </div> ); }; ``` 在上面的示例中,我们定义了Dialog组件的API,包括title、content、onConfirm和onCancel等输入参数。然后,我们编写了Dialog组件的业务逻辑,包括渲染组件、处理用户输入等。最后,我们在App组件中使用Dialog组件,提供了相应的输入参数和回调函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值