vue3+ts(<script setup lang=“ts“>)刷新页面后保持下拉框选中效果

news2024/9/22 19:22:18

效果图:

 

代码: 

<template>
  <div class="app-layout">
    <div class="app-box">
      <div class="header">
        <div class="header-left"></div>
        <div class="title">室外智能健身房数据中心</div>
        <div class="header-right">
          <p class="p2">
            <i class="iconfont icon-home_icon_position"></i>
            {{ curInfo.siteName }}
            <div class="dropdown-box">
              <img
                src="~@/assets/images/icon/drop_down.png"
                @click="isOpen = !isOpen"
                alt=""
              />
              <div class="dropdown-cont">
                <transition name="fade">
                  <div v-if="isOpen" class="dropdown">
                    <div class="dropdown-item" :class="{activeMenu:index === menuIdx}"  v-for="(item,index) in menuList" :key="index" @click="changeMenu(index,item.path)">{{ item.name }}</div>
                  </div>
                </transition>
            </div>
          </div>
          </p>
        </div>
      </div>
      <div class="main-container">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, onUnmounted,onMounted, ref } from "vue";
import * as dayjs from "dayjs";
import { getUrlKey } from "@/utils";
import axios from "axios";
import { useRouter,useRoute  } from "vue-router";
const router = useRouter();
const route = useRoute();
const menuList = [
  { name: '首页', path: '/chartApp/home' },
  { name: '查看运动记录', path: '/chartApp/sportsList' },
  { name: '用户管理', path: '/chartApp/userList' },
]
const menuIdx = ref(0);
let curInfo = reactive({
  deviceNo: "",
  time: "2023-00-00 00:00:00",
  // 天气
  weather: "",
  temperature: "",
  // 空气质量
  aqi: "",
  category: "",
  weekday: "",
  siteName: "中国航发北京航空材料研究院",
  cityName: "",
});
const isOpen = ref(false);//下拉框
let curTimer = null;
const getCurTime = () => {
  curTimer = setTimeout(() => {
    curInfo.time = dayjs().format("YYYY-MM-DD HH:mm:ss");
    getCurTime();
  }, 1000);
};

const wKEY = "ef38ffd9e9804ae77f5f9342ca2c3975";
let weatherTimer = null;
const getWeather = (adcode: string) => {
  axios
    .get(
      `https://restapi.amap.com/v3/weather/weatherInfo?key=${wKEY}&city=${adcode}`
    )
    .then((res3) => {
      let resultTq = res3.data;
      if (resultTq.lives[0].weather) {
        curInfo.weather = resultTq.lives[0].weather;
        curInfo.temperature = resultTq.lives[0].temperature;
      }
    });
  weatherTimer = setTimeout(() => {
    getWeather(adcode);
  }, 1000 * 60 * 15);
};
// 获取天气
const getWeatherData = () => {
  axios
    .get(
      `https://restapi.amap.com/v3/config/district?keywords=${curInfo.cityName}&key=${wKEY}`
    )
    .then((res) => {
      let result = res.data;
      if (result?.districts[0].adcode) {
        // 此处需轮询 每15分钟获取一次
        getWeather(result?.districts[0].adcode);
      }
    });
};
// 获取天气质量
const getCategoryData = () => {
  const KEY = "a815396d62d043a2bd19395d35997d49";
  axios
    .get(
      `https://geoapi.qweather.com/v2/city/lookup?location=${curInfo.cityName}&key=${KEY}&number=1`
    )
    .then((res) => {
      let result = res.data;

      if (result?.location[0].id) {
        // 当天获取一次
        axios
          .get(
            `https://devapi.qweather.com/v7/air/now?key=${KEY}&location=${result?.location[0].id}`
          )
          .then((res3) => {
            let resultObj = res3.data?.now;
            curInfo.aqi = resultObj.aqi;
            curInfo.category = resultObj.category;
          });
      }
    });
};
// 查看运动记录
const changeMenu = (index, path) => {
  menuIdx.value = index;
  router.push(path);
  isOpen.value = false;
}

const initLayout = () => {
  // 优点取url 设备号
  if (getUrlKey("dNo")) {
    localStorage.setItem(
      "DEVICE_NO",
      JSON.stringify({
        devNo: getUrlKey("dNo"),
      })
    );
  }
  curInfo.deviceNo = JSON.parse(localStorage.getItem("DEVICE_NO"))?.devNo;
  getCurTime();
};
initLayout();
onMounted(() => {
  // 刷新页面保持下拉框选择效果
  switch (route.name) {
    case "home":
      menuIdx.value = 0;
      break;
    case "userList":
      menuIdx.value = 2;
      break;
    case "sportsList":
      menuIdx.value = 1;
      break;
    default:
      menuIdx.value = 0;
      break;
  }
});
// 销毁
onUnmounted(() => {
  clearTimeout(curTimer);
  clearTimeout(weatherTimer);
  curTimer = null;
  weatherTimer = null;
});
</script>
<style lang="scss" scoped>
.app-layout {
  position: relative;
  padding: 30px;
  width: 100vw;
  min-height: 100vh;
  overflow: hidden;
  background: url("@/assets/images/back/them_bg.png") no-repeat;
  background-size: 100% 100%;
  color: #d3ffff;
  font-family: PingFang SC, PingFang SC-Medium;
  scrollbar-width: none; 
  height: 0;
  overflow-y: scroll;
}
.app-layout::-webkit-scrollbar {
        /*滚动条整体样式*/
        width: 0 !important;
     
      }
      .app-layout::-webkit-scrollbar-thumb {
        /*滚动条里面小方块*/
        width: 0 !important;
        
      }
.app-box {
  width: 100%;
  height: auto;
  border: 1px solid #005989;
  border-radius: 30px;
  box-shadow: 0px 0px 8px 0px #004789 inset;
}
.header {
  display: flex;
  width: 100%;
  height: 86px;
  background: url("@/assets/images/back/heard.png") no-repeat;
  background-size: 100% 100%;
  .title {
    padding-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 550px;
    height: 100%;
    font-family: PingFang SC, PingFang SC-Bold;
    font-size: 30px;
    font-weight: 700;
    text-align: CENTER;
    line-height: 42px;
    letter-spacing: 6px;
  }
  .header-left,
  .header-right {
    padding: 20px 0 10px 0;
    width: 655px;
    height: 100%;

    display: flex;
    align-items: center;
    justify-content: center;
  }
  .header-left {
    .p1 {
      margin-bottom: 6px;
      padding-left: 124px;
      font-size: 18px;
    }
    .p2 {
      text-align: right;
      padding-right: 30px;
      font-size: 20px;
      .tq-one {
        margin-right: 24px;
      }
      .iconfont {
        margin: 0 3px;
        font-size: 22px;
      }
    }
  }
  .score {
    display: inline-block;
    vertical-align: top;
    margin-top: 1px;
    margin-left: 8px;
    padding: 2px 4px;
    font-size: 15px;
    color: #ffffff;
    border-radius: 2px;
  }
  .bg-color1 {
    background: #29cd94;
  }
  .bg-color2 {
    background: #f7d631;
  }
  .bg-color3 {
    background: #ff9933;
  }
  .bg-color4 {
    background: #ff2626;
  }
  .bg-color5 {
    background: #b133ff;
  }
  .bg-color6 {
    background: #b21b1b;
  }
  .header-right {
    .p1 {
      margin-bottom: 6px;
      text-align: right;
      padding-right: 124px;
      font-size: 14px;
      span {
        padding: 2px 10px;
        background: rgba(112, 217, 250, 0.1);
        border: 1px solid rgba(77, 243, 243, 0.3);
        border-radius: 12px;
        box-shadow: 0px 0px 8px 0px #004789 inset;
      }
    }
    .p2 {
      display: flex;
      align-items: center;
      font-size: 18px;
      .dropdown-box{
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: flex-start;
        margin-left: 30px;
        position: relative;
        .dropdown-cont{
          position: absolute;
          left: 0;
          top: 0.14rem;
          z-index: 9999;
        }
        .dropdown{
          white-space: nowrap;
          background: rgba(18,60,92,0.60);
          border: 1px solid #005989;
          box-shadow: 0px 0px 8px 0px #004789 inset; 
          padding: 0.08rem 0.1rem;
          font-size: 0.0938rem;
          .dropdown-item{
            cursor: pointer;
          }
          .dropdown-item:not(:last-child){
           margin-bottom: 0.06rem;
          }
          .activeMenu{
            color: rgb(53, 204, 151);
            font-weight: 700;
          }
        }
      }
      .iconfont {
        font-size: 20px;
        margin-right: 10px;
      }
      img {
        width: 20px;
        height: 20px;
        cursor: pointer;
      }
    }
  }
}
.main-container {
  position: relative;
  padding: 30px;
  width: 100%;
  box-sizing: border-box;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1678594.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

K8s 二进制部署 上篇

一 K8S按装部署方式&#xff1a; ① Minikube Minikube是一个工具&#xff0c;可以在本地快速运行一个单节点微型K8S&#xff0c;仅用于学习、预览K8S的一些特 性使用。 部署地址&#xff1a;https://kubernetes.io/docs/setup/minikube ② Kubeadmin Kubeadmin也是一个工…

简单聊聊分布式和集群

前言 分布式和集群&#xff0c;我们都听的比较多&#xff0c;分布式系统和集群的概念对于刚进入职场的小伙伴可能不是很清楚&#xff0c;这篇文章我们就一起看看两者到底是什么&#xff0c;有什么区别。 什么是分布式系统&#xff1f; 先看下书面解释&#xff1a; 分布式系统…

【easyX】动手轻松掌握easyX 1

01 简单绘图 在这个程序中&#xff0c;我们先初始化绘图窗口。其次&#xff0c;简单绘制两条线。 #include <graphics.h>//绘图库头文件 #include <stdio.h> int main() {initgraph(640, 480);//初始化640✖480绘图屏幕line(200, 240, 440, 240);//画线(200,240)…

英语单词量测试

网址&#xff1a;https://preply.com/en/learn/english/test-your-vocab 测试结果&#xff1a; 细节&#xff1a;英语母语者有20000-35000个单词的词汇量&#xff0c;8岁孩子的词汇量在8000个左右。而不是我们教育系统里说的&#xff0c;6000个单词足够用了。足够用&#xff0…

你写HTML的时候,会注重语义化吗?

其实说到语义化&#xff0c;多年前端开发经验的老手估计也不会太在意&#xff0c;有时候工期太紧&#xff0c;有时候自己疏忽&#xff0c;也就不那么在意了&#xff0c;直接DIVCSS一把梭下去了。 目录 什么是HTML 什么是HTML语义化 HTML语义化所带来的好处 我把CSS样式引入…

如何在 Linux 上检查 CPU 和硬盘温度

为了更好地监测您的Linux系统的硬件健康状况&#xff0c;如CPU与硬盘温度、风扇转速等关键指标&#xff0c;采用lm_sensors与hddtemp这两款强大工具是明智之选。以下是关于这些工具的详尽指南&#xff0c;包括它们的功能介绍、安装步骤以及如何配置lm_sensors&#xff0c;旨在为…

在Ubuntu22.04搭建xfce远程桌面

由于Ubuntu22.04云服务器&#xff08;带GPU&#xff09;只开放部分端口&#xff0c;某些服务&#xff08;如nacos&#xff09;有Web前端需要访问&#xff0c;但是相应的端口并没有开放&#xff0c;只有SSH端口可以使用。于是&#xff0c;就在Ubuntu22.04上安装xfce桌面环境&…

企业为什么进行大数据迁移以及注意事项

在当今数字化时代&#xff0c;数据的迁移成为了企业优化其数据架构、提高数据处理能力、确保业务连续性和数据安全的关键步骤。企业可能出于多种原因&#xff0c;如成本效益、性能提升、系统升级、数据集中管理或云服务集成等&#xff0c;选择将数据从一个存储系统迁移到另一个…

3-3 基于RYU的流量风暴事件原理与响应策略

在传统网络中&#xff0c;存在着一定的广播流量&#xff0c;占据了一部分的网络带宽。同时&#xff0c;在有环的拓扑中&#xff0c;如果不运行某些协议&#xff0c;广播数据还会引起网络风暴&#xff0c;使网络瘫痪。 如有以下的一个网络拓扑结构&#xff08;3_2_topoplus.py) …

素数筛详解c++

一、埃式筛法 代码 二、线性筛法&#xff08;欧拉筛法&#xff09; 主要的思想就是一个质数的倍数(倍数为1除外)肯定是合数&#xff0c;那么我们利用这个质数算出合数&#xff0c;然后划掉这个合数&#xff0c;下次就可以不用判断它是不是质数&#xff0c;节省了大量的时间。 …

python使用opencv实现手势识别并控制ppt

需要使用到的包 from collections import dequeimport cv2 import numpy as np import math import shutilimport sys import os import time#这个求出现频率最高的太慢了&#xff0c;所以把它放弃了 from collections import Counter准备好安装包后需要获取图片 def star():…

解决找不到msvcr100.dll,无法继续执行代码的5种方案

当你在使用电脑过程中&#xff0c;系统突然弹出一个提示框&#xff0c;显示“找不到msvcr100.dll&#xff0c;无法继续执行代码”&#xff0c;msvcr100.dll是Microsoft Visual C Redistributable Package的一部分&#xff0c;它是一个至关重要的动态链接库文件&#xff0c;许多…

从零入门激光SLAM(十六)——卡尔曼滤波基础

一、卡尔曼滤波简介KF 卡尔曼滤波器&#xff08;Kalman Filter&#xff09;是一种用于估计动态系统状态的递归算法。它通过结合系统的动态模型和噪声观测数据&#xff0c;提供对系统状态的最优估计。卡尔曼滤波器广泛应用于信号处理、控制系统、导航、计算机视觉等领域。 卡尔…

视频智能检测AI智能分析网关V4告警消息推送:公众号消息推送的配置步骤介绍

TSINGSEE青犀智能分析网关V4属于高性能、低功耗的软硬一体AI边缘计算硬件设备&#xff0c;目前拥有3种型号&#xff08;8路/16路/32路&#xff09;&#xff0c;支持Caffe/DarkNet/TensorFlow/PyTorch/MXNet/ONNX/PaddlePaddle等主流深度学习框架。硬件内部署了近40种AI算法模型…

极越07来了, 要把特斯拉ModelS 拉下马?

文 | AUTO芯球 作者 | 雷慢 喵了个咪的&#xff01;国内智能驾驶汽车圈下半年要杀出个大黑马&#xff0c; 它就是极越07&#xff01; 自北京车展亮相引起央视报道之后&#xff0c;工信部近日公式了它的产品信息&#xff0c; 这意味着&#xff0c;极越07真的要量产了&#…

国内用户如何免费抢先体验GPT-4o(国内如何免费使用各类GPT产品,包含chatgpt、claude、Gemini等)

文章目录 📖 介绍 📖🏡 演示环境 🏡📒 GPT-4o抢先体验 📒📝 方法介绍🎈 永久免费🎈 其他工具⚓️ 相关链接 ⚓️📖 介绍 📖 “OpenAI的最新突破——GPT-4o已经到来,国内用户如何免费体验这一AI革命性产品?” 随着OpenAI的GPT-4o模型的发布,全球AI领域…

搭建Prometheus+grafana监控系统

1. 项目目标 &#xff08;1&#xff09;熟练部署安装node_exporter &#xff08;2&#xff09;熟练部署安装prometheus &#xff08;3&#xff09;熟练部署安装grafana 2. 项目准备 2.1. 规划节点 主机名 主机IP 节点规划 prometheus-server 10.0.1.10 server prome…

怎么批量下载视频?DY视频爬虫在线提取采集工具

短视频批量下载工具&#xff0c;具有多种模块和功能&#xff0c;方便用户快速批量下载短视频。该软件的详细介绍&#xff1a; 功能模块介绍&#xff1a; 一. 搜索词批量搜索下载 视频关键词添加&#xff1a;支持添加多个视频关键词Q530269148进行全平台视频搜索。历史去重&a…

STM32最小系统

组件描述主控芯片STM32F103C8T6等时钟源外部晶体振荡器或者陶瓷谐振器&#xff0c;通常在4MHz到25MHz之间复位电路包括复位按钮和复位电路&#xff0c;用于将单片机置于初始状态电源电路提供稳定的电压&#xff0c;通常为3.3V或5V编程/调试接口SWD接口或JTAG接口等&#xff0c;…

继承,多态,封装以及对象的打印

前言&#xff1a; 我们都知道Java是一种面向对象的编程语言&#xff0c;面向对象语言的三大特性就是继承&#xff0c;多态&#xff0c;封装&#xff0c;而这些特性正好的Java基础的一个主体内容。在学到这之前&#xff0c;我们肯定已经学习过了类和对象&#xff0c;所以这部分…