vue3: baidusubway using typescript

article/2025/8/12 13:41:18

项目结构:

<!--npm install -D tailwindcss-3d  BaiduSubwayMap.vue npm install -D tailwindcss postcss autoprefixer-->
<template><div class="relative w-full h-screen"><!-- 地图容器 --><div id="subway-container" class="w-full h-full"></div><!-- 缩放控制 --><div class="fixed bottom-4 right-4 flex flex-col space-y-2 z-10"><button @click="zoomIn" class="w-10 h-10 rounded-full bg-white shadow-md flex items-center justify-center hover:bg-gray-100 transition-colors"><i class="fa fa-plus text-gray-700"></i></button><button @click="zoomOut" class="w-10 h-10 rounded-full bg-white shadow-md flex items-center justify-center hover:bg-gray-100 transition-colors"><i class="fa fa-minus text-gray-700"></i></button></div><!-- 地铁图例 --><div id="legend" class="fixed top-4 right-4 max-w-xs bg-white rounded-lg shadow-lg p-4 hidden md:block z-10"><h3 class="font-medium text-gray-800 mb-3">地铁线路图例</h3><div id="legendContent" class="space-y-1 text-sm"><div v-for="line in subwayLines" :key="line.id" class="flex items-center"><span class="subway-line" :style="{ backgroundColor: line.color || '#3b82f6' }"></span><span>{{ line.name }}</span></div></div></div></div></template><script lang="ts">import { defineComponent, ref, onMounted, onUnmounted, watch} from 'vue';  //,PropTypeinterface SubwayLine {id: string;name: string;color?: string;}interface RouteStep {instruction: string;distance?: number;duration?: number;}interface RouteResult {steps: RouteStep[];distance?: number;duration?: number;}export default defineComponent({name: 'BaiduSubwayMap',props: {currentCity: {type: String,required: true},startStation: {type: String,required: true},endStation: {type: String,required: true},cityData: Object as () => Record<string, { start: string; end: string }>  //vue 3.3//Vue 3//cityData: {//type: Object as PropType<Record<string, { start: string; end: string }>>,//required: true//}},emits: ['routeFound', 'error', 'mapLoaded'],setup(props, { emit }) {const subway = ref<any>(null);const direction = ref<any>(null);const subwayLines = ref<SubwayLine[]>([]);const isMapLoaded = ref(false);// 监听城市变化watch(() => props.currentCity, async (newCity, oldCity) => {if (newCity !== oldCity) {console.log(`城市切换: ${oldCity} → ${newCity}`);await loadCitySubway(newCity);}});// 生命周期钩子onMounted(() => {initMap();});onUnmounted(() => {cleanupSubwayInstance();});// 监听城市或站点变化watch([() => props.currentCity, () => props.startStation, () => props.endStation], () => {if (isMapLoaded.value && props.startStation && props.endStation) {searchRoute();}});// 初始化地图const initMap = () => {try {// 检查百度地图API是否加载成功if (typeof BMapSub === 'undefined') {emit('error', '百度地图API加载失败,请检查API密钥是否正确');return;}// 加载当前城市的地铁地图loadCitySubway(props.currentCity);} catch (error) {console.error('初始化地图时出错:', error);emit('error', '初始化地图时出错,请刷新页面');}};// 加载指定城市的地铁地图const loadCitySubway = (cityName: string) => {// 重置地图容器const container = document.getElementById('subway-container');if (container) container.innerHTML = '';// 清理旧的地铁实例cleanupSubwayInstance();try {// 查找城市信息const city = BMapSub.SubwayCitiesList.find(c => c.name === cityName);if (!city) {emit('error', `未找到${cityName}的地铁数据,请尝试其他城市`);return;}console.log(`加载${cityName}地铁地图,城市代码: ${city.citycode}`);// 创建新的地铁实例subway.value = new BMapSub.Subway('subway-container', city.citycode);// 绑定地铁加载完成事件subway.value.addEventListener('subwayloaded', () => {console.log(`${cityName}地铁地图加载完成`);onSubwayLoaded(cityName);emit('mapLoaded', true);});// 绑定错误处理subway.value.addEventListener('subwayloaderror', onSubwayLoadError);} catch (e) {console.error('创建地铁实例时出错:', e);emit('error', `加载${cityName}地铁数据失败,请稍后再试`);}};// 地铁加载完成回调const onSubwayLoaded = (cityName: string) => {try {// 初始化路线规划direction.value = new BMapSub.Direction(subway.value);// 设置路线规划完成后的回调direction.value.addEventListener('directioncomplete', handleRouteResults);isMapLoaded.value = true;emit('mapLoaded', true);// 生成线路图例generateLineLegend();// 如果有起点和终点,执行搜索if (props.startStation && props.endStation) {searchRoute();}} catch (e) {console.error('初始化地铁地图时出错:', e);emit('error', `初始化${cityName}地铁地图失败,请稍后再试`);}};// 地铁加载错误回调const onSubwayLoadError = () => {emit('error', `加载${props.currentCity}地铁数据失败,请稍后再试`);isMapLoaded.value = false;};// 清理旧的地铁实例const cleanupSubwayInstance = () => {if (subway.value) {try {subway.value.removeEventListener('subwayloaded', onSubwayLoaded);subway.value.removeEventListener('subwayloaderror', onSubwayLoadError);// 仅在地铁已初始化且有destroy方法时尝试销毁if (isMapLoaded.value && typeof subway.value.destroy === 'function') {// 移除路线规划器的事件监听器if (direction.value) {direction.value.removeEventListener('directioncomplete', handleRouteResults);direction.value = null;}// 尝试销毁地铁实例subway.value.destroy();}} catch (e) {console.error('销毁地铁实例时出错:', e);} finally {// 无论如何都重置地铁实例和状态subway.value = null;isMapLoaded.value = false;}}};// 生成线路图例const generateLineLegend = () => {try {// 获取线路信息if (!subway.value) return;const lines = subway.value.getLines();if (lines && lines.length > 0) {// 只显示前10条线路以避免图例过长const displayLines = lines.slice(0, 10);subwayLines.value = displayLines.map(line => ({id: line.id,name: line.name,color: line.color}));}} catch (e) {console.error('生成线路图例时出错:', e);}};// 搜索路线const searchRoute = () => {if (!isMapLoaded.value || !direction.value) {emit('error', '地图加载中,请稍候再试');return;}if (!props.startStation || !props.endStation) {emit('error', '请输入起点站和终点站');return;}// 验证站点是否属于当前城市const validStations = getValidStations(props.currentCity);if (validStations && !validStations.includes(props.startStation)) {emit('error', `起点站“${props.startStation}”不存在于${props.currentCity}地铁系统中`);return;}if (validStations && !validStations.includes(props.endStation)) {emit('error', `终点站“${props.endStation}”不存在于${props.currentCity}地铁系统中`);return;}// 执行路线搜索try {direction.value.search(props.startStation, props.endStation);} catch (e) {console.error('搜索路线时出错:', e);emit('error', '搜索路线时出错,请重试');}};// 处理路线规划结果const handleRouteResults = (results: any) => {try {if (!results || results.length === 0) {emit('error', `未找到从${props.startStation}到${props.endStation}的路线,请尝试其他站点`);return;}// 选择第一条路线(通常是最优路线)const route = results[0];// 格式化路线结果const formattedRoute: RouteResult = {steps: route.steps || [],distance: route.distance,duration: route.duration};// 发送路线结果给父组件emit('routeFound', formattedRoute);} catch (e) {console.error('处理路线结果时出错:', e);emit('error', '处理路线信息时出错,请重试');}};// 地图缩放控制const zoomIn = () => {if (subway.value) {try {subway.value.setZoom(subway.value.getZoom() + 1);} catch (e) {console.error('地图缩放时出错:', e);}}};const zoomOut = () => {if (subway.value) {try {subway.value.setZoom(subway.value.getZoom() - 1);} catch (e) {console.error('地图缩放时出错:', e);}}};// 获取当前城市的有效站点列表const getValidStations = (cityName: string): string[] | null => {try {if (!subway.value) {return null;}// 获取所有线路const lines = subway.value.getLines();if (!lines || lines.length === 0) {return null;}// 收集所有站点const stations = new Set<string>();lines.forEach(line => {if (line.stations && line.stations.length > 0) {line.stations.forEach(station => {stations.add(station.name);});}});return Array.from(stations);} catch (e) {console.error('获取站点列表时出错:', e);return null;}};return {subwayLines,zoomIn,zoomOut};}});</script><style type="text/tailwindcss">@layer utilities {.subway-line {display: inline-block;width: 12px;height: 2px;margin: 0 4px;vertical-align: middle;}}</style>

<!-- SubWayView.vue -->
<template><div class="font-sans"><!-- 搜索面板 --><divv-show="panelVisible"class="fixed top-4 left-1/2 transform -translate-x-1/2 bg-white rounded-xl shadow-lg p-6 max-w-md w-full z-50 transition-all duration-300"><div class="flex justify-between items-center mb-4"><h2 class="text-xl font-bold text-gray-900">{{ panelTitle }}</h2><button@click="closePanel"class="text-gray-500 hover:text-gray-700 focus:outline-none"><i class="fa fa-times text-lg"></i></button></div><div class="space-y-4"><!-- 城市选择 --><div><label class="block text-sm font-medium text-gray-700 mb-1">城市</label><div class="relative"><inputv-model="currentCity"@input="handleCityInput"@keypress.enter="changeCity"class="w-full px-4 py-2 border rounded-lg focus:ring-blue-500 focus:border-blue-500"placeholder="请输入城市名称"/><divv-show="citySuggestions.length > 0"class="absolute left-0 right-0 top-full mt-1 bg-white rounded-lg shadow-lg z-50"><divv-for="suggestion in citySuggestions":key="suggestion"@click="selectCity(suggestion)"class="px-4 py-2 hover:bg-gray-100 cursor-pointer">{{ suggestion }}</div></div></div><div class="flex space-x-2 mt-2"><button@click="changeCity"class="flex-1 bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg shadow-md">切换城市</button><button@click="resetToDefault"class="flex-1 bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-2 px-4 rounded-lg"><i class="fa fa-refresh mr-1"></i> 重置默认</button></div></div><!-- 站点输入 --><div><div class="relative"><div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none"><i class="fa fa-map-marker text-blue-500"></i></div><inputv-model="startStation"@keypress.enter="searchRoute"class="w-full pl-10 pr-4 py-2 border rounded-lg focus:ring-blue-500 focus:border-blue-500"placeholder="请输入起点站"/><divv-show="isDefaultStartStation"class="absolute right-3 top-1/2 transform -translate-y-1/2 text-xs text-gray-400">默认</div></div><div class="relative mt-4"><div class="absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none"><i class="fa fa-flag text-red-500"></i></div><inputv-model="endStation"@keypress.enter="searchRoute"class="w-full pl-10 pr-4 py-2 border rounded-lg focus:ring-blue-500 focus:border-blue-500"placeholder="请输入终点站"/><divv-show="isDefaultEndStation"class="absolute right-3 top-1/2 transform -translate-y-1/2 text-xs text-gray-400">默认</div></div></div><!-- 查询按钮 --><button@click="searchRoute"class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-lg shadow-lg mt-4">查询路线</button><!-- 路线结果 --><div class="mt-4 bg-gray-100 rounded-lg p-4 text-sm"><div v-if="loading" class="text-gray-500 animate-pulse"><i class="fa fa-spinner fa-spin mr-1"></i> {{ loadingMessage }}</div><div v-else-if="errorMessage" class="text-red-500"><i class="fa fa-exclamation-circle mr-1"></i> {{ errorMessage }}</div><div v-else-if="routeResults"><!-- 路线展示逻辑保持不变 --><div class="bg-white rounded-lg shadow-sm p-4 mb-4"><div class="flex justify-between items-center mb-3"><h3 class="font-medium">{{ startStation }} → {{ endStation }}</h3><span class="bg-green-100 text-green-800 text-xs px-2 py-1 rounded-full"><i class="fa fa-clock-o mr-1"></i> 约{{ routeResults.duration || '未知' }}分钟</span></div><!-- 路线步骤展示 --></div></div><div v-else class="text-gray-500">请输入起点和终点,点击查询路线</div></div></div></div><!-- 显示面板按钮 --><buttonv-show="!panelVisible"@click="showPanel"class="fixed top-4 left-4 bg-white hover:bg-gray-100 text-gray-800 font-medium py-2 px-4 rounded-lg shadow-md z-50"><i class="fa fa-search mr-2"></i> 显示搜索面板</button><!-- 百度地铁地图组件 --><BaiduSubwayMap:currentCity="currentCity":startStation="startStation":endStation="endStation":cityData="cityData"@routeFound="handleRouteFound"@error="handleError"@mapLoaded="handleMapLoaded"/></div></template><script lang="ts">import { defineComponent, ref, computed, onMounted, watch } from 'vue';import BaiduSubwayMap from '../components/BaiduSubwayMap.vue';interface CityData {[city: string]: {start: string;end: string;};}export default defineComponent({name: 'SubWayView',components: {BaiduSubwayMap},setup() {// 状态管理const currentCity = ref('深圳');const startStation = ref('');const endStation = ref('');const panelVisible = ref(true);const loading = ref(false);const loadingMessage = ref('');const errorMessage = ref('');const routeResults = ref(null);const cityData = ref<CityData>({});const citySuggestions = ref<string[]>([]);const cityHistory = ref<string[]>([]); // 新增:历史记录数组const panelTitle = ref('深圳地铁线路规划');  //// 计算属性const isDefaultStartStation = computed(() => {return cityData.value[currentCity.value]?.start === startStation.value;});const isDefaultEndStation = computed(() => {return cityData.value[currentCity.value]?.end === endStation.value;});// 生命周期钩子onMounted(() => {loadCityData();loadSavedState();});// 从city.json加载城市数据const loadCityData = async () => {try {console.log('开始加载城市数据...');loading.value = true;loadingMessage.value = '正在加载城市数据...';const response = await fetch('city.json');cityData.value = await response.json();console.log('城市数据加载成功:', cityData.value);// 设置当前城市的默认站点setDefaultStations();loading.value = false;} catch (error) {console.error('加载城市数据失败:', error);errorMessage.value = '加载城市数据失败,请稍后再试';loading.value = false;}};// 加载保存的状态const loadSavedState = () => {try {const savedState = localStorage.getItem('subwayMapState');if (savedState) {const parsedState = JSON.parse(savedState);// 恢复当前城市if (parsedState.currentCity && cityData.value[parsedState.currentCity]) {currentCity.value = parsedState.currentCity;panelTitle.value = `${currentCity.value}地铁线路规划`;}// 恢复站点if (parsedState.startStation) {startStation.value = parsedState.startStation;}if (parsedState.endStation) {endStation.value = parsedState.endStation;}// 恢复面板可见性if (typeof parsedState.panelVisible === 'boolean') {panelVisible.value = parsedState.panelVisible;}console.log('从本地存储恢复状态:', parsedState);}} catch (e) {console.error('恢复应用状态失败:', e);}};// 保存当前状态到本地存储const saveState = () => {try {const stateToSave = {currentCity: currentCity.value,startStation: startStation.value,endStation: endStation.value,panelVisible: panelVisible.value};localStorage.setItem('subwayMapState', JSON.stringify(stateToSave));} catch (e) {console.error('保存应用状态失败:', e);}};// 设置当前城市的默认站点const setDefaultStations = () => {const defaultStations = cityData.value[currentCity.value];if (defaultStations) {// 只有在站点为空时设置默认值,保留用户修改if (!startStation.value) {startStation.value = defaultStations.start;}if (!endStation.value) {endStation.value = defaultStations.end;}}   };// 切换城市const changeCity = () => {console.log(`点击:选择城市...`);const cityName1 = currentCity.value.trim();console.log(`点击:选择城市${cityName1}`);    const defaultStations = cityData.value[currentCity.value];if (defaultStations) {startStation.value = defaultStations.start;endStation.value = defaultStations.end;panelTitle.value = `${currentCity.value}地铁线路规划`;// 保存状态saveState();}        // 清除错误消息errorMessage.value = null;};// 处理城市输入const handleCityInput = () => {const query = currentCity.value.trim().toLowerCase();if (query.length < 2) {citySuggestions.value = [];return;}// 检查输入的城市是否有效(存在于cityData中)const isValidCity = cityData.value[query];if (isValidCity && !cityHistory.value.includes(query)) {// 添加到历史记录(去重)cityHistory.value.push(query);}//const allCities = [...new Set([...Object.keys(cityData.value), ...cityHistory.value])];const matchedCities = allCities.filter(city => city.toLowerCase().includes(query));// 过滤匹配的城市//const matchedCities = Object.keys(cityData.value).filter(city =>//city.toLowerCase().includes(query)//);// 更新建议列表citySuggestions.value = matchedCities;};// 选择城市const selectCity = (cityName: string) => {currentCity.value = cityName;console.log(`换了地图:选择城市${cityName}`);      //setDefaultStations(); // 强制设置默认站点// itySuggestions.value = [];if (!cityHistory.value.includes(cityName)) {cityHistory.value.push(cityName);}//citySuggestions.value = [];const defaultStations = cityData.value[currentCity.value];if (defaultStations) {startStation.value = defaultStations.start;endStation.value = defaultStations.end;panelTitle.value = `${currentCity.value}地铁线路规划`;// 保存状态saveState();}};// 搜索路线const searchRoute = () => {if (!startStation.value || !endStation.value) {errorMessage.value = '请输入起点站和终点站';return;}// 保存当前状态saveState();// 清空错误消息//errorMessage.value = null;};// 处理路线结果const handleRouteFound = (results: any) => {routeResults.value = results;loading.value = false;// 保存当前状态saveState();};// 处理错误const handleError = (message: string) => {errorMessage.value = message;loading.value = false;};// 处理地图加载完成const handleMapLoaded = () => {loading.value = false;};// 关闭面板const closePanel = () => {panelVisible.value = false;saveState();};// 显示面板const showPanel = () => {panelVisible.value = true;saveState();};// 重置为默认值const resetToDefault = () => {const defaultStations = cityData.value[currentCity.value];if (defaultStations) {startStation.value = defaultStations.start;endStation.value = defaultStations.end;panelTitle.value = `${currentCity.value}地铁线路规划`;// 保存状态saveState();}};// 监听面板可见性变化watch(panelVisible, () => {saveState();});// 监听站点变化watch([startStation, endStation], () => {saveState();});return {currentCity,startStation,endStation,panelVisible,loading,loadingMessage,errorMessage,routeResults,cityData,citySuggestions,panelTitle,isDefaultStartStation,isDefaultEndStation,changeCity,handleCityInput,selectCity,searchRoute,closePanel,showPanel,resetToDefault,handleRouteFound, // 确保将方法添加到返回对象中handleError,handleMapLoaded};}});</script><style scoped>/* 优化字体和间距 */@tailwind base;@tailwind components;@tailwind utilities;/* 修复搜索面板层级问题 */.z-50 {z-index: 50;}</style>

输出:


http://www.hkcw.cn/article/soDqiHVOMA.shtml

相关文章

【递归、搜索与回溯】专题二、二叉树中的深搜

文章目录 1.计算布尔二叉树的值1.1 题目1.2 思路1.3 代码 2.求根节点到叶节点数字之和2.1 题目2.2 思路2.3 代码 3.二叉树剪枝3.1 题目3.2 思路3.3 代码 4.验证二叉搜索树4.1 题目4.2 思路4.3 代码 5.二叉搜索树中第K小的元素5.1 题目5.2 思路5.3 代码 6.二叉树的所有路径6.1 题…

Windows商店中的免费扫雷游戏应用

《扫雷》是一款经典的单人益智小游戏&#xff0c;1992年微软发布的Windows 3.1中加入该游戏&#xff0c;从此风靡全世界。游戏目标是通过逻辑推理&#xff0c;在最短的时间内根据点击格子出现的数字找出所有非雷格子&#xff0c;同时避免踩雷。 此Windows应用实现了经典扫雷的…

无法运用pytorch环境、改环境路径、隔离环境

一.未建虚拟环境时 1.创建新项目后&#xff0c;直接运行是这样的。 2.设置中Virtualenv找不到pytorch环境&#xff1f;因为此时没有创建新虚拟环境。 3.选择conda环境&#xff08;全局环境&#xff09;时&#xff0c;是可以下载环境的。 运行结果如下&#xff1a; 是全局环境…

古老的传说(Player、Stage)是否还能在蓝桥云课ROS中重现-250601(失败)

古老的传说是否还能在蓝桥云课ROS中重现-250601 经典复现何其难&#xff0c;百分之二就凉凉&#xff01; 古老的传说 那是很久很久以前的故事……上个世纪的一个机器人项目 Player、Stage这个项目最早起源于1999年&#xff0c;由美国南加州大学机器人研究实验室开发&#xff0…

机器学习:逻辑回归与混淆矩阵

本文目录&#xff1a; 一、逻辑回归Logistic Regression二、混淆矩阵&#xff08;一&#xff09;精确率precision&#xff08;二&#xff09;召回率recall&#xff08;三&#xff09;F1-score&#xff1a;了解评估方向的综合预测能力&#xff08;四&#xff09;Roc曲线&#xf…

Spring是如何实现属性占位符解析

Spring属性占位符解析 核心实现思路1️⃣ 定义占位符处理器类2️⃣ 处理 BeanDefinition 中的属性3️⃣ 替换具体的占位符4️⃣ 加载配置文件5️⃣ Getter / Setter 方法 源码见&#xff1a;mini-spring 在使用 Spring 框架开发过程中&#xff0c;为了实现配置的灵活性&#xf…

继承与多态

继承与多态的分析 继承继承与访问限定比较派生类和基类关系派生类的构造顺序基类对象&#xff08;指针&#xff09;派生类对象&#xff08;指针&#xff09;的转换重载和隐藏 虚函数静态绑定与动态绑定指针调用其他调用的绑定方式虚函数实现的依赖 多态 继承 继承的本质&#…

API异常信息如何实时发送到钉钉

#背景 对于一些重要的API&#xff0c;开发人员会非常关注API有没有报错&#xff0c;为了方便开发人员第一时间获取错误信息&#xff0c;我们可以使用插件来将API报错实时发送到钉钉群。 接下来我们就来实操如何实现 #准备工作 #创建钉钉群 如果已有钉钉群&#xff0c;可以跳…

Amazon GameLift实战指南:低成本构建高并发全球游戏服务器架构

一、为什么游戏服务器需要GameLift&#xff1f; 行业痛点 传统自建服务器&#xff1a;扩容慢、DDoS防御弱、全球延迟不均 开源解决方案&#xff08;如Agones&#xff09;&#xff1a;运维成本高、需K8s深度知识 云虚拟机手动扩缩容&#xff1a;响应延迟导致玩家流失 GameLi…

2025安装与配置archlinux很详细

不知不觉&#xff0c;距离上次安装archlinux已经2年多了。我又打算把archlinux作为主力机使用了。 以前也写过一些类似的文章&#xff0c;有一些不变的内容&#xff0c;我直接从原来的文章中复制了&#xff08;包括截图&#xff09;。 《2021年vmware安装archlinux》 https:/…

字节golang后端二面

前端接口使用restful格式&#xff0c;post与get的区别是什么&#xff1f; HTTP网络返回的状态码有哪些&#xff1f; go语言切片与数组的区别是什么&#xff1f; MySQL实现并发安全避免两个事务同时对一个记录写操作的手段有哪些&#xff1f; 如何实现业务的幂等性&#xff08;在…

MyBatis03——SpringBoot整合MyBatis

目录 一、springboot整合mybatis 二、搭建环境 1、引入jar包 2、配置文件 3、准备控制层、业务层、持久层 4、SQLMapper文件 ​编辑 三、动态sql 四、分页 4.1逻辑分页 4.2物理分页 4.2.1引入分页插件在pom.xml 4.2.2使用分页插件 五、事务 编程式事务 声明式事…

【linux】知识梳理

操作系统的分类 1. 桌⾯操作系统: Windows/macOS/Linux 2. 移动端操作系统: Android(安卓)/iOS(苹果) 3. 服务器操作系统: Linux/Windows Server 4. 嵌⼊式操作系统: Android(底层是 Linux) Liunx介绍 liunx系统:服务器端最常见的操作系统类型 发行版:Centos和Ubuntu 远程连接操…

计算机网络第1章(上):网络组成与三种交换方式全解析

目录 一、计算机网络的概念二、计算机网络的组成和功能2.1 计算机网络的组成2.2 计算机网络的功能 三、电路交换、报文交换、分组交换3.1 电路交换&#xff08;Circuit Switching&#xff09;3.2 报文交换&#xff08;Message Switching&#xff09;3.3 分组交换&#xff08;Pa…

经典面试题:一文了解常见的缓存问题

在面试过程中&#xff0c;面试官的桌子上摆放着很多高频的面试题&#xff0c;能否顺利回答决定了你面试通过的概率。其中缓存问题就是其中的一份&#xff0c;可以说掌握缓存问题及解决方法是面试前必须准备的内容。那么缓存有什么典型的问题&#xff0c;出现的原因是什么&#…

Python Turtle实战:打造高精度图形化秒表

&#x1f49d;&#x1f49d;&#x1f49d;欢迎莅临我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐&#xff1a;「storms…

Python实现P-PSO优化算法优化卷积神经网络CNN回归模型项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档&#xff09;&#xff0c;如需数据代码文档可以直接到文章最后关注获取。 1.项目背景 随着人工智能和深度学习技术的快速发展&#xff0c;卷积神经网络&#xff08;CNN&#xff09;在图像分类、目标检测…

OVD开放词汇检测 Detic 训练COCO数据集实践

0、引言 纯视觉检测当前研究基本比较饱和&#xff0c;继续创新提升空间很小&#xff0c;除非在CNN和transformer上提出更强基础建模方式。和文本结合是当前的一大趋势&#xff0c;也是计算机视觉和自然语言处理结合的未来趋势&#xff0c;目前和文本结合的目标检测工作还是有很…

leetcode0404. 左叶子之和-easy

1 题目&#xff1a;左叶子之和 官方标定难度&#xff1a;易 给定二叉树的根节点 root &#xff0c;返回所有左叶子之和。 示例 1&#xff1a; 输入: root [3,9,20,null,null,15,7] 输出: 24 解释: 在这个二叉树中&#xff0c;有两个左叶子&#xff0c;分别是 9 和 15&#…

PINNs案例——二维磁场计算

基于物理信息的神经网络是一种解决偏微分方程计算问题的全新方法… 有关PINN基础详见&#xff1a;PINNs案例——中心热源温度场预测问题的torch代码 今日分享代码案例&#xff1a;二维带电流源磁场计算 该案例参考学习论文&#xff1a;[1]张宇娇&#xff0c;孙宏达&#xff0…