Browse Source

元素拖动实现

pull/69/head
zq 2 months ago
parent
commit
d1e386b365
  1. 16
      package-lock.json
  2. 1
      package.json
  3. 79
      src/components/paymentMethod.vue
  4. 13
      src/views/Register.vue

16
package-lock.json

@ -16,6 +16,7 @@
"vue": "^2.6.14",
"vue-clickaway": "^2.2.2",
"vue-router": "^3.5.1",
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2"
},
"devDependencies": {
@ -10311,6 +10312,12 @@
"websocket-driver": "^0.7.4"
}
},
"node_modules/sortablejs": {
"version": "1.10.2",
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.10.2.tgz",
"integrity": "sha512-YkPGufevysvfwn5rfdlGyrGjt7/CRHwvRPogD/lC+TnvcN29jDpCifKP+rBqf+LRldfXSTh+0CGLcSg0VIxq3A==",
"license": "MIT"
},
"node_modules/source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmmirror.com/source-map/-/source-map-0.6.1.tgz",
@ -11259,6 +11266,15 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true
},
"node_modules/vuedraggable": {
"version": "2.24.3",
"resolved": "https://registry.npmjs.org/vuedraggable/-/vuedraggable-2.24.3.tgz",
"integrity": "sha512-6/HDXi92GzB+Hcs9fC6PAAozK1RLt1ewPTLjK0anTYguXLAeySDmcnqE8IC0xa7shvSzRjQXq3/+dsZ7ETGF3g==",
"license": "MIT",
"dependencies": {
"sortablejs": "1.10.2"
}
},
"node_modules/vuex": {
"version": "3.6.2",
"resolved": "https://registry.npmmirror.com/vuex/-/vuex-3.6.2.tgz",

1
package.json

@ -16,6 +16,7 @@
"vue": "^2.6.14",
"vue-clickaway": "^2.2.2",
"vue-router": "^3.5.1",
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2"
},
"devDependencies": {

79
src/components/paymentMethod.vue

@ -1,32 +1,33 @@
<template>
<div class="payment-wrap">
<div class="payment-item" v-for="item in paymentList" :key="item.name">
<dl>
<dt>
<img v-if="item.type == '1'" src="@/assets/register/weixin_pay.png" alt="">
<img v-if="item.type == '2'" src="@/assets/register/zhifubao_pay.png" alt="">
<img v-if="item.type == '3'" src="@/assets/register/taobao_pay.png" alt="">
<img v-if="item.type == '4'" src="@/assets/register/jingdong_pay.png" alt="">
</dt>
<dd>
<p>{{ item.name }}</p>
<p>{{ item.num }}</p>
</dd>
</dl>
<GuipSwitch :modelValue="item.flag" activeText="开启" inactiveText="关闭" @change="onSwitchChange">
</GuipSwitch>
</div>
<draggable v-model="list" @start="drag=true" @end="onEnd" :move="checkMove" handle=".drag-handle" >
<div class="payment-item" v-for="item in list" :key="item.name">
<dl>
<dt class="drag-handle">
<img :src="item.img" alt="">
</dt>
<dd>
<p>{{ item.name }}</p>
<p>{{ item.num }}</p>
</dd>
</dl>
<el-form>
<GuipSwitch :modelValue="item.flag" activeText="开启" inactiveText="关闭" @change="onSwitchChange">
</GuipSwitch>
</el-form>
</div>
</draggable>
</div>
</template>
<script>
import GuipSwitch from '@/components/GuipSwitch.vue';
import draggable from 'vuedraggable';
export default {
name: '',
props:['paymentList'],
components: {
GuipSwitch
GuipSwitch,
draggable
},
data(){
return {
@ -35,13 +36,48 @@ export default {
'2':'zhifubao_pay.png',
'3':'taobao_pay.png',
'4':'jingdong_pay.png',
}
},
list:[],
drag: false,
}
},
watch:{
paymentList: {
immediate: true,
handler(newVal) {
this.list = newVal;
},
},
},
methods:{
onSwitchChange(data){
//
console.log(data,'---');
},
onEnd() {
this.drag = false;
// list props paymentList $emit
console.log('Drag and drop ended', this.list); //
},
checkMove(evt) {
//
const targetIndex = this.list.length - 1; // 1
//
// console.log(evt.relatedContext.index === evt.draggedContext.index,targetIndex === evt.draggedContext.index,'0000targetIndex00');
if ((evt.relatedContext.index === targetIndex) || (targetIndex === evt.draggedContext.index)) {
return false; //
}
return true; //
}
// onStart(event) {
// console.log(event,'event====');
// //
// const index = this.list.findIndex(item => item.id === event.draggedContext.element.id);
// // event.cancel()
// if (index === this.list.length - 1) {
// event.cancel(); //
// }
// }
}
}
</script>
@ -77,5 +113,8 @@ export default {
color: #1E2226;
}
}
.drag-handle {
cursor: move; /* 鼠标悬停时显示可拖拽光标 */
}
}
</style>

13
src/views/Register.vue

@ -479,7 +479,7 @@
</div>
</div>
<!-- 设置域名弹出框 -->
<GuipDialog :dialogVisible="dialogVisible" :title="dialogTitle" :show-close-button="false"
<GuipDialog :dialogVisible="true" :title="dialogTitle" :show-close-button="false"
:show-cancel-button="showCancelButton" @confirm="handleConfirm" @cancel="handleCancel" @close="handleClose"
@dialogVisibleChange="dialogVisibleChange">
<PaymentMethod :paymentList="paymentList" />
@ -535,7 +535,6 @@
</div>
</el-dialog>
<Footer></Footer>
<div class="register-btns">
<GuipButton type="system" :btnstyle="{ width: '144px', height: '46px' }" @click="jumpCurStep">跳过</GuipButton>
<GuipButton type="primary" :btnstyle="{ width: '144px', height: '46px' }" @click="finishCurStep">完成</GuipButton>
@ -543,7 +542,6 @@
</div>
</template>
<script>
import Footer from '@/components/Footer.vue';
import GuipButton from '@/components/GuipButton.vue';
import GuipFormItem from '@/components/GuipFormItem.vue';
import GuipInput from '@/components/GuipInput.vue';
@ -567,7 +565,6 @@ export default {
GuipRadio,
GuipSelect,
SvgIcon,
Footer,
GuipSwitch,
GuipDialog,
PaymentMethod,
@ -772,24 +769,28 @@ export default {
type: '1',
name: '小知攻城狮',
num: '1520574481 (wx1bda8b3d08d169cb)',
flag: true
flag: true,
img:require('@/assets/register/weixin_pay.png')
},
{
type: '2',
name: '自收款',
num: 'wangyong@kuailebanshou.com',
img:require('@/assets/register/zhifubao_pay.png'),
flag: true
},
{
type: '3',
name: '店铺收款',
num: '轻歌曼舞82',
img:require('@/assets/register/taobao_pay.png'),
flag: false
},
{
type: '4',
name: '京东收款',
name: '平台检测卡',
num: 'celunwen',
img:require('@/assets/register/jingdong_pay.png'),
flag: false
},
],

Loading…
Cancel
Save