词云组件

news/2025/10/1 13:58:53/文章来源:https://www.cnblogs.com/shuihanxiao/p/19122405

效果图:

image

 

组件代码:

<template><div class="post"><div class="portal-title flex-h justify-between"><div class="flex-h"><img class="icon" :src="iconSrc" alt="" /><div class="name">{{ title }}</div></div></div><!-- 顶部词云 --><div class="data-container"><div v-for="(item, index) in dataItems" :key="index" class="data-item" :style="getItemStyle(index)"><img v-if="index < 3" :src="getCrownIcon(index)" alt="icon" class="crown-icon" /><span>{{ item.postName }}</span></div></div></div>
</template><script lang="ts" name="" setup>
import { ref, onMounted, watch } from "vue";
// 获取皇冠图标的路径
// 1
const goldIcon = "https:///word-icon1.png";
//2
const silverIcon = "https:///word-icon2.png";
// 3
const bronzeIcon = "https:///word-icon3.png";const getCrownIcon = (index: number): string => {switch (index) {case 0:return goldIcon;case 1:return silverIcon;case 2:return bronzeIcon;default:return "";}
};
// 定义父组件传递的 props
const props = defineProps({// 组件标题
  title: {type: String,default: "三维师像矩阵",},// 标题图标
  iconSrc: {type: String,default: "https:///mine/icon-threed.png",},dataSource: {type: Array,required: true,default: () => [],},
});const dataItems = ref<any>([]);const updateDataItems = (dataSource: any) => {// 遍历从后端返回的 data,提取 `postName` 和 `enrollmentCount`const newData = dataSource.map((item: any) => ({postName: item.postName,enrollmentCount: item.enrollmentCount,}));newData.sort((a: any, b: any) => Number(b.enrollmentCount) - Number(a.enrollmentCount));// 将新的数据赋值给 `dataItems`dataItems.value = newData;
};
// 监听 dataSource 变化
watch(() => props.dataSource,(newdataSource) => {if (newdataSource && Array.isArray(newdataSource)) {updateDataItems(newdataSource);}},{ immediate: true }, // 立即执行
);onMounted(() => {// 确保 props.dataSource 中的数据已经传递过来if (props.dataSource && Array.isArray(props.dataSource)) {updateDataItems(props.dataSource);}
});
/// 用于存储已生成的数据项位置,避免重叠
const positions: { top: number; left: number }[] = [{ top: 24, left: 38 },{ top: 46, left: 26 },{ top: 55, left: 59 },{ top: 3, left: 54 },{ top: 14, left: 75 },{ top: 40, left: 74 },{ top: 80, left: 69 },{ top: 75, left: 42 },{ top: 80, left: 7 },{ top: 64, left: 15 },{ top: 33, left: 2 },{ top: 12, left: 17 },
];
// 检查两个位置是否重叠(阈值调整为更大,确保不会重叠)
const isOverlap = (top: number, left: number) => {const threshold = 19; // 允许的最小距离阈值,单位:百分比return positions.some((pos) => Math.abs(pos.top - top) < threshold && Math.abs(pos.left - left) < threshold);
};// 递归生成不重叠的随机位置
const generateRandomPosition = (): { top: number; left: number } => {const topValue = Math.random() * 80;const leftValue = -1 + Math.random() * 85;// 检查是否重叠if (isOverlap(topValue, leftValue)) {return generateRandomPosition(); // 如果重叠,重新生成位置
  }// 不重叠则存储位置
  positions.push({ top: topValue, left: leftValue });return { top: topValue, left: leftValue };
};
//背景随机
// const bg = [
//   "https:///word-bg1.png",
//   "https:///word-bg2.png",
//   "https:///word-bg3.png",
//   "https:///word-bg4.png",
// ]
// const colorsList = ["#738FF7", "#F06B7F", "#45C1C0","#59BAF6"];
// 背景图和文字颜色的对应组合
const bgColorCombinations = [{bg: "https:///word-bg1.png",color: "#738FF7",},{bg: "https:///word-bg2.png",color: "#F06B7F",},{bg: "https:///word-bg3.png",color: "#45C1C0",},{bg: "https:///word-bg4.png",color: "#59BAF6",},
];
// 随机选择一个背景组合
const getRandomBgColor = () => {return bgColorCombinations[Math.floor(Math.random() * bgColorCombinations.length)];
};// 根据排名动态生成样式
const getItemStyle = (index: number): any => {// // 随机取一个背景图// const randomBg = bg[Math.floor(Math.random() * bg.length)];// // 随机取一个文字颜色// const randomColor = colorsList[Math.floor(Math.random() * colorsList.length)];// 随机选择一个背景组合const { bg, color } = getRandomBgColor();const baseStyle: any = {fontWeight: "normal",fontSize: "14px",padding: "6px 24px 4px",// backgroundImage: "url('@/assets/pic/backup.png')",
    backgroundImage: `url(${bg})`,backgroundSize: "cover",backgroundRepeat: "no-repeat",color: color, // 随机文字颜色display: "flex",alignItems: "center",justifyContent: "center",whiteSpace: "nowrap", // 防止文本换行position: "absolute",};// 动态生成位置
  let positionStyle: any;switch (index) {case 0:positionStyle = { top: "24%", left: "38%" };break;case 1:positionStyle = { top: "46%", left: "26%" };break;case 2:positionStyle = { top: "55%", left: "59%" };break;case 3:positionStyle = { top: "3%", left: "54%" };break;case 4:positionStyle = { top: "14%", left: "75%" };break;case 5:// positionStyle = { top: "40%", left: "74%" };positionStyle = { top: "12%", left: "17%" };break;case 6:positionStyle = { top: "80%", left: "69%" };break;case 7:positionStyle = { top: "75%", left: "42%" };break;case 8:positionStyle = { top: "80%", left: "7%" };break;case 9:// positionStyle = { top: "64%", left: "15%" };positionStyle = { top: "33%", left: "2%" };break;case 10:positionStyle = { top: "33%", left: "2%" };break;case 11:positionStyle = { top: "12%", left: "17%" };break;default:const { top, left } = generateRandomPosition(); // 生成不重叠的随机位置positionStyle = { top: `${top}%`, left: `${left}%` };break;}// 动态设置背景图,前三名使用不同的背景// const backgroundImage =//   index < 3//     ? `url(${new URL("@/assets/pic/backup2.png", import.meta.url)})`//     : `url(${new URL("@/assets/pic/backup.png", import.meta.url)})`;return {...baseStyle,// backgroundImage,//前三不同背景时启用// fontWeight: index < 3 ? "bold" : "normal",// backgroundSize: index < 3 ? "cover" : "contain",//前三背景图// fontSize: index === 0 ? "17px" : index === 1 ? "16px" : index === 2 ? "15px" : "14px", //不同大小fontSize: "14px", //统一大小padding: index === 0 ? "7px 15px 8px" : index === 1 ? "7px 12px 7px" : index === 2 ? "8px 12px 8px" : "11px 24px 11px",...positionStyle,};
};
</script><style lang="scss" scoped>
.post {position: relative;width: 100%;height: 260px;margin: 0 auto;padding: 12px 16px;margin-bottom: 55px;
}
.portal-title {.icon {width: 30px;height: 30px;margin-right: 8px;}.name {font-weight: 600;font-size: 16px;line-height: 24px;text-align: left;color: var(--theme-font-color);}
}.post-box-background {position: absolute;width: 100%;height: 100%;border-radius: 50%;top: 0;left: 0;transform: translate(-50%, -50%);z-index: 0;
}.data-container {position: absolute;width: 95%;height: 100%;z-index: 1;
}.data-item {text-align: center;padding: 6px 24px 4px;z-index: 1;white-space: nowrap;line-height: 1;letter-spacing: 2px;min-width: 100px;
}
span {letter-spacing: 1px;font-family: PingFang SC, PingFang SC;
}
.crown-icon {width: 20px;height: 20px;margin-right: 3px;
}
</style>

父组件使用:

  <BsyWordCloud:dataSource="dataSource"/> <script setup lang="ts">const dataSource=[{postName:'鞠躬尽瘁1'},{postName:'循循善诱2'},{postName:'良师益友3'},{postName:'最美教师4'},{postName:'最美教师5'},{postName:'人力资源6'},{postName:'人力资源7'},{postName:'人力资源8'},{postName:'人力资源9'}]
</script> 

 

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

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

相关文章

域名 网站名称网站建设对电子商务的作用

&#x1f308;个人主页: 程序员不想敲代码啊 &#x1f3c6;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f44d;点赞⭐评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共…

网站制作的关键技术新乡手机网站建设电话

文章目录 一、JavaScript 逻辑运算符1、逻辑运算符 概念2、逻辑与运算符 &&3、逻辑或运算符 ||4、逻辑非运算符 !5、完整代码示例 一、JavaScript 逻辑运算符 1、逻辑运算符 概念 JavaScript 中的 逻辑运算符 的作用是 对 布尔值 进行运算 , 运算完成 后 的 返回值 也是…

没有网站也可以做外贸吗wordpress和万网

碰撞 Collision. [kəˈliʒən] 碰撞&#xff1b;冲突&#xff1b;&#xff08;意见&#xff0c;看法&#xff09;的抵触&#xff1b;&#xff08;政党等的&#xff09;倾轧 选择一个需要添加碰撞器的游戏对象后 Component->Physics- Unity一共为对象提供了6 种碰撞器&…

监控设备网站制作工作服厂家联系方式

目录 1. 更换yum源更新系统软件包&#xff1a; 1.1备份yum源 1.1.1创建备份目录&#xff1a; 1.1.2移动现有仓库配置文件到备份目录&#xff1a; 1.1.3验证备份&#xff1a; 1.2更换yum源 1.2.1添加yum源 1.2.2删除和建立yum缓存 1.3更新系统软件包 1.4 yum与dnf介绍…

2025 年超声波清洗机品牌最新权威推荐排行榜:龙门式 / 悬挂式 / 全自动等多类型设备厂家 TOP3 精选,助力企业精准选购

当前电子、机械、医疗、汽车、新能源等精密制造行业飞速发展,对零部件清洗的精度、效率及环保标准提出更高要求,超声波清洗机作为核心清洗设备,市场需求持续攀升。但市场上品牌繁杂,产品质量、技术水平与服务能力差…

树的统一迭代法

树的统一迭代法是一种比较通用的遍历方法,通过标记法来实现前序、中序、后序遍历,核心思想是通过栈中加入空指针来标记访问节点和处理节点的时机 树的递归遍历 递归遍历比较简单,只要完成模板,更改添加元素的位置代…

怎么seo网站排名wordpress搭建电影

1、自己准备训练语料文件 根据自己的业务场景准备训练数据&#xff0c;比如用户在商城上的同购行为序列或同浏览行为序列。 我们希望通过自己训练业务相关的语料word2vec模型来获得词嵌入、词相关性查询等。 1.1 准备语料库文件 # 示例&#xff1a;准备自己的一个大规模的语…

集团网站开发费用关键词优化的价格查询

1. 题目 给你一个 n 行 m 列的二维网格 grid 和一个整数 k。你需要将 grid 迁移 k 次。 每次「迁移」操作将会引发下述活动&#xff1a; 位于 grid[i][j] 的元素将会移动到 grid[i][j 1]。 位于 grid[i][m - 1] 的元素将会移动到 grid[i 1][0]。 位于 grid[n - 1][m - 1] …

asp网站源码+access+机械移动网站开发技术有哪些

实验项目&#xff1a;RSA公钥加密与签名实验 1.实验目的 本实验的学习目标是让学生获得 RSA 算法的动手经验。 通过课堂学习&#xff0c;学生应该已经了解 RSA 算法的理论部分&#xff0c; 知道在数学上如何生成公钥、私钥以及如何执行加密、解密和签名生成、验证。 通过使用…

深入解析:4-6〔O҉S҉C҉P҉ ◈ 研记〕❘ WEB应用攻击▸文件上传漏洞-A

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

2025 年冷却塔品牌最新推荐排行榜:玻璃钢冷却塔、闭式冷却塔、方型逆流式冷却塔优质厂家 TOP3 精选,赋能企业选购

随着工业生产与建筑行业的快速发展,冷却塔作为关键散热设备,市场需求日益攀升。但当前市场上冷却塔品牌数量众多,产品质量与性能参差不齐,从散热效率到节能效果,从材质耐用性到售后服务,差异显著。许多企业在选购…

详细介绍:基于Chrome140的FB账号自动化——脚本撰写(二)

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

CentOS7二进制安装包方式部署K8S集群之CA根证书生成 - 实践

CentOS7二进制安装包方式部署K8S集群之CA根证书生成 - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consol…

网站地址栏做1个响应式设计网站好

全世界只有3.14 % 的人关注了爆炸吧知如何才能学好数学&#xff1f;我国著名数学家苏步青先生曾说&#xff1a;"要学好数学&#xff0c;方法不外乎打好基础&#xff0c;多做习题&#xff0c;多加思索和分析”。为了帮助大家学好数学&#xff0c;今天&#xff0c;超模君要给…

旅游网站开发系统的er图网站建设 公司 广州

1.android电池充满电剩余时间 android电量还需多长时间充满时间计算参考下面链接: [Android Framework] 8.1 Battery系列(四) 电量还需多长时间充满时间计算_batteryinfo.java-CSDN博客 从这个链接中可以看出android默认的计算方式为平均计算每1%所需要的时间,在乘以剩余的电…

旅游景区网站源码长沙网络科技有限公司有哪些

介绍 赋值运算符就是将某个运算后的值&#xff0c; 赋给指定的变量。 赋值运算符的分类 基本赋值运算符 例如&#xff1a; int a 10; 复合赋值运算符 &#xff0c; - &#xff0c; * &#xff0c; / &#xff0c; % 等 a b; [等价 a a b; ] a - b; [等价 a a - b; ] …

可以做进销存的网站系统百度网站改版工具

QQ的庞大安装量带动了腾讯系的所有产品的安装量&#xff0c;QQ浏览器作为腾讯旗下开发的浏览工具&#xff0c;也拥有不俗的装机量。QQ浏览器不仅是沾了QQ的光&#xff0c;其自身实力也有不俗的&#xff0c;QQ浏览器的应用中心与其他浏览器的扩展中心一般支持用户安装各种浏览器…

软件设计师——03 数据结构(上) - 详解

软件设计师——03 数据结构(上) - 详解2025-10-01 13:31 tlnshuju 阅读(0) 评论(0) 收藏 举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block…

深圳网站建设公司地图建站官网模板

给自己一个目标&#xff0c;然后坚持一段时间&#xff0c;总会有收获和感悟&#xff01; 在实际项目开发中&#xff0c;多少都会遇到高并发的情况&#xff0c;有可能是网络问题&#xff0c;连续点击鼠标无反应快速发起了N多次调用接口&#xff0c; 导致极短时间内重复调用了多次…

DailyPaper-2025-9-30

感觉今天 paper 质量不是很高, 刚考完试太累了也读不很下去. SLA: Beyond Sparsity in Diffusion Transformers via Fine-Tunable Sparse-Linear Attention https://arxiv.org/abs/2509.24006SLA, a trainable attenti…