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": "^2.6.14",
"vue-clickaway": "^2.2.2", "vue-clickaway": "^2.2.2",
"vue-router": "^3.5.1", "vue-router": "^3.5.1",
"vuedraggable": "^2.24.3",
"vuex": "^3.6.2" "vuex": "^3.6.2"
}, },
"devDependencies": { "devDependencies": {
@ -10311,6 +10312,12 @@
"websocket-driver": "^0.7.4" "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": { "node_modules/source-map": {
"version": "0.6.1", "version": "0.6.1",
"resolved": "https://registry.npmmirror.com/source-map/-/source-map-0.6.1.tgz", "resolved": "https://registry.npmmirror.com/source-map/-/source-map-0.6.1.tgz",
@ -11259,6 +11266,15 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true "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": { "node_modules/vuex": {
"version": "3.6.2", "version": "3.6.2",
"resolved": "https://registry.npmmirror.com/vuex/-/vuex-3.6.2.tgz", "resolved": "https://registry.npmmirror.com/vuex/-/vuex-3.6.2.tgz",

1
package.json

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

79
src/components/paymentMethod.vue

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

13
src/views/Register.vue

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

Loading…
Cancel
Save