<template>
  <div class="layout">
    <el-tabs
      v-model="tabLabel"
      v-loading="loading"
      type="card"
      @tab-click="tabClick"
    >
      <el-tab-pane
        label="IP库"
        name="IP库"
      >
        <manager-ui
          :query-model="formIp.threatIntelligenceIpMap"
          :query-items="queryItemsIp"
          :static-data="staticData"
          :column-items="columnItemsIp"
          :table-data="tableData"
          :pagination="formIp.page"
          :spread-threshold="4"
          show-table-tools
          :show-add-btn="showIpAddBtn()"
          :show-download-btn="showIpDownloadBtn()"
          @allDownload="exportThreatIp()"
          @selection-change="doSelectHandle"
          @search="searchIp"
          @searchClick="formIp.page.current=1;searchIp();batchRows = [];"
          @resetForm="formIp.page.current=1;resetFormIp();batchRows = [];"
          @create="addThreatIp"
        >
          <template #type="{scope}">
            {{ scope.row.type | toCase(staticData.typeList,'dataId', 'dataName') }}
          </template>
          <template #operate="{scope}">
            <el-context-menu
              :menus="menusIp"
              :visibles="[]"
              :scope="scope"
              :default="defaultV"
              @oper="clickRow"
            />
          </template>
          <template slot="tableDropdown">
            <el-button type="text" v-rule-code="'threatIntelligenceIp_import'">
              <span @click="dialogVisible=true">
                <i class="el-icon-upload" />导入数据
              </span>
            </el-button>
          </template>
          <template slot="tableTools">
            <el-button type="text" v-rule-code="'threatIntelligenceIp_export'">
              <span @click="exportThreatIp">
                <i class="el-icon-download" />导出
              </span>
            </el-button>
            <el-button type="text" v-rule-code="'threatIntelligenceIp_del'">
              <span @click="batchDeleteThreatIp">
                <icon name="trash" />删除
              </span>
            </el-button>
          </template>
        </manager-ui>
      </el-tab-pane>
      <el-tab-pane
        label="域名库"
        name="域名库"
      >
        <manager-ui
          :query-model="formRealm.threatIntelligenceRealmMap"
          :query-items="queryItemsRealm"
          :static-data="staticData"
          :column-items="columnItemsRealm"
          :table-data="tableData"
          :pagination="formRealm.page"
          :spread-threshold="4"
          show-table-tools
          :show-add-btn="showRealmAddBtn()"
          :show-download-btn="showRealmDownloadBtn()"
          @allDownload="exportThreatRealm()"
          @selection-change="doSelectHandle"
          @search="searchRealm"
          @searchClick="formRealm.page.current=1;searchRealm();batchRows = [];"
          @resetForm="formRealm.page.current=1;resetFormRealm();batchRows = [];"
          @create="addThreatRealm"
        >
          <template #intelType="{scope}">
            {{ scope.row.intelType | toCase(staticData.typeList,'dataId', 'dataName') }}
          </template>
          <template #operate="{scope}">
            <el-context-menu
              :menus="menusRealm"
              :visibles="[]"
              :scope="scope"
              :default="defaultV"
              @oper="clickRow"
            />
          </template>

          <template slot="tableDropdown">
            <el-button type="text" v-rule-code="'threatIntelligenceRealm_import'">
              <span @click="dialogVisible=true">
                <i class="el-icon-upload" />导入数据
              </span>
            </el-button>
          </template>

          <template slot="tableTools">
            <el-button type="text" v-rule-code="'threatIntelligenceRealm_export'">
              <span @click="exportThreatRealm">
                <i class="el-icon-download" />导出
              </span>
            </el-button>
            <el-button type="text" v-rule-code="'threatIntelligenceRealm_del'">
              <span @click="batchDeleteThreatRealm">
                <icon name="trash" />删除
              </span>
            </el-button>
          </template>
        </manager-ui>
      </el-tab-pane>
      <el-tab-pane
        label="URL库"
        name="URL库"
      >
        <manager-ui
          :query-model="formUrl.threatIntelligenceRealmMap"
          :query-items="queryItemsUrl"
          :static-data="staticData"
          :column-items="columnItemsUrl"
          :table-data="tableData"
          :pagination="formUrl.page"
          :spread-threshold="4"
          show-table-tools
          :show-add-btn="showUrlAddBtn()"
          :show-download-btn="showUrlDownloadBtn()"
          @allDownload="exportThreatUrl()"
          @selection-change="doSelectHandle"
          @search="searchUrl"
          @searchClick="formUrl.page.current=1;searchUrl();batchRows = [];"
          @resetForm="formUrl.page.current=1;resetFormUrl();batchRows = [];"
          @create="addThreatUrl"
        >
          <template #intelType="{scope}">
            {{ scope.row.intelType | toCase(staticData.typeList,'dataId', 'dataName') }}
          </template>
          <template #operate="{scope}">
            <el-context-menu
              :menus="menusUrl"
              :visibles="[]"
              :scope="scope"
              :default="defaultV"
              @oper="clickRow"
            />
          </template>

          <template slot="tableDropdown">
            <el-button type="text" v-rule-code="'threatIntelligenceUrl_import'">
              <span @click="dialogVisible=true">
                <i class="el-icon-upload" />导入数据
              </span>
            </el-button>
          </template>

          <template slot="tableTools">
            <el-button type="text" v-rule-code="'threatIntelligenceUrl_export'">
              <span @click="exportThreatUrl">
                <i class="el-icon-download" />导出
              </span>
            </el-button>
            <el-button type="text" v-rule-code="'threatIntelligenceUrl_del'">
              <span @click="batchDeleteThreatUrl">
                <icon name="trash" />删除
              </span>
            </el-button>
          </template>
        </manager-ui>
      </el-tab-pane>
      <el-tab-pane
        label="文件库"
        name="文件库"
      >
        <manager-ui
          :query-model="formFile.threatIntelligenceFileMap"
          :query-items="queryItemsFile"
          :static-data="staticData"
          :column-items="columnItemsFile"
          :table-data="tableData"
          :pagination="formFile.page"
          :spread-threshold="4"
          show-table-tools
          :show-add-btn="showFileAddBtn()"
          :show-download-btn="showFileDownloadBtn()"
          @allDownload="exportThreatFile()"
          @selection-change="doSelectHandle"
          @search="searchFile"
          @searchClick="formFile.page.current=1;searchFile();batchRows = [];"
          @resetForm="formFile.page.current=1;resetFormFile();batchRows = [];"
          @create="addThreatFile"
        >
          <template #isWhite="{scope}">
            {{ scope.row.isWhite | toCase(staticData.isWhiteList,'dataId', 'dataName') }}
          </template>
          <template #operate="{scope}">
            <el-context-menu
              :menus="menusFile"
              :visibles="[]"
              :scope="scope"
              :default="defaultV"
              @oper="clickRow"
            />
          </template>

          <!-- <template slot="tableDropdown">
            <el-button type="text" v-rule-code="'threatIntelligenceIp_import'">
              <span @click="dialogVisible=true">
                <i class="el-icon-upload" />导入文件
              </span>
            </el-button>
          </template> -->

          <template slot="tableTools">
            <el-button type="text" v-rule-code="'threatIntelligenceFile_export'">
              <span @click="exportThreatFile">
                <i class="el-icon-download" />导出
              </span>
            </el-button>
            <el-button type="text" v-rule-code="'threatIntelligenceFile_del'">
              <span @click="batchDeleteThreatFile">
                <icon name="trash" />删除
              </span>
            </el-button>
          </template>
        </manager-ui>
      </el-tab-pane>
      <el-tab-pane
        label="漏洞库"
        name="漏洞库"
      >
        <manager-ui
          :query-model="formVul.vulLibraryMap"
          :query-items="queryItemsVul"
          :static-data="staticData"
          :column-items="columnItemsVul"
          :table-data="tableData"
          :pagination="formVul.page"
          :spread-threshold="4"
          show-table-tools
          :show-add-btn="showVulAddBtn()"
          :show-download-btn="showVulDownloadBtn()"
          @allDownload="exportThreatVul()"
          @selection-change="doSelectHandle"
          @search="searchVul"
          @searchClick="formVul.page.current=1;searchVul();batchRows = [];"
          @resetForm="formVul.page.current=1;resetFormVul();batchRows = [];"
          @create="addThreatVul"
        >
          <template #type="{scope}">
            {{ scope.row.type | toCase(staticData.typeList,'dataId', 'dataName') }}
          </template>
          <template #operate="{scope}">
            <el-context-menu
              :menus="menusVul"
              :visibles="[]"
              :scope="scope"
              :default="defaultV"
              @oper="clickRow"
            />
          </template>
          <template slot="tableDropdown">
            <el-button type="text" v-rule-code="'vulLibrary_import'">
              <span @click="dialogVisible=true">
                <i class="el-icon-upload" />导入数据
              </span>
            </el-button>
          </template>
          <template slot="tableTools">
            <el-button type="text" v-rule-code="'vulLibrary_export'">
              <span @click="exportThreatVul">
                <i class="el-icon-download" />导出
              </span>
            </el-button>
            <el-button type="text" v-rule-code="'vulLibrary_del'">
              <span @click="batchDeleteThreatVul">
                <icon name="trash" />删除
              </span>
            </el-button>
          </template>
        </manager-ui>
      </el-tab-pane>
    </el-tabs>
    <!-- IP库弹窗 -->
    <manager-dialog
      :title="dialogTitle()"
      :visible.sync="addnewDialogIp"
      :before-close="closeDialogFormIp"
      :close-on-click-modal="false"
      :icon="dialogIcon()"
    >
      <el-form
        ref="dialogFormIp"
        label-width="120px"
        :model="dialogFormIp"
        :label-position="labelPosition"
        :rules="rules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="IP："
              prop="ip"
              :rules="[ { required: true, message: 'IP不能为空'},{validator:ipCheck,trigger: 'blur'} ]">
              <el-input v-model="dialogFormIp.ip" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="情报来源名称："
              prop="sourceName"
              :rules="[ { required: false, message: '情报来源名称不能为空'}]">
              <el-input v-model="dialogFormIp.sourceName" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="威胁类型："
              prop="type"
              :rules="[ { required: false, message: '威胁类型不能为空'}]">
              <el-select
                v-model="dialogFormIp.type"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.typeList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="威胁级别："
              prop="severity"
              :rules="[ { required: false, message: '威胁级别不能为空'}]">
              <el-input v-model="dialogFormIp.severity" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="置信度："
              prop="confidence"
              :rules="[ { required: false, message: '置信度不能为空'},{validator:validConfidence,trigger: 'blur'}]"
              >
              <el-input v-model="dialogFormIp.confidence" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="国家："
              prop="country"
              :rules="[ { required: false, message: '国家不能为空'}]">
             <el-input v-model="dialogFormIp.country" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="省份："
              prop="province"
              :rules="[ { required: false, message: '省份不能为空'}]">
              <el-input v-model="dialogFormIp.province" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="地市："
              prop="city"
              :rules="[ { required: false, message: '地市不能为空'}]">
             <el-input v-model="dialogFormIp.city" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="纬度："
              prop="lat"
              :rules="[ { required: false, message: '纬度不能为空'}]">
             <el-input v-model="dialogFormIp.lat" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
           <el-col :span="12">
            <el-form-item
              v-show="true"
              label="经度："
              prop="lng"
              :rules="[ { required: false, message: '经度不能为空'}]">
             <el-input v-model="dialogFormIp.lng" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="ASN："
              prop="asn" >
             <el-input v-model="dialogFormIp.asn" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button  v-show="type!=3" @click="resetDialogFormIp">重置</el-button>
        <b v-loading="importLoading" class="importLoading">
          <el-button
            v-show="type==1"
            type="primary"
            @click="submitDialogFormIp"
          >提交</el-button>
        </b>
        <el-button
          v-show="type==2"
          type="primary"
          @click="modifyThreatIp"
        >修改</el-button>
      </span>
    </manager-dialog>

    <!-- 域名库弹窗 -->
    <manager-dialog
      :title="dialogTitle()"
      :visible.sync="addnewDialogRealm"
      :before-close="closeDialogFormRealm"
      :close-on-click-modal="false"
      :icon="dialogIcon()"
    >
      <el-form
        ref="dialogFormRealm"
        label-width="120px"
        :model="dialogFormRealm"
        :label-position="labelPosition"
        :rules="rules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="域名："
              prop="iocName"
              :rules="[ { required: true, message: '域名不能为空'},{validator:nullCheck,trigger: 'blur'}]">
              <el-input v-model="dialogFormRealm.iocName" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="情报来源名称："
              prop="sourceName"
              :rules="[ { required: false, message: '情报来源名称不能为空'}]">
              <el-input v-model="dialogFormRealm.sourceName" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="威胁类型："
              prop="intelType"
              :rules="[ { required: false, message: '威胁类型不能为空'}]">
              <el-select
                v-model="dialogFormRealm.intelType"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.typeList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="威胁级别："
              prop="severity"
              :rules="[ { required: false, message: '威胁级别不能为空'}]">
              <el-input v-model="dialogFormRealm.severity" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="置信度："
              prop="confidence"
              :rules="[ { required: false, message: '置信度不能为空'},{validator:validConfidence,trigger: 'blur'}]"
              >
              <el-input v-model="dialogFormRealm.confidence" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="受感染平台信息："
              prop="platform"
              :rules="[ { required: false, message: '受感染平台信息不能为空'}]">
            <el-input v-model="dialogFormRealm.platform" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="是否为APT："
              prop="APT"
              :rules="[ { required: false, message: '是否为APT不能为空'}]">
              <el-select
                v-model="dialogFormRealm.APT"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.APTList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="是否可解析："
              prop="resolves"
              :rules="[ { required: false, message: '是否可解析不能为空'}]">
              <el-select
                v-model="dialogFormRealm.resolves"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.resolvesList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="通信使用的应用协议："
              prop="application"
              :rules="[ { required: false, message: '通信使用的应用协议不能为空'}]">
            <el-input v-model="dialogFormRealm.application" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="通信连接的具体URI地址："
              prop="uri"
              :rules="[ { required: false, message: '通信连接的具体URI地址不能为空'}]">
            <el-input v-model="dialogFormRealm.uri" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="主机类型："
              prop="levelType"
              :rules="[ { required: false, message: '主机类型不能为空'}]">
              <el-select
                v-model="dialogFormRealm.levelType"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.levelList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="端口："
              prop="port"
              :rules="[ { required: false, message: '端口不能为空'},{validator:portCheck,trigger: 'blur'}]">
            <el-input v-model="dialogFormRealm.port" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button  v-show="type!=3" @click="resetDialogFormRealm">重置</el-button>
        <b v-loading="importLoading" class="importLoading">
          <el-button
            v-show="type==1"
            type="primary"
            @click="submitDialogFormRealm"
          >提交</el-button>
        </b>
        <el-button
          v-show="type==2"
          type="primary"
          @click="modifyThreatRealm"
        >修改</el-button>
      </span>
    </manager-dialog>

    <!-- URL库弹窗 -->
    <manager-dialog
      :title="dialogTitle()"
      :visible.sync="addnewDialogUrl"
      :before-close="closeDialogFormUrl"
      :close-on-click-modal="false"
      :icon="dialogIcon()"
    >
      <el-form
        ref="dialogFormUrl"
        label-width="120px"
        :model="dialogFormUrl"
        :label-position="labelPosition"
        :rules="rules"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="URL："
              prop="iocName"
              :rules="[ { required: true, message: 'URL不能为空'},{validator:nullCheck,trigger: 'blur'}]">
              <el-input v-model="dialogFormUrl.iocName" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="情报来源名称："
              prop="sourceName"
              :rules="[ { required: false, message: '情报来源名称不能为空'}]">
              <el-input v-model="dialogFormUrl.sourceName" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="威胁类型："
              prop="intelType"
              :rules="[ { required: false, message: '威胁类型不能为空'}]">
              <el-select
                v-model="dialogFormUrl.intelType"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.typeList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="威胁级别："
              prop="severity"
              :rules="[ { required: false, message: '威胁级别不能为空'}]">
              <el-input v-model="dialogFormUrl.severity" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="置信度："
              prop="confidence"
              :rules="[ { required: false, message: '置信度不能为空'},{validator:validConfidence,trigger: 'blur'}]"
              >
              <el-input v-model="dialogFormUrl.confidence" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="受感染平台信息："
              prop="platform"
              :rules="[ { required: false, message: '受感染平台信息不能为空'}]">
            <el-input v-model="dialogFormUrl.platform" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="是否为APT："
              prop="APT"
              :rules="[ { required: false, message: '是否为APT不能为空'}]">
              <el-select
                v-model="dialogFormUrl.APT"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.APTList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="是否可解析："
              prop="resolves"
              :rules="[ { required: false, message: '是否可解析不能为空'}]">
              <el-select
                v-model="dialogFormUrl.resolves"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.resolvesList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="通信使用的应用协议："
              prop="application"
              :rules="[ { required: false, message: '通信使用的应用协议不能为空'}]">
            <el-input v-model="dialogFormUrl.application" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="通信连接的具体URI地址："
              prop="uri"
              :rules="[ { required: false, message: '通信连接的具体URI地址不能为空'}]">
            <el-input v-model="dialogFormUrl.uri" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="主机类型："
              prop="levelType"
              :rules="[ { required: false, message: '主机类型不能为空'}]">
              <el-select
                v-model="dialogFormUrl.levelType"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.levelList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="端口："
              prop="port"
              :rules="[ { required: false, message: '端口不能为空'},{validator:portCheck,trigger: 'blur'}]">
            <el-input v-model="dialogFormUrl.port" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button  v-show="type!=3" @click="resetDialogFormUrl">重置</el-button>
        <b v-loading="importLoading" class="importLoading">
          <el-button
            v-show="type==1"
            type="primary"
            @click="submitDialogFormUrl"
          >提交</el-button>
        </b>
        <el-button
          v-show="type==2"
          type="primary"
          @click="modifyThreatUrl"
        >修改</el-button>
      </span>
    </manager-dialog>

    <!-- 文件库弹窗 -->
    <manager-dialog
      :title="dialogTitle()"
      :visible.sync="addnewDialogFile"
      :before-close="closeDialogFormFile"
      :close-on-click-modal="false"
      :icon="dialogIcon()"
    >
      <el-form
        ref="dialogFormFile"
        label-width="120px"
        :model="dialogFormFile"
        :label-position="labelPosition"
        :rules="rules"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="检测文件：" prop="fileName">
              <el-upload ref="fileName" action="" :auto-upload="false" :on-change="uploadChange3" :disabled="type == 3" :file-list="fileList">
                <el-button type="primary" size="mini">上传</el-button>
              </el-upload>
              <span v-show="fileUpload && type == 3"
                      @click="donwloadFile(dialogFormFile.filePath)"
                      style="cursor:pointer;color:#619FEE">{{dialogFormFile.fileName=='null'?'暂未上传文件':dialogFormFile.fileName}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="是否白名单文件："
              prop="isWhite"
              :rules="[ { required: false, message: '是否白名单文件不能为空'}]">
              <el-select
                v-model="dialogFormFile.isWhite"
                placeholder="请选择"
                :disabled="type == 3"
                style="width:100%;">
                <el-option
                  v-for="item in staticData.isWhiteList"
                  :key="item.dataId"
                  :label="item.dataName"
                  :value="item.dataId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="病毒类型："
              prop="malwareType"
              :rules="[ { required: false, message: '病毒类型不能为空'}]">
              <el-input v-model="dialogFormFile.malwareType" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button  v-show="type!=3" @click="resetDialogFormFile">重置</el-button>
        <b v-loading="importLoading" class="importLoading">
          <el-button
            v-show="type==1"
            type="primary"
            @click="submitDialogFormFile"
            v-loading="fileLoading"
          >提交</el-button>
        </b>
        <el-button
          v-show="type==2"
          type="primary"
          @click="modifyThreatFile"
          v-loading="fileLoading"
        >修改</el-button>
      </span>
    </manager-dialog>

    <!-- 漏洞库弹窗 -->
    <manager-dialog
      :title="dialogTitle()"
      :visible.sync="addnewDialogVul"
      :before-close="closeDialogFormVul"
      :close-on-click-modal="false"
      :icon="dialogIcon()"
    >
      <el-form
        ref="dialogFormVul"
        label-width="120px"
        :model="dialogFormVul.vulLibrary"
        :label-position="labelPosition"
        :rules="rules"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item
              v-show="true"
              label="漏洞名称："
              prop="vulName"
              :rules="[ { required: true, message: '漏洞名称不能为空'},{validator:nullCheck,trigger: 'blur'} ]">
              <el-input v-model="dialogFormVul.vulLibrary.vulName" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="危害等级："
              prop="vulLevel"
              :rules="[ { required: false, message: '危害等级不能为空'} ]">
              <el-input v-model="dialogFormVul.vulLibrary.vulLevel" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              v-show="true"
              label="漏洞类型："
              prop="vulType"
              :rules="[ { required: false, message: '漏洞类型不能为空'}]">
              <el-input v-model="dialogFormVul.vulLibrary.vulType" :disabled="type == 3"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="相关链接：" prop="vulUrl">
             <el-input v-model="dialogFormVul.vulLibrary.vulUrl" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="CVE编号：" prop="cveNum">
             <el-input v-model="dialogFormVul.vulLibrary.cveNum" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="CNNVD编号：" prop="cnnvdNum">
             <el-input v-model="dialogFormVul.vulLibrary.cnnvdNum" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item v-show="true" label="公开时间：" prop="pTime">
             <el-input v-model="dialogFormVul.vulLibrary.pTime" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-show="true" label="更新时间：" prop="uTime">
             <el-input v-model="dialogFormVul.vulLibrary.uTime" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item v-show="true" label="威胁类型：" prop="dType">
             <el-input v-model="dialogFormVul.vulLibrary.dType" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item v-show="true" label="厂商：" prop="vulVendor">
             <el-input v-model="dialogFormVul.vulLibrary.vulVendor" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="漏洞简介：" prop="vulProfile">
             <el-input v-model="dialogFormVul.vulLibrary.vulProfile" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="漏洞公告：" prop="vulKnow">
             <el-input v-model="dialogFormVul.vulLibrary.vulKnow" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="参考网址：" prop="vulWebsite">
             <el-input v-model="dialogFormVul.vulLibrary.vulWebsite" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="受影响实体：" prop="affectedEntity">
             <el-input v-model="dialogFormVul.vulLibrary.affectedEntity" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item v-show="true" label="补丁：" prop="vulPatch">
             <el-input v-model="dialogFormVul.vulLibrary.vulPatch" :disabled="type == 3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--操作系统-->
          <el-col :span="24" >
            <el-form-item v-show="true" label="影响程序：">
              <el-row>
                  <el-form :model="dialogFormVul.versionInfo" label-width="5px"  >
                      <el-row  >
                        <el-col :span="21">
                          <el-form-item prop="deviceTypeId">
                            <el-select v-model="dialogFormVul.versionInfo.deviceTypeId" placeholder="程序类型" :disabled="type == 3">
                                <el-option v-for="item in staticData.appInfoType" :key="item.dataId" :label="item.dataName" :value="item.dataId">
                                </el-option>
                            </el-select>
                          </el-form-item>
                        </el-col>
                        <el-col :span="21" >
                          <el-form-item prop="version">
                              <el-input v-model="dialogFormVul.versionInfo.version" placeholder="程序版本，多个用';'隔开。" :disabled="type == 3"></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="21" >
                          <el-form-item prop="versionDesc">
                              <el-input v-model="dialogFormVul.versionInfo.versionDesc" placeholder="版本详情" :disabled="type == 3"></el-input>
                          </el-form-item>
                        </el-col>
                        <el-col :span="1" :offset="1"> <el-button size="small" @click="rightAddBtn()" :disabled="type == 3" type="primary" style="margin-top: 2px;float:right">添加</el-button></el-col>
                      </el-row>
                  </el-form>
                <!-- </el-col> -->
            </el-row>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" >
            <el-form-item label="影响范围：" prop="versionList">
              <el-table :data="dialogFormVul.versionList">
                <el-table-column prop="deviceType" label="设备类型">
                  <template slot-scope="scope">
                    {{scope.row.deviceType |toCase(staticData.appInfoType,'dataId', 'dataName')}}
                  </template>
                </el-table-column>
                <el-table-column prop="versionTag" label="版本"></el-table-column>
                <el-table-column prop="versionDesc" label="版本详情"></el-table-column>
                <el-table-column  width="60" label="操作" >
                  <template slot-scope="scope">
                    <el-button type="text" size="small" :disabled="type == 3"  @click.native.prevent="deleteRow(scope.$index,dialogFormVul.versionList)">删除</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer">
        <el-button  v-show="type!=3" @click="resetDialogFormVul">重置</el-button>
        <b v-loading="importLoading" class="importLoading">
          <el-button
            v-show="type==1"
            type="primary"
            @click="submitDialogFormVul"
          >提交</el-button>
        </b>
        <el-button
          v-show="type==2"
          type="primary"
          @click="modifyThreatVul"
        >修改</el-button>
      </span>
    </manager-dialog>

    <!-- 导入 -->
    <manager-dialog
      :visible.sync="dialogVisible"
      title="导入"
      icon="el-icon-upload"
      @close="closedialog">
      <el-form
        ref="updateForm"
        :model="updateParams">
        <el-form-item label="上传文件：" prop="file">
          <el-upload
            ref="upload" action="" :auto-upload="false" accept=".xlsx,.txt" :on-change="uploadChange">
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
      <p class="downloadTemplate">
        <span @click="downTempTemplate">下载导入文件模板</span>
      </p>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">关闭</el-button>
        <b v-loading="importLoading" class="importLoading">
          <el-button type="primary" @click="uploadFileHandle()">提交</el-button>
        </b>
      </span>
    </manager-dialog>
  </div>
</template>

<script>
import { getThreatIntelligenceIp,addThreatIntelligenceIp,updateThreatIntelligenceIp,deleteThreatIntelligenceIp,exportThreatIntelligenceIp,
  getIPOtherList,getTypeList,templateIpFile,importIpUpfile } from './api/threatIp-result'
import { getThreatIntelligenceRealm,addThreatIntelligenceRealm,updateThreatIntelligenceRealm,deleteThreatIntelligenceRealm,exportThreatIntelligenceRealm,
  templateRealmFile,importRealmUpfile } from './api/threatRealm-result'
import { getThreatIntelligenceUrl,addThreatIntelligenceUrl,updateThreatIntelligenceUrl,deleteThreatIntelligenceUrl,exportThreatIntelligenceUrl,
  templateUrlFile,importUrlUpfile } from './api/threatUrl-result'
import { getThreatIntelligenceFile,addThreatIntelligenceFile,updateThreatIntelligenceFile,deleteThreatIntelligenceFile,exportThreatIntelligenceFile,
  getFileOtherList,templateFileFile,importFileUpfile } from './api/threatFile-result'
import { getThreatIntelligenceVul,addThreatIntelligenceVul,updateThreatIntelligenceVul,deleteThreatIntelligenceVul,exportThreatIntelligenceVul,
  getVulOtherList,templateVulFile,importVulUpfile,getAssetTypeSubByAssetType,getRuleById } from './api/threatVul-result'
import {baseUrl} from '@ability/utils/request'
import { checkRuleCodeExit } from '@ability/directive/rule-code'
import CIDR from "cidr-js";

export default {
  name: 'threatIntelligence',
  components: {

  },
  props: ['_ids'],
  data() {

    return {
      cidr: null,
      loading: false,
      isResetPagination: false,
      tabLabel: 'IP库',
      formIp: {
        threatIntelligenceIpMap: {
          ip: null,
        },
        page: {
          current: 1,
          size: 10,
          total: 0
        }
      },
      formRealm: {
        threatIntelligenceRealmMap: {
          iocName: null,
          iocType: 'domain'
        },
        page: {
          current: 1,
          size: 10,
          total: 0
        }
      },
      formUrl: {
        threatIntelligenceRealmMap: {
          iocName: null,
          iocType: 'url'
        },
        page: {
          current: 1,
          size: 10,
          total: 0
        }
      },
      formFile: {
        threatIntelligenceFileMap: {
          fileName: null,
        },
        page: {
          current: 1,
          size: 10,
          total: 0
        }
      },
      formVul: {
        vulLibraryMap: {
          vulNameLike: null,
          cveNumLike: null
        },
        page: {
          current: 1,
          size: 10,
          total: 0
        }
      },
      // 查询条件
      queryItemsIp: [
        {
          type: 'input',
          span: 12,
          key: 'ip',
          label: 'IP'
        }
      ],
      queryItemsRealm: [
        {
          type: 'input',
          span: 12,
          key: 'iocName',
          label: '域名'
        }
      ],
      queryItemsUrl: [
        {
          type: 'input',
          span: 12,
          key: 'iocName',
          label: 'URL'
        }
      ],
      queryItemsFile: [
        {
          type: 'input',
          span: 12,
          key: 'fileName',
          label: '文件名称'
        }
      ],
      queryItemsVul: [
        {
          type: 'input',
          span: 12,
          key: 'vulNameLike',
          label: '漏洞名称'
        },
        {
          type: 'input',
          span: 12,
          key: 'cveNumLike',
          label: 'CVE编号'
        }
      ],
      tableData: [],
      batchRows: [], // 存取表格批量或单选中行
      dialogVisible: false,
      labelPosition: 'right',
      type: null,
      addnewDialogIp: false,
      addnewDialogRealm: false,
      addnewDialogUrl: false,
      addnewDialogFile: false,
      addnewDialogVul: false,
      importLoading: false,
      dialogFormIp:{
        id: null,
        ip: null,
        sourceName: null,
        type: null,
        severity: null,
        confidence: null,
        country: null,
        province: null,
        city: null,
        lat: null,
        lng: null,
        asn: null
      },
      dialogFormRealm:{
        realmId: null,
        iocName: null,
        sourceName: null,
        intelType: null,
        severity: null,
        confidence: null,
        platform: null,
        APT: null,
        resolves: null,
        application: null,
        uri: null,
        levelType: null,
        port: null
      },
      dialogFormUrl:{
        realmId: null,
        iocName: null,
        sourceName: null,
        intelType: null,
        severity: null,
        confidence: null,
        platform: null,
        APT: null,
        resolves: null,
        application: null,
        uri: null,
        levelType: null,
        port: null
      },
      dialogFormVul:{
        vulLibrary:{
          itemId:null,
          vulLevel:"",
          vulType :"",
          vulUrl:"",
          cveNum:"",
          cnnvdNum:"",
          pTime:"",
          dTime:"",
          dType:"",
          vulVendor:"",
          vulProfile:"",
          vulKnow:"",
          vulWebsite:"",
          affectedEntity:"",
          vulPatch:"",
          isManul:""
        },
        versionInfo:{
          deviceTypeId:null,
          version:"",
          versionDesc:"",
        },
        versionList:[]
      },
      dialogFormFile:{
        filePath: null,
        fileName: null,
        isWhite: null,
        malwareType: null,
      },
      fileLoading: false,
      fileUpload: false,
      fileList: [],
      updateParams: {
        'file': null
      },
      rules: {
        updateParams: {
          file: [
            { validator: this.validateFile }
          ]
        },
        fileName:[{validator:this.validateFile3}]
      },
      menusIp: [
        {
          text: '查看',
          command: 'detail',
          icon: 'el-icon-s-order'
        }, {
          text: '修改',
          command: 'modify',
          icon: 'el-icon-edit',
          ruleCode: 'threatIntelligenceIp_upd'
        }, {
          text: '删除',
          command: 'del',
          icon: 'el-icon-delete',
          iconColor: 'red',
          ruleCode: 'threatIntelligenceIp_del'
        }
      ],
      menusRealm: [
        {
          text: '查看',
          command: 'detail',
          icon: 'el-icon-s-order'
        }, {
          text: '修改',
          command: 'modify',
          icon: 'el-icon-edit',
          ruleCode: 'threatIntelligenceRealm_upd'
        }, {
          text: '删除',
          command: 'del',
          icon: 'el-icon-delete',
          iconColor: 'red',
          ruleCode: 'threatIntelligenceRealm_del'
        }
      ],
      menusUrl: [
        {
          text: '查看',
          command: 'detail',
          icon: 'el-icon-s-order'
        }, {
          text: '修改',
          command: 'modify',
          icon: 'el-icon-edit',
          ruleCode: 'threatIntelligenceUrl_upd'
        }, {
          text: '删除',
          command: 'del',
          icon: 'el-icon-delete',
          iconColor: 'red',
          ruleCode: 'threatIntelligenceUrl_del'
        }
      ],
      menusFile: [
        {
          text: '查看',
          command: 'detail',
          icon: 'el-icon-s-order'
        }, {
          text: '修改',
          command: 'modify',
          icon: 'el-icon-edit',
          ruleCode: 'threatIntelligenceFile_upd'
        }, {
          text: '删除',
          command: 'del',
          icon: 'el-icon-delete',
          iconColor: 'red',
          ruleCode: 'threatIntelligenceFile_del'
        }
      ],
      menusVul: [
        {
          text: '查看',
          command: 'detail',
          icon: 'el-icon-s-order'
        }, {
          text: '修改',
          command: 'modify',
          icon: 'el-icon-edit',
          ruleCode: 'vulLibrary_upd'
        }, {
          text: '删除',
          command: 'del',
          icon: 'el-icon-delete',
          iconColor: 'red',
          ruleCode: 'vulLibrary_del'
        }
      ],
      defaultV: 3,
      staticData: {
        typeList:[],
        APTList:[
          {"dataId":"1","dataName":"是"},
          {"dataId":"0","dataName":"否"}
        ],
        resolvesList:[
          {"dataId":"1","dataName":"是"},
          {"dataId":"0","dataName":"否"}
        ],
        levelList:[
          {"dataId":0,"dataName":"防弹主机"},
          {"dataId":1,"dataName":"hacked 主机"},
          {"dataId":2,"dataName":"主机服务"},
          {"dataId":3,"dataName":"FastFlux"},
          {"dataId":4,"dataName":"未知"}
        ],
        isWhiteList:[
          {"dataId":"1","dataName":"是"},
          {"dataId":"0","dataName":"否"}
        ],
        appInfoType:[]
      },
      columnItemsIp: [
        {
          _key: 'selection',
          type: 'selection',
          width: 50
        },
        {
          _key: 'ip',
          prop: 'ip',
          label: 'IP',
          showOverflowTooltip: true
        },
        {
          _key: 'sourceName',
          prop: 'sourceName',
          label: '情报来源名称',
          showOverflowTooltip: true
        },
        {
          _key: 'type',
          prop: 'type',
          label: '威胁类型',
          showOverflowTooltip: true,
          render: true
        },
        {
          _key: 'severity',
          prop: 'severity',
          label: '威胁级别',
          showOverflowTooltip: true
        },
        {
          _key: 'confidence',
          prop: 'confidence',
          label: '置信度',
          showOverflowTooltip: true
        },
        {
          _key: 'createTime',
          prop: 'createTime',
          label: '情报源添加时间',
          width: 150,
          showOverflowTooltip: true
        },
        {
          _key: 'operate',
          prop: 'operate',
          label: '操作',
          render: true,
          width: 100
        }
      ],
      columnItemsRealm: [
        {
          _key: 'selection',
          type: 'selection',
          width: 50
        },
        {
          _key: 'iocName',
          prop: 'iocName',
          label: '域名',
          showOverflowTooltip: true
        },
        {
          _key: 'sourceName',
          prop: 'sourceName',
          label: '情报来源名称',
          showOverflowTooltip: true
        },
        {
          _key: 'intelType',
          prop: 'intelType',
          label: '威胁类型',
          render: true,
          showOverflowTooltip: true,
        },
        {
          _key: 'severity',
          prop: 'severity',
          label: '威胁级别',
          showOverflowTooltip: true
        },
        {
          _key: 'confidence',
          prop: 'confidence',
          label: '置信度',
          showOverflowTooltip: true
        },
        {
          _key: 'createTime',
          prop: 'createTime',
          label: '情报源添加时间',
          width: 150,
          showOverflowTooltip: true
        },
        {
          _key: 'operate',
          prop: 'operate',
          label: '操作',
          render: true,
          width: 100
        }
      ],
      columnItemsUrl: [
        {
          _key: 'selection',
          type: 'selection',
          width: 50
        },
        {
          _key: 'iocName',
          prop: 'iocName',
          label: 'URL',
          showOverflowTooltip: true
        },
        {
          _key: 'sourceName',
          prop: 'sourceName',
          label: '情报来源名称',
          showOverflowTooltip: true
        },
        {
          _key: 'intelType',
          prop: 'intelType',
          label: '威胁类型',
          render: true,
          showOverflowTooltip: true,
        },
        {
          _key: 'severity',
          prop: 'severity',
          label: '威胁级别',
          showOverflowTooltip: true
        },
        {
          _key: 'confidence',
          prop: 'confidence',
          label: '置信度',
          showOverflowTooltip: true
        },
        {
          _key: 'createTime',
          prop: 'createTime',
          label: '情报源添加时间',
          width: 150,
          showOverflowTooltip: true
        },
        {
          _key: 'operate',
          prop: 'operate',
          label: '操作',
          render: true,
          width: 100
        }
      ],
      columnItemsFile: [
        {
          _key: 'selection',
          type: 'selection',
          width: 50
        },
        {
          _key: 'fileName',
          prop: 'fileName',
          label: '文件名称',
          showOverflowTooltip: true
        },
        {
          _key: 'fileValue',
          prop: 'fileValue',
          label: 'SHA256',
          showOverflowTooltip: true
        },
        {
          _key: 'isWhite',
          prop: 'isWhite',
          label: '是否白名单文件',
          render: true,
          showOverflowTooltip: true,
        },
        {
          _key: 'malwareType',
          prop: 'malwareType',
          label: '病毒类型',
          showOverflowTooltip: true
        },
        {
          _key: 'scanDate',
          prop: 'scanDate',
          label: '最近扫描时间',
          width: 150,
          showOverflowTooltip: true
        },
        {
          _key: 'operate',
          prop: 'operate',
          label: '操作',
          render: true,
          width: 100
        }
      ],
      columnItemsVul: [
        {
          _key: 'selection',
          type: 'selection',
          width: 50
        },
        {
          _key: 'vulName',
          prop: 'vulName',
          label: '漏洞名称',
          showOverflowTooltip: true
        },
        {
          _key: 'vulLevel',
          prop: 'vulLevel',
          label: '危害等级',
          showOverflowTooltip: true
        },
        {
          _key: 'vulUrl',
          prop: 'vulUrl',
          label: '相关链接',
          showOverflowTooltip: true,
        },
        {
          _key: 'cnnvdNum',
          prop: 'cnnvdNum',
          label: 'CNNVD编号',
          showOverflowTooltip: true
        },
        {
          _key: 'cveNum',
          prop: 'cveNum',
          label: 'CVE编号',
          showOverflowTooltip: true,
        },
        {
          _key: 'vulType',
          prop: 'vulType',
          label: '漏洞类型',
          showOverflowTooltip: true
        },
        {
          _key: 'pTime',
          prop: 'pTime',
          label: '公开时间',
          showOverflowTooltip: true,
        },
        {
          _key: 'dType',
          prop: 'dType',
          label: '威胁类型',
          showOverflowTooltip: true
        },
        {
          _key: 'uTime',
          prop: 'uTime',
          label: '更新时间',
          width: 150,
          showOverflowTooltip: true
        },
        {
          _key: 'operate',
          prop: 'operate',
          label: '操作',
          render: true,
          width: 100
        }
      ],
    }
  },
  computed: {

  },
  watch: {

  },
  created: function() {
    this.cidr = new CIDR();
    this.getassetSmallType(4);
    this.getTypeList();
    this.tabClick();
  },
  mounted() {

  },
  methods: {
    tabClick() {
      if (this.tabLabel == 'IP库') {
        this.searchIp();
      } else if (this.tabLabel == '域名库'){
        this.searchRealm();
      } else if (this.tabLabel == 'URL库'){
        this.searchUrl();
      } else if (this.tabLabel == '文件库'){
        this.searchFile();
      } else if (this.tabLabel == '漏洞库'){
        this.searchVul();
      }
    },
    ipCheck: function (rule, value, callback){
      if (value) {
        let isRightIp = true;
        if (value.indexOf("/") != -1) {
          console.log("/");

          var results = this.cidr.range(value);
          console.log(results);

          if (results == null || results.start == "0.0.0.0") {
            isRightIp = false;
          }
        } else if (value.indexOf("-") != -1) {
          var ips = value.split("-");
          ips[1] = ips[1]*1;
          let lastnum = ips[0].split(".");
          lastnum = lastnum[lastnum.length-1];
          if(!this.isIp(ips[0]) || ips[1] == NaN || ips[1]>255 || ips[1]<0 || ips[1] < lastnum){
            isRightIp = false;
          }
        } else {
          if (!this.isIp(value)) {
            isRightIp = false;
          }
        }
        if (!isRightIp) {
          callback(new Error('IP地址/IP段格式错误'));
        }else {
          callback();
        }
      }else {
        callback(new Error('IP地址/IP段不能为空'));
      }
    },
    isIp: function (value) {
      if (!value) {
        // callback(new Error("IP地址不能为空"));
        callback();
      } else {
        var regIpv4 = /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
        var regIpv6 = /^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$/;
        if (!regIpv4.test(value) && !regIpv6.test(value)) {
          return false;
          // callback(new Error('IP地址/IP段格式错误'));
        } else {
          return true;

        }
      }
    },
    nullCheck: function (rule, value, callback) {
      if(value.split(" ").join("").length == 0){
        callback("不能全为空格");
      }else{
        callback();
      }
    },

    validConfidence:function(rule, value, callback){
      if (value) {
        var reg = /^[0-9]*$/
        if (reg.test(value) === false) {
          return callback(new Error('置信度必须为数字'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    },
    validateFile: function(rule, value, callback) {
      if (!this.$refs.upload.uploadFiles.length) {
        callback(new Error('请选择要上传的文件'))
        // } else if (this.$refs.upload.uploadFiles.length > 1) {
        //   callback(new Error('每次上传只支持一个文件'));
      } else {
        var regx = new RegExp('(.xlsx)$')
        if (!regx.test(this.$refs.upload.uploadFiles[0].name)) {
          callback(new Error('文件格式只支持xlsx'))
        }
        callback()
      }
    },
    portCheck: function (rule, value, callback) {
      if (!value) {
        callback();
      }
      var reg = /^([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{4}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
      if (!reg.test(value)) {
        callback("端口格式错误");
      } else {
        callback();
      }
    },
    uploadChange3:function(file,filelist){
      if(filelist.length && filelist.length >=1 ){
        this.$refs.dialogFormFile.validateField('fileName');
      }
      if(filelist.length>1){
        filelist.splice(0,1);
      }
      this.$refs.fileName.$el.children[0].children[1].value = "";
    },
    validateFile3: function (rule, value, callback) {
      if (!this.$refs.fileName.uploadFiles.length) {
        callback(new Error('请选择要上传的文件'));
      } else {
        callback();
      }
    },
    showIpAddBtn() {
      return checkRuleCodeExit('threatIntelligenceIp_add')
    },
    showIpDownloadBtn(){
      return checkRuleCodeExit('threatIntelligenceIp_export')
    },
    showRealmAddBtn() {
      return checkRuleCodeExit('threatIntelligenceRealm_add')
    },
    showRealmDownloadBtn(){
      return checkRuleCodeExit('threatIntelligenceRealm_export')
    },
    showUrlAddBtn() {
      return checkRuleCodeExit('threatIntelligenceUrl_add')
    },
    showUrlDownloadBtn(){
      return checkRuleCodeExit('threatIntelligenceUrl_export')
    },
    showFileAddBtn() {
      return checkRuleCodeExit('threatIntelligenceFile_add')
    },
    showFileDownloadBtn(){
      return checkRuleCodeExit('threatIntelligenceFile_export')
    },
    showVulAddBtn() {
      return checkRuleCodeExit('vulLibrary_add')
    },
    showVulDownloadBtn(){
      return checkRuleCodeExit('vulLibrary_export')
    },
    clickRow(command, scope, index, rows) {
      if (command === 'detail') {
        this.type = 3;
        if (this.tabLabel == 'IP库') {
          this.addnewDialogIp = true;
          //this.getdetailIp(scope.row.id);
          this.backIpData(scope.row);
        }else if (this.tabLabel == '域名库'){
          this.addnewDialogRealm = true;
          this.backRealmData(scope.row);
        }else if (this.tabLabel == 'URL库'){
          this.addnewDialogUrl = true;
          this.backUrlData(scope.row);
        }else if (this.tabLabel == '文件库'){
          this.fileUpload = true;
          this.addnewDialogFile = true;
          this.backFileData(scope.row);
        }else if (this.tabLabel == '漏洞库'){
          this.addnewDialogVul = true;
          this.backVulData(scope.row);
        }
      }else if(command === 'modify'){
        this.type = 2;
        if (this.tabLabel == 'IP库') {
          this.dialogFormIp.id = scope.row.id;
          this.addnewDialogIp = true;
          //this.getdetailIp(scope.row.id);
          this.backIpData(scope.row);
        }else if (this.tabLabel == '域名库'){
          this.addnewDialogRealm = true;
          this.backRealmData(scope.row);
        }else if (this.tabLabel == 'URL库'){
          this.addnewDialogUrl = true;
          this.backUrlData(scope.row);
        }else if (this.tabLabel == '文件库'){
          this.fileUpload = true;
          this.fileList = [];
          let file = {
            url: scope.row.filePath,
            name: scope.row.fileName
          }
          this.fileList.push(file);
          this.addnewDialogFile = true;
          this.backFileData(scope.row);
        }else if (this.tabLabel == '漏洞库'){
          this.addnewDialogVul = true;
          this.backVulData(scope.row);
        }
      }else if(command === 'del'){
        var arr = []
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (this.tabLabel == 'IP库') {
            arr.push(scope.row.id)
            this.deleteThreatIp(arr)
          }else if (this.tabLabel == '域名库'){
            arr.push(scope.row.realmId)
            this.deleteThreatRealm(arr)
          }else if (this.tabLabel == 'URL库'){
            arr.push(scope.row.realmId)
            this.deleteThreatUrl(arr)
          }else if (this.tabLabel == '文件库'){
            arr.push(scope.row.id)
            this.deleteThreatFile(arr)
          }else if (this.tabLabel == '漏洞库'){
            arr.push(scope.row.itemId)
            this.deleteThreatVul(arr)
          }
        }).catch(() => { })
      }
    },
    backIpData(row){
      this.dialogFormIp.ip = row.ip;
      this.dialogFormIp.sourceName = row.sourceName;
      this.dialogFormIp.type = row.type;
      this.dialogFormIp.severity = row.severity;
      this.dialogFormIp.confidence = row.confidence;
      //调整原先从id查询接口获取数据为列表查询接口中获取
      this.dialogFormIp.country = row.COUNTRY;
      this.dialogFormIp.province = row.PROVINCE;
      this.dialogFormIp.city = row.CITY;
      this.dialogFormIp.lat = row.LAT;
      this.dialogFormIp.lng = row.LNG;
      this.dialogFormIp.asn = row.ASN;
    },
    backRealmData(row){
      this.dialogFormRealm = JSON.parse(JSON.stringify(row))
    },
    backUrlData(row){
      this.dialogFormUrl = JSON.parse(JSON.stringify(row))
    },
    backFileData(row){
      this.dialogFormFile = JSON.parse(JSON.stringify(row))
    },
    backVulData(row){
      var oRow = JSON.parse(JSON.stringify(row));
      this.dialogFormVul.vulLibrary = oRow
      this.getVersionList(oRow);
    },
    dialogTitle() {
      return this.type == 1 ? '新增'
        : this.type == 2 ? '修改'
          : this.type == 3 ? '查看'
            : ''
    },
    dialogIcon() {
      return this.type == 1 ? 'el-icon-document-add'
        : this.type == 2 ? 'el-icon-edit'
          : this.type == 3 ? 'el-icon-s-order'
            : ''
    },
    searchIp() {
      const self = this
      self.loading = true
      const temp = JSON.parse(JSON.stringify(self.formIp))
      getThreatIntelligenceIp(temp)
        .then(response => {
          if (response.data.returnCode == '0') {
            self.tableData = response.data.data.list
            self.formIp.page.total = response.data.data.page.total;
            // this.dataTotal = response.data.data.page.total
            // this.currentPageIndex = response.data.data.page.current
          } else {
            self.$message.error(response.data.returnMsg)
          }
          self.loading = false
        })
        .catch(error => {
          if (error.response) {
            self.$message.error(error.response.data.detail)
          }
          self.loading = false
        })
    },
    searchRealm() {
      const self = this
      self.loading = true
      self.formRealm.threatIntelligenceRealmMap.iocType = 'domain';
      const temp = JSON.parse(JSON.stringify(self.formRealm))
      getThreatIntelligenceRealm(temp)
        .then(response => {
          if (response.data.returnCode == '0') {
            self.tableData = response.data.data.list
            self.formRealm.page.total = response.data.data.page.total;
          } else {
            self.$message.error(response.data.returnMsg)
          }
          self.loading = false
        })
        .catch(error => {
          if (error.response) {
            self.$message.error(error.response.data.detail)
          }
          self.loading = false
        })
    },
    searchUrl() {
      const self = this
      self.loading = true
      self.formUrl.threatIntelligenceRealmMap.iocType = 'url';
      const temp = JSON.parse(JSON.stringify(self.formUrl))
      getThreatIntelligenceUrl(temp)
        .then(response => {
          if (response.data.returnCode == '0') {
            self.tableData = response.data.data.list
            self.formUrl.page.total = response.data.data.page.total;
          } else {
            self.$message.error(response.data.returnMsg)
          }
          self.loading = false
        })
        .catch(error => {
          if (error.response) {
            self.$message.error(error.response.data.detail)
          }
          self.loading = false
        })
    },
    searchFile() {
      const self = this
      self.loading = true
      const temp = JSON.parse(JSON.stringify(self.formFile))
      getThreatIntelligenceFile(temp)
        .then(response => {
          if (response.data.returnCode == '0') {
            self.tableData = response.data.data.list
            self.formFile.page.total = response.data.data.page.total;
          } else {
            self.$message.error(response.data.returnMsg)
          }
          self.loading = false
        })
        .catch(error => {
          if (error.response) {
            self.$message.error(error.response.data.detail)
          }
          self.loading = false
        })
    },
    searchVul() {
      const self = this
      self.loading = true
      const temp = JSON.parse(JSON.stringify(self.formVul))
      getThreatIntelligenceVul(temp)
        .then(response => {
          if (response.data.returnCode == '0') {
            self.tableData = response.data.data.list
            self.formVul.page.total = response.data.data.page.total;
          } else {
            self.$message.error(response.data.returnMsg)
          }
          self.loading = false
        })
        .catch(error => {
          if (error.response) {
            self.$message.error(error.response.data.detail)
          }
          self.loading = false
        })
    },
    resetFormIp() {
      this.formIp.threatIntelligenceIpMap.ip = null,
      this.searchIp()
    },
    resetFormRealm() {
      this.formRealm.threatIntelligenceRealmMap.iocName = null,
      this.formRealm.threatIntelligenceRealmMap.iocType = "domain",
      this.searchRealm()
    },
    resetFormRealm() {
      this.formUrl.threatIntelligenceRealmMap.iocName = null,
      this.formUrl.threatIntelligenceRealmMap.iocType = "url",
      this.searchRealm()
    },
    resetFormFile() {
      this.formFile.threatIntelligenceFileMap.fileName = null,
      this.searchFile()
    },
    resetFormVul() {
      this.formVul.vulLibraryMap.vulNameLike = null,
      this.formVul.vulLibraryMap.cveNumLike = null,
      this.searchVul()
    },
    downTempTemplate: function() {
      if (this.tabLabel == 'IP库') {
        this.downIpTemplate()
      }else if (this.tabLabel == '域名库'){
        this.downRealmTemplate()
      }else if (this.tabLabel == 'URL库'){
        this.downUrlTemplate()
      }else if (this.tabLabel == '漏洞库'){
        this.downVulTemplate()
      }
    },
    downIpTemplate: function() {
      this.$message.info('正在生成导入模版,请稍等')
      templateIpFile().then((resp) => {
        if (resp.data.returnCode == '0') {
          window.location.href = baseUrl + '/analyze/' + resp.data.data.url
        }
      }, (error) => {
        this.$message.error(error.message)
      })
    },
    downRealmTemplate: function() {
      this.$message.info('正在生成导入模版,请稍等')
      templateRealmFile().then((resp) => {
        if (resp.data.returnCode == '0') {
          window.location.href = baseUrl + '/analyze/' + resp.data.data.url
        }
      }, (error) => {
        this.$message.error(error.message)
      })
    },
    downUrlTemplate: function() {
      this.$message.info('正在生成导入模版,请稍等')
      templateUrlFile().then((resp) => {
        if (resp.data.returnCode == '0') {
          window.location.href = baseUrl + '/analyze/' + resp.data.data.url
        }
      }, (error) => {
        this.$message.error(error.message)
      })
    },
    downVulTemplate: function() {
      this.$message.info('正在生成导入模版,请稍等')
      templateVulFile().then((resp) => {
        if (resp.data.returnCode == '0') {
          window.location.href = baseUrl + '/analyze/' + resp.data.data.url
        }
      }, (error) => {
        this.$message.error(error.message)
      })
    },
    uploadChange: function(file, filelist) {
      if (filelist.length > 1) {
        filelist.splice(0, 1)
      }
      this.$refs.upload.$el.children[0].children[1].value = ''
    },

    doSelectHandle: function(selection, row) {
      this.batchRows = selection
    },
    addThreatIp() {
      this.type = 1
      this.addnewDialogIp = true
    },
    addThreatRealm(){
      this.type = 1
      this.addnewDialogRealm = true
    },
    addThreatUrl(){
      this.type = 1
      this.addnewDialogUrl = true
    },
    addThreatFile(){
      this.type = 1
      this.addnewDialogFile = true
    },
    addThreatVul(){
      this.type = 1
      this.addnewDialogVul = true
    },
    submitDialogFormIp() { // IP新增提交
      this.$refs['dialogFormIp'].validate((valid) => {
        if (valid) {
          var form = JSON.parse(JSON.stringify(this.dialogFormIp));
          var param = {threatIntelligenceIp:form};
          addThreatIntelligenceIp(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('新增成功')
              this.$refs.dialogFormIp.resetFields();
              this.addnewDialogIp = false
              this.searchIp()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogIp = false
          })
        } else {
          return false
        }
      })
    },
    submitDialogFormRealm() { // 域名库新增提交
      this.$refs['dialogFormRealm'].validate((valid) => {
        if (valid) {
          this.dialogFormRealm.iocType = 'domain';
          var form = JSON.parse(JSON.stringify(this.dialogFormRealm));
          var param = {threatIntelligenceRealm:form};
          addThreatIntelligenceRealm(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('新增成功')
              this.$refs.dialogFormRealm.resetFields()
              this.addnewDialogRealm = false
              this.searchRealm()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogRealm = false
          })
        } else {
          return false
        }
      })
    },
    submitDialogFormUrl() { // URL库新增提交
      this.$refs['dialogFormUrl'].validate((valid) => {
        if (valid) {
          this.dialogFormUrl.iocType = 'url';
          var form = JSON.parse(JSON.stringify(this.dialogFormUrl));
          var param = {threatIntelligenceRealm:form};
          addThreatIntelligenceUrl(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('新增成功')
              this.$refs.dialogFormUrl.resetFields()
              this.addnewDialogUrl = false
              this.searchUrl()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogUrl = false
          })
        } else {
          return false
        }
      })
    },
    submitDialogFormFile() { // 文件库新增提交
      this.fileLoading = true;
      this.$refs['dialogFormFile'].validate((valid) => {
        if (valid) {
          var formData = new FormData();
          formData.append("file",this.$refs.fileName.uploadFiles[0].raw);
          this.dialogFormFile.fileName = this.$refs.fileName.uploadFiles[0].name;
          // var param = JSON.parse(JSON.stringify(this.dialogFormFile));
          let jsonStr = JSON.stringify(this.dialogFormFile)
          formData.append("param", jsonStr);
          addThreatIntelligenceFile(formData).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('新增成功')
              this.$refs.dialogFormFile.resetFields()
              this.addnewDialogFile = false
              this.searchFile()
              this.fileList = []
              this.dialogFormFile={
                filePath: null,
                fileName: null,
                isWhite: null,
                malwareType: null,
              }
            }
            this.fileLoading = false;
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogFile = false
            this.fileLoading = false;
          })
        } else {
          return false
        }
      })
    },
    submitDialogFormVul() { // 漏洞库新增提交
      this.$refs['dialogFormVul'].validate((valid) => {
        if (valid) {
          var param = JSON.parse(JSON.stringify(this.dialogFormVul));
          addThreatIntelligenceVul(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('新增成功')
             this.$refs.dialogFormVul.resetFields()
              this.addnewDialogVul = false
              this.searchVul()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogVul = false
          })
        } else {
          return false
        }
      })
    },
    modifyThreatIp() {
      this.$refs['dialogFormIp'].validate((valid) => {
        if (valid) {
          var form = JSON.parse(JSON.stringify(this.dialogFormIp));
          var param = {threatIntelligenceIp:form};
          updateThreatIntelligenceIp(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('修改成功')
              this.addnewDialogIp = false
              this.searchIp()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogIp = false
          })
        } else {
          return false
        }
      })
    },
    modifyThreatRealm() {
      this.$refs['dialogFormRealm'].validate((valid) => {
        if (valid) {
          var form = JSON.parse(JSON.stringify(this.dialogFormRealm));
          var param = {threatIntelligenceRealm:form};
          updateThreatIntelligenceRealm(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('修改成功')
              this.addnewDialogRealm = false
              this.searchRealm()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogRealm = false
          })
        } else {
          return false
        }
      })
    },
    modifyThreatUrl() {
      this.$refs['dialogFormUrl'].validate((valid) => {
        if (valid) {
          var form = JSON.parse(JSON.stringify(this.dialogFormUrl));
          var param = {threatIntelligenceRealm:form};
          updateThreatIntelligenceUrl(param).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('修改成功')
              this.addnewDialogUrl = false
              this.searchUrl()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogUrl = false
          })
        } else {
          return false
        }
      })
    },
    modifyThreatFile() {
      this.fileLoading = true;
      this.$refs['dialogFormFile'].validate((valid) => {
        if (valid) {
          var formData = new FormData();
          formData.append("file",this.$refs.fileName.uploadFiles[0].raw);
          this.dialogFormFile.fileName = this.$refs.fileName.uploadFiles[0].name;
          let jsonStr = JSON.stringify(this.dialogFormFile)
          formData.append("param", jsonStr);
          // this.dialogFormFile.fileName = this.$refs.fileName.uploadFiles[0].name;
          // var form = JSON.parse(JSON.stringify(this.dialogFormFile));
          // var param = {threatIntelligenceFile:form};
          updateThreatIntelligenceFile(formData).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('修改成功')
              this.addnewDialogFile = false
              this.searchFile()
              this.fileList = []
              this.dialogFormFile={
                filePath: null,
                fileName: null,
                isWhite: null,
                malwareType: null,
              }
            }
            this.fileLoading = false;
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogFile = false
            this.fileLoading = false;
          })
        } else {
          return false
        }
      })
    },
    modifyThreatVul() {
      this.$refs['dialogFormVul'].validate((valid) => {
        if (valid) {
          var form = JSON.parse(JSON.stringify(this.dialogFormVul));
          updateThreatIntelligenceVul(form).then(resp => {
            if (resp.data.returnCode == '0') {
              this.$message.success('修改成功')
              this.addnewDialogVul = false
              this.searchVul()
            }
          }).catch(error => {
            this.$message.error(error.message)
            this.addnewDialogVul = false
          })
        } else {
          return false
        }
      })
    },
    closeDialogFormIp(){
      this.resetDialogFormIp();
      this.addnewDialogIp = false;
    },
    closeDialogFormRealm(){
      this.resetDialogFormRealm();
      this.addnewDialogRealm = false;
    },
    closeDialogFormUrl(){
      this.resetDialogFormUrl();
      this.addnewDialogUrl = false;
    },
    closeDialogFormFile(){
      this.fileList = [];
      this.resetDialogFormFile();
      this.fileUpload = false;
      this.addnewDialogFile = false;
    },
    closeDialogFormVul(){
      this.resetDialogFormVul();
      this.addnewDialogVul = false;
    },
    resetDialogFormIp(){
      this.$refs.dialogFormIp.resetFields()
      this.dialogFormIp={
        id: null,
        ip: null,
        sourceName: null,
        type: null,
        severity: null,
        confidence: null,
        country: null,
        province: null,
        city: null,
        lat: null,
        lng: null,
        asn: null
      }
    },
    resetDialogFormRealm(){
      this.$refs.dialogFormRealm.resetFields()
      this.dialogFormRealm={
        realmId: null,
        iocName: null,
        sourceName: null,
        intelType: null,
        severity: null,
        confidence: null,
        platform: null,
        APT: null,
        resolves: null,
        application: null,
        uri: null,
        levelType: null,
        port: null
      }
    },
    resetDialogFormUrl(){
      this.$refs.dialogFormUrl.resetFields()
      this.dialogFormUrl={
        realmId: null,
        iocName: null,
        sourceName: null,
        intelType: null,
        severity: null,
        confidence: null,
        platform: null,
        APT: null,
        resolves: null,
        application: null,
        uri: null,
        levelType: null,
        port: null
      }
    },
    resetDialogFormFile(){
      this.$refs.dialogFormFile.resetFields()
      this.dialogFormFile={
        filePath: null,
        fileName: null,
        isWhite: null,
        malwareType: null,
      }
    },
    resetDialogFormVul(){
      this.$refs.dialogFormVul.resetFields()
      this.dialogFormVul={
        vulLibrary:{
          itemId:null,
          vulLevel:"",
          vulType :"",
          vulUrl:"",
          cveNum:"",
          cnnvdNum:"",
          pTime:"",
          dTime:"",
          dType:"",
          vulVendor:"",
          vulProfile:"",
          vulKnow:"",
          vulWebsite:"",
          affectedEntity:"",
          vulPatch:"",
          isManul:""
        },
        versionInfo:{
          deviceTypeId:null,
          version:"",
          versionDesc:"",
        },
        versionList:[]
      }
    },
    exportThreatIp: function() {
      var ids = this.batchRows.map(function(item) {
        return item.id
      })
      var params = {}
      params = JSON.parse(JSON.stringify(this.formIp))
      params.ids = ids
      exportThreatIntelligenceIp(params).then((resp) => {
        if (resp.data.returnCode == '0') {
          this.$store.dispatch('user/beginRefresh')
          this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
        }
      }, (error) => {
        console.log(error)
      })
    },
    exportThreatRealm: function() {
      var ids = this.batchRows.map(function(item) {
        return item.realmId
      })
      var params = {}
      params = JSON.parse(JSON.stringify(this.formRealm))
      params.ids = ids
      exportThreatIntelligenceRealm(params).then((resp) => {
        if (resp.data.returnCode == '0') {
          this.$store.dispatch('user/beginRefresh')
          this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
        }
      }, (error) => {
        console.log(error)
      })
    },
    exportThreatUrl: function() {
      var ids = this.batchRows.map(function(item) {
        return item.realmId
      })
      var params = {}
      params = JSON.parse(JSON.stringify(this.formUrl))
      params.ids = ids
      exportThreatIntelligenceUrl(params).then((resp) => {
        if (resp.data.returnCode == '0') {
          this.$store.dispatch('user/beginRefresh')
          this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
        }
      }, (error) => {
        console.log(error)
      })
    },
    exportThreatFile: function() {
      var ids = this.batchRows.map(function(item) {
        return item.id
      })
      var params = {}
      params = JSON.parse(JSON.stringify(this.formFile))
      params.ids = ids
      exportThreatIntelligenceFile(params).then((resp) => {
        if (resp.data.returnCode == '0') {
          this.$store.dispatch('user/beginRefresh')
          this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
        }
      }, (error) => {
        console.log(error)
      })
    },
    exportThreatVul: function() {
      var ids = this.batchRows.map(function(item) {
        return item.itemId
      })
      var params = {}
      params = JSON.parse(JSON.stringify(this.formVul))
      params.ids = ids
      exportThreatIntelligenceVul(params).then((resp) => {
        if (resp.data.returnCode == '0') {
          this.$store.dispatch('user/beginRefresh')
          this.$message.success('已加入离线任务队列，请在离线任务栏进行查看')
        }
      }, (error) => {
        console.log(error)
      })
    },
    uploadFileHandle: function() {
      this.$refs['updateForm'].validate((valid) => {
        if (valid) {
          var formData = new FormData()
          formData.append('file', this.$refs.upload.uploadFiles[0].raw)
          this.importLoading = true
          if (this.tabLabel == 'IP库') {
            importIpUpfile(formData).then((rsp) => {
              if (rsp.data.returnCode == 0) {
                this.$message.success("已加入离线任务队列，请在离线任务栏进行查看")
                this.dialogVisible = false
                this.searchIp()
              }
              this.importLoading = false
            }, (error) => {
              this.importLoading = false
              this.$message.error(error.message)
            })
          } else if (this.tabLabel == '域名库'){
            formData.append("type", "domain");
            importRealmUpfile(formData).then((rsp) => {
              if (rsp.data.returnCode == 0) {
                this.$message.success("已加入离线任务队列，请在离线任务栏进行查看")
                this.dialogVisible = false
                this.searchRealm()
              }
              this.importLoading = false
            }, (error) => {
              this.importLoading = false
              this.$message.error(error.message)
            })
          } else if (this.tabLabel == 'URL库'){
            formData.append("type", "url");
            importUrlUpfile(formData).then((rsp) => {
              if (rsp.data.returnCode == 0) {
                this.$message.success("已加入离线任务队列，请在离线任务栏进行查看")
                this.dialogVisible = false
                this.searchUrl()
              }
              this.importLoading = false
            }, (error) => {
              this.importLoading = false
              this.$message.error(error.message)
            })
          } else if (this.tabLabel == '漏洞库'){
            importVulUpfile(formData).then((rsp) => {
              if (rsp.data.returnCode == 0) {
                this.$message.success("已加入离线任务队列，请在离线任务栏进行查看")
                this.dialogVisible = false
                this.searchVul()
              }
              this.importLoading = false
            }, (error) => {
              this.importLoading = false
              this.$message.error(error.message)
            })
          }
        } else {
          return false
        }
      })
    },
    //文件下载
    donwloadFile: function (file) {
      if (file != "" && file != null) {
        this.$message.info("正在下载,请稍等");
        var elemIF = document.createElement("a");
        elemIF.href = baseUrl + "/analyze/" + file;
        elemIF.download = baseUrl + "/analyze/" + file;

        elemIF.style.display = "none";
        document.body.appendChild(elemIF);
        elemIF.click();
        document.body.removeChild(elemIF);
      }
    },
    /*
     *单选和批量删除
     */
    deleteThreatIp(ids) {
      var params = {}
      params.ids = ids
      deleteThreatIntelligenceIp(params).then((resp) => {
        var d = resp.data
        if (d.returnCode == '0') {
          this.$message({
            message: d.returnMsg,
            type: 'success'
          })
          this.addnewDialogIp = false
          this.batchRows = []
          if (this.isResetPagination) {
            this.pagination.current = 1
            this.isResetPagination = false
          }
          this.searchIp()
        }
      }, (error) => {
        this.$message({
          message: '删除失败,Error Info ' + error,
          type: 'error'
        })
      })
    },
    deleteThreatRealm(ids) {
      var params = {}
      params.ids = ids
      deleteThreatIntelligenceRealm(params).then((resp) => {
        var d = resp.data
        if (d.returnCode == '0') {
          this.$message({
            message: d.returnMsg,
            type: 'success'
          })
          this.addnewDialogRealm = false
          this.batchRows = []
          if (this.isResetPagination) {
            this.pagination.current = 1
            this.isResetPagination = false
          }
          this.searchRealm()
        }
      }, (error) => {
        this.$message({
          message: '删除失败,Error Info ' + error,
          type: 'error'
        })
      })
    },
    deleteThreatUrl(ids) {
      var params = {}
      params.ids = ids
      deleteThreatIntelligenceUrl(params).then((resp) => {
        var d = resp.data
        if (d.returnCode == '0') {
          this.$message({
            message: d.returnMsg,
            type: 'success'
          })
          this.addnewDialogUrl = false
          this.batchRows = []
          if (this.isResetPagination) {
            this.pagination.current = 1
            this.isResetPagination = false
          }
          this.searchUrl()
        }
      }, (error) => {
        this.$message({
          message: '删除失败,Error Info ' + error,
          type: 'error'
        })
      })
    },
    deleteThreatFile(ids) {
      var params = {}
      params.ids = ids
      deleteThreatIntelligenceFile(params).then((resp) => {
        var d = resp.data
        if (d.returnCode == '0') {
          this.$message({
            message: d.returnMsg,
            type: 'success'
          })
          this.addnewDialogFile = false
          this.batchRows = []
          if (this.isResetPagination) {
            this.pagination.current = 1
            this.isResetPagination = false
          }
          this.searchFile()
        }
      }, (error) => {
        this.$message({
          message: '删除失败,Error Info ' + error,
          type: 'error'
        })
      })
    },
    deleteThreatVul(ids) {
      var params = {}
      params.ids = ids
      deleteThreatIntelligenceVul(params).then((resp) => {
        var d = resp.data
        if (d.returnCode == '0') {
          this.$message({
            message: d.returnMsg,
            type: 'success'
          })
          this.addnewDialogVul = false
          this.batchRows = []
          if (this.isResetPagination) {
            this.pagination.current = 1
            this.isResetPagination = false
          }
          this.searchVul()
        }
      }, (error) => {
        this.$message({
          message: '删除失败,Error Info ' + error,
          type: 'error'
        })
      })
    },
    batchDeleteThreatIp() {
      var ids = this.batchRows.map(function(item) {
        return item.id
      })
      if (ids.length == 0) {
        this.$message.warning('请选择删除的记录')
        return false
      }

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        if (ids.length == this.tableData.length) {
          this.isResetPagination = true
        }
        this.deleteThreatIp(ids)
      }).catch(() => { })
    },
    batchDeleteThreatRealm() {
      var ids = this.batchRows.map(function(item) {
        return item.realmId
      })
      if (ids.length == 0) {
        this.$message.warning('请选择删除的记录')
        return false
      }

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        if (ids.length == this.tableData.length) {
          this.isResetPagination = true
        }
        this.deleteThreatRealm(ids)
      }).catch(() => { })
    },
    batchDeleteThreatUrl() {
      var ids = this.batchRows.map(function(item) {
        return item.realmId
      })
      if (ids.length == 0) {
        this.$message.warning('请选择删除的记录')
        return false
      }

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        if (ids.length == this.tableData.length) {
          this.isResetPagination = true
        }
        this.deleteThreatUrl(ids)
      }).catch(() => { })
    },
    batchDeleteThreatFile() {
      var ids = this.batchRows.map(function(item) {
        return item.id
      })
      if (ids.length == 0) {
        this.$message.warning('请选择删除的记录')
        return false
      }

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        if (ids.length == this.tableData.length) {
          this.isResetPagination = true
        }
        this.deleteThreatFile(ids)
      }).catch(() => { })
    },
    batchDeleteThreatVul() {
      var ids = this.batchRows.map(function(item) {
        return item.itemId
      })
      if (ids.length == 0) {
        this.$message.warning('请选择删除的记录')
        return false
      }

      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
        if (ids.length == this.tableData.length) {
          this.isResetPagination = true
        }
        this.deleteThreatVul(ids)
      }).catch(() => { })
    },
    closedialog: function() {
      this.$refs.upload.clearFiles()
      this.$refs.updateForm.resetFields()
    },
    //单条查询
    getdetailIp(id){
      getIPOtherList(id).then((rep) => {
        this.dialogFormIp.country = rep.data.data.map.COUNTRY;
        this.dialogFormIp.province = rep.data.data.map.PROVINCE;
        this.dialogFormIp.city = rep.data.data.map.CITY;
        this.dialogFormIp.lat = rep.data.data.map.LAT;
        this.dialogFormIp.lng = rep.data.data.map.LNG;
        this.dialogFormIp.asn = rep.data.data.map.ASN;
      }, (error) => {
        console.log(error);
      })
    },
    deleteRow: function (index, rows) {
      rows.splice(index, 1)
    },
    getTypeList(){
      getTypeList().then(resp => {
        if (resp.data.returnCode == '0') {
          this.staticData.typeList = resp.data.data.list;
        }
      }).catch(error => {
        this.$message.error(error.message)
      })
    },
    rightAddBtn: function () {
      if(this.dialogFormVul.versionInfo.deviceTypeId == null){
        this.$message.error("系统类型为空，不能够添加！");
        return;
      }
      var param = JSON.parse(JSON.stringify(this.dialogFormVul.versionInfo));
      let version = param.version;
      if(version){
        let versionList = version.split(";");
        var that = this;
        versionList.reverse().forEach(function(item,index){
          that.dialogFormVul.versionList.push({
            deviceType:param.deviceTypeId,
            versionTag:versionList[index],
            versionDesc:param.versionDesc
          });
        })
      }else{
        this.dialogFormVul.versionList.push({
          deviceType:param.deviceTypeId,
          versionTag:param.version,
          versionDesc:param.versionDesc,
        });
      }
      this.dialogFormVul.versionInfo.deviceTypeId = null;
      this.dialogFormVul.versionInfo.version = "";
      this.dialogFormVul.versionInfo.versionDesc = "";
    },
    //版本信息回填
    getVersionList: function(value) {
      this.dialogFormVul.versionList = [];
      let param = {
        "itemId":value.itemId,
        "isManul":value.isManul
      };
      getRuleById(param).then(
        resp => {
          if(resp.data.returnCode=="0"){
            this.dialogFormVul.versionList = JSON.parse(JSON.stringify(resp.data.data));
          }
        },
        error => {
          this.$message.error(error.message);
        }
      );
    },
     //资产小类
    getassetSmallType: function(value) {
      this.staticData.appInfoType = [];
      getAssetTypeSubByAssetType(value).then(
        resp => {
          for (let temp in resp.data.data.list) {
            this.staticData.appInfoType.push(resp.data.data.list[temp]);
          }
        },
        error => {
          this.$message.error(error.message);
        }
      );
    },
  },

}

</script>
<style scoped>
  /* @import url(./layoutStyle.css); */

  table {
    border-right: 1px solid #dcdee2;
    border-bottom: 1px solid #dcdee2;
    border-collapse: collapse;
  }

  table td {
    border-left: 1px solid #dcdee2;
    border-top: 1px solid #dcdee2;
  }

</style>
