Commit ea0d8107 by 姜雷

修改穿梭框组件实现

parent d615ea14
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
slot="option" slot="option"
slot-scope="option" slot-scope="option"
> >
<option class="option-wrap"> <div class="option-wrap">
<span>{{option.data.name+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'}}</span> <span>{{option.data.label}}</span>
<span>{{option.data.name}}</span>&nbsp;
<span>{{option.data.name}}</span> <span>{{option.data.name}}</span>
</option> <span>{{option.data.label}}</span>
</div>
</template> </template>
</ks-transfer> </ks-transfer>
</list-layout> </list-layout>
...@@ -24,26 +24,17 @@ export default { ...@@ -24,26 +24,17 @@ export default {
data() { data() {
return { return {
list: [ list: [
{ { id: 1, label: '1111', name: '213' },
id: 1, { id: 2, label: '2222', name: '213' },
label: '1111', { id: 3, label: '3333', name: '213' },
name: '213', { id: 4, label: '3223', name: '213' },
}, { id: 5, label: '5555', name: '213' },
{ { id: 6, label: '6666', name: '213' },
id: 2, { id: 7, label: '7777', name: '213' },
label: '2222', { id: 8, label: '8888', name: '213' },
name: '213', { id: 9, label: '9999', name: '213' },
}, { id: 10, label: '1465', name: '213' },
{ { id: 11, label: '2387', name: '213' },
id: 3,
label: '3333',
name: '213',
},
{
id: 4,
label: '3223',
name: '213',
},
], ],
value: [1, 3], value: [1, 3],
}; };
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "rym-element-ui", "name": "rym-element-ui",
"version": "0.1.59", "version": "0.1.60",
"description": "任意门组件库", "description": "任意门组件库",
"main": "lib/rymUi.common.js", "main": "lib/rymUi.common.js",
"scripts": { "scripts": {
......
...@@ -19,16 +19,21 @@ ...@@ -19,16 +19,21 @@
</div> </div>
</div> </div>
<div class="transfer-allData-box"> <div class="transfer-allData-box">
<select <ul
class="transfer-allData-select" class="transfer-allData-select"
multiple tabindex="1"
v-model="selected.all" @focus="() => resetSelect('value')"
> >
<template v-for="(item, index) in allDataOptions"> <template v-for="(item, index) in allDataOptions">
<option <li
:class="{'selected': selected.all.indexOf(getValue('key', item))>-1}"
:key="index" :key="index"
:id="index"
:value="getValue('key', item)" :value="getValue('key', item)"
@click="() => selectedValueHandle('all', getValue('key', item))"
@dblclick="() => addClickValue(getValue('key', item))" @dblclick="() => addClickValue(getValue('key', item))"
@mousedown="() => dragstartHandle('all', index)"
@mouseover="() => dragingHandle('all', index)"
> >
<slot <slot
name="option" name="option"
...@@ -37,9 +42,9 @@ ...@@ -37,9 +42,9 @@
> >
{{ getValue('label', item) }} {{ getValue('label', item) }}
</slot> </slot>
</option> </li>
</template> </template>
</select> </ul>
</div> </div>
</div> </div>
<div class="transfer-btnBox"> <div class="transfer-btnBox">
...@@ -102,17 +107,20 @@ ...@@ -102,17 +107,20 @@
</div> </div>
</div> </div>
<div class="transfer-selectData-box"> <div class="transfer-selectData-box">
<select <ul
class="transfer-selectData-select" class="transfer-selectData-select"
multiple tabindex="2"
v-model="selected.value" @focus="() => resetSelect('all')"
> >
<template v-for="(item, index) in selectDataOptions"> <template v-for="(item, index) in selectDataOptions">
<li
<option :class="{'selected': selected.value.indexOf(getValue('key', item))>-1}"
:key="index" :key="index"
:value="getValue('key', item)" :value="getValue('key', item)"
@click="() => selectedValueHandle('value', getValue('key', item))"
@dblclick="() => removeClickValue(getValue('key', item))" @dblclick="() => removeClickValue(getValue('key', item))"
@mousedown="() => dragstartHandle('value', index)"
@mouseover="() => dragingHandle('value', index)"
> >
<slot <slot
name="option" name="option"
...@@ -121,11 +129,11 @@ ...@@ -121,11 +129,11 @@
> >
{{ getValue('label', item) }} {{ getValue('label', item) }}
</slot> </slot>
</option> </li>
</template> </template>
</select> </ul>
</div> </div>
</div> </div>
</div> </div>
...@@ -150,6 +158,9 @@ export default { ...@@ -150,6 +158,9 @@ export default {
all: [], all: [],
value: [], value: [],
}, },
dragging: false,
startIndex: undefined,
lastIndex: undefined,
}; };
}, },
watch: { watch: {
...@@ -212,6 +223,7 @@ export default { ...@@ -212,6 +223,7 @@ export default {
}, },
removeClickValue(val) { removeClickValue(val) {
this.trueValue = this.trueValue.filter(item => item !== val); this.trueValue = this.trueValue.filter(item => item !== val);
this.selected.value = this.selected.value.filter(item => item !== val);
}, },
addSelectedValue(flag) { addSelectedValue(flag) {
this.trueValue = flag this.trueValue = flag
...@@ -243,11 +255,56 @@ export default { ...@@ -243,11 +255,56 @@ export default {
if (key === 'key') return item.id; if (key === 'key') return item.id;
return item[key]; return item[key];
}, },
selectedValueHandle(key, val) {
this.selected[key] = [val];
},
dragstartHandle(key, index) {
let value =
key === 'value'
? this.selectDataOptions[index]
: this.allDataOptions[index];
this.selectedValueHandle(value);
this.startIndex = index;
this.dragging = true;
document.addEventListener('mouseup', this.dragendHandle);
},
dragingHandle(key, index) {
if (this.dragging) {
let value =
key === 'value'
? this.selectDataOptions[index]
: this.allDataOptions[index];
this.lastIndex = index;
let options =
key === 'value' ? this.selectDataOptions : this.allDataOptions;
if (this.lastIndex > this.startIndex) {
this.selected[key] = options
.slice(this.startIndex, this.lastIndex + 1)
.map(item => this.getValue('key', item));
} else {
this.selected[key] = options
.slice(this.lastIndex, this.startIndex + 1)
.map(item => this.getValue('key', item));
}
}
},
dragendHandle(e) {
this.dragging = false;
this.startIndex = undefined;
this.lastIndex = undefined;
document.removeEventListener('mouseup', this.dragendHandle);
},
resetSelect(key) {
this.selected[key] = [];
},
}, },
}; };
</script> </script>
<style lang="scss"> <style lang="scss">
@import '@/assets/styles/variables.scss';
.transfer-wrap { .transfer-wrap {
height: 600px; height: 600px;
display: flex; display: flex;
...@@ -260,8 +317,19 @@ export default { ...@@ -260,8 +317,19 @@ export default {
height: 560px; height: 560px;
.transfer-selectData-select, .transfer-selectData-select,
.transfer-allData-select { .transfer-allData-select {
background-color: #fff;
margin: 0;
padding: 0;
overflow-y: auto;
width: 100%; width: 100%;
height: 100%; height: 100%;
li {
user-select: none;
&.selected {
color: #fff;
background-color: $subMenuBg;
}
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment