WXL
2024-02-04 cf9259c2ebee0e82c32864a1ee91d96c403b9099
src/components/Regular/index.vue
@@ -51,29 +51,31 @@
          <el-tag
            :key="crux"
            type="success"
            v-for="crux in dynamiccruxs"
            v-for="crux in item.dynamiccruxs"
            closable
            effect="dark"
            :disable-transitions="false"
            @close="handleClosecrux(crux)"
            @close="handleClosecrux(crux, item)"
          >
            {{ crux }}
          </el-tag>
          <el-select
            v-model="inputValue"
            v-if="inputVisible"
            @change="handleInputConfirm"
            v-if="item.inputVisible"
            @change="handleInputConfirm(item)"
            filterable
            remote
            allow-create
            reserve-keyword
            default-first-option
            :loading="loading"
            placeholder="请选择"
          >
            <el-option
              v-for="item in regular"
              :key="item.label"
              :label="item.label"
              :value="item.label"
              v-for="items in regular"
              :key="items.label"
              :label="items.label"
              :value="items.label"
            >
            </el-option>
          </el-select>
@@ -81,7 +83,7 @@
            v-else
            class="button-new-tag"
            size="small"
            @click="showInput"
            @click="showInput(item)"
            >+ 新增</el-button
          >
        </div>
@@ -91,29 +93,31 @@
          <el-tag
            :key="crux"
            type="warning"
            v-for="crux in nodynamiccruxs"
            v-for="crux in item.nodynamiccruxs"
            closable
            effect="dark"
            :disable-transitions="false"
            @close="handleClosecrux(crux)"
            @close="handleClosecrux(crux, item)"
          >
            {{ crux }}
          </el-tag>
          <el-select
            v-model="inputValue"
            v-if="noinputVisible"
            @change="handleInputConfirm"
            v-if="item.noinputVisible"
            @change="handleInputConfirm(item)"
            filterable
            remote
            allow-create
            reserve-keyword
            default-first-option
            :loading="loading"
            placeholder="请选择"
          >
            <el-option
              v-for="item in noregular"
              :key="item.value"
              :label="item.label"
              :value="item.label"
              v-for="items in noregular"
              :key="items.value"
              :label="items.label"
              :value="items.label"
            >
            </el-option>
          </el-select>
@@ -121,7 +125,7 @@
            v-else
            class="button-new-tag"
            size="small"
            @click="showInputno"
            @click="showInputno(item)"
            >+ 新增</el-button
          >
        </div>
@@ -145,9 +149,33 @@
        >
        <el-col :span="8">
          <div style="text-align: right; padding-right: 10px">
            <el-button type="danger" @click="deloption(item)" round
              >删除</el-button
            >
            <el-button
              v-if="controlsc"
              @click="$emit('addoption', item)"
              type="success"
              icon="el-icon-circle-plus-outline"
              circle
            ></el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              circle
              @click="$emit('deloption', item)"
            ></el-button>
            <el-button
              v-if="controlsc"
              @click="$emit('syioption', item)"
              type="primary"
              icon="el-icon-top"
              circle
            ></el-button>
            <el-button
              v-if="controlsc"
              @click="$emit('xiayioption', item)"
              type="primary"
              icon="el-icon-bottom"
              circle
            ></el-button>
          </div>
        </el-col>
      </el-row>
@@ -176,7 +204,7 @@
      loading: false,
      regular: [],
      noregular: [],
      nodynamiccruxs: ["别"],
      nodynamiccruxs: ["别", "不"],
      dynamiccruxs: ["好"],
    };
  },
@@ -186,31 +214,53 @@
      required: true,
      default: () => [],
    },
    controlsc: {
      type: Boolean,
      default: true,
    },
  },
  created() {
    this.regular = store.getters.regular;
    this.noregular = store.getters.noregular;
  },
  methods: {
    // 生成正则
    generateRegex() {
    generateRegex(row) {
      let index = this.TargetoptionList.indexOf(row);
      console.log(index);
      let regex = "";
      let regexno = "";
      let hostregex = "";
      let hostregexno = "";
      for (let i = 0; i < this.dynamiccruxs.length; i++) {
        regex += `${this.dynamiccruxs[i]}|`;
      for (
        let i = 0;
        i < this.TargetoptionList[index].dynamiccruxs.length;
        i++
      ) {
        regex += `${this.TargetoptionList[index].dynamiccruxs[i]}|`;
      }
      for (let i = 0; i < this.nodynamiccruxs.length; i++) {
        regexno += `${this.nodynamiccruxs[i]}|`;
      for (
        let i = 0;
        i < this.TargetoptionList[index].nodynamiccruxs.length;
        i++
      ) {
        regexno += `${this.TargetoptionList[index].nodynamiccruxs[i]}|`;
      }
      regex = regex.slice(0, -1);
      regexno = regexno.slice(0, -1);
      hostregex = "^(?!." + `${regexno}` + ")(.(" + `${regex}` + ")+.*)$";
      console.log(hostregex);
      hostregex = "(?=.*(?:" + `${regex}` + ")).*$";
      hostregexno = "^(?!.(?:" + `${regexno}` + ")).*$";
      this.TargetoptionList[index].hostregex = hostregex;
      this.TargetoptionList[index].hostregex2 = hostregexno;
      console.log(hostregex, "确定字匹配");
      console.log(hostregexno, "否定字匹配");
      this.handleSelectionChange();
    },
    // 控制文件
    handleChange(file, fileList) {
@@ -225,44 +275,63 @@
      );
    },
    handleClosecrux(crux) {
    handleClosecrux(crux, item) {
      if (this.whether == 1) {
        this.dynamiccruxs.splice(this.dynamiccruxs.indexOf(crux), 1);
      } else {
        this.nodynamiccruxs.splice(this.nodynamiccruxs.indexOf(crux), 1);
      }
      this.generateRegex();
      this.generateRegex(item);
    },
    handleInputConfirm() {
    handleInputConfirm(row) {
      let index = this.TargetoptionList.indexOf(row);
      if (this.whether == 1 && this.inputValue) {
        if (this.dynamiccruxs.indexOf(this.inputValue) == -1) {
          this.dynamiccruxs.push(this.inputValue);
        if (
          this.TargetoptionList[index].dynamiccruxs.indexOf(this.inputValue) ==
          -1
        ) {
          this.TargetoptionList[index].dynamiccruxs.push(this.inputValue);
        } else {
          this.$message.error("关键字已存在");
        }
        this.inputVisible = false;
        // this.inputVisible = false;
        this.TargetoptionList[index].inputVisible = false;
      } else if (this.whether == 2 && this.inputValue) {
        console.log(this.inputValue);
        console.log(this.nodynamiccruxs.indexOf(this.inputValue));
        if (this.nodynamiccruxs.indexOf(this.inputValue) == -1) {
          this.nodynamiccruxs.push(this.inputValue);
        console.log(
          this.TargetoptionList[index].nodynamiccruxs.indexOf(this.inputValue)
        );
        if (
          this.TargetoptionList[index].nodynamiccruxs.indexOf(
            this.inputValue
          ) == -1
        ) {
          this.TargetoptionList[index].nodynamiccruxs.push(this.inputValue);
        } else {
          this.$message.error("关键字已存在");
        }
        this.noinputVisible = false;
        // this.noinputVisible = false;
        this.TargetoptionList[index].noinputVisible = false;
      }
      this.generateRegex();
      this.generateRegex(row);
      this.inputValue = "";
    },
    showInput() {
      this.inputVisible = true;
    showInput(row) {
      let index = this.TargetoptionList.indexOf(row);
      // this.TargetoptionList[index].inputVisible = true;
      this.$set(this.TargetoptionList[index], "inputVisible", true);
      this.whether = 1;
    },
    showInputno() {
      this.noinputVisible = true;
    showInputno(row) {
      let index = this.TargetoptionList.indexOf(row);
      // this.TargetoptionList[index].noinputVisible = true;
      this.$set(this.TargetoptionList[index], "noinputVisible", true);
      this.whether = 2;
      console.log(2);
    },
    handleSelectionChange(selection) {
      console.log(this.TargetoptionList);
      this.$emit("handleSelectionChange", selection);
    },
  },
};