<template>
<div>
<div style="width:90%;height:40px;line-height:40px;margin:auto;">
<div style="float:left;font-size: 15px;">我的应用</div>
<div style="float:right;font-size: 15px;" @click="edit">{{status==false?'编辑':'完成'}}</div>
</div>
<div class="funslist">
<movable-area style="width:100%;margin:auto;height:180px;">
<div v-for="(item,index) in choose_list" :key="index">
<div
v-if="item.status == true"
class="application"
:data-index="index"
@longpress="longtap"
@touchstart="touchs(index)"
@touchend="touchend"
@touchmove="touchm"
>
<img class="fi-img" :src="item.src">
<view class="fi-text">{{item.name}}</view>
<view class="fi-badge" @click="alldelfun(item.id,index)" v-if="status==true">-</view>
</div>
</div>
<div style="clear:both;"></div>
<movable-view
animation
direction="all"
damping="5000"
:x="x"
:y="y"
friction="1"
:disabled="disabled"
>
<view :hidden="hidden">
<div class="application1">
<img class="fi-img" :src="list.src">
<view class="fi-text">{{list.name}}</view>
</div>
</view>
</movable-view>
</movable-area>
</div>
<div style="margin-top:20px;">
<h2 class="title">全部应用</h2>
<div class="funslist">
<div v-for="(item,index) in all_list" :key="index">
<div class="application1">
<img class="fi-img" :src="item.src">
<view class="fi-text">{{item.name}}</view>
<view
class="fi-badge"
v-if="item.status==true && status==true"
@click="alldelfun(item.id,index)"
>-</view>
<view
class="fi-badge"
v-if="item.status==false && status==true"
style="background:#1892e0"
@click="alladdfun(item.id,index)"
>+</view>
</div>
</div>
<div style="clear:both;"></div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
hidden: true,
flag: false,
x: 0,
y: 0,
disabled: true,
elements: [],
all_list: [
{
id: 1,
name: "我的课程",
src: "../../static/image/new_11.png",
url: "../studentTimetab/main",
status: true
},
{
id: 2,
name: "点击报名",
src: "../../static/image/new_13.png",
url: "../student/main",
status: true
},
{
id: 3,
name: "学生菜谱",
src: "../../static/image/new_14.png",
url: "../studentMenu/main",
status: true
},
{
id: 4,
name: "请假申请",
src: "../../static/image/new_15.png",
url: "../studentLeave/main",
status: true
}],
choose_list: [
{
id: 1,
name: "我的课程",
src: "../../static/image/new_11.png",
url: "../studentTimetab/main",
status: true
},
{
id: 2,
name: "点击报名",
src: "../../static/image/new_13.png",
url: "../student/main",
status: true
},
{
id: 3,
name: "学生菜谱",
src: "../../static/image/new_14.png",
url: "../studentMenu/main",
status: true
},
{
id: 4,
name: "请假申请",
src: "../../static/image/new_15.png",
url: "../studentLeave/main",
status: true
}],
beginIndex: null,
list: {},
status: false
};
},
methods: {
//编辑
edit() {
this.status = !this.status;
},
//删减
alldelfun(id, index) {
this.all_list[index].status = false;
this.choose_list[index].status = false;
},
alladdfun(id, index) {
let num = 0;
let that = this;
this.all_list.forEach(e => {
if (e.status == true) {
num++;
}
});
if (num == 7) {
this.$index.showToast("应用已达最高数量,请先移除部分再添加");
} else {
that.$set(that.all_list[index], "status", true);
that.$set(that.choose_list[index], "status", true);
}
},
//长按
longtap(e) {
if (this.status == true) {
this.x = e.currentTarget.offsetLeft;
this.y = e.currentTarget.offsetTop;
this.hidden = false;
this.flag = true;
}
},
//触摸开始
touchs(index) {
if (this.status == true) {
this.beginIndex = index;
this.list = this.choose_list[index];
}
},
//触摸结束
touchend(e) {
let that = this;
if (!that.flag) {
return;
}
const endx = e.mp.changedTouches[0].pageX;
const endy = e.mp.changedTouches[0].pageY;
for (var j = 0; j < that.elements.length; j++) {
const item = that.elements[j];
if (
endx > item.left &&
endx < item.right &&
endy > item.top &&
endy < item.bottom
) {
const endIndex = item.dataset.index;
const beginIndex = that.beginIndex;
//向后移动
if (beginIndex < endIndex) {
console.log("向后移");
let tem = that.choose_list[beginIndex];
for (let i = beginIndex; i < endIndex; i++) {
that.choose_list[i] = that.choose_list[i + 1];
}
that.choose_list[endIndex] = tem;
}
//向前移动
if (beginIndex > endIndex) {
console.log("向前移");
let tem = that.choose_list[beginIndex];
for (let i = beginIndex; i > endIndex; i--) {
that.choose_list[i] = that.choose_list[i - 1];
}
that.choose_list[endIndex] = tem;
}
}
}
that.hidden = true;
that.flag = false;
},
//滑动
touchm(e) {
if (this.flag && this.status == true) {
const x = e.mp.touches[0].pageX;
const y = e.mp.touches[0].pageY;
this.x = x - 65;
this.y = y - 45;
}
}
},
mounted() {
var query = wx.createSelectorQuery();
var nodesRef = query.selectAll(".application");
nodesRef
.fields(
{
dataset: true,
rect: true
},
result => {
this.elements = result;
console.log(this.elements);
}
)
.exec();
}
};
</script>
<style>
.title {
width: 90%;
margin: 10px auto 0;
font-size: 15px;
}
.funslist {
width: 90%;
margin: 0 auto;
margin-top: 10px;
}
.funslist .fi-img {
display: block;
width: 40%;
height: 30px;
margin: 10px auto 5px;
}
.application,
.application1 {
width: 75px;
height: 75px;
margin-left: 5px;
margin-right: 5px;
float: left;
background: #eee;
margin-bottom: 10px;
border-radius: 5px;
padding-bottom: 5px;
position: relative;
}
.fi-text {
width: 100%;
height: 20px;
line-height: 20px;
font-size: 13px;
text-align: center;
}
.fi-badge {
position: absolute;
width: 15px;
height: 15px;
border-radius: 50%;
color: #fff;
background: #e34f57;
top: 5px;
right: 5px;
color: #fff;
text-align: center;
line-height: 12px;
font-size: 14px;
}
</style>

mpvue 小程序应用拖动排序的更多相关文章

  1. 微信小程序列表拖动排序Demo

    wxml页面编写 <view class="container"> <view bindtap="box" class="box&q ...

  2. 第一个mpvue小程序开发总结

    前言 说起小程序,其实在去年我都还只试着照着官方文档写过demo的,不过现在这家公司小程序做得比较多,我来之后也参与了几个小程序的开发了,最开始那几个是用的wepy,最近一个开始转用mpvue开发,最 ...

  3. mpvue 小程序开发之 数据埋点统计

    mpvue 小程序开发之 数据埋点统计 在开发过程中,有数据统计的需求,需要获取小程序当前页面和来源页面的数据,以及页面的停留时间 在对小程序api进行了一番研究之后,发现获取这些数据其实并不难 当前 ...

  4. 微信小程序通讯录字母排序

    微信小程序通讯录 字母排序效果: demo地址:https://github.com/PeachCoder/wechat-contacts

  5. 微信小程序错误——mpvue小程序:未找到 app.json 中的定义的 pages "pages/XXX/XXX" 对应的 WXML 文件

    背景 在刚开始学习开发小程序时,使用微信开发工具在app.json建立页面,写好配置文件名称后,应该会自动生成页面的4个文件,结果没有生成文件,反而报错:mpvue小程序:未找到 app.json 中 ...

  6. mpvue小程序开发之 iconfont图标引入

    背景: mpvue进行小程序项目开发时候,会有很多图标需求,但是小程序官方提供的icon图标库实在有限而且也不利于调样式,所有想到和之前前端项目一样引入iconfont. 图标加入购物车及项目 下载到 ...

  7. mpvue小程序开发之 wx.getUserInfo获取用户信息授权

    一.背景 在使用美团的mpvue2.0框架搭建起小程序项目后,做获取用户信息时遇到一些问题:微信小程序更新api后,获取用户信息只能通过button上的绑定方法 来获取用户信息,vue上方法绑定不能直 ...

  8. mpVue小程序全栈开发

    1.微信小程序,mpVue和wepy的对比 2. 3.es6中关于数组的一些方法 <script> let arr = [,,,] // 遍历 arr.forEach(v => { ...

  9. mpvue小程序图片404

    mpvue开发小程序时候,要添加静态本地图片 <img src="../../images/bg.png" alt=""> 会报错: VM14878 ...

随机推荐

  1. Json-lib 进行java与json字符串转换之一

    这篇文章主要介绍了在java中,JSON字符串与java对象的相互转换实例详解,非常不错,具有参考借鉴价值,需要的朋友可以参考下. 在开发过程中,经常需要和别的系统交换数据,数据交换的格式有XML.J ...

  2. javascript 中的JSON.stringify - 将对象和数组转换为json格式(来源于网络)

          JSON.stringify 函数 (JavaScript) 将 JavaScript 值转换为 JavaScript 对象表示法 (Json) 字符串.     JSON.stringi ...

  3. leetcode628

    这道题十分不容易啊,做到半夜. class Solution { public: static int cmp628(int a, int b) { return a > b; } static ...

  4. Navicat for Oracle中如何使用外键

    转自:https://blog.csdn.net/weixin_39183543/article/details/80555104 1. 外键名最后保存的时候自动生成: 2. 参考模式自动生成: 3. ...

  5. Android编译系统产品线

    1.Android源码中的产品线解析 通常产品厂商在拿到Android源码后会在Android源码基础上进行定制修改,以匹配适应自己的产品.这就引入了产品线的概念.Android系统源码中,产品相关的 ...

  6. opencv中文网站相关下载

    http://wiki.opencv.org.cn/index.php/Download

  7. JS中,根据div数值判断弹出窗口

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. hbase.client.RetriesExhaustedException: Can't get the locations hive关联Hbase查询报错

    特征1: hbase.client.RetriesExhaustedException: Can't get the locations 特征2: hbase日志报错如下:org.apache.zoo ...

  9. Hbase优化记录

    <configuration><property><name>hbase.rootdir</name><value>hdfs://gagcl ...

  10. pthon之函数式编程

    函数式编程是一种抽象计算的编程范式. 不同语言的抽象层次不同:计算机硬件->汇编语言->C语言->Python语言 指令        ->           ->函数 ...