杨磊
2024-06-12 db966eb618d50a472fa6d882445eda2912be3c62
src/pages/territory/territory.vue
@@ -4,7 +4,7 @@
    <headNav :idIndex="idIndex" text="中医地域医谱" style="z-index: 999" />
    <view
      class="flex flex-center"
      style="width: 100%; margin: 0.2rem 0 0.34rem; justify-content: flex-start"
      style="width: 100%; margin: 20px 0 34px; justify-content: flex-start"
    >
      <advancedSearch
        class="Search"
@@ -14,7 +14,7 @@
        :keyword="keyword"
      />
      <ul class="flex">
        <li style="" v-for="(item, index) in dynasty" :key="item.id">
        <li v-for="(item, index) in dynasty" :key="item.id">
          <view
            @click="SchoolClick(item.id)"
            class="flex flex-center font-family school"
@@ -104,6 +104,7 @@
            {{ item.birthAndDeath ? item.birthAndDeath : "-" }}
          </li>
          <li>来源: {{ item.source ? item.source : "-" }}</li>
          <li>籍贯: {{ item.nativPlace ? item.nativPlace : "-" }}</li>
          <li
            v-if="SearchArr.length - 1 !== index"
            style="margin: 0.1rem 0; border-bottom: 1px solid #d8d8d8"
@@ -113,7 +114,7 @@
    </el-card>
    <!-- echarts里面的数据点击后弹框 -->
    <div class="mapBox">
    <div class="mapBox" id="mapBox" v-loading="mapLoading">
      <div id="map"></div>
      <el-card
        class="box-card echartsTrue"
@@ -147,7 +148,12 @@
            籍贯: {{ currentMark.nativePlace ? currentMark.nativePlace : "-" }}
          </li>
          <li>医学分科: {{ currentMark.barnch ? currentMark.barnch : "-" }}</li>
          <li>小传: {{ currentMark.medical ? currentMark.medical : "-" }}</li>
          <li
            class="medicalLi"
            :title="currentMark.medical ? currentMark.medical : '-'"
          >
            小传: {{ currentMark.medical ? currentMark.medical : "-" }}
          </li>
        </ul>
        <el-button
          class="flex"
@@ -220,14 +226,19 @@
import { loadBMap } from "@/static/map.js";
import L from "leaflet";
import "leaflet.chinatmsproviders";
import * as echarts from "echarts";
import "echarts/extension/bmap/bmap";
import { getRetrieval, getDynasty } from "@/api/index.js";
import {
  getRetrieval,
  getDynasty,
  getPreCount,
  getDynastyData,
} from "@/api/index.js";
export default {
  data() {
    return {
      loading: true,
      mapLoading: true,
      // echarts元素点击时出来的弹窗和坐标
      keyword: "",
      isEchTrue: false,
@@ -407,83 +418,230 @@
    this.getDynastyList();
    this.getDataList();
    this.getHaveDataDynasty();
  },
  methods: {
    getHaveDataDynasty() {
      getDynastyData().then((res) => {
        console.log(res, "getHaveDataDynasty");
      });
    },
    getDynastyList() {
      getDynasty().then((res) => {
        this.dynasty1 = res.list;
        console.log("dynasty1", res.list);
      });
    },
    showCard(info) {
      const item = this.markerList.find((f) => f.id == info.id);
      console.log(item, "item");
      var latlng = L.latLng(item.yCoord, item.xCoord);
      this.map.setView(latlng, 10);
      this.isEchTrue = true;
      this.currentMark = {
        name: item?.WEAK_NAME[0]?.content1,
        nikeName: item?.ALIAS[0]?.content2,
        nativePlace: item?.content1,
        barnch: item?.MEDICAL_BRANCH[0]?.content1,
        medical: item?.MEDICAL_EXPERTISE[0]?.content1,
      };
      this.$nextTick(() => {
        this.isTop = "12%";
        this.isLeft = "41.1%";
      });
      setTimeout(() => {
        this.isEchTrue = true;
        this.currentMark = {
          name: item?.NAME[0]?.content1,
          nikeName: item?.ALIAS[0]?.content2,
          nativePlace: item?.content1,
          barnch: item?.MEDICAL_BRANCH[0]?.content1,
          medical: item?.BIOGRAPHY,
          id: item.id,
        };
        this.$nextTick(() => {
          this.isTop =
            document.getElementById("mapBox").offsetHeight / 2 - 295 + "px";
          this.isLeft =
            document.getElementById("mapBox").offsetWidth / 2 - 171 + "px";
        });
      }, 300);
    },
    getDataList() {
      this.SearchArr = [];
      this.loading = true;
      this.mapLoading = true;
      // 这里改成了分页的接口,需要调用多次取出所有数据
      let times = 0;
      getPreCount({
        keyword: this.keyword,
        dynasty: this.dynasty1Color,
      }).then(async (res) => {
        const totalCount = res.object;
        if (totalCount % 200 == 0) {
          times = totalCount / 200 - 1;
        } else {
          times = Math.floor(totalCount / 200);
        }
        console.log(times, "times");
        if (times == 0 || times < 0) times = 1;
        let markerList = [];
        for (let i = 1; i <= times; i++) {
          const curData = await this.getDataPageInfo(i);
          if (curData) {
            markerList = [...markerList, ...curData];
          }
          if (i == 1) {
            this.loading = false;
            this.mapLoading = false;
            this.markerList = markerList;
            this.initMap(markerList);
          } else {
            if (curData && curData.length) {
              for (let j = 0; j < curData.length; j++) {
                const ele = curData[j];
                let currentClassName = "map-circle-name";
                if (ele.dynastyInfo) {
                  switch (ele.dynastyInfo.dynastyChs) {
                    case "夏":
                      currentClassName = "map-circle-xia";
                      break;
                    case "商":
                      currentClassName = "map-circle-shang";
                      break;
                    case "西周":
                      currentClassName = "map-circle-zhou";
                      break;
                    case "秦":
                      currentClassName = "map-circle-qin";
                      break;
                    case "汉":
                      currentClassName = "map-circle-han";
                      break;
                    case "隋":
                      currentClassName = "map-circle-sui";
                      break;
                    case "唐":
                      currentClassName = "map-circle-tang";
                      break;
                    case "明":
                      currentClassName = "map-circle-ming";
                      break;
                  }
                }
                let icon = L.divIcon({
                  html: `<div class='${currentClassName} ripple'></div>`,
                  iconSize: [80, 80],
                  className: "map-circle",
                });
                const temp_mark = L.marker([ele.yCoord, ele.xCoord], {
                  icon: icon,
                }).addTo(this.map);
                temp_mark.on("click", (e) => {
                  setTimeout(() => {
                    this.isEchTrue = true;
                    this.currentMark = {
                      name: ele?.NAME[0]?.content1,
                      nikeName: ele?.ALIAS[0]?.content2,
                      nativePlace: ele?.content1,
                      barnch: ele?.MEDICAL_BRANCH[0]?.content1,
                      medical: ele?.BIOGRAPHY,
                      id: ele.id,
                    };
                    this.isTop = e.containerPoint.y - 295 + "px";
                    this.isLeft = e.containerPoint.x - 171 + "px";
                  }, 300);
                });
              }
            }
          }
          if (i == times) {
            this.SearchArr = markerList.map((item) => ({
              birthAndDeath: item?.BIRTH_YEAR[0]?.content1
                ? item?.BIRTH_YEAR[0]?.content1 +
                  "-" +
                  item?.DEATH_YEAR[0]?.content1
                : "-",
              name: item?.NAME[0]?.content1,
              source: "-",
              nativPlace: item?.NATIVE_PLACE[0].content1,
              id: item.id,
            }));
            this.markerList = markerList;
            // this.initMap(markerList);
          }
        }
      });
      // 问题:
      // 搜索结果不对
      // 点击地图标点出现弹框,拖动地图时应关闭弹框
      getRetrieval({
        keyword: this.keyword,
        dynasty: this.dynasty1Color,
        page: 1,
        pageSize: 1000,
      }).then((res) => {
        this.loading = false;
        if (res.object) {
          let markerList = [];
          const listData = res.object.personList;
          for (let i = 0; i < listData.length; i++) {
            const item = listData[i];
            if (item.NATIVE_PLACE?.length > 0) {
              item.NATIVE_PLACE.forEach((citem) => {
                if (citem.xCoord && citem.yCoord) {
                  const currentDynasty = this.dynasty1.find(
                    (f) => f.id == item.PERIOD[0].content1
                  );
                  if (currentDynasty) {
                    item.dynastyInfo = currentDynasty;
                  }
                  markerList.push({ ...citem, ...item });
                }
              });
            }
          }
          this.initMap(markerList);
          this.SearchArr = markerList.map((item) => ({
            birthAndDeath: item?.BIRTH_YEAR[0]?.content1
              ? item?.BIRTH_YEAR[0]?.content1 +
                "-" +
                item?.DEATH_YEAR[0]?.content1
              : "-",
            name: item?.NAME[0]?.content1,
            source: "-",
            id: item.id,
          }));
          this.markerList = markerList;
        } else {
          this.initMap([]);
        }
      });
      // getRetrieval({
      //   keyword: this.keyword,
      //   dynasty: this.dynasty1Color,
      //   page: 1,
      //   pageSize: 200,
      // }).then((res) => {
      //   this.loading = false;
      //   if (res.object) {
      //     let markerList = [];
      //     const listData = res.object.personList;
      //     for (let i = 0; i < listData.length; i++) {
      //       const item = listData[i];
      //       if (item.NATIVE_PLACE?.length > 0) {
      //         item.NATIVE_PLACE.forEach((citem) => {
      //           if (citem.xCoord && citem.yCoord) {
      //             const currentDynasty = this.dynasty1.find(
      //               (f) => f.id == item.PERIOD[0].content1
      //             );
      //             if (currentDynasty) {
      //               item.dynastyInfo = currentDynasty;
      //             }
      //             markerList.push({ ...citem, ...item });
      //           }
      //         });
      //       }
      //     }
      //     this.initMap(markerList);
      //     this.SearchArr = markerList.map((item) => ({
      //       birthAndDeath: item?.BIRTH_YEAR[0]?.content1
      //         ? item?.BIRTH_YEAR[0]?.content1 +
      //           "-" +
      //           item?.DEATH_YEAR[0]?.content1
      //         : "-",
      //       name: item?.NAME[0]?.content1,
      //       source: "-",
      //       id: item.id,
      //     }));
      //     this.markerList = markerList;
      //   } else {
      //     this.initMap([]);
      //   }
      // });
    },
    async getDataPageInfo(count) {
      const res = await getRetrieval({
        keyword: this.keyword,
        dynasty: this.dynasty1Color,
        page: count,
        pageSize: 200,
      });
      if (res.object) {
        let markerList = [];
        const listData = res.object.personList;
        for (let i = 0; i < listData.length; i++) {
          const item = listData[i];
          if (item.NATIVE_PLACE?.length > 0) {
            item.NATIVE_PLACE.forEach((citem) => {
              if (citem.xCoord && citem.yCoord) {
                const currentDynasty = this.dynasty1.find(
                  (f) => f.id == item.PERIOD[0].content1
                );
                if (currentDynasty) {
                  item.dynastyInfo = currentDynasty;
                }
                markerList.push({ ...citem, ...item });
              }
            });
          }
        }
        return markerList;
      } else {
        return [];
      }
    },
    onMapMoveEnd() {
      console.log("地图拖动了");
      this.isEchTrue = false;
@@ -512,6 +670,13 @@
          minZoom: 3,
        })
        .addTo(map);
      L.tileLayer
        .chinaProvider("TianDiTu.Normal.Annotion", {
          key: "76bc34ead7e30e663a4eded8aeaf5860",
          maxZoom: 18,
          minZoom: 3,
        })
        .addTo(map);
      let DefaultIcon1 = L.icon({
        iconUrl: this.icoName,
        iconSize: [24, 41], //  图标的大小    【值1,值2】 为具体你自定义图标的尺寸,比如我图标尺寸是32×52,表示该图标:宽度32像素,高度:52像素,那么值1:就是32,值2:就是52
@@ -525,9 +690,9 @@
        className: "map-circle",
      });
      this.map = map;
      if (markerList.length) {
        for (let i = 0; i < markerList.length; i++) {
          const item = markerList[i];
      if (this.markerList.length) {
        for (let i = 0; i < this.markerList.length; i++) {
          const item = this.markerList[i];
          let currentClassName = "map-circle-name";
          if (item.dynastyInfo) {
            switch (item.dynastyInfo.dynastyChs) {
@@ -567,25 +732,19 @@
            icon: icon,
          }).addTo(map);
          temp_mark.on("click", (e) => {
            console.log(e, "123123");
            this.isEchTrue = true;
            this.currentMark = {
              name: item?.WEAK_NAME[0]?.content1,
              nikeName: item?.ALIAS[0]?.content2,
              nativePlace: item?.content1,
              barnch: item?.MEDICAL_BRANCH[0]?.content1,
              medical: item?.MEDICAL_EXPERTISE[0]?.content1,
            };
            this.$nextTick(() => {
              this.isTop =
                e.containerPoint.y -
                document.querySelector(".echartsTrue").offsetHeight +
                "px";
              this.isLeft =
                e.containerPoint.x -
                document.querySelector(".echartsTrue").offsetWidth +
                "px";
            });
            setTimeout(() => {
              this.isEchTrue = true;
              this.currentMark = {
                name: item?.WEAK_NAME[0]?.content1,
                nikeName: item?.ALIAS[0]?.content2,
                nativePlace: item?.content1,
                barnch: item?.MEDICAL_BRANCH[0]?.content1,
                medical: item?.BIOGRAPHY,
                id: item.id,
              };
              this.isTop = e.containerPoint.y - 295 + "px";
              this.isLeft = e.containerPoint.x - 171 + "px";
            }, 300);
          });
        }
      }
@@ -608,7 +767,7 @@
    // 查看更多>>
    viewMoreClick() {
      uni.navigateTo({
        url: "/pages/character/detail",
        url: "/pages/character/detail?id=" + this.currentMark.id,
      });
    },
  },
@@ -824,10 +983,27 @@
  animation: ripple-animation 1s infinite linear;
}
@keyframes ripple-animation {
/* @keyframes ripple-animation {
  to {
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
} */
::v-deep .cleanupBtn {
  right: 60px !important;
}
::v-deep .widget_input {
  min-width: 240px !important;
}
.medicalLi {
  height: 50px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
</style>