Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwei1994 committed May 19, 2020
1 parent 0b0cbd3 commit 61c67bd
Show file tree
Hide file tree
Showing 14 changed files with 628 additions and 123 deletions.
12 changes: 8 additions & 4 deletions components/common/prompt.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
:password="popupConfig.password"
v-model="popupInput"
:placeholder="popupConfig.placeholder"
:maxlength="popupConfig.maxlength"
focus="true"
placeholder-style="color:#999"
:confirm-type="popupConfig.confirmType"
/>
</view>
<view class="popupBut">
<button @click="onPopupBut">{{ popupConfig.confirmText }}</button>
<button @click="onConfirm">{{ popupConfig.confirmText }}</button>
</view>
</view>
</view>
Expand Down Expand Up @@ -49,6 +51,8 @@ export default {
placeholder: '',
password: false,
inputType: 'text',
maxlength: 140,
confirmType: "done"
},
popupInput: '',
popupShow: false
Expand Down Expand Up @@ -89,15 +93,15 @@ export default {
onPopupHide() {
this.popupShow = false;
},
onPopupBut() {
onConfirm() {
if (this.popupInput == '') {
uni.showToast({
title: this.popupConfig.placeholder || '请输入',
title: '请输入',
icon: 'none'
});
return;
}
this.$emit('change', {
this.$emit('confirm', {
close:() => {
this.popupShow = false;
},
Expand Down
194 changes: 194 additions & 0 deletions components/common/swipe-action/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<template>
<view class="swipe_action_box" @touchstart="onTouchstart" @touchmove="onTouchmove" @touchcancel="onTouchcancel" @touchend="onTouchend">
<view class="swipe_action_item" :style="{ transform: 'translateX(' + translateX + 'rpx)', transition: 'transform ' + animationTime + 'ms cubic-bezier(.165, .84, .44, 1)' }">
<view class="swipe_action_content"><slot></slot></view>
<view class="swipe_action_btn" ref="swipeActionBtn">
<view v-for="(item,index) of options" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px',
color: item.style && item.style.color ? item.style.color : '#FFFFFF'
}" @click.stop="onClick(index,item)">{{ item.text }}</view>
</view>
</view>
</view>
</template>

<script>
// #ifdef APP-NVUE
const dom = weex.requireModule('dom');
// #endif
export default {
props: {
/**
* 按钮内容
*/
options: {
type: Array,
default () {
return []
}
},
/**
* 禁用
*/
disabled: {
type: Boolean,
default: false
},
/**
* 变量控制开关
*/
show: {
type: Boolean,
default: false
},
/**
* 是否自动关闭
*/
autoClose: {
type: Boolean,
default: true
}
},
data() {
return {
//开始触摸时间
startTime: 0,
//开始触摸距离
touchStartX: 0,
//最大距离
maxWidth: 150,
//滑动距离
translateX: 0,
animationTime: 0,
//上次的位置
currentX: 0
};
},
created() {
if(this.options && typeof(this.options) == "object"){
this.maxWidth = 150 * this.options.length;
}
},
mounted() {
setTimeout(() => {
dom.getComponentRect(this.$refs['swipeActionBtn'], (data) => {
console.log(data);
});
},500);
},
//方法
methods: {
// 手指触摸动作开始
onTouchstart(e) {
if(this.disabled){
return;
}
//储存手指触摸坐标,当前时间戳,当前坐标
this.touchStartX = e.touches[0].clientX;
this.startTime = new Date().getTime();
this.currentX = this.translateX;
},
// 手指触摸后移动
onTouchmove(e) {
if(this.disabled){
return;
}
//手指当前坐标
const clientX = e.touches[0].clientX;
//计算滑动距离
const difference = this.touchStartX - clientX;
//判断左滑还是右滑
if (difference > 0) {
//计算当前已滑动距离
const leftDifference = this.currentX - Math.abs(difference);
//判断是否大于滑动的最大宽度
if (this.maxWidth < Math.abs(leftDifference)) {
this.animationTime = 0;
this.translateX = -this.maxWidth;
} else {
this.animationTime = 0;
this.translateX = leftDifference;
}
} else {
const rightDifference = this.currentX + Math.abs(difference);
if (0 < rightDifference) {
this.animationTime = 0;
this.translateX = 0;
} else {
this.animationTime = 0;
this.translateX = rightDifference;
}
}
},
// 手指触摸动作被打断,如来电提醒,弹窗
onTouchcancel(e) {
if(this.disabled){
return;
}
this.finallySlide(e.changedTouches[0].clientX);
},
// 手指触摸动作结束
onTouchend(e) {
if(this.disabled){
return;
}
this.finallySlide(e.changedTouches[0].clientX);
},
//最终判断滑动
finallySlide(finallyX) {
//手指离开的时间
const endTime = new Date().getTime();
//手机滑动屏幕的总花费时间
const timeDifference = endTime - this.startTime;
//手指触摸总滑动距离
const distanceDifference = this.touchStartX - finallyX;
//判断最终滑动方向
if (distanceDifference > 0) {
//判断是否滑动到左边 滑动距离超过3分之一 或者 滑动时间在300毫秒并且距离在4分之一
if (Math.abs(this.translateX) > this.maxWidth / 2 || (timeDifference < 300 && distanceDifference > this.maxWidth / 4)) {
this.animationTime = 350;
this.translateX = -this.maxWidth;
} else {
this.animationTime = 350;
this.translateX = 0;
}
} else if (distanceDifference < 0) {
//判断是否滑动到右边 滑动距离超过3分之一 或者 滑动时间在300毫秒并且距离在4分之一
if (Math.abs(this.translateX) < this.maxWidth / 2 || (timeDifference < 300 && Math.abs(distanceDifference) > this.maxWidth / 4)) {
this.animationTime = 350;
this.translateX = 0;
} else {
this.animationTime = 350;
this.translateX = -this.maxWidth;
}
}
}
}
};
</script>
<style lang="scss" scoped>
.swipe_action_box {
overflow: hidden;
width: 100vw;
}
.swipe_action_item {
display: flex;
// transition: transform 350ms cubic-bezier(.165, .84, .44, 1);
}
.swipe_action_content {
width: 100vw;
flex-shrink: 0;
}
.swipe_action_btn {
display: flex;
flex-shrink: 0;
}
.swipe_action_btn > view {
padding: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 0 20rpx;
}
</style>
3 changes: 2 additions & 1 deletion config/baseUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const courtConfig = {
//微信公众号APPID
publicAppId: "",
//请求接口
baseUrl: "http://192.168.1.10:8088/project/",
// baseUrl: "http://192.168.1.10:8088/project/",
// baseUrl: "http://47.107.117.196/home_decoration/",
baseUrl: "http://dev.kemean.net/home_decoration/",
//webSocket地址
// socketUrl: "ws://localhost:8001/",
//平台名称
Expand Down
19 changes: 19 additions & 0 deletions config/requestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ setTimeout(() => {
});
},200);
// #endif

//可以new多个request来支持多个域名请求
let $http = new request({
//接口请求地址
Expand All @@ -33,6 +34,24 @@ let $http = new request({
'project_token': base.projectToken, //项目token(可删除)
}
});
// 添加获取七牛云token的方法
$http.getQnToken = function(callback){
//该地址需要开发者自行配置(每个后台的接口风格都不一样)
$http.get("api/kemean/aid/qn_upload").then(data => {
/*
*接口返回参数:
*visitPrefix:访问文件的域名
*token:七牛云上传token
*folderPath:上传的文件夹
*/
callback({
visitPrefix: data.visitPrefix,
token: data.token,
folderPath: data.folderPath
});
});
}

//当前接口请求数
let requestNum = 0;
//请求开始拦截器
Expand Down
12 changes: 12 additions & 0 deletions pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"navigationBarTitleText": "图片上传/文件上传"
}
},
{
"path": "pages/demo/quUploadFile",
"style": {
"navigationBarTitleText": "七牛云图片上传/文件上传"
}
},
{
"path": "pages/demo/areaSelect",
"style": {
Expand All @@ -36,6 +42,12 @@
"navigationBarTitleText": "弹窗输入框"
}
},
{
"path": "pages/demo/swipeAction",
"style": {
"navigationBarTitleText": "滑动操作"
}
},
{
"path": "pages/template/webView",
"style": {
Expand Down
8 changes: 8 additions & 0 deletions pages/demo/common.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<image src="../../static/demo/icon_case.png" mode="aspectFit"></image>
<text>图片上传/文件上传</text>
</view>
<view class="nav_list" @click="onPageJump('/pages/demo/quUploadFile')">
<image src="../../static/demo/icon_case.png" mode="aspectFit"></image>
<text>七牛云图片上传/文件上传</text>
</view>
<view class="nav_list" @click="onPageJump('/pages/demo/areaSelect')">
<image src="../../static/demo/icon_case.png" mode="aspectFit"></image>
<text>地区选择</text>
Expand All @@ -25,6 +29,10 @@
<image src="../../static/demo/icon_case.png" mode="aspectFit"></image>
<text>弹窗输入框</text>
</view>
<view class="nav_list" @click="onPageJump('/pages/demo/swipeAction')">
<image src="../../static/demo/icon_case.png" mode="aspectFit"></image>
<text>滑动操作</text>
</view>
</view>
</template>

Expand Down
24 changes: 20 additions & 4 deletions pages/demo/list.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<template>
<view class="">
<nav-bar title="列表"></nav-bar>
<nav-bar title="下拉刷新/上拉加载列表"></nav-bar>
<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" @down="downCallback" @up="upCallback">
<view class="notice">本Demo的下拉刷新: 添加新数据到列表顶部</view>
<view class="notice">引入插件:https://ext.dcloud.net.cn/plugin?id=343</view>
<view class="table_box">
<view class="table_title">使用文档</view>
<view class="table_content">
<text @click="onJumpWebview('http://www.mescroll.com/')">文档地址:http://www.mescroll.com/</text>
</view>
</view>
<view class="news-li" v-for="news in dataList" :key="news.id">
<view>{{news.title}}</view>
<view class="new-content">{{news.content}}</view>
Expand Down Expand Up @@ -65,8 +69,20 @@
//联网失败, 结束加载
this.mescroll.endErr();
})
},
onJumpWebview(url){
// #ifdef H5
window.open(url);
// #endif
// #ifndef H5
this.$store.commit("setWebViewUrl", url);
uni.navigateTo({
url: '/pages/template/webView'
});
// #endif
}
}
},
}
</script>

Expand Down
Loading

0 comments on commit 61c67bd

Please sign in to comment.