当前位置: 首页 > ai >正文

封装索引列表

效果

直接上代码

<template><div class="css-index"><el-inputv-model="searchText"placeholder="输入属性名搜索"clearableclass="search-box"/><div class="index-container"><div class="index-nav"><divv-for="letter in indexLetters":key="letter"class="nav-item"@click="scrollToLetter(letter)">{{ letter }}</div></div><div class="index-main"><div v-for="(group, letter) in filteredGroups":key="letter"class="index-group":ref="`group-${letter}`"><h3 class="group-title">{{ letter }}</h3><div class="property-list"><divv-for="prop in group":key="prop.name"class="property-item"@click="handleSelect(prop)"><span class="prop-name">{{ prop.name }}</span></div></div></div></div></div></div>
</template><script>
export default {name: 'CssIndexList',props: {// 接收处理后的列表数据cssProperties: {type: Object,required: true}},data() {return {searchText: ''}},computed: {// 转换数据结构processedProps() {return Object.keys(this.cssProperties).filter(name => {// 过滤无效属性return !name.startsWith('-webkit') && !name.startsWith('offset') && name !== 'length' && name !== 'parentRule'}).map(name => ({name,value: this.cssProperties[name]}))},// 按首字母分组groupedProps() {const groups = {}this.processedProps.forEach(prop => {const firstLetter = prop.name[0].toUpperCase()if (!groups[firstLetter]) {groups[firstLetter] = []}groups[firstLetter].push(prop)})return groups},// 过滤后的分组filteredGroups() {if (!this.searchText) return this.groupedPropsconst filtered = {}const searchKey = this.searchText.toLowerCase()Object.keys(this.groupedProps).forEach(letter => {const items = this.groupedProps[letter].filter(prop =>prop.name.toLowerCase().includes(searchKey))if (items.length > 0) {filtered[letter] = items}})return filtered},// 索引字母列表indexLetters() {return Object.keys(this.filteredGroups).sort()}},methods: {scrollToLetter(letter) {const el = this.$refs[`group-${letter}`]?.[0]el?.scrollIntoView({ behavior: 'smooth', block: 'start' })},handleSelect(prop) {this.$emit('select', prop.name)}}
}
</script><style scoped>
/* 保持原有样式不变 */
.css-index {width: 100%;height: 600px;display: flex;flex-direction: column;
}.search-box {margin-bottom: 15px;
}.index-container {flex: 1;display: flex;border: 1px solid #ebeef5;border-radius: 4px;overflow: hidden;
}.index-nav {width: 40px;background: #f5f7fa;padding: 10px 0;overflow-y: auto;
}.nav-item {padding: 4px;text-align: center;font-size: 12px;color: #606266;cursor: pointer;transition: all 0.3s;
}.nav-item:hover {color: #409eff;transform: scale(1.2);
}.index-main {flex: 1;overflow-y: auto;padding: 15px;
}.group-title {margin: 10px 0;color: #909399;font-size: 14px;padding-left: 8px;border-left: 3px solid #409eff;
}.property-list {display: grid;grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));gap: 10px;
}.property-item {padding: 8px 12px;border-radius: 4px;background: #f8f9fa;cursor: pointer;transition: all 0.2s;
}.property-item:hover {background: #ebf3ff;transform: translateX(4px);
}.prop-name {font-family: monospace;color: #303133;font-size: 13px;
}
</style>

使用

<indexed-list:css-properties="processedCssProperties"@select="handlePropSelect"/>mounted() {let cssList = window.getComputedStyle(document.body)for (const key of cssList) {this.processedCssProperties[key] = key}},handlePropSelect(prop) {console.log('选中属性:', prop)// 可以在这里处理属性复制等操作}

http://www.xdnf.cn/news/9401.html

相关文章:

  • AXI3、AXI4 和 AXI5 的详细差异对比
  • 第三章、运动学逆解(双足轮根据腿高求舵机角度)
  • 完全卸载VS Code--Windows版
  • 在 Vue + Vite 项目中,直接使用相对路径或绝对路径引用本地图片资源时,图片无法正确显示。
  • Claude 4对比Claude 3.7全面评测:2025最新AI模型实测对比
  • 山东大学软件学院创新项目实训开发日志——第十三周
  • xilinx 7系列底层可配置逻辑块CLB中的LUT、FF等资源
  • IT编程学习资料大全​​​​​​​​
  • 嵌入式学习之系统编程(六)线程
  • 打破边界 智启新篇 新一代质检LIMS系统的演进蓝图
  • QGis实现geoserver上的样式展示(方便样式编辑)
  • ShardingSphere-读写分离
  • leetcode0611. 有效三角形的个数-medium
  • ROS2学习(14)------ ROS2Launch 多节点启动与配置脚本
  • 基于stm32的 永磁同步电机二电平驱动控制系统设计
  • OpenKylin文件管理器界面层级切换问题
  • 多相电机驱动控制学习(1)——基于双dq坐标系的六相/双三相PMSM驱动控制
  • ABC 377
  • 互联网医疗问诊APP原型设计:12个实战案例解析
  • Workflow
  • 如何合理选择智能外呼机器人:多维评估
  • SAP-ABAP:SAP的DMS根据物料号获取附件详解
  • 网络通信的基石:深入理解帧与报文
  • [BUG记录]0X10 会话切换服务响应NRC 0x10
  • <<运算符重载 和 c_str() 的区别和联系
  • TF 卡和 NM 卡有何区别?
  • openinstall支持豆瓣广告监测,赋能品牌深挖社交流量
  • Baklib知识中台体系构建与应用解析
  • 比较转录组-油料作物-文献精读133
  • Jenkins实践(10):pipeline构建历史展示包名和各阶段间传递参数