• el-table实现穿梭功能


     第一种

    1. <script>
    2. export default {
    3. data () {
    4. return {
    5. search: {
    6. phone: '',
    7. page: {
    8. current: 1,
    9. size: 10
    10. }
    11. },
    12. tableTotal: 0,
    13. tableData1: [],
    14. tableData2: [],
    15. nowSelectData: [], // 左边选中列表数据
    16. nowSelectRightData: [], // 右边选中列表数据
    17. phoneRight: ''
    18. }
    19. },
    20. mounted () {
    21. this.getTableList()
    22. },
    23. methods: {
    24. // 获取左侧数据
    25. getTableList () {
    26. this.tableData1 = [
    27. { phone: "111", nickName: "张三", id: "1" },
    28. { phone: "222", nickName: "李四", id: "2" },
    29. { phone: "333", nickName: "王五", id: "3" },
    30. { phone: "444", nickName: "翠花", id: "4" },
    31. { phone: "555", nickName: "小花", id: "5" },
    32. { phone: "666", nickName: "佚名", id: "6" }
    33. ]
    34. },
    35. // 右边查询
    36. searchBtn () {
    37. const tableData2 = JSON.parse(localStorage.getItem('tableData2'))
    38. if (this.phoneRight === '' || !this.phoneRight) {
    39. this.tableData2 = tableData2
    40. } else {
    41. this.tableData2 = tableData2.filter(item => item.id.indexOf(this.phoneRight) > -1)
    42. }
    43. },
    44. // 右边重置
    45. resetBtn () {
    46. this.phoneRight = ''
    47. this.tableData2 = JSON.parse(localStorage.getItem('tableData2'))
    48. },
    49. // 重置
    50. clearSearch () {
    51. this.search = {
    52. phone:'',
    53. page: {
    54. current: 1,
    55. size: 10
    56. }
    57. }
    58. this.getTableList()
    59. },
    60. /**
    61. * 分页
    62. */
    63. handleSizeChange (val) {
    64. this.search.page.current = 1
    65. this.search.page.size = val
    66. this.getTableList()
    67. },
    68. handleCurrentChange (val) {
    69. this.search.page.current = val
    70. this.getTableList()
    71. },
    72. // 左边全选事件
    73. checkAll (row) {
    74. this.nowSelectData = row;
    75. },
    76. // 右边全选事件
    77. checkRightAll (row) {
    78. this.nowSelectRightData = row;
    79. },
    80. // 左边选中事件
    81. checkLeft (row) {
    82. this.nowSelectData = row;
    83. },
    84. // 右边选中事件
    85. checkRight (row) {
    86. this.nowSelectRightData = row;
    87. },
    88. // 点击去右边
    89. right () {
    90. this.tableData2 = this.tableData2.concat(this.nowSelectData);
    91. this.handleRemoveTabList(this.nowSelectData, this.tableData1);
    92. // 按钮禁用
    93. this.nowSelectData = [];
    94. localStorage.setItem('tableData2', JSON.stringify(this.tableData2))
    95. },
    96. // 点击去左边
    97. left () {
    98. this.tableData1 = this.tableData1.concat(this.nowSelectRightData);
    99. this.handleRemoveTabList(this.nowSelectRightData, this.tableData2);
    100. // 按钮禁用
    101. this.nowSelectRightData = [];
    102. },
    103. // 方法
    104. handleRemoveTabList (isNeedArr, originalArr) {
    105. if (isNeedArr.length && originalArr.length) {
    106. for (let i = 0; i < isNeedArr.length; i++) {
    107. for (let k = 0; k < originalArr.length; k++) {
    108. // 注意,nickName为唯一值,如果不为唯一值那么会出错
    109. if (isNeedArr[i]["nickName"] === originalArr[k]["nickName"]) {
    110. console.log("-----------1111");
    111. originalArr.splice(k, 1);
    112. }
    113. }
    114. }
    115. }
    116. }
    117. }
    118. }
    119. script>
    120. <style lang="less" scoped>
    121. ::v-deep .el-table-dialog {
    122. border: 1px solid #e8e6e6;
    123. thead {
    124. // color: black;
    125. th {
    126. background-color: #f4f4f4;
    127. .cell {
    128. font-weight: bold;
    129. }
    130. }
    131. th:last-child {
    132. text-align: center;
    133. }
    134. }
    135. }
    136. .search-bg {
    137. margin: 0 !important;
    138. }
    139. style>

    第二种,只是纯表单穿梭,没有其他功能

    1. <script>
    2. export default {
    3. data () {
    4. return {
    5. tableData1: [
    6. { phone: "132344", nickName: "张三", id: "1" },
    7. { phone: "132344", nickName: "李四", id: "2" },
    8. { phone: "132344", nickName: "王五", id: "3" },
    9. { phone: "132344", nickName: "翠花", id: "4" },
    10. { phone: "132344", nickName: "小花", id: "5" },
    11. { phone: "132346", nickName: "佚名", id: "6" }
    12. ],
    13. tableData2: [],
    14. nowSelectData: [], // 左边选中列表数据
    15. nowSelectRightData: [], // 右边选中列表数据
    16. }
    17. },
    18. methods: {
    19. // 左边全选事件
    20. checkAll (row) {
    21. this.nowSelectData = row;
    22. },
    23. // 右边全选事件
    24. checkRightAll (row) {
    25. this.nowSelectRightData = row;
    26. },
    27. // 左边选中事件
    28. checkLeft (row) {
    29. this.nowSelectData = row;
    30. },
    31. // 右边选中事件
    32. checkRight (row) {
    33. this.nowSelectRightData = row;
    34. },
    35. // 点击去右边
    36. right () {
    37. this.tableData2 = this.tableData2.concat(this.nowSelectData);
    38. this.handleRemoveTabList(this.nowSelectData, this.tableData1);
    39. // 按钮禁用
    40. this.nowSelectData = [];
    41. },
    42. // 点击去左边
    43. left () {
    44. this.tableData1 = this.tableData1.concat(this.nowSelectRightData);
    45. this.handleRemoveTabList(this.nowSelectRightData, this.tableData2);
    46. // 按钮禁用
    47. this.nowSelectRightData = [];
    48. },
    49. // 方法
    50. handleRemoveTabList (isNeedArr, originalArr) {
    51. if (isNeedArr.length && originalArr.length) {
    52. for (let i = 0; i < isNeedArr.length; i++) {
    53. for (let k = 0; k < originalArr.length; k++) {
    54. // 注意,nickName为唯一值,如果不为唯一值那么会出错
    55. if (isNeedArr[i]["nickName"] === originalArr[k]["nickName"]) {
    56. console.log("-----------1111");
    57. originalArr.splice(k, 1);
    58. }
    59. }
    60. }
    61. }
    62. }
    63. }
    64. }
    65. script>
    66. <style lang="less" scoped>
    67. ::v-deep .el-table-dialog {
    68. border: 1px solid #e8e6e6;
    69. thead {
    70. // color: black;
    71. th {
    72. background-color: #f4f4f4;
    73. .cell {
    74. font-weight: bold;
    75. }
    76. }
    77. th:last-child {
    78. text-align: center;
    79. }
    80. }
    81. }
    82. style>

  • 相关阅读:
    华为od德科面试数据算法解析 2022-6-1 IP地址转换成整数
    【面试系列】后端开发工程师 高频面试题及详细解答
    Java排序算法(六):希尔排序
    JVM内存设置与查看
    excel导出加水印内存溢出问题解决思路
    压缩上传的图片并返回图片路径
    Spring Cloud Gateway整合Swagger聚合微服务系统API文档(非Zuul)
    数字时代的探索与革新:Socks5代理的引领作用
    分布式协同AI基准测试项目Ianvs:工业场景提升5倍研发效率
    Boost搜索引擎
  • 原文地址:https://blog.csdn.net/qq_41588991/article/details/133277160