<!--
 * @Author: changjun
 * @FilePath: /yuan-qingdao-zld-browser/src/views/screen/threatComponents/LatestSecurityEvents.vue
 * @Date: 2022-09-09 10:12:49
 * @Description: 
 * @LastEditTime: 2023-09-01 17:39:33
 * @LastEditors: 曹文丽
-->
<script setup lang="ts">
import { Teleport, reactive, ref, unref, onMounted, watch } from "vue";
import screenDetailBg from "../../../assets/image/screen/screenDetailBg.png";
import screenDetailHeaderBg from "../../../assets/image/screen/screenDetailHeaderBg.png";
import screenDetailContentBg from "../../../assets/image/screen/screenDetailContentBg.png";
import screenDetailClose from "../../../assets/image/screen/screenDetailClose.png";
import { Swiper, SwiperSlide } from "swiper/vue";
import { Autoplay } from "swiper";
import "swiper/css";
import { useGlobalThreatEvent } from "../logic/useGlobalThreatEvent";
import { useGetChartData } from "../../../components/chart/logic";
import { mapMapping } from "../../../assets/map/provinceData";
import { ElMessageBox } from "element-plus";
const mapData = mapMapping();
const { currentCity, currentDate } = useGlobalThreatEvent();

const swiperModules = [Autoplay];
const autoplayProps = {
  delay: 1000,
  loop: true,
  disableOnInteraction: false,
  pauseOnMouseEnter: true,
};
const detailDailog = reactive({
  showDialog: false,
  title: "威胁风险事件详情",
});

const mySwiper = ref();
const list = ref([]) as any;
const init = async () => {
  const params = {
    type: unref(currentDate),
  } as any;
  if (unref(currentCity) !== mapData?.name) {
    params.region = unref(currentCity);
  }
  const res =
    (await useGetChartData(
      "/threatIncidentScreen/queryNewThreatRisk",
      (res) => res,
      params
    )) || [];
  res.forEach((item) => {
    item.ip_location = item.sourceIp;
    // +
    // " / " +
    // (item.attackOperator || "-") +
    // " / " +
    // (item.attackEnterprise || "-");
  });
  list.value = res;
};
const detailShow = ref(false);
const currentDetailInfo = ref("");
const handleClose = () => {
  currentDetailInfo.value = "";
  detailShow.value = false;
};
const detailInfo = ref({});
const toDetail = (e) => {
  if (mapData?.en === "anhui") {
    detailDailog.showDialog = true;
  } else {
    detailShow.value = true;
  }
  detailInfo.value = e;
};
onMounted(() => {
  init();
});

watch(currentCity, () => {
  init();
});

watch(currentDate, () => {
  init();
});
</script>

<template>
  <div class="module-block LatestSecurityEvents">
    <Swiper v-if="list.length" ref="mySwiper" class="screen-latest-security-events-box" direction="vertical"
      :modules="swiperModules" :slidesPerView="4" :autoplay="autoplayProps" :space-between="0" :observer="true"
      :observe-parents="true">
      <div class="line"></div>
      <SwiperSlide v-for="(item, index) in list" :key="index">
        <div class="top-title">
          <div class="top-title-left">
            <div class="top-title-left-bg">
              <div class="top-title-left-cil"></div>
            </div>
          </div>
          <div class="top-title-bg">{{ item.eventType }}</div>
        </div>
        <div class="item">
          <div class="title-box">
            <div class="title-source">
              <div class="title-source-left">
                <div class="source-icon">源IP</div>
                <div class="source-content">
                  {{ item.srcIp }}
                </div>
              </div>
              <div class="adress-flex">
                <div class="city">归属地：{{ item.srcCity }}</div>
                <div class="more" @click="toDetail(item)">
                  <img src='../../../assets/image/screen/threat-event/safe-item-more.png' alt="" />
                </div>
              </div>
            </div>
          </div>
          <div class="title-box goal-item">
            <div class="title-source">
              <div class="title-source-left">
                <div class="source-icon goal">目的IP</div>
                <div class="source-content">
                  {{ item.destIp }}
                </div>
              </div>
              <div class="adress-flex">
                <div class="city">归属地：{{ item.destCity || "-" }}</div>
              </div>
            </div>
          </div>
          <div class="info-desc">
            <div class="label">时间：</div>
            <div class="label-content">
              {{ item.discoveryTime }}
            </div>
          </div>
        </div>
      </SwiperSlide>
    </Swiper>
    <ya-empty v-else></ya-empty>
    <Teleport to="body">
      <div class="mask-box" v-if="detailShow">
        <div class="custom-dialog">
          <img :src="screenDetailBg" alt="" class="custom-dialog-bg" />
          <img :src="screenDetailHeaderBg" alt="" class="custom-dialog-header" />
          <img @click.stop="handleClose" :src="screenDetailClose" class="custom-dialog-header-close" alt="" />
          <div class="custom-header-text">威胁风险事件详情</div>
          <img :src="screenDetailContentBg" alt="" class="custom-dialog-content-bg" />
          <div class="custom-dialog-content">
            <div class="custom-dialog-content-center">
              <div class="custom-dialog-content-top">
                <div class="custom-dialog-content-top-img">
                  <img src="../../../assets/image/screen/threat-event/safe-item-detail.png" alt="" />
                </div>
                <div>
                  <div class="custom-dialog-content-top-title">
                    {{ detailInfo.eventType || "-" }}
                  </div>
                  <div class="custom-dialog-content-top-info">
                    <span>威胁等级：</span>{{ detailInfo.level || "-"
                    }}<span class="line">|</span><span>事件说明：</span>{{ "-" }}
                  </div>
                </div>
              </div>
              <div class="table">
                <div class="flex-st">
                  <div class="flex-st">
                    <div class="dialog-label">源IP</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcIp || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源IP运营商</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcOperator || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源IP单位</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcEnterprise || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源端口</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcPort || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源IP归属地</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcCity || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP</div>
                    <div class="dialog-value">
                      {{ detailInfo.destIp || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP运营商</div>
                    <div class="dialog-value">
                      {{ detailInfo.destOperator || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP单位</div>
                    <div class="dialog-value">
                      {{ detailInfo.destEnterprise || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的端口</div>
                    <div class="dialog-value">
                      {{ detailInfo.destPort || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP归属地</div>
                    <div class="dialog-value">
                      {{ detailInfo.destCity || "-" }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <YaDialog custom-class="LatestSecurityEventsDialog" :dialogProps="detailDailog">
        <template #content>
          <div class="custom-dialog-content">
            <div class="custom-dialog-content-center">
              <div class="custom-dialog-content-top">
                <div class="custom-dialog-content-top-img">
                  <img src="../../../assets/image/screen/threat-event/safe-item-detail.png" alt="" />
                </div>
                <div>
                  <div class="custom-dialog-content-top-title">
                    {{ detailInfo.eventType || "-" }}
                  </div>
                  <div class="custom-dialog-content-top-info">
                    <span>威胁等级：</span>{{ detailInfo.level || "-"
                    }}<span class="line">|</span><span>事件说明：</span>{{ "-" }}
                  </div>
                </div>
              </div>
              <div class="table">
                <div class="flex-st">
                  <div class="flex-st">
                    <div class="dialog-label">源IP</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcIp || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源IP运营商</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcOperator || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源IP单位</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcEnterprise || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源端口</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcPort || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">源IP归属地</div>
                    <div class="dialog-value">
                      {{ detailInfo.srcCity || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP</div>
                    <div class="dialog-value">
                      {{ detailInfo.destIp || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP运营商</div>
                    <div class="dialog-value">
                      {{ detailInfo.destOperator || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP单位</div>
                    <div class="dialog-value">
                      {{ detailInfo.destEnterprise || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的端口</div>
                    <div class="dialog-value">
                      {{ detailInfo.destPort || "-" }}
                    </div>
                  </div>
                  <div class="flex-st">
                    <div class="dialog-label">目的IP归属地</div>
                    <div class="dialog-value">
                      {{ detailInfo.destCity || "-" }}
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </template>
      </YaDialog>
    </Teleport>
  </div>
</template>
<style lang="scss" scoped>
@import "../../../assets/font/font.css";

.module-block {
  width: 100%;
  height: 708px;
  // padding: 30px 0 0 0;
  box-sizing: border-box;
  padding-top: 17px;
  padding-bottom: 10px;
}

::v-deep .swiper {
  height: 100% !important;
  // margin-left: 10px !important;
}

::v-deep .swiper-slide {
  border-left: 3px solid rgba(16, 200, 253, 0.2);
  position: relative;
  left: 20px;
  // margin-bottom: 0 !important;
  // padding-top: 19px;
  padding-bottom: 25px;
}
</style>

<style lang="scss">
.screen-latest-security-events-box {
  width: 100%;
  height: 345px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  font-size: 14px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.5);

  .top-title {
    display: flex;
    position: absolute;
    width: 100%;
    left: -10px;

    .top-title-bg {
      background: url("../../../assets/image/screen/threat-event/safe-top-bg.png") no-repeat;
      background-size: 100% 100%;
      width: 75%;
      height: 30px;
      font-weight: 400;
      color: #dfeef3;
      font-size: 16px;
      font-family: YouSheBiaoTiHei;
      line-height: 30px;
      text-indent: 31px;
      position: relative;
      top: -5px;
    }

    .top-title-left {
      display: flex;

      .top-title-left-bg {
        background: #071545;
        border: 2px solid #10c8fd;
        border-radius: 50%;
        width: 14px;
        height: 14px;
        position: relative;
      }

      .top-title-left-cil {
        position: absolute;
        top: 3px;
        left: 3px;
        width: 8px;
        height: 8px;
        background: #ffffff;
        border-radius: 50%;
      }
    }
  }

  .item {
    // width: 100%;
    margin-left: 10px;
    background: url("../../../assets/image/screen/threat-event/safe-item-bg.png") no-repeat;
    background-size: 100% 100%;
    margin-top: 35px;
    padding: 16px;
    padding-top: 20px;

    .title-box {
      font-weight: 400;
      padding-left: 10px;

      .title {
        font-size: 20px;
        font-weight: 500;
        color: #23ceff;
      }
    }

    .goal-item {
      margin-top: 15px;
    }

    .title-source {
      display: flex;
      position: relative;
      align-items: center;

      // justify-content: space-between;
      .title-source-left {
        display: flex;
        align-items: center;
      }

      .source-icon {
        font-size: 12px;
        text-align: center;
        width: 44px;
        height: 20px;
        line-height: 20px;
        background: rgba(180, 140, 255, 0.31);
        border: 2px solid #b48cff;
        border-radius: 2px;
        margin-right: 6px;
      }

      .goal {
        background: rgba(252, 139, 24, 0.31);
        border: 2px solid #fc8b18;
      }

      .source-content {
        font-size: 16px;
        box-sizing: border-box;
        color: #9aefff;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: inline-block;
        width: 150px;
      }

      .adress-flex {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex: 1;
      }

      .city {
        font-size: 14px;
        font-weight: 400;
        color: #9aefff;
      }

      .more {
        img {
          width: 18px;
          height: 14px;
          cursor: pointer;
        }

        margin-right: 20px;
      }
    }

    .flex-bt {
      justify-content: space-between;
    }

    .info-desc {
      display: flex;
      align-items: center;
      font-size: 14px;
      font-weight: 500;
      color: #9aefff;
      padding: 0 10px;
      margin-top: 16px;

      .label {
        color: #67b4c3;
      }
    }

    .line {
      width: 1px;
      height: 100px;
      background: #58b4d5;
    }
  }
}

// 弹窗
.mask-box {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

.custom-dialog {
  width: 1214px;
  height: 625px;
  position: relative;

  .custom-dialog-bg {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
  }

  .custom-dialog-header {
    width: 1101px;
    height: 51px;
    position: absolute;
    top: 10px;
    left: 15px;
  }

  .custom-header-text {
    position: absolute;
    top: 28px;
    left: 45px;
    font-size: 20px;
    font-family: "PangMenZhengDao";
    color: #ffffff;
    line-height: 23px;
    letter-spacing: 3px;
    text-shadow: 0px 0px 8px #008aff;
  }

  .custom-dialog-header-close {
    width: 115px;
    height: 32px;
    position: absolute;
    top: 0;
    right: 0;
    z-index: 1;
    cursor: pointer;
  }

  .custom-dialog-content-bg {
    width: 1182px;
    height: 532px;
    position: absolute;
    top: 76px;
    left: 16px;
  }
}

.custom-dialog-content {
  width: 1187px;
  height: 532px;
  position: absolute;
  top: 76px;
  left: 16px;
  color: #fff;
  font-family: Arial;
  font-weight: 400;
  color: #ffffff;
  padding: 16px;
  box-sizing: border-box;
  word-break: break-all;
  overflow-y: auto;

  .custom-dialog-content-center {
    border: 1px solid #2a4f76;
    border-bottom: 0;
  }

  .custom-dialog-content-top {
    display: flex;
    align-items: center;
    padding: 20px;

    .custom-dialog-content-top-img {
      img {
        width: 93px;
        height: 105px;
      }
    }

    .custom-dialog-content-top-title {
      font-size: 24px;
      font-family: PangMenZhengDao;
      background: linear-gradient(0deg,
          rgb(26, 215, 255) 1.07421875%,
          #c2f7ff 100%);
      -webkit-background-clip: text;
      color: transparent;
    }

    .custom-dialog-content-top-info {
      font-size: 14px;
      font-weight: 400;
      color: #b4f3ff;
      margin-top: 4px;

      span {
        color: #71c5d5;
      }

      .line {
        height: 11px;
        color: #8cecff;
        margin: 0 11px;
      }
    }
  }
}

.flex-st {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}

.table {
  border: 1px solid #2a4f76;
  border-bottom: 0;
}

.dialog-label {
  width: 149px;
  height: 35px;
  line-height: 35px;
  padding-left: 26px;
  font-weight: 400;
  color: #71c5d5;
  font-size: 14px;
  background: rgba(19, 66, 107, 0.6);
  border: 1px solid #2a4f76;
  border-right: 0;
  border-left: 0;
  border-top: 0;
}

.dialog-value {
  padding-left: 46px;
  width: 353px;
  font-size: 14px;
  font-weight: 400;
  color: #b4f3ff;
  height: 35px;
  line-height: 35px;
  border: 1px solid #2a4f76;
  border-top: 0;
}

.dialog-value:nth-child(even) {
  border-right: 0;
}
</style>
