当前位置:网站首页>ivew 穿梭框Transfer组件高亮显示操作值
ivew 穿梭框Transfer组件高亮显示操作值
2022-07-17 05:23:00 【£漫步 云端彡】
项目场景:
Transfer(穿梭框),双栏穿梭选择框,常用于将多个项目从一边移动到另一边。这个组件在多个数据之间选择时非常方便。所有的控制都由组件完成,只需要最后保存组件目标值即可。
问题描述:
由于所有方式都由组件完成,因此会出现一种情况,当操作元素左右穿梭时,这些穿梭值与原数据样式一样,数据过多时,无法区分。而且组件没有任何一种方法直接可以特殊高亮显示。如下图所示(数据虽打马赛克,但可清晰看到数据颜色是相同的):

原因分析:
我在百度上找了好久都没有找到解决方案,最后查看官网说明和源码研究,哈哈,其实也没看懂多少,大概知道组件并没有提供一种方式去处理这个问题。但是从官网可以看到render-format原生属性,查看元素之后,这个函数最后将返回值包含在span标签内部充当元素处理,发现使用HTML元素标签也是可以识别的哦。因此可以用这个方式去解决问题

解决方案:
首先需要在vue data中定义几个数据
// 穿梭框左右移动操作值,
optionItems: [],
// 穿梭框右边值,后台获取
selectClientUserIds: [],
// 穿梭框左边值,后台获取
clientUsers: [],
// 初始化时选中值,赋值之后不再改变
initSelectItems: [],
页面代码
<Transfer ref="refTransfer" :titles="['客户端用户','授权用户']" :data="clientUsers" :target-keys="selectClientUserIds" filterable :filter-method="filterClientUser" @on-change="clientUsersChange" :render-format="renderFormat" :list-style="listStyle">
</Transfer>
部分js处理函数
// 打开弹出框,获取数据
openclientUserManageModal(id) {
this.clientUserManageId = id;
this.clientUsers = [];
this.selectClientUserIds = [];
// 清空穿梭框搜索条件
this.$refs.refTransfer.$children[0].query = '';
this.$refs.refTransfer.$children[2].query = '';
// 清空穿梭框复选框
this.$refs.refTransfer.$children[0].toggleSelectAll();
this.$refs.refTransfer.$children[2].toggleSelectAll();
// 清空选中项
this.optionItems = [];
//获取选中用户ID
getGrantClientUserIds({
id: id
}).then((result) => {
if (result.status === 1) {
// 获取选中值,即穿梭框右边的值
this.selectClientUserIds = result.data;
// initSelectItems 默认初始化选中值
this.initSelectItems = JSON.parse(JSON.stringify(result.data))
} else {
this.$Message.error(result.msg ? result.msg : "获取数据失败")
}
})
//获取所有客户端用户列表
getAllClientUsers().then((result) => {
if (result.status == 1) {
// 初始化穿梭框左边的值
this.clientUsers = result.data;
} else {
this.$Message.error(result.msg ? result.msg : "获取数据失败")
}
})
this.$nextTick(() => {
this.clientUserManageVisible = true;
console.log(this.$refs.refTransfer)
})
},
filterClientUser(data, query) {
return data.username.toLowerCase().indexOf(query.toLowerCase()) > -1 ||
data.compName.toLowerCase().indexOf(query.toLowerCase()) > -1;
},
/** * 重点处理函数,在穿梭框左右移动的时候,将移动过的数据key值保存在optionItems中, * @param {Object} targetKeys 目标的key集合 * @param {Object} direction 移动方向 * @param {Object} moveKeys 移动的key数据 */
clientUsersChange(targetKeys, direction, moveKeys) {
this.selectClientUserIds = targetKeys;
// 默认选中方在右侧,即目标方
for (let moveKey of moveKeys) {
if (this.initSelectItems.indexOf(moveKey) > -1) {
//如果是默认选中值
if (direction === 'left') {
//左移时添加
this.optionItems.push(moveKey)
} else if (direction === 'right') {
// 右移时移除
let index = this.optionItems.indexOf(moveKey);
if (index > -1) {
this.optionItems.splice(index, 1);
}
}
} else {
// 不是默认选中值
if (direction === 'left') {
// 左移时移除
let index = this.optionItems.indexOf(moveKey);
if (index > -1) {
this.optionItems.splice(index, 1);
}
} else if (direction === 'right') {
// 右移时添加
this.optionItems.push(moveKey)
}
}
}
},
/** * 数据格式处理 * 穿梭框数据格式 * @param {Object} data */
renderFormat(data) {
// 如果包含在操作项,显示为蓝色,否则默认
if (this.optionItems.indexOf(data.key) != -1) {
return '<label style="color: #2D8CF0;">' + data.username + ' | ' + data.compName +
'</label>';
} else {
return '<label>' + data.username + ' | ' + data.compName + '</label>';
}
},
效果如下,可以看到操作后的数据颜色不同:
边栏推荐
- Performance test and price comparison of cloud servers of Alibaba cloud, Tencent cloud, Huawei cloud, ucloud and Tianyi cloud
- Review summary of MySQL
- Speed feedback single closed loop DC speed regulation system based on Simulink
- Arm server building my world (MC) version 1.18.2 private server tutorial
- ARM服务器搭建 我的世界(MC) 1.18.2 版私服教程
- PyTorch学习日记(四)
- M simulation of UWB MIMO radar target detection based on MATLAB, considering time reversal
- 华为云 鲲鹏ARM云服务器 和 x86云服务器 性能评测对比
- 快速学会cut命令,uniq命令的使用
- Data protection / disk array raid protection IP segment 103.103.188 xxx
猜你喜欢

基于simulink的转速反馈单闭环直流调速系统
![Minecraft integration package [gtnh] gray Technology: new vision server building tutorial](/img/59/d5f226f57cfd7d28d5a76ff38fae16.png)
Minecraft integration package [gtnh] gray Technology: new vision server building tutorial

Solve the problem that the unit test coverage of sonar will be 0

传奇游戏架设教程

IP103.53.125.xxx IP地址段 详解

天翼雲 杭州 雲主機(VPS) 性能評測

My world 1.12.2 Magic Baby (Fairy treasure dream) service opening tutorial

Speed feedback single closed loop DC speed regulation system based on Simulink
Xiaodi network security notes - Information Collection - architecture, construction, WAF (8)

My world 1.18.1 forge version open service tutorial, can install mod, with panel
随机推荐
WCDMA soft handoff performance matlab simulation m, comparing the average number of activation sets (MasN), activation set update rate (Asur) and call interruption probability (OP) three performance i
SNN学习日记——安装SpikingJelly
听说今天发博客能领徽章!
Minecraft integration package [gtnh] gray Technology: new vision server building tutorial
m基于matlab的MIMO信道容量分析,对比了不同天线数量;非码本预编码SVD,GMD;码本预编码DFT,TxAA以及空间分集
UCloud(优刻得) 上海 ARM 云服务器评测
快速掌握sort命令,tr命令
Xiaodi network security - Notes (5)
字典,集合的使用,数据类型的转换
爬虫基础—代理的基本原理
Évaluation des performances de la machine virtuelle Tianyi Cloud Hangzhou (VPS)
企业或个人域名备案怎么弄
Performance test and price comparison of cloud servers of Alibaba cloud, Tencent cloud, Huawei cloud, ucloud and Tianyi cloud
爬虫基础—爬虫的基本原理
基于simulink的转速反馈单闭环直流调速系统
m基于matlab的BTS天线设计,带GUI界面
Yuanzi racehorse.
M simulation of 16QAM and 2DPSK communication links based on Simulink, and get the bit error rate curve by calling Simulink model through MATLAB
M based on the MIMO channel capacity analysis of MATLAB, different antenna numbers are compared; Non codebook precoding SVD, GMD; Codebook precoding DFT, TXAA and spatial diversity
Pytorch learning diary (4)