<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>
- 微信小程序列表拖动排序Demo
wxml页面编写 <view class="container"> <view bindtap="box" class="box&q ...
- 第一个mpvue小程序开发总结
前言 说起小程序,其实在去年我都还只试着照着官方文档写过demo的,不过现在这家公司小程序做得比较多,我来之后也参与了几个小程序的开发了,最开始那几个是用的wepy,最近一个开始转用mpvue开发,最 ...
- mpvue 小程序开发之 数据埋点统计
mpvue 小程序开发之 数据埋点统计 在开发过程中,有数据统计的需求,需要获取小程序当前页面和来源页面的数据,以及页面的停留时间 在对小程序api进行了一番研究之后,发现获取这些数据其实并不难 当前 ...
- 微信小程序通讯录字母排序
微信小程序通讯录 字母排序效果: demo地址:https://github.com/PeachCoder/wechat-contacts
- 微信小程序错误——mpvue小程序:未找到 app.json 中的定义的 pages "pages/XXX/XXX" 对应的 WXML 文件
背景 在刚开始学习开发小程序时,使用微信开发工具在app.json建立页面,写好配置文件名称后,应该会自动生成页面的4个文件,结果没有生成文件,反而报错:mpvue小程序:未找到 app.json 中 ...
- mpvue小程序开发之 iconfont图标引入
背景: mpvue进行小程序项目开发时候,会有很多图标需求,但是小程序官方提供的icon图标库实在有限而且也不利于调样式,所有想到和之前前端项目一样引入iconfont. 图标加入购物车及项目 下载到 ...
- mpvue小程序开发之 wx.getUserInfo获取用户信息授权
一.背景 在使用美团的mpvue2.0框架搭建起小程序项目后,做获取用户信息时遇到一些问题:微信小程序更新api后,获取用户信息只能通过button上的绑定方法 来获取用户信息,vue上方法绑定不能直 ...
- mpVue小程序全栈开发
1.微信小程序,mpVue和wepy的对比 2. 3.es6中关于数组的一些方法 <script> let arr = [,,,] // 遍历 arr.forEach(v => { ...
- mpvue小程序图片404
mpvue开发小程序时候,要添加静态本地图片 <img src="../../images/bg.png" alt=""> 会报错: VM14878 ...
随机推荐
- Beautiful Soup 4.2.0
Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式 快速开始 pip install beaut ...
- java.lang.OutOfMemoryError: Java heap space异常
最近使用Tomcat跑项目时,其他项目可以正常运行,但有一个项目报java.lang.OutOfMemoryError: Java heap space异常,查了资料后,找到一个处理我所遇见异常的解决 ...
- Eclipse 快键键(持续更新)
本人抛弃一些简单常见的快键键,例如 ctrl+c ,+v ,+z之类的 1.ctrl+d 删除一整行 2.ctrl+f 搜索 3.光标选中几行,ctrl+alt+↓ 向下复制选中的那几行 4.光标 ...
- Django的serializers使用
Serializer 在这里通过一个验证用户身份的例子说明rest_framework中serializer.Serializer的使用. 编写serializer Serializer的使用不需要依 ...
- elmah数据库sql脚本
/* 错误管理工具 SQL代码 */CREATE TABLE dbo.ELMAH_Error( ErrorId UNIQUEIDENTIFIER NOT NULL, Application NVARC ...
- 基本的数据类型 void关键字 都存在类类型
- structs2----数据封装以及拦截器
技术分析之在Struts2框架中使用Servlet的API 1. 在Action类中也可以获取到Servlet一些常用的API * 需求:提供JSP的表单页面的数据,在Action中使用Servlet ...
- css 层叠式样式表(3)
样式分类 大小 -- 调整div大小,长 width,高 height.长可以直接100%横向沾满屏幕,高不可以. 背景 background-color 背景色 background-image ...
- JavaPersistenceWithMyBatis3笔记-第1章-001
一.介绍 1.项目结构 2.数据库结构 二.代码 1.Mapper package com.mybatis3.mappers; import java.util.List; import com.my ...
- 华为JAVA机试流程
1.JAVA机试流程:①打开IE浏览器,输入机试系统IP地址(以当天告知的地址为准):②输入姓名.手机,选择“C/C++”或“JAVA”,登录:③登录后显示题目,阅读题目并点击页面最下方的“下载框架文 ...