index.vue 3.06 KB
<!--
 * @Author: panda
 * @Date: 2021-09-27 13:40:37
 * @LastEditTime: 2021-09-27 17:04:20
 * @LastEditors: Please set LastEditors
 * @Description: 参数缺省设置
 * @FilePath: /fanxing_new/src/views/resource/publicConfig/index.vue
-->
<template>
  <div class="config-box">
    <div class="switch-box">
      <el-radio v-model="radio" label="defaultConfigTemplate"
        >正常配置</el-radio
      >
      <el-radio v-model="radio" label="illegalStopDefaultConfigTemplate"
        >违停配置</el-radio
      >
    </div>
    <el-row>
      <el-col :span="3" class="search-box">
        <el-input
          placeholder="请输入内容"
          v-model="paramsval"
          class="input-with-select"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="$refs.iframeconfig.contentWindow.clickButton(paramsval)"
          ></el-button>
        </el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="20" class="content-box">
        <iframe
          id="iframeconfig"
          ref="iframeconfig"
          src="./dynamicParameters.html"
          frameborder="0"
          width="100%"
          height="600"
          scrolling="no"
        ></iframe>
      </el-col>
      <el-col :span="1" :offset="19">
        <el-button type="primary" @click="saveConfig" class="save-btn"
          >保存</el-button
        >
      </el-col>
    </el-row>
  </div>
</template>

<script>
import xml from "./baseConfig.js";
export default {
  data() {
    return {
      paramsval: "",
      radio: "defaultConfigTemplate",
      config: "",
      configid: "",
    };
  },
  watch: {
    radio(val) {
      this.getbaseConf(val);
    },
  },
  methods: {
    xmlInit: function (obj) {
      this.$refs.iframeconfig.contentWindow.loadParameterTree(
        obj.content,
        '<?xml version="1.0" encoding="GBK"?><root></root>'
      );
    },
    getbaseConf(type) {
      this.$api.device.getConfig(type).then((res) => {
        this.config = res.data.content;
        this.configid = res.data.id;
        this.xmlInit(res.data);
      });
    },
    saveConfig() {
      this.$refs.iframeconfig.contentWindow.submit();
      //ifram 传递回来的饿xml
      let XMLStr = this.$refs.iframeconfig.contentWindow.xmlStr;
      if (!XMLStr) {
        XMLStr = this.config;
      }
      this.$api.device
        .saveConfig(this.configid, { content: XMLStr })
        .then((res) => {
          if (res.ecode == 200) {
            this.$message({
              type: "success",
              message: "保存成功!",
            });
          } else {
            this.$message({
              type: "error",
              message: "保存失败!",
            });
          }
        });
    },
  },
  mounted() {
    setTimeout(() => {
      this.getbaseConf("defaultConfig");
    }, 2000);
  },
};
</script>

<style>
.config-box {
  margin: 10px;
  background: #fff;
  overflow: hidden;
}
.switch-box {
  margin: 10px 0 0 10px;
}
.search-box,
.content-box {
  margin: 10px;
}
.save-btn {
  float: right;
  margin-bottom: 20px;
}
</style>