Newer
Older
KaiFengH5 / src / views / home / home_homePage.vue
@鲁yixuan 鲁yixuan on 9 Jul 14 KB update
<template>
  <div id="home_homePage">
    <!-- <van-nav-bar safe-area-inset-top /> -->
    <!-- 顶部天气数据与定位数据 -->
    <div id="HeaderBG">
      <div id="HeaderTop">
        <div id="HeaderName">运维巡查系统</div>
        <div id="locationName"><van-icon name="location-o" />{{ AllData.locationName }}</div>
        <div id="Weather1">{{ AllData.weatherInfo.text }}</div>
      </div>
      <div id="Headerbottom">
        <div class="Headerbottom_1">
          <img src="@/assets/images/sstq.png" alt="" />
          <div class="concent_font">实时天气</div>
        </div>
        <div class="Headerbottom_2">
          <div class="concent1">{{ AllData.weatherInfo.temp }}℃</div>
          <div class="concent_font">温度</div>
        </div>
        <div class="Headerbottom_3">
          <div class="concent1">{{ AllData.weatherInfo.wind_class }}</div>
          <div class="concent_font">{{ AllData.weatherInfo.wind_dir }}</div>
        </div>
      </div>
    </div>
    <div id="CentBox">
      <!-- 中部菜单类型 -->
      <div id="typeBox">
        <div
          class="typeList"
          v-for="(item, index) in AllData.typeListData"
          :key="index"
          @click="$router.push(item.toPath)"
        >
          <van-badge :content="item.num" :show-zero="false"> <img class="typeImg" :src="item.icon" alt="" /></van-badge>
          <div class="typeFont">{{ item.name }}</div>
        </div>
      </div>
      <!-- 主要工单内容部分 -->
      <div id="listBox">
        <van-pull-refresh v-model="AllData.refreshing" @refresh="onRefresh">
          <van-list
            v-model:loading="AllData.loading"
            :finished="AllData.finished"
            finished-text="没有更多了"
            @load="onLoad"
          >
            <div class="ListClass" v-for="item in AllData.list" :key="item" :title="item">
              <div class="ListTop">{{ item.title + `(${item.id})` }}</div>
              <div class="ListBottom">
                <div class="LeftFont">
                  <p class="P1">{{ item.content }}</p>
                  <!-- <p class="P2">请在2021年6月10日前处理</p> -->
                </div>
                <div class="rightBtn" @click="messageClick(item)">
                  <!-- 按钮,根据权限进行展示 -->
                  <div class="Btn_Class Btn_Class1" v-show="item.status == 'unread'">未读</div>
                  <div class="Btn_Class Btn_Class2" v-show="item.status == 'read'">已读</div>
                </div>
              </div>
            </div>
          </van-list>
        </van-pull-refresh>
        <van-empty description="暂无消息" v-if="AllData.list.length == 0" />
      </div>
    </div>
  </div>
</template>

<script setup name="home_homePage">
import axios from 'axios';
import typeImg1 from '@/assets/images/xxtz.png';
import typeImg2 from '@/assets/images/rwxc.png';
import typeImg3 from '@/assets/images/czgd.png';
import typeImg4 from '@/assets/images/jcgj.png';
import { SeeMessage, queryUserMessageClass } from '@/api/meessageApi.js';
import { getCurrentInstance } from 'vue';
import { showConfirmDialog } from 'vant';
import { useRouter } from 'vue-router';

const { proxy } = getCurrentInstance();
const router = useRouter();

const AllData = reactive({
  locationName: '',
  weatherInfo: {
    text: '阴',
    code: '02',
    temp: 19.8,
    feels_like: 20,
    rh: 40,
    wind_class: '1级',
    wind_speed: 0.9,
    wind_dir: '南风',
    wind_angle: 187,
    prec: 0.0,
    clouds: 95,
    vis: 8500,
    pressure: 1017,
    dew: 5,
    uv: 2,
  },
  typeListData: [
    {
      name: '消息通知',
      icon: typeImg1,
      num: 0,
      toPath: '',
    },
    {
      name: '任务巡查',
      icon: typeImg2,
      num: 0,
      toPath: '/TaskInspection',
    },
    {
      name: '测站工单',
      icon: typeImg3,
      num: 0,
      toPath: '',
    },
    {
      name: '监测告警',
      icon: typeImg4,
      num: 0,
      toPath: '',
    },
  ],
  // 列表
  list: [{ content: '1' }],
  loading: false,
  finished: false,
  refreshing: false,
  // 接口数据
  search: {
    current: 0,
    size: 10,
    receiver: localStorage.getItem('userNo'), //接收人
    refId: '', //关联编号
    refType: '', //关联类型
    status: '', //状态(未读 unread / 已读 read)
    type: '', //类型(运维工单 ops_work_order)
  },
});

// 获取消息统计
const getMessageCount = () => {
  let params = {
    taskUserId: localStorage.getItem('LoginUserID'),
  };
  queryUserMessageClass(params).then((res) => {
    // console.log(res.data.data);
    if (res && res.data.code == 1) {
      let datas = res.data.data;
      AllData.typeListData[0].num = datas.messageNum; //消息通知
      AllData.typeListData[1].num = datas.taskNum; //任务巡查
      AllData.typeListData[2].num = datas.orderNum; //测站工单
      AllData.typeListData[3].num = datas.alarmNum; //监测告警
    }
  });
};

// 获取当前城市
const getCityName = () => {
  let CityName = '';
  // 安卓拿到的数据
  let res = {
    aoiName: '黄河大街与大梁路交叉口',
    city: '开封市',
    district: '龙亭区',
    lat: 34.8,
    lng: 114.32,
    poiName: '',
    province: '河南省',
    street: '黄河大街与大梁路交叉口北160米',
  };
  AllData.locationName = res.province + res.city + res.district + res.aoiName;
  if (res.city) {
    CityName = res.city.replace(/市/g, '');
  } else {
    CityName = '开封';
  }
  axios
    .get(
      `https://gfapi.mlogcn.com/function/v001/city?location=${CityName}&items=10&area=china&language=CHN&withTz=false&withPoi=false&key=F2hH0eoTQS99jaKr3v4AIWFQkJwRjMAU&output_type=json`
    )
    .then((res) => {
      if (res && res.data.areaList) getWeather(res.data.areaList[0].areacode);
    });
};
// 获取天气信息
const getWeather = (code) => {
  axios
    .get(`https://gfapi.mlogcn.com/weather/v001/now?key=F2hH0eoTQS99jaKr3v4AIWFQkJwRjMAU&areacode=${code}`)
    .then((res) => {
      AllData.weatherInfo = res.data.result.realtime;
    })
    .catch((error) => {});
};
// 获取列表数据
const onLoad = async () => {
  // if (AllData.refreshing) {
  //   AllData.list = [];
  //   AllData.search.current = 1;
  //   AllData.refreshing = false;
  // } else {
  //   AllData.search.current++;
  // }
  // let res = await messagePage(AllData.search);
  // if (res && res.data.code == 1) {
  //   AllData.list = AllData.list.concat(res.data.data.list);
  //   AllData.loading = false;
  //   if (AllData.list.length >= res.data.data.total) {
  //     AllData.finished = true;
  //   }
  // }
  AllData.loading = false;
};
// 列表数据刷新
const onRefresh = () => {
  // 清空列表数据
  AllData.finished = false;
  // 重新加载数据
  // 将 loading 设置为 true,表示处于加载状态
  AllData.loading = true;
  onLoad();
};
// 点击消息处理
const messageClick = (item) => {
  if (item.status == 'read') {
    // 消息已阅读
    // proxy.showSuccessToast("此消息已阅读");
    TypeToPath(item.type);
  } else {
    showConfirmDialog({
      // message: `消息已查看,是否对 ${item.title} 进行处理?`,
      message: item.content,
      confirmButtonText: '去处理',
      cancelButtonText: '仅查看',
    })
      .then(() => {
        console.log(1);
        SeeMessages(item, true);
      })
      .catch(() => {
        console.log(2);
        SeeMessages(item, false);
      });
  }
};
// 阅读消息
const SeeMessages = async (item, bol) => {
  const res = await SeeMessage(item.id);
  if (res && res.data.code == 1) {
    item.status = 'read';
    if (bol) {
      // 需要进行跳转
      TypeToPath(item.type);
    }
  }
};
// 根据消息类型跳转对应的列表页
const TypeToPath = (type) => {
  console.log(type);
  switch (type) {
    case 'taskpatrol':
      console.log('任务巡查');
      router.push('/PatrolList');
      break;
    case 'station':
      console.log('测站工单');
      router.push('/measuringStationList');

      break;
    case 'alarm':
      console.log('监测告警');
      router.push('/monitorList');

      break;
    case 'other':
      console.log('其他工单');

      break;

    default:
      console.log('消息通知');
      router.push('/message');
      break;
  }
};

onMounted(() => {
  getCityName(); //获取当前城市
  // onLoad();
  // getMessageCount();
});
</script>

<style lang="less" scoped>
#home_homePage {
  width: 100%;
  height: 100%;
  background: #f2f1f6;
  #HeaderBG {
    width: 100%;
    height: 410px;
    background: linear-gradient(90deg, #3d84ff 0%, #53c0fe 100%);
    box-sizing: border-box;
    padding-top: 30px;
    #HeaderTop {
      width: 100%;
      height: 160px;
      display: flex;
      flex-direction: column;
      flex-wrap: wrap;
      padding: 0 32px;
      box-sizing: border-box;
      #HeaderName {
        height: 90px;
        line-height: 120px;
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 34px;
        color: #ffffff;
        width: calc(100% - 110px);
      }
      #locationName {
        height: 70px;
        line-height: 60px;
        width: calc(100% - 110px);
        font-family: PingFang SC;
        font-weight: 500;
        font-size: 24px;
        color: #ffffff;
        white-space: nowrap; /* 不换行 */
        overflow: hidden; /* 隐藏超出部分 */
        text-overflow: ellipsis; /* 显示省略号 */
      }
      #Weather1 {
        width: 110px;
        height: 160px;
        line-height: 160px;
        text-align: center;
        font-weight: bold;
        font-size: 2rem;
        color: #ffffff;
      }
    }
    #Headerbottom {
      width: calc(100% - 60px);
      height: 130px;
      box-sizing: border-box;
      margin-left: 30px;
      border-radius: 10px;
      background: #ffffff30;
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      align-items: center;
      .Headerbottom_1 {
        width: 150px;
        height: 130px;
        background: #ffffff10;
        text-align: center;
        box-sizing: border-box;
        padding-top: 20px;
        img {
          width: 50px;
          height: 50px;
        }
        .concent_font {
          font-family: Source Han Sans CN;
          font-weight: bold;
          font-size: 20px;
          color: #ffffff;
          line-height: 30px;
          height: 40px;
          text-align: center;
        }
      }

      .Headerbottom_2,
      .Headerbottom_3 {
        width: calc(50% - 75px);
        height: 130px;
        box-sizing: border-box;
        padding-top: 25px;

        .concent_font {
          font-family: PingFang SC;
          font-weight: 500;
          font-size: 22px;
          color: #ffffff;
          line-height: 40px;
          height: 40px;
          text-align: center;
        }
      }
      .Headerbottom_2 {
        position: relative;
        &::after {
          content: '';
          display: block;
          width: 1px;
          height: 40px;
          background: #ffffff;
          position: absolute;
          right: 0;
          top: 45px;
        }
      }

      .concent1 {
        height: 50px;
        font-family: PingFang SC;
        font-weight: bold;
        font-size: 45px;
        color: #ffffff;
        line-height: 40px;
        text-align: center;
      }
    }
  }

  #CentBox {
    width: calc(100% - 60px);
    height: calc(100% - 360px);
    position: relative;
    top: -50px;
    left: 30px;
    // background: red;
    #typeBox {
      height: 190px;
      background: #ffffff;
      border-radius: 10px;
      display: flex;
      flex-direction: row;
      flex-wrap: nowrap;
      justify-content: center;
      align-items: center;
      box-shadow: 0px 5px 20px #00000066;

      .typeList {
        width: 25%;
        height: 190px;
        text-align: center;
        box-sizing: border-box;
        padding-top: 35px;
        .typeImg {
          width: 80px;
          height: 80px;
        }
        .typeFont {
          font-family: PingFang SC;
          font-size: 20px;
          color: #000000;
          line-height: 40px;
          text-align: center;
        }
      }
    }
    #listBox {
      width: 100%;
      height: calc(100% - 200px);
      overflow: auto;
      margin-top: 10px;
      // background: red;
      .ListClass {
        width: 100%;
        height: auto;
        background: #ffffff;
        border-radius: 10px;
        margin-bottom: 20px;
        .ListTop {
          width: 100%;
          height: 70px;
          box-sizing: border-box;
          border-bottom: 1px solid #eaeaea;
          font-family: PingFang SC;
          font-weight: bold;
          font-size: 28px;
          color: #566170;
          line-height: 70px;
          padding-left: 30px;
          white-space: nowrap; /* 不换行 */
          overflow: hidden; /* 隐藏超出部分 */
          text-overflow: ellipsis; /* 显示省略号 */
        }
        .ListBottom {
          width: 100%;
          height: auto;
          min-height: 120px;
          display: flex;
          flex-direction: row;
          flex-wrap: nowrap;
          .LeftFont {
            width: calc(100% - 120px);
            height: auto;

            .P1 {
              width: 100%;
              height: auto;
              min-height: 130px;
              margin: 0;
              font-family: PingFang SC;
              font-weight: 500;
              font-size: 22px;
              color: #86909c;
              box-sizing: border-box;
              padding-left: 30px;
              overflow: hidden; /* 隐藏超出部分 */
              text-overflow: ellipsis; /* 显示省略号 */
              white-space: pre-wrap;
              line-height: 40px;
            }
          }
          .rightBtn {
            width: 120px;
            box-sizing: border-box;
            padding-top: 37px;
            .Btn_Class {
              width: 100px;
              height: 46px;
              text-align: center;
              line-height: 48px;
              border-radius: 23px;
            }
            .Btn_Class1 {
              color: #5594ff;
              border: 1px solid #a8c9ff;
              background: #edf4ff;
            }
            .Btn_Class2 {
              color: #86909c;
              border: 1px solid #d2d2d2;
              background: #f0f0f0;
            }
          }
        }
      }
    }
  }
}
</style>