Browse Source

[修改] 个人中心页面获得红线改为绑定手机号

[新增] 上传图片组件
[新增] 拖拽排序组件,后期上传图片组件基于此做排序
master
邓平艺 5 years ago
parent
commit
f0900247e9
  1. 1
      App.vue
  2. 22
      common/styles/sharedIconFont.css
  3. 154
      components/lf-uploadImage/lf-uploadImage.vue
  4. 6
      pages.json
  5. 2
      pages/my/index.vue
  6. 325
      pages/test/drag.vue
  7. 10
      pages/test/test.vue

1
App.vue

@ -119,6 +119,7 @@
@import "@/uview-ui/index.scss";
@import '@/common/styles/theme.css';
@import '@/common/styles/common.css';
@import '@/common/styles/sharedIconFont.css';
@import '@/common/styles/iconfont.css';
//

22
common/styles/sharedIconFont.css

@ -0,0 +1,22 @@
@font-face {
font-family: "lf-iconfont"; /* Project id 2758976 */
src: url('//at.alicdn.com/t/font_2758976_9bezuvselm.woff2?t=1629452232587') format('woff2'),
url('//at.alicdn.com/t/font_2758976_9bezuvselm.woff?t=1629452232587') format('woff'),
url('//at.alicdn.com/t/font_2758976_9bezuvselm.ttf?t=1629452232587') format('truetype');
}
.lf-iconfont {
font-family: "lf-iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.lf-icon-shanchu:before {
content: "\e674";
}
.lf-icon-jia:before {
content: "\e715";
}

154
components/lf-uploadImage/lf-uploadImage.vue

@ -0,0 +1,154 @@
<template>
<view class="upload-images">
<view class="upload-image-item"
:style="{order: uploadButton == 'front' ? '1' : '2'}"
@click="uploadImage"
v-if="(count == -1) || (image_list.length < count)">
<text class="lf-iconfont lf-icon-jia upload-image-item-after"></text>
</view>
<view class="upload-image-item"
:style="{order: uploadButton == 'front' ? '2' : '1'}"
v-for="(item, index) in image_list" :key="index"
@click="lookImage(index)">
<image :src="item" mode="aspectFill"></image>
<view class="remove-image" @click.stop="removeInage(index)" v-if="showDelete">
<text class="lf-iconfont lf-icon-shanchu"></text>
</view>
</view>
</view>
</template>
<script>
export default {
props: {
uploadButton: {
type: String, // frontbehind
default: 'front'
},
showDelete: {
type: Boolean, //
default: true
},
count: {
type: Number, // , 6
default: 6
},
size: {
type: Number, // M
default: 10
},
drag: {
type: Boolean, // TODO
default: false
}
},
data(){
return {
image_list: []
}
},
onLoad(){
},
methods: {
//
uploadImage(){
let current_count = this.$props.count - this.image_list.length;
if(this.$props.count == -1){
current_count = 9;
}
if(current_count == 0) return;
uni.chooseImage({
count: current_count,
complete: result => {
if(result.errMsg == "chooseImage:fail cancel"){
return; //
}
let tempFiles = result.tempFiles;
let image_list = [];
let overstep = false;
tempFiles.map(item => {
//
let size = Math.floor((Number(this.$props.size) || 1) * 1024 * 1024);
if(item.size < size){
image_list.push(item.path);
}else{
overstep = true;
}
})
if(overstep){
uni.showModal({
title: '温馨提示',
content: '您上传的图片含有超出10M大小的限制,请优化大小后再上传!',
showCancel: false
})
}
this.image_list.push(...image_list);
}
})
},
//
lookImage(current){
if(this.image_list.length <= 0) return;
this.$u.throttle(() => {
uni.previewImage({
urls: this.image_list,
current: current
});
}, 500);
},
//
removeInage(current){
this.image_list.splice(current, 1);
},
//
getUploadImage(){
return this.image_list;
}
}
}
</script>
<style lang="scss" scoped="scoped">
.upload-images{
display: flex;
flex-wrap: wrap;
margin-top: 30rpx;
margin-bottom: 18rpx;
.upload-image-item{
width: 220rpx;
height: 220rpx;
background: #DDDDDD;
position: relative;
margin-right: 12rpx;
&:nth-child(3n){
margin-right: 0rpx;
}
&:nth-child(n+4){
margin-top: 12rpx;
}
image{
width: 100%;
height: 100%;
}
.remove-image{
position: absolute;
right: -4rpx;
top: -18rpx;
color: #e74c3c;
font-size: 40rpx;
padding: 8rpx;
}
}
.upload-image-item-after{
position: absolute;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 60rpx;
color: #999999;
}
}
</style>

6
pages.json

@ -185,6 +185,12 @@
"navigationBarTitleText": "测试专用"
}
},
{
"path": "pages/test/drag",
"style": {
"navigationBarTitleText": "测试拖拽"
}
},
{
"path": "pages/my/innerMonologue",
"style": {

2
pages/my/index.vue

@ -13,7 +13,7 @@
</view>
</view>
<view class="lf-bg-white span-btn1" @click="$url('/pages/my/exclusiveMatch')">
获得红线
绑定手机号
</view>
</view>
<view class="lf-row-between" style="height: 98rpx;padding: 0 32rpx;">

325
pages/test/drag.vue

@ -0,0 +1,325 @@
<template>
<view>
<view :style="{'overflow-x': overOnePage ? 'hidden' : 'initial'}">
<view class="item-wrap" :style="{'height': itemWrapHeight +'px'}">
<view class="item"
:class="{'cur': cur == index, 'zIndex': curZ == index, 'itemTransition': itemTransition}"
v-for="(item, index) in list"
:key="index"
:id="'item'+index"
:data-key="item.key"
:data-index="index"
:style="[itemStyle(index, item, item.key)]"
@longpress="longPress"
@touchmove.stop="touchMove"
@touchend.stop="touchEnd">
<view class="info">
<view>
<image :src="item.data"></image>
</view>
</view>
</view>
</view>
</view>
<view v-if="overOnePage" class="indicator">
<view>滑动此区域滚动页面</view>
</view>
</view>
</template>
<script>
export default {
props: {
},
data(){
return {
touch: false,
startX: 0,
startY: 0,
columns: 3,
item: {},
tranX: 0,
tranConstX: 0,
itemWrap: {},
tranY: 0,
teanConstY: 0,
overOnePage: false,
windowHeight: 0,
originKey: null,
list: [],
cur: -1,
curZ: -1,
listData: [
'https://picsum.photos/200',
'https://picsum.photos/200',
'https://picsum.photos/200',
'https://picsum.photos/200',
'https://picsum.photos/200/300'],
itemWrapHeight: 0
}
},
computed: {
itemStyle(){
let that = this;
return function(index, item, key){
let style_obj = {
width: Math.floor(100 / that.columns) +'%',
'margin-top': Math.ceil((key+1) / that.columns) * 5 +'px'
}
let str = 'translate3d(';
if(index === that.cur){
str += that.tranX +'px';
str += ', ';
str += that.tranY +'px';
}else{
str += item.tranX +'px';
str += ', ';
str += item.tranY +'px';
}
str += ', 0px)';
style_obj.transform = str;
return style_obj;
}
}
},
mounted(){
this.init();
},
methods: {
//
longPress(e) {
this.touch = true;
this.startX = e.changedTouches[0].pageX
this.startY = e.changedTouches[0].pageY
let index = e.currentTarget.dataset.index;
if(this.columns === 1) { // X
this.tranConstX = 0;
} else { // X, 使 item
this.tranConstX = this.startX - this.item.width / 2 - this.itemWrap.left;
}
// Y, 使 item
this.teanConstY = this.startY - this.item.height / 2 - this.itemWrap.top;
this.tranY = this.teanConstY;
this.tranX = this.tranConstX;
this.cur = index;
this.curZ = index;
// #ifndef H5
uni.vibrateShort();
// #endif
},
//
touchMove(e) {
if (!this.touch) return;
let tranX = e.touches[0].pageX - this.startX + this.tranConstX; // TODO
let tranY = e.touches[0].pageY - this.startY + this.teanConstY;
let overOnePage = this.overOnePage;
// , page
if(overOnePage) {
if(e.touches[0].clientY > this.windowHeight - this.item.height) {
uni.pageScrollTo({
scrollTop: e.touches[0].pageY + this.item.height - this.windowHeight,
duration: 300
});
} else if(e.touches[0].clientY < this.item.height) {
uni.pageScrollTo({
scrollTop: e.touches[0].pageY - this.item.height,
duration: 300
});
}
}
this.tranX = tranX;
this.tranY = tranY;
let originKey = e.currentTarget.dataset.key;
let endKey = this.calculateMoving(tranX, tranY);
//
if (originKey == endKey || this.originKey == originKey) return;
this.originKey = originKey;
this.insert(originKey, endKey);
},
// key
calculateMoving(tranX, tranY) {
let rows = Math.ceil(this.list.length / this.columns) - 1;
let i = Math.round(tranX / this.item.width);
let j = Math.round(tranY / this.item.height);
i = i > (this.columns - 1) ? (this.columns - 1) : i;
i = i < 0 ? 0 : i;
j = j < 0 ? 0 : j;
j = j > rows ? rows : j;
let endKey = i + this.columns * j;
endKey = endKey >= this.list.length ? this.list.length - 1 : endKey;
return endKey
},
// keykeykey
insert(origin, end) {
let list;
if (origin < end) {
list = this.list.map((item) => {
if (item.key > origin && item.key <= end) {
item.key = item.key - 1;
} else if (item.key == origin) {
item.key = end;
}
return item
});
this.getPosition(list);
} else if (origin > end) {
list = this.list.map((item) => {
if (item.key >= end && item.key < origin) {
item.key = item.key + 1;
} else if (item.key == origin) {
item.key = end;
}
return item
});
this.getPosition(list);
}
},
// list
getPosition(data, vibrate = true) {
let list = data.map((item, index) => {
item.tranX = this.item.width * (item.key % this.columns);
item.tranY = Math.floor(item.key / this.columns) * this.item.height;
return item
});
this.list = list;
if(!vibrate) return;
this.itemTransition = true;
// #ifndef H5
uni.vibrateShort();
// #endif
let listData = [];
list.forEach((item) => {
listData[item.key] = item.data
});
// change
this.$emit('change', {listData: listData});
},
//
touchEnd() {
if (!this.touch) return;
this.clearData();
},
//
clearData() {
this.originKey = -1;
this.touch = false;
this.cur = -1;
this.tranX = 0;
this.tranY = 0;
//
setTimeout(() => {
this.curZ = -1;
}, 300)
},
//
init() {
// , 使
let list = this.listData.map((item, index) => {
return {
key: index,
tranX: 0,
tranY: 0,
data: item
}
});
this.list = list;
this.itemTransition = false;
this.windowHeight = uni.getSystemInfoSync().windowHeight;
setTimeout(() => {
//
this.createSelectorQuery().select(".item").boundingClientRect((res) => {
let rows = Math.ceil(this.list.length / this.columns);
this.item = res;
this.getPosition(this.list, false);
let itemWrapHeight = rows * res.height;
this.itemWrapHeight = itemWrapHeight;
this.createSelectorQuery().select(".item-wrap").boundingClientRect((res) => {
this.itemWrap = res;
let overOnePage = itemWrapHeight + res.top > this.windowHeight;
this.overOnePage = overOnePage;
}).exec();
}).exec();
}, 300)
}
}
}
</script>
<style lang="scss" scoped="scoped">
.item-wrap {
position: relative;
.item {
position: absolute;
width: 100%;
z-index: 1;
&.itemTransition {
transition: transform 0.3s;
}
&.zIndex {
z-index: 2;
}
&.cur {
background: #1998FE;
transition: initial;
}
}
}
.info {
position: relative;
padding-top: 100%;
background: #ffffff;
margin-right: 5px;
&:nth-child(3n){
margin-right: 0px;
}
& > view {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
box-sizing: border-box;
image {
width: 100%;
height: 100%;
}
}
}
.indicator {
position: fixed;
z-index: 99999;
right: 0rpx;
top: 50%;
margin-top: -250rpx;
padding: 20rpx;
& > view {
width: 36rpx;
height: 500rpx;
background: #ffffff;
border-radius: 30rpx;
box-shadow: 0 0 10rpx -4rpx rgba(0, 0, 0, 0.5);
color: pink;
padding-top: 90rpx;
box-sizing: border-box;
font-size: 24rpx;
text-align: center;
opacity: 0.8;
}
}
</style>

10
pages/test/test.vue

@ -14,7 +14,7 @@
</view> -->
<!-- </view> -->
<div class="box-wrapper">
<!-- <div class="box-wrapper">
<div style="margin-top:0px" class="box"></div>
<div class="box spe"></div>
<div class="box spe"></div>
@ -24,7 +24,10 @@
<div class="box"></div>
<div class="box spe"></div>
<div class="box spe"></div>
</div>
</div> -->
<lf-upload-image></lf-upload-image>
<drag />
</view>
</template>
@ -34,7 +37,10 @@
}
</style>
<script>
import lfUploadImage from "@/components/lf-uploadImage/lf-uploadImage.vue"
import drag from './drag.vue';
export default {
components: { lfUploadImage, drag },
data(){
return {

Loading…
Cancel
Save