vue3+Element Plus實(shí)現(xiàn)自定義穿梭框的詳細(xì)代碼
先上效果圖:具體細(xì)節(jié)可以自己調(diào)整這里主要說(shuō)明 派單,取消這兩個(gè)按鈕的實(shí)現(xiàn)
DOM部分代碼:
<el-row style="min-height: 7.5rem"> <el-col :span="10" style="border: 1px solid #E1E1E1;border-radius: 5px"> <div> <div style="border-radius: 5px 5px 0px 0px; border-bottom: 1px solid #42A4ED;display: flex; justify-content: space-around;background: #42A4ED"> <div id="rec" style=" font-weight: bolder; cursor: pointer;/*鼠標(biāo)變成手指樣式*/ transition: all 0.3s; color: #fff;"> <p style="padding: 10px 10px;height: 40px;"></p> </div> </div> <div style="padding-bottom: 20px;margin: auto; min-height: 15%;width:80%;font-size: .2rem; color:#0c1a24;background-color: #fff;"> <el-row> <el-col :span="20" style="margin-left: 40px; margin-top: 10px;"> <el-input :style="{ margin: 'auto', height: '30px'}" v-model.trim="formData.orgName" v-show="flag == 'REC'" placeholder="請(qǐng)輸入組織名稱"> <template #append> <img @click="getUserData()" src="@/assets/images/icon/search.png" style="position:relative;top:0px;right: 0px;cursor: pointer"> </template> </el-input> </el-col> </el-row> </div> <el-table v-loading="flagTbale" ref="selectedLeft" align='center' :row-style="{ height: '30px', padding: '0 0' }" highlight-current-row :data="tableData" @selection-change="handleLeftSelectionChange" :cell-style="{ padding: '3px', background: '#fff', paddingLeft: '0', color: '#666' }" :header-cell-style="{ background: '#42A4ED', color: '#FFFFFF', height: '20px', fontSize: '0.2rem', fontWeight: 'bold' }" :header-row-style="{ padding: '10px' }"> <el-table-column type="selection" width="50" prop="select"></el-table-column> <el-table-column :show-overflow-tooltip="true" align="center" v-for="col in cols" :key="col.id" :label="col.label" :prop="col.prop" :width="col.width"> </el-table-column> </el-table> <div style="height: 1rem;margin-bottom:0.2rem;display: flex; justify-content: center;"> <el-pagination class="pagination" small layout="prev, pager, next" @size-change="handleSizeChange" :pager-count="3" @current-change="handleCurrentChange" v-model:current-page="pageNum" v-model:page-size="pageSize" :total="total" /> </div> </div> </el-col> <!-- 中間按鈕 --> <!--中間按鈕開始--> <el-col :span="2" class="layui-transfer-active" style="margin: 230px 3% 0 5%;"> <div> <el-button class="setting-btn" style="width: 70%;" @click="buttonRight" type="primary" :disabled="fxDisabled"> 派單 </el-button> </div> <div> <el-button class="setting-btn mt20" style="width: 70%;" @click="buttonLeft" type="primary" :disabled="qxfxDisabled">取消 </el-button> </div> </el-col> <el-col :span="10" style="border: 1px solid #E1E1E1;border-radius: 5px"> <div> <div style="border-radius: 5px 5px 0px 0px; border-bottom: 0px solid #42A4ED;display: flex; justify-content: space-around;background: #42A4ED"> <div id="reced" style="font-family: SourceHanSansCN-Medium; font-weight: bolder; cursor: pointer;/*鼠標(biāo)變成手指樣式*/ transition: all 0.3s; color: #fff;"> <p style="padding: 1px 0px;height: 4px;"></p> </div> </div> <el-table ref="selectedRight" align='center' max-height="470px" :row-style="{ height: '30px', padding: '0 0' }" highlight-current-row :data="sharedData" @selection-change="handleRightSelectionChange" :cell-style="{ padding: '3px', background: '#fff', paddingLeft: '0', color: '#666' }" :header-cell-style="{ background: '#42A4ED', color: '#FFFFFF', height: '20px', fontSize: '0.2rem', fontWeight: 'bold' }" :header-row-style="{ padding: '10px' }" > <el-table-column type="selection" width="55" prop="select"></el-table-column> <el-table-column :show-overflow-tooltip="true" align="center" v-for="col in cols" :key="col.id" :label="col.label" :prop="col.prop" :width="col.width"> </el-table-column> </el-table> </div> </el-col> </el-row>
穿梭框的table表頭是動(dòng)態(tài)的html中無(wú)需修改,使用這個(gè)組件首先需要在scripe中創(chuàng)建如下變量
const tableData = ref([]) //左側(cè)數(shù)據(jù) const selectedLeft = ref([])// 左側(cè)選中數(shù)據(jù) const sharedData = ref([])//右側(cè)數(shù)據(jù) const selectedRight = ref([])// 右側(cè)選中數(shù)據(jù) //表格loading const flagTbale = ref(false) //可以去除所有的flagTbale 變量即可去除loading功能 //兩個(gè)table表頭 const cols = ref([ { id: 1, prop: 'latnName', label: '本地網(wǎng)' }, { id: 2, prop: 'orgId', label: '組織編碼' }, { id: 3, prop: 'orgName', label: '組織' }, ])
然后就是最重要的按鈕功能
// 取消按鈕 const buttonLeft = async () => { if (!selectedRight.value || !Array.isArray(selectedRight.value)) { selectedRight.value = []; } // 將右側(cè)選中的數(shù)據(jù)移動(dòng)到左側(cè) tableData.value = tableData.value.concat(selectedRight.value); // 從右側(cè)數(shù)據(jù)中移除已經(jīng)移動(dòng)的數(shù)據(jù) sharedData.value = sharedData.value.filter(item => !selectedRight.value.includes(item)); // 清空右側(cè)選中的數(shù)據(jù) selectedRight.value = []; } // 分享按鈕 const buttonRight = async () => { if (!selectedLeft.value || !Array.isArray(selectedLeft.value)) { selectedLeft.value = []; } // 將左側(cè)選中的數(shù)據(jù)移動(dòng)到右側(cè) sharedData.value = sharedData.value.concat(selectedLeft.value); // 從左側(cè)數(shù)據(jù)中移除已經(jīng)移動(dòng)的數(shù)據(jù) tableData.value = tableData.value.filter(item => !selectedLeft.value.includes(item)); // 清空左側(cè)選中的數(shù)據(jù) selectedLeft.value = []; }
按鈕禁用邏輯實(shí)現(xiàn)
// 按鈕是否禁用 const qxfxDisabled = ref(true) const fxDisabled = ref(true) // 左側(cè)表格選中事件 const handleLeftSelectionChange = (selection) => { if (selection.length !== 0) { fxDisabled.value = false } if (selection.length === 0) { fxDisabled.value = true } }; // 右側(cè)表格選中事件 const handleRightSelectionChange = (selection) => { selectedRight.value = selection; if (selection.length !== 0) { qxfxDisabled.value = false } if (selection.length === 0) { qxfxDisabled.value = true } };
到這里你就可以使用在這個(gè)組件了。這是經(jīng)過插分的代碼原本還擁有表頭切換的邏輯如有需要可留言.我后續(xù)可以在做整理
到此這篇關(guān)于vue3+Element Plus實(shí)現(xiàn)自定義穿梭框的文章就介紹到這了,更多相關(guān)vue3 Element Plus穿梭框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue動(dòng)態(tài)綁定多個(gè)class以及帶上三元運(yùn)算或其他條件
這篇文章主要介紹了vue動(dòng)態(tài)綁定多個(gè)class以及帶上三元運(yùn)算或其他條件,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04Vue.js實(shí)現(xiàn)文件上傳和進(jìn)度條顯示功能
在現(xiàn)代Web開發(fā)中,文件上傳是一個(gè)常見而重要的需求,無(wú)論是在用戶上傳頭像、文檔或者其他類型的文件時(shí),良好的用戶體驗(yàn)都是至關(guān)重要的,在這篇博客中,我們將介紹如何使用Vue.js來(lái)實(shí)現(xiàn)文件上傳功能,同時(shí)顯示上傳進(jìn)度條,需要的朋友可以參考下2024-11-11vue router下的html5 history在iis服務(wù)器上的設(shè)置方法
這篇文章主要介紹了vue router下的html5 history在iis服務(wù)器上的設(shè)置方法,需要的朋友參考下吧2017-10-10vue3在自定義hooks中使用useRouter報(bào)錯(cuò)的解決方案
這篇文章主要介紹了vue3在自定義hooks中使用useRouter報(bào)錯(cuò)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08Vue Router去掉url中默認(rèn)的錨點(diǎn)#
vue-router默認(rèn)hash模式——使用URL的hash來(lái)模擬一個(gè)完整的URL,于是當(dāng)URL改變時(shí),頁(yè)面不會(huì)重新加載。這篇文章主要介紹了Vue Router去掉url中默認(rèn)的錨點(diǎn)#,需要的朋友可以參考下2018-08-08詳解在vue-cli項(xiàng)目中安裝node-sass
本篇文章主要介紹了詳解在vue-cli項(xiàng)目中安裝node-sass ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-06-06