当前位置:   article > 正文

vue3+Element Plus实现自定义穿梭框_如果要在element plus组件库中的穿梭框头部加一个输入框

如果要在element plus组件库中的穿梭框头部加一个输入框

先上效果图:具体细节可以自己调整这里主要说明 派单,取消这两个按钮的实现

DOM部分代码:

  1. <el-row style="min-height: 7.5rem">
  2. <el-col :span="10" style="border: 1px solid #E1E1E1;border-radius: 5px">
  3. <div>
  4. <div style="border-radius: 5px 5px 0px 0px;
  5. border-bottom: 1px solid #42A4ED;display: flex;
  6. justify-content: space-around;background: #42A4ED">
  7. <div id="rec" style="
  8. font-weight: bolder;
  9. cursor: pointer;/*鼠标变成手指样式*/
  10. transition: all 0.3s;
  11. color: #fff;">
  12. <p style="padding: 10px 10px;height: 40px;"></p>
  13. </div>
  14. </div>
  15. <div style="padding-bottom: 20px;margin: auto;
  16. min-height: 15%;width:80%;font-size: .2rem;
  17. color:#0c1a24;background-color: #fff;">
  18. <el-row>
  19. <el-col :span="20" style="margin-left: 40px; margin-top: 10px;">
  20. <el-input :style="{ margin: 'auto', height: '30px'}" v-model.trim="formData.orgName"
  21. v-show="flag == 'REC'" placeholder="请输入组织名称">
  22. <template #append>
  23. <img @click="getUserData()" src="@/assets/images/icon/search.png"
  24. style="position:relative;top:0px;right: 0px;cursor: pointer">
  25. </template>
  26. </el-input>
  27. </el-col>
  28. </el-row>
  29. </div>
  30. <el-table v-loading="flagTbale" ref="selectedLeft" align='center' :row-style="{ height: '30px', padding: '0 0' }"
  31. highlight-current-row :data="tableData" @selection-change="handleLeftSelectionChange"
  32. :cell-style="{ padding: '3px', background: '#fff', paddingLeft: '0', color: '#666' }"
  33. :header-cell-style="{ background: '#42A4ED', color: '#FFFFFF', height: '20px', fontSize: '0.2rem', fontWeight: 'bold' }"
  34. :header-row-style="{ padding: '10px' }">
  35. <el-table-column type="selection" width="50" prop="select"></el-table-column>
  36. <el-table-column :show-overflow-tooltip="true" align="center" v-for="col in cols" :key="col.id"
  37. :label="col.label" :prop="col.prop" :width="col.width">
  38. </el-table-column>
  39. </el-table>
  40. <div style="height: 1rem;margin-bottom:0.2rem;display: flex; justify-content: center;">
  41. <el-pagination class="pagination" small layout="prev, pager, next" @size-change="handleSizeChange"
  42. :pager-count="3" @current-change="handleCurrentChange" v-model:current-page="pageNum"
  43. v-model:page-size="pageSize" :total="total" />
  44. </div>
  45. </div>
  46. </el-col>
  47. <!-- 中间按钮 -->
  48. <!--中间按钮开始-->
  49. <el-col :span="2" class="layui-transfer-active" style="margin: 230px 3% 0 5%;">
  50. <div>
  51. <el-button class="setting-btn" style="width: 70%;" @click="buttonRight" type="primary"
  52. :disabled="fxDisabled">
  53. 派单
  54. </el-button>
  55. </div>
  56. <div>
  57. <el-button class="setting-btn mt20" style="width: 70%;" @click="buttonLeft" type="primary"
  58. :disabled="qxfxDisabled">取消
  59. </el-button>
  60. </div>
  61. </el-col>
  62. <el-col :span="10" style="border: 1px solid #E1E1E1;border-radius: 5px">
  63. <div>
  64. <div style="border-radius: 5px 5px 0px 0px;
  65. border-bottom: 0px solid #42A4ED;display: flex;
  66. justify-content: space-around;background: #42A4ED">
  67. <div id="reced" style="font-family: SourceHanSansCN-Medium;
  68. font-weight: bolder;
  69. cursor: pointer;/*鼠标变成手指样式*/
  70. transition: all 0.3s;
  71. color: #fff;">
  72. <p style="padding: 1px 0px;height: 4px;"></p>
  73. </div>
  74. </div>
  75. <el-table ref="selectedRight" align='center' max-height="470px" :row-style="{ height: '30px', padding: '0 0' }"
  76. highlight-current-row :data="sharedData" @selection-change="handleRightSelectionChange"
  77. :cell-style="{ padding: '3px', background: '#fff', paddingLeft: '0', color: '#666' }"
  78. :header-cell-style="{ background: '#42A4ED', color: '#FFFFFF', height: '20px', fontSize: '0.2rem', fontWeight: 'bold' }"
  79. :header-row-style="{ padding: '10px' }"
  80. >
  81. <el-table-column type="selection" width="55" prop="select"></el-table-column>
  82. <el-table-column :show-overflow-tooltip="true" align="center" v-for="col in cols" :key="col.id"
  83. :label="col.label" :prop="col.prop" :width="col.width">
  84. </el-table-column>
  85. </el-table>
  86. </div>
  87. </el-col>
  88. </el-row>

穿梭框的table表头是动态的html中无需修改,使用这个组件首先需要在scripe中创建如下变量

  1. const tableData = ref([]) //左侧数据
  2. const selectedLeft = ref([])// 左侧选中数据
  3. const sharedData = ref([])//右侧数据
  4. const selectedRight = ref([])// 右侧选中数据
  5. //表格loading
  6. const flagTbale = ref(false) //可以去除所有的flagTbale 变量即可去除loading功能
  7. //两个table表头
  8. const cols = ref([
  9. { id: 1, prop: 'latnName', label: '本地网' },
  10. { id: 2, prop: 'orgId', label: '组织编码' },
  11. { id: 3, prop: 'orgName', label: '组织' },
  12. ])

然后就是最重要的按钮功能

  1. // 取消按钮
  2. const buttonLeft = async () => {
  3. if (!selectedRight.value || !Array.isArray(selectedRight.value)) {
  4. selectedRight.value = [];
  5. }
  6. // 将右侧选中的数据移动到左侧
  7. tableData.value = tableData.value.concat(selectedRight.value);
  8. // 从右侧数据中移除已经移动的数据
  9. sharedData.value = sharedData.value.filter(item => !selectedRight.value.includes(item));
  10. // 清空右侧选中的数据
  11. selectedRight.value = [];
  12. }
  13. // 分享按钮
  14. const buttonRight = async () => {
  15. if (!selectedLeft.value || !Array.isArray(selectedLeft.value)) {
  16. selectedLeft.value = [];
  17. }
  18. // 将左侧选中的数据移动到右侧
  19. sharedData.value = sharedData.value.concat(selectedLeft.value);
  20. // 从左侧数据中移除已经移动的数据
  21. tableData.value = tableData.value.filter(item => !selectedLeft.value.includes(item));
  22. // 清空左侧选中的数据
  23. selectedLeft.value = [];
  24. }

按钮禁用逻辑实现

  1. // 按钮是否禁用
  2. const qxfxDisabled = ref(true)
  3. const fxDisabled = ref(true)
  4. // 左侧表格选中事件
  5. const handleLeftSelectionChange = (selection) => {
  6. if (selection.length !== 0) {
  7. fxDisabled.value = false
  8. }
  9. if (selection.length === 0) {
  10. fxDisabled.value = true
  11. }
  12. };
  13. // 右侧表格选中事件
  14. const handleRightSelectionChange = (selection) => {
  15. selectedRight.value = selection;
  16. if (selection.length !== 0) {
  17. qxfxDisabled.value = false
  18. }
  19. if (selection.length === 0) {
  20. qxfxDisabled.value = true
  21. }
  22. };

到这里你就可以使用在这个组件了。这是经过插分的代码原本还拥有表头切换的逻辑如有需要可留言.我后续可以在做整理

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/223920
推荐阅读
相关标签
  

闽ICP备14008679号