<!--
 * @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:43
 * @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: false,
  disableOnInteraction: false,
  pauseOnMouseEnter: true,
};

const detailShow = ref(false);
const currentDetailInfo = ref("");
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/queryNewSecurityIncident",
      (res) => res,
      params
    )) || [];
  res.forEach((item) => {
    item.ip_location =
      item.sourceIp +
      " / " +
      (item.attackOperator || "-") +
      " / " +
      (item.attackEnterprise || "-");
  });
  list.value = res;
  console.log(list, "[[[]]]");
};
let detailDailog = reactive({
  showDialog: false,
  title: "安全事件详情",
});
const detailBtnClick = (item) => {
  console.log(item, "00000");
  currentDetailInfo.value = item.payLoad;
  if (mapData?.en == "anhui") {
    detailDailog.showDialog = true;
  } else {
    detailShow.value = true;
  }
};

const handleClose = () => {
  currentDetailInfo.value = "";
  detailShow.value = false;
};

onMounted(() => {
  init();
});

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

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

<template>
  <div class="module-block">
    <Swiper v-if="list.length" ref="mySwiper" class="screen-latest-security-events-box" direction="vertical"
      :modules="swiperModules" :slidesPerView="3" :autoplay="autoplayProps" :space-between="27" :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 class="createTime">{{ item.createTime }}</div>
          </div>
          <div class="detail-btn" @click="detailBtnClick(item)">详情>></div>
        </div>
        <div class="item">
          <div class="title-box">
            <div class="title">{{ item.name || "" }}</div>
            <div class="title-source">
              <div class="source-icon">来源</div>
              <div class="source-content">
                {{ item.ip_location
                }}<CustomTooltip :show="true" text=""></CustomTooltip>
              </div>
            </div>
          </div>
          <div class="info-desc">
            <div class="label">涉及单位重要信息系统IP：</div>
            <div class="label-content">
              {{ item.systemIp }} | {{ item.city }}
            </div>
          </div>
          <div class="info-desc">
            <div class="label">涉及行业：</div>
            <div class="label-content">{{ item.industryType }}</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" v-if="currentDetailInfo">
            {{ currentDetailInfo }}
          </div>
          <ya-empty class="positionRelative" v-else></ya-empty>
        </div>
      </div>
      <!-- 查看-->
      <div class="ya-dialog-info">
        <YaDialog :dialogProps="detailDailog">
          <template #content>
            <div class="custom-dialog-content1" v-if="currentDetailInfo">
              {{ currentDetailInfo }}
            </div>
            <ya-empty v-else></ya-empty>
          </template>
        </YaDialog>
      </div>
    </Teleport>
  </div>
</template>

<style lang="scss" scoped>
.positionRelative {
  position: relative;
}

.module-block {
  width: 100%;
  height: 570px;
  padding: 30px 0 0 0;
  box-sizing: border-box;
}

.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: 1182px;
  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-content1 {
  color: #fff;
  font-family: Arial;
  font-weight: 400;
  color: #ffffff;
  word-break: break-all;
  overflow-y: auto;
}

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

::v-deep .swiper-slide {
  // height:150px !important;
  border-left: 1px solid #58b4d5;
  position: relative;
  left: 20px;
  margin-bottom: 0 !important;
  // padding-top: 19px;
  padding-bottom: 55px;
}
</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;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    width: 100%;
    left: -10px;

    .top-title-left {
      display: flex;

      .createTime {
        margin-left: 10px;
      }

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

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

  .detail-btn {
    color: #51c8f7;
    cursor: pointer;
    margin-right: 10px;
  }

  .item {
    width: 93%;
    margin-left: 5%;
    padding-bottom: 10px;
    background: linear-gradient(91deg,
        #09334a 0%,
        rgba(0, 174, 255, 0.28) 100%);
    border: 1px solid;
    border-image: linear-gradient(89deg,
        rgba(83, 204, 251, 0.15),
        rgba(83, 204, 251, 0.5)) 1 1;
    color: rgba(255, 255, 255, 1);
    margin-top: 35px;

    .title-box {
      // display: flex;
      // justify-content: space-between;
      padding: 13px 17px;
      padding-bottom: 0;

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

      .title-source {
        display: flex;
        position: relative;

        // right: 10px;
        .source-icon {
          width: 45px;
          height: 23px;
          background: #d99408;
          border: 1px solid #d99408;
          border-radius: 2px;
          font-size: 14px;
          font-weight: 400;
          color: #ffffff;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        .source-content {
          max-width: 425px;
          cursor: default;
          height: 24px;
          line-height: 24px;
          background: rgba(217, 148, 8, 0.5);
          border: 1px solid #d99408;
          border-radius: 2px;
          font-size: 14px;
          font-weight: 400;
          padding: 0 10px;
          box-sizing: border-box;
          color: #ffffff;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          display: inline-block;
        }
      }
    }

    .info-desc {
      display: flex;
      align-items: center;
      font-size: 14px;
      font-weight: 400;
      color: #ffffff;
      padding: 0 17px;
      margin-top: 12px;

      .label {
        color: rgba(255, 255, 255, 0.5);
      }
    }

    .line {
      width: 1px;
      height: 100px;
      background: #58b4d5;
    }
  }
}
</style>
