Compare commits

...

4 Commits

Author SHA1 Message Date
唐明明
e0dba81324 merge 2021-09-25 17:18:31 +08:00
唐明明
63b16b2802 新增门店管理店员管理营销推广码 2021-09-25 17:17:08 +08:00
唐明明
ce16270b75 merge 2021-09-25 15:55:29 +08:00
唐明明
847f573ff3 能量球 2021-09-25 15:33:25 +08:00
35 changed files with 4903 additions and 405 deletions

View File

@@ -170,16 +170,64 @@
},
"name": "ResetPassword"
},{
"path": "pages/wallet/fragment",
"path": "pages/verification/index",
"name": "verificationIndex",
"auth": true,
"style": {
"navigationBarTitleText": "能量碎片记录",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#774ffd",
"navigationBarTextStyle": "white"
},
"name": "Fragment"
}
],
"navigationBarTitleText": "扫码核销"
}
},{
"path": "pages/verification/history",
"name": "verificationHistory",
"auth": true,
"style": {
"navigationBarTitleText": "核销记录"
}
},{
"path": "pages/shop/lists",
"name": "shopLists",
"auth": true,
"style": {
"navigationBarTitleText": "部门/门店"
}
},{
"path": "pages/shop/create",
"name": "shopCreate",
"auth": true,
"style": {
"navigationBarTitleText": "创建部门/门店"
}
},{
"path": "pages/employees/list",
"name": "employeesList",
"auth": true,
"style": {
"navigationBarTitleText": "员工管理"
}
},{
"path": "pages/employees/add",
"name": "employeesAdd",
"auth": true,
"style": {
"navigationBarTitleText": "添加员工"
}
},{
"path": "pages/instrument/Spread",
"name": "instrumentSpread",
"auth": true,
"style": {
"navigationBarTitleText": "营销推广码"
}
}, {
"path": "pages/wallet/fragment",
"style": {
"navigationBarTitleText": "能量碎片记录",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#774ffd",
"navigationBarTextStyle": "white"
},
"name": "Fragment"
}],
"globalStyle": {
"navigationStyle": "custom",
"backgroundColor": "#F5F5F5"

311
pages/employees/add.vue Normal file
View File

@@ -0,0 +1,311 @@
<template>
<view class="content" v-if="!loging">
<!-- 基础信息 -->
<view class="info-card">
<view class="cover">
<view class="cover-add vertical" @click="updCover">
<block v-if="cover.showpath != ''">
<image :src="cover.showpath" mode="aspectFill"></image>
</block>
<block v-else>
<image class="cover-default" src="@/static/icons/add-icon.png" mode="widthFix"></image>
<view>员工寸照</view>
</block>
</view>
</view>
<view class="info-text">
<view class="info-inputs">
<input type="text" v-model="name" placeholder="姓名"/>
</view>
<view class="info-inputs">
<input type="number" v-model="phone" placeholder="手机号码"/>
</view>
<view class="info-inputs">
<input type="text" v-model="job" placeholder="职业"/>
</view>
<view class="info-inputs">
<picker :range="section" range-key="name" :value="sectionIndex" @change="pickerChange">
<view class="picker-text">
{{section[sectionIndex].name}}
<uni-icons class="icon" type="arrowdown" color="#555"></uni-icons>
</view>
</picker>
</view>
</view>
</view>
<view class="jurisdiction switch">
<view class="item">
<label>
<view class="item-title">设为推荐</view>
<view class="item-info">设为推荐员工将在企业自媒体中优先展示</view>
<switch class="item-switch" :checked="isPosition" color="#e93340" @change="switchChange" />
</label>
</view>
</view>
<!-- 权限设置 -->
<view class="title">权限设置</view>
<view class="jurisdiction">
<checkbox-group @change="permissionChange">
<view class="item" v-for="(item, index) in permissions" :key="index">
<label>
<view class="item-title">{{item.title}}</view>
<view class="item-info">{{item.description}}</view>
<checkbox class="item-checkbox" :checked="item.check" color="#e93340" :value="item.permission_id" />
</label>
</view>
</checkbox-group>
</view>
<!-- 按钮 -->
<view class="add-btns">
<button size="default" @click="onAddEmployees">{{type === 'PUT' ? '修改': '添加'}}</button>
</view>
</view>
</template>
<script>
import { employeesConfig, addEmployees, employeesInfo, employeesPut } from '@/apis/interfaces/employees'
import { uploads } from '@/apis/interfaces/uploading'
export default {
data() {
return {
type : '',
loging : true,
section : [],
permissions : [],
permissionIds: [],
sectionIndex : 0,
cover : {
showpath : '',
path : ''
},
name : '',
phone : '',
job : '',
isPosition : false
};
},
created() {
if(this.$Route.query.type === 'PUT'){
this.type = 'PUT'
uni.setNavigationBarTitle({
title: '编辑员工'
})
}
employeesConfig().then(res => {
this.section = res.store
if(this.$Route.query.type === 'PUT'){
employeesInfo(this.$Route.query.id || 4).then(res => {
let permissionIds = []
for(let val of res.permission){
if(val.check){
permissionIds.push(val.permission_id)
}
}
this.permissions = res.permission
this.sectionIndex = this.section.findIndex(val => val.store_id == res.store.store_id)
this.permissionIds= permissionIds
this.name = res.name
this.phone = res.mobile
this.job = res.job
this.cover = res.cover
this.isPosition = res.is_position
this.loging = false
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
}else{
this.permissions = res.permissions
this.loging = false
}
})
},
methods:{
// 设为推荐
switchChange(e){
this.isPosition = e.detail.value
},
// 选择部门
pickerChange(e){
this.sectionIndex = e.detail.value
},
// 权限选择
permissionChange(e){
this.permissionIds = e.detail.value
},
// 上传照片
updCover(){
uni.chooseImage({
crop: {width: 229, height: 320},
success: path=> {
uploads([{
uri : path.tempFilePaths[0]
}]).then(res => {
this.cover = {
showpath: res.url[0],
path : res.path[0]
}
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
}
})
},
// 添加员工
onAddEmployees(){
let data = {
name : this.name,
mobileNo : this.phone,
job : this.job,
cover : this.cover.path,
position : this.isPosition ? 1: 0,
order : 0,
store_id : this.section[this.sectionIndex].store_id,
permission : this.permissionIds
}
let submitAdd = this.type == 'PUT' ? employeesPut(this.$Route.query.id, data) : addEmployees(data)
submitAdd.then(res => {
uni.showModal({
title : '提示',
content : res,
showCancel : false,
success : () => {
this.$Router.back()
}
})
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
}
}
}
</script>
<style lang="scss" scoped>
.content{
min-height: 100vh;
@extend .ios-bottom;
.title{
padding: ($padding/2) $padding;
color: $text-gray;
}
.jurisdiction{
background: white;
&.switch{
margin-top: $margin;
}
.item{
position: relative;
padding: $padding 150rpx $padding $padding;
&::after{
position: absolute;
left: $padding;
right: 0;
bottom: 0;
height: 1rpx;
content: " ";
background: $border-color;
}
&:last-child::after{
display: none;
}
.item-checkbox{
position: absolute;
right: $padding;
top: 50%;
height: 40rpx;
margin-top: -27rpx;
}
.item-switch{
position: absolute;
right: $padding;
top: 50%;
height: 40rpx;
margin-top: -27rpx;
}
.item-title{
font-size: $title-size;
padding-bottom: $margin/3;
}
.item-info{
font-size: $title-size-m;
color: $text-gray;
}
}
}
// 基础信息
.info-card{
background: white;
padding: $padding;
position: relative;
min-height: 238rpx;
.cover{
position: absolute;
top: $padding;
left: $padding;
background: #f8f8f8;
width: 229rpx;
height: 320rpx;
.cover-add{
position: absolute;
width: 100%;
height: 100%;
text-align: center;
image{
width: 229rpx;
height: 320rpx;
}
image.cover-default{
width: 128rpx;
}
color: $text-gray-m;
font-size: $title-size-m;
}
}
.info-text{
padding-left: $padding + 229;
.info-inputs{
height: 80rpx;
line-height: 80rpx;
border-bottom: solid 1rpx $border-color;
input{
height: 80rpx;
}
.picker-text{
position: relative;
padding-right: 80rpx;
.icon{
position: absolute;
right: 0;
top: 0;
}
}
}
}
}
// 添加按钮
.add-btns{
padding: $padding;
button[size='default']{
height: 90rpx;
line-height: 90rpx;
padding: 0;
margin: 0;
background: $text-price;
font-size: $title-size;
font-weight: bold;
color: white;
border-radius: 0;
}
}
}
</style>

260
pages/employees/list.vue Normal file
View File

@@ -0,0 +1,260 @@
<template>
<view class="ios-bottom" v-if="!loding">
<view class="header-flex">
员工数量 {{total}}
<view class="add-btn" @click="addEmployees">添加员工</view>
</view>
<!-- 员工列表 -->
<uni-collapse v-if="lists.length > 0">
<block v-for="(listItem, listIndex) in lists" :key="listIndex">
<uni-collapse-item :show-animation="true" :open="listIndex === 0">
<template v-slot:title>
<view class="collapse-title">{{listItem.name}}</view>
</template>
<block v-if="listItem.data.length > 0">
<view class="employees-border" v-for="(item, index) in listItem.data" :key="index">
<uni-swipe-action>
<uni-swipe-action-item :rightOptions="options" @click="onEmployees($event, listIndex, index)">
<view class="employees-item">
<view class="cover">
<block v-if="item.user.avatar === ''">{{item.name.slice(0,1)}}</block>
<block v-else>
<image class="cover-img" :src="item.user.avatar" mode="aspectFill"></image>
</block>
</view>
<view class="content">
<view class="nickname nowrap">{{item.name}}<text>{{item.job}}</text></view>
<view class="job nowrap">
<text v-for="(permissionItem, permissionIndex) in item.permission" :key="permissionIndex">{{permissionItem}}</text>
</view>
</view>
</view>
</uni-swipe-action-item>
</uni-swipe-action>
</view>
</block>
<block v-else>
<view class="employees-null">店铺暂无员工</view>
</block>
</uni-collapse-item>
</block>
</uni-collapse>
<view v-else class="list-null">
<image class="icon" src="@/static/icons/listnull-icon.png" mode="widthFix" />
<view class="sub-title">暂未添加员工</view>
<view class="sub-btn" @click="$Router.push({name: 'employeesAdd'})">添加员工</view>
</view>
</view>
</template>
<script>
import { employees, employeesDelete } from '@/apis/interfaces/employees'
export default {
data() {
return {
loding : true,
lists : [],
total : 0,
options : [{
text : '编辑',
type : 'PUT',
style : {
backgroundColor: '#3688ee'
}
},{
text : '删除',
type : 'DELETE',
style : {
backgroundColor: '#e93340'
}
}]
};
},
onShow(){
employees().then(res => {
this.lists = res.data
this.total = res.total
this.loding = false
})
},
methods:{
// 编辑,删除
onEmployees(e, upIndex, index){
let type = e.content.type,
val = this.lists[upIndex].data[index]
if(type == 'PUT'){
this.$Router.push({name: 'addEmployees', params: {type: 'PUT', id: val.employee_id}})
return
}
uni.showModal({
title : '提示',
content : '删除后无法恢复,确定删除员工[' + val.name + ']吗?',
cancelText : '取消',
cancelColor : '#555',
confirmText : '确认',
confirmColor: '#e93340',
success : res => {
if(res.confirm) {
employeesDelete(val.employee_id).then(res => {
uni.showToast({
title: res,
icon : 'none'
})
this.lists[upIndex].data.splice(index, 1)
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
}
}
})
},
// 添加员工
addEmployees(){
if(this.lists.length <= 0){
uni.showModal({
title : '提示',
content : '暂未创建门店,无法添加员工',
cancelText : '稍后创建',
cancelColor : '#555',
confirmText : '立即创建',
confirmColor: '#e93340',
success : res => {
if(res.confirm) {
this.$Router.push({name: 'shopCreate'})
}
}
})
return
}
this.$Router.push({name: 'employeesAdd'})
}
}
};
</script>
<style lang="scss" scoped>
.collapse-title{
padding: 0 $padding;
line-height: 90rpx;
font-weight: bold;
font-size: $title-size-lg;
}
.employees-item {
background: white;
padding: ($padding - 10) $padding;
position: relative;
&::before {
position: absolute;
bottom: 0;
left: $padding + 98;
right: 0;
content: ' ';
height: 1rpx;
background: $border-color;
}
.cover {
position: absolute;
top: $padding - 10;
left: $padding;
background: $text-price;
color: white;
height: 88rpx;
width: 88rpx;
line-height: 88rpx;
text-align: center;
border-radius: 50%;
overflow: hidden;
font-size: $title-size-lg;
.cover-img {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
}
.content {
height: 88rpx;
padding-left: 108rpx;
.nickname{
line-height: 40rpx;
font-size: $title-size;
padding-bottom: 10rpx;
text{
font-size: $title-size-sm;
color: $text-gray-m;
padding-left: 10rpx;
}
}
.job{
line-height: 38rpx;
text{
background-color: $border-color-lg;
color: $text-gray;
padding: 0 10rpx;
line-height: 38rpx;
margin-left: $margin/2;
display: inline-block;
&:first-child{
margin-left: 0;
}
}
}
}
}
// 空提示
.list-null{
width: 100vw;
height: 100vh;
box-sizing: border-box;
text-align: center;
background: white;
padding-bottom: 20vh;
@extend .vertical;
.sub-title{
color: $text-gray;
font-size: $title-size-m;
}
.icon{
width: 288rpx;
}
.sub-btn{
width: 200rpx;
height: 70rpx;
line-height: 70rpx;
text-align: center;
background: $mian-color;
color: white;
display: inline-block;
margin-top: $margin*2;
}
}
.employees-null{
text-align: center;
line-height: 10vh;
padding-bottom: $padding;
font-size: $title-size-m;
color: $text-gray;
}
// 添加员工header
.header-flex{
background: white;
padding: ($padding/2) $padding;
display: flex;
justify-content: space-between;
margin-bottom: $margin - 10;
line-height: 60rpx;
color: $text-gray;
.add-btn{
background: $mian-color;
color: white;
width: 150rpx;
text-align: center;
font-size: $title-size-m;
}
}
</style>

View File

@@ -1,51 +1,60 @@
<template>
<view class="content">
<!-- 水晶获得公告 -->
<view class="notice" v-if="notice.length >= 1">
<swiper class="notice-swiper" :vertical="true" autoplay circular>
<swiper-item v-for="(item, index) in notice" :key="index">
<view class="notice-item">
<image class="notice-cover" :src="item.avatar" mode="aspectFill"></image>
<view class="notice-title ellipsis">{{item.nickname}} {{item.title}} {{item.amount}}</view>
</view>
</swiper-item>
</swiper>
</view>
<!-- 账户余额 -->
<view class="info">
<view class="info-number">
<image class="number-background number-rotate" src="@/static/background/chain-back-01.png" />
<view class="info-content webkit-box">
<view class="text">{{isAuth ? '持有原石量': '恒量发行原石量'}}<uni-icons class="help-icon" @click="showHelp('occ')" type="help-filled" size="18" color="#fff" /></view>
<view class="number">{{occ}}</view>
<view class="login" @click="$Router.push({name: 'Login'})" v-if="!isAuth">立即登录</view>
<view class="login" @click="openWallet" v-else>我的钱包</view>
<view class="total">
<view class="item nowrap"><image src="@/static/icons/gemstone-icon.png"/>能量球 99</view>
<view class="item nowrap"><image src="@/static/icons/crystal-icon.png"/>能量碎片 11</view>
</view>
<!-- 矿机 -->
<view class="ore">
<image class="ore-back" src="@/static/background/chain-back-00.png" mode="widthFix"></image>
<view class="ball">
<view class="shadow"></view>
</view>
<view class="ore-lists">
<view class="oct-float ore-item" v-for="(item, index) in crystalArr" :key="index" @click="ledCrystal(index)">
<block v-if="item.amount !== null">
<image src="/static/imgs/crystal-ore-icon.png" mode="widthFix" class="icon" />
<view class="text">能量碎片{{ item.amount || '-'}}</view>
</block>
</view>
<navigator url="../index/index" open-type="switchTab" hover-class="none" class="oct-float ore-item-nav">
<image src="/static/imgs/gemstone-ore-icon.png" mode="widthFix" class="icon" />
<view class="text">购物<uni-icons type="arrowright" color="#FFFFFF" size="14"></uni-icons></view>
</navigator>
</view>
</view>
<!-- 公告信息 -->
<!-- <view class="increase">今日消费100元预计原石单价增长0.1%</view> -->
<!-- 任务分类 -->
<scroll-view class="task-block" scroll-x="true">
<view class="item" v-for="(item, index) in categoryArr" :key="index" @click="JumpUrl(item.url, item.title)">
<view class="text">{{ item.remark }}</view>
<view class="icon">
<image :src="item.cover" />
</view>
<view class="title">{{ item.title }}</view>
</view>
</scroll-view>
<!-- 平台概况 -->
<view class="situation">
<view class="header">
<view class="header-item">
<view class="title">平台原石余量<uni-icons class="help-icon" @click="showHelp('occBalance')" type="help-filled" size="18" color="#009b69" /></view>
<view class="title">平台原石余量<uni-icons class="help-icon" @click="showHelp('occBalance')" type="help-filled" size="18" color="rgba(255,255,255,.3)" /></view>
<view class="number ellipsis">{{ occBalance }}</view>
</view>
<view class="header-item">
<view class="title">昨日瓜分水晶<uni-icons class="help-icon" @click="showHelp('yesterdayCrystal')" type="help-filled" size="18" color="#009b69" /></view>
<view class="title">昨日瓜分水晶<uni-icons class="help-icon" @click="showHelp('yesterdayCrystal')" type="help-filled" size="18" color="rgba(255,255,255,.3)" /></view>
<view class="number ellipsis">{{ yesterdayCrystal }}</view>
</view>
<view class="header-item">
<view class="title">区块链高度<uni-icons class="help-icon" @click="showHelp('blockHeight')" type="help-filled" size="18" color="#009b69" /></view>
<view class="title">区块链高度<uni-icons class="help-icon" @click="showHelp('blockHeight')" type="help-filled" size="18" color="rgba(255,255,255,.3)" /></view>
<view class="number ellipsis">{{ blockHeight }}</view>
</view>
<view class="header-item">
<view class="title">平台累计盈利额<uni-icons class="help-icon" @click="showHelp('gain')" type="help-filled" size="18" color="#009b69" /></view>
<view class="title">平台累计盈利额<uni-icons class="help-icon" @click="showHelp('gain')" type="help-filled" size="18" color="rgba(255,255,255,.3)" /></view>
<view class="number ellipsis">{{ gain }}</view>
</view>
<view class="header-item">
<view class="title">已开通节点数<uni-icons class="help-icon" @click="showHelp('nodeNumber')" type="help-filled" size="18" color="#009b69" /></view>
<view class="title">已开通节点数<uni-icons class="help-icon" @click="showHelp('nodeNumber')" type="help-filled" size="18" color="rgba(255,255,255,.3)" /></view>
<view class="number ellipsis">{{ nodeNumber }}</view>
</view>
</view>
@@ -93,11 +102,10 @@
import F2 from '@/uni_modules/lime-f2/components/lime-f2/f2.min.js'
import lF2 from '@/uni_modules/lime-f2/components/lime-f2/'
export default {
components: {
lF2
},
data() {
return {
crystalArr : [],
categoryArr : [],
occs: {},
blockHeight: 0,
occBalance: 0,
@@ -125,8 +133,8 @@
// 求助信息
showHelp(type) {
uni.showModal({
title: '提示',
content: this.helpToast[type],
title: '提示',
content: this.helpToast[type],
showCancel: false
})
},
@@ -179,6 +187,7 @@
// occ信息
getOcc(){
occ().then(res => {
console.log(res)
this.occs = res.occs
this.yesterdayCrystal = res.yesterday_crystal
this.occ = res.occ
@@ -190,7 +199,10 @@
if(res.help_toast) this.helpToast = res.help_toast
this.showCartc(res.movements)
}).catch(err => {
console.log(err)
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 绘制图表
@@ -264,154 +276,100 @@
</script>
<style scoped>
/* 气泡漂浮 */
.number-float{
/* 星球旋转 */
.ball{
position: absolute;
height: 480rpx;
width: 480rpx;
top: 50%;
left: 50%;
margin-top: -240rpx;
margin-left: -240rpx;
border-radius: 50%;
-webkit-transform-style: preserve-3d;
background: url(/static/background/chain-back-02.png) repeat-x;
background-size: auto 100%;
-webkit-animation: move-map 30s infinite linear;
-moz-animation: move-map 30s infinite linear;
-o-animation: move-map 30s infinite linear;
-ms-animation: move-map 30s infinite linear;
animation: move-map 30s infinite linear;
box-shadow: 0 0 50rpx 50rpx rgba(31,25,34, .2);
}
.shadow{
position: absolute;
top: 1%;
left: 5%;
width: 90%;
height: 90%;
border-radius: 50%;
filter: blur(5px);
z-index: 3;
background: radial-gradient(circle at 50% 0, rgba(255,255,255, .6) , rgba(255, 255, 255, .0) 58%);
}
.ball:before,
.ball::after{
position: absolute;
top: 0;
left: 0;
content: "";
width: 100%;
height: 100%;
border-radius: 50%;
filter: blur(5px);
z-index: 2;
}
.ball:before {
background: radial-gradient(circle at 100% 50%, #5881d3 , rgba(255, 255, 255, .0) 45%);
}
.ball::after {
background: radial-gradient(circle at 0 50%, #ca66e0 , rgba(255, 255, 255, .0) 45%);
}
@-webkit-keyframes move-map {
0% {background-position: -1250rpx 0; }
100% {background-position: 0 0;}
}
@-ms-keyframes move-map {
0% {background-position: -1250rpx 0; }
100% {background-position: 0 0;}
}
@keyframes move-map {
0% {background-position: -1250rpx 0; }
100% {background-position: 0 0;}
}
/* 水晶漂浮动画 */
.oct-float {
animation: 4s octfloat infinite;
}
@keyframes octfloat{
0%{
@keyframes octfloat {
0% {
margin-top: 0;
}
50%{
50% {
margin-top: 15rpx;
}
100%{
100% {
margin-top: 0;
}
}
/* 背景旋转 */
.number-rotate{
animation: 30s octrotate infinite linear;
}
@keyframes octrotate{
from{
transform:rotate(0deg);
}
to{
transform:rotate(360deg);
}
}
</style>
<style lang="scss">
// 背景
<style lang="scss" scoped>
.content{
background: $mian-color-deep;
min-height: 100vh;
padding-top: var(--status-bar-height);
box-sizing: border-box;
background-image: url(@/static/background/chain-back-00.png);
background-size: 100%;
background-position: top center;
background-repeat: no-repeat;
}
// 求助icon
.help-icon{
vertical-align: middle;
margin-bottom: 4px;
margin-left: $margin/2;
opacity: .7;
}
// 原石账户
.info{
margin-top: calc(#{$margin * 2} + 60rpx);
padding: var(--status-bar-height) $padding * 2 $padding * 3;
text-align: center;
.info-number{
position: relative;
display: inline-block;
width: 568rpx;
height: 568rpx;
.number-background{
width: 100%;
height: 100%;
}
.info-content{
position: absolute;
top: 12%;
left: 12%;
width: 76%;
height: 76%;
background-image: url(@/static/background/chain-back-02.png);
background-size: cover;
color: white;
.text{
font-size: $title-size-m;
text-shadow: 2rpx 2rpx 0 rgba($color: $mian-color-deep, $alpha: .5);
}
.number{
font-weight: bold;
font-size: $title-size + 8;
line-height: 70rpx;
text-shadow: 2rpx 2rpx 0 rgba($color: $mian-color-deep, $alpha: .5);
}
.login{
margin-top: $margin;
background-color: $mian-color;
display: inline-block;
padding: ( $padding / 2 ) $padding;
font-size: $title-size-m;
border-radius: 30rpx;
border:solid 1rpx $mian-color-deep;
}
}
}
}
// 预计增长
.increase{
margin: 0 ($margin + $margin / 2) ($margin * 2);
background: rgba($color: $mian-color, $alpha: .1);
text-align: center;
height: 80rpx;
line-height: 80rpx;
font-size: $title-size-m;
color: $mian-color;
border-radius: $radius-sm;
padding: 0 $padding;
}
// 公告信息
.notice{
position: fixed;
top: $margin * 2;
left: $margin + $margin / 2;
right: $margin + $margin / 2;
padding-top: var(--status-bar-height);
z-index: 99;
.notice-swiper{
height: 60rpx;
}
.notice-item{
position: relative;
height: 60rpx;
padding-left: 80rpx;
padding-right: $padding * 2;
display: inline-block;
background: rgba($color: $mian-color-deep, $alpha: .3);
border-radius: 30rpx;
box-sizing: border-box;
max-width: 100%;
.notice-cover{
position: absolute;
height: 60rpx;
width: 60rpx;
left: 0;
top: 0;
background-color: $mian-color-deep;
border-radius: 50%;
}
.notice-title{
line-height: 60rpx;
color: white;
font-size: $title-size-m;
}
}
min-height: calc(100vh - 60px);
background: #1f1922;
overflow: hidden;
}
// 平台概况
.situation{
margin: 0 ($margin + $margin / 2);
background-image: linear-gradient(to bottom, rgba($color: $mian-color, $alpha: .1), $mian-color-deep);
border-radius: $radius-sm;
padding: $padding;
margin: 0 $margin;
background-image: linear-gradient(to bottom, $block-color, #1f1922);
border-radius: $radius;
padding: $padding $padding/2 $padding*2;
// 平台统计
.header{
display: flex;
@@ -419,23 +377,22 @@
margin-bottom: $margin*2;
.number{
color: white;
font-size: $title-size + 4;
font-size: $title-size;
padding-top: $padding/2;
font-weight: bold;
line-height: 90rpx;
}
.title{
color: $mian-color;
font-weight: bold;
color: rgba($color: white, $alpha: .4);
font-size: $title-size-sm;
}
.header-item{
width: 50%;
padding: $padding $padding / 2;
padding: $padding / 2;
box-sizing: border-box;
&:first-child{
width: 100%;
.number{
font-size: $title-size + 10;
font-size: $title-size;
}
}
}
@@ -446,12 +403,12 @@
flex-wrap: wrap;
margin: 0 -$margin / 2;
.node-item{
background: rgba($color: $mian-color, $alpha: .2);
background: rgba($color: $block-color, $alpha: .8);
width: calc(50% - #{$margin});
margin: $margin / 2;
padding: $padding;
box-sizing: border-box;
border-radius: $radius-sm;
border-radius: $radius/2;
}
.number{
font-size: $title-size + 4;
@@ -459,21 +416,20 @@
color: white;
}
.title{
font-size: $title-size-m;
font-weight: bold;
color: rgba($color: white, $alpha: .7);
font-size: $title-size-sm;
color: white;
}
}
// 图表
.chart{
background: rgba($color: $mian-color, $alpha: .2);
background: rgba($color: $block-color, $alpha: .8);
padding: $padding;
border-radius: $radius-sm;
margin-top: $margin*2;
border-radius: $radius/2;
margin-top: $margin;
.title{
text-align: center;
line-height: 80rpx;
color: rgba($color: $mian-color, $alpha: 1.0);
color: white;
font-size: $title-size-m;
}
.chart-f2{
@@ -481,4 +437,137 @@
}
}
}
// 数据统计
.total {
position: relative;
margin: $margin;
background: #2b2449;
padding: 0;
display: flex;
border-radius: $radius;
.item {
width: 50%;
padding: 0 $padding;
text-align: center;
color: white;
font-size: $title-size-sm;
line-height: 76rpx;
image{
width: 38rpx;
height: 38rpx;
vertical-align: top;
margin-top: calc((76rpx - 38rpx) / 2);
margin-right: $margin / 2;
}
}
&::before {
position: absolute;
top: 0;
bottom: 0;
content: "";
width: 2rpx;
left: 50%;
background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, .7), transparent);
}
}
// 求助icon
.help-icon{
vertical-align: middle;
margin-left: $margin/3;
opacity: .7;
}
// 矿石
.ore {
position: relative;
padding-top: 120%;
&>image {
width: 100%;
position: absolute;
top: 0;
left: 0;
}
.ore-lists {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
.oct-float-item{
position: absolute;
text-align: center;
.text {
margin-top: $margin / 2;
color: white;
font-size: $title-size-sm;
line-height: 40rpx;
text-shadow: 0 3rpx 3rpx rgba($color: #000000, $alpha: .2);
}
.icon {
width: 58rpx;
vertical-align: top;
}
}
.ore-item-nav{
@extend .oct-float-item;
right: $margin * 3;
top: 12%;
}
.ore-item {
@extend .oct-float-item;
&:nth-child(1) { top: 16%; left: 13%; }
&:nth-child(2) { top: 50%; right: 10%; }
&:nth-child(3) { top: 23%; right: 20%; }
&:nth-child(4) { top: 70%; left: 33%;}
&:nth-child(5) { top: 40%; left: 20%; }
&:nth-child(6) { top: 58%; left: 10%;}
&:nth-child(7) { top: 10%; right: 43%;}
&:nth-child(8) { top: 46%; right: 29%;}
}
}
}
// 任务
.task-block {
white-space: nowrap;
.item {
background: rgba($color: $mian-color, $alpha: .2);
display: inline-block;
margin-left: $margin;
width: 210rpx;
padding: $padding * 2 $padding;
border-radius: $radius;
box-sizing: 0 0 4rpx 4rpx rgba($color: #000000, $alpha: .06);
text-align: center;
&:first-child {
margin-left: $margin + $margin/2;
}
&:last-child {
margin-right: $margin + $margin/2;
}
.icon {
display: inline-block;
margin: $margin 0;
width: 98rpx;
height: 98rpx;
line-height: 98rpx;
background: $mian-color-deep;
border-radius: 50%;
text-align: center;
image {
width: 56rpx;
height: 56rpx;
vertical-align: middle;
}
}
.text {
font-size: $title-size-m;
color: $mian-color;
}
.title {
font-size: $title-size;
color: white;
font-weight: bold;
}
}
}
</style>

249
pages/instrument/Spread.vue Normal file
View File

@@ -0,0 +1,249 @@
<template>
<view class="content">
<view class="codeContent">
<image class="codeContent-back" src="../../static/icons/store_codeBack.png" mode="widthFix"></image>
<image class="codeContent-cont" src="../../static/icons/store_contBack.png" mode="widthFix"></image>
<view class="textContent">
<view class="company">
<image class="company-logo" :src="companyInfo.cover" mode="aspectFill"></image>
<view class="company-cont">
<view class="nowrap company-name">{{companyInfo.name}}</view>
<view class="company-tips">易货平台</view>
</view>
</view>
<view class="code">
<image class="code-img" :src="companyInfo.code" mode="aspectFit"></image>
<!-- <view class="code-text">简单扫一扫即可进入平台</view> -->
</view>
<!-- @click="shareCanvas" -->
<view class="codeBnt">
扫码推广
</view>
</view>
</view>
<canvas class="codeImg" canvas-id="qrcodeCard"></canvas>
</view>
</template>
<script>
import { companiesCode } from '@/apis/interfaces/store'
export default {
data() {
return {
companyInfo : ''
}
},
created() {
companiesCode().then(res=>{
this.companyInfo = res
})
},
methods: {
// 绘制图片
shareCanvas(e){
uni.showLoading({
title: '加载中',
})
// 下载头像
let avatarImg = new Promise(success=>{
uni.getImageInfo({
src : this.companyInfo.cover,
success : res => {
success(res.path)
}
})
})
// 下载二维码
let codeImg = new Promise(success => {
uni.getImageInfo({
src : this.companyInfo.code,
success : res => {
success(res.path)
}
})
})
Promise.all([avatarImg, codeImg]).then(res => {
// 绘制海报
const ctx = uni.createCanvasContext('qrcodeCard')
ctx.save()
// 绘制背景图片
ctx.drawImage('../../static/icons/store_downBack', 0, 0, 375, 603)
// 绘制头像
ctx.drawImage(res[0], 0, 0, 60, 60)
// 绘制二维码
ctx.drawImage(res[1], 140, 250, 110, 110)
// 文字
ctx.setFontSize(16)
ctx.fillText(this.companyInfo.name, 194, 180 , 270)
ctx.setFontSize(16)
ctx.fillText('邀请你加入易货平台', 194, 180 , 270)
ctx.save();
ctx.beginPath(); //开始绘制
ctx.arc(50 / 2 + 170, 50 / 2 + 110, 50 / 2, 0, Math.PI * 2, false);
ctx.clip();
// 保存图片
ctx.draw(true, () => {
uni.hideLoading()
uni.canvasToTempFilePath({
canvasId: 'qrcodeCard',
x: 0,
y: 0,
success: res => {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success : res=>{
if (res.errMsg == "saveImageToPhotosAlbum:ok"){
uni.showToast({
title: '分享海报已保存至相册',
icon : 'none'
})
}else{
uni.hideLoading()
}
},
fail : err=>{
if (err.errMsg == "saveImageToPhotosAlbum:fail auth deny"){
uni.showModal({
title : '提示',
content : '暂未授权小程序写入您的相册,无法存储二维码海报',
confirmColor: '#d82526',
confirmText : '去设置',
success : res=>{
if (res.confirm){
uni.openSetting()
}
}
})
}
}
})
}
})
})
}).catch(err=>{
uni.showToast({
title: '海报下载,请检查网络',
icon : 'none'
})
})
}
}
}
</script>
<style lang="scss" scoped>
.content {
background-color: #e93340;
height: 100vh;
width: 100vw;
}
.codeContent {
position: relative;
width: 100%;
height: 100vh;
.codeContent-back {
width: 100%;
height: 100%;
z-index: 1;
position: absolute;
}
.codeContent-cont {
left: 5%;
width: 90%;
top: 100px;
z-index: 2;
position: absolute;
}
.codeContent-tips {
position: absolute;
top: 0;
right: 20rpx;
width: 200rpx;
z-index: 2;
}
.textContent {
position: absolute;
padding: 20rpx 20rpx 0 40rpx;
box-sizing: border-box;
width: 70%;
z-index: 3;
left: 15%;
right: 15%;
top: 140px;
}
.company {
width: 100%;
.company-logo {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
}
.company-cont {
position: absolute;
width: 100%;
height: 230rpx;
left: 0;
top: 0;
padding: 20rpx 20rpx 30rpx 210rpx;
font-size: $title-size;
.company-name {
font-weight: 600;
margin: 10rpx 0;
}
.company-tips {
font-size: 26rpx;
color: #787878;
}
}
}
.code {
text-align: center;
width: 100%;
box-sizing: border-box;
margin-bottom: $margin;
.code-img {
width: 90%;
}
.code-text {
color: #787878;
margin-top: $margin - 10;
font-size: $title-size;
}
}
}
.codeBnt {
background-color: #e1293f;
text-align: center;
border-radius: 10rpx;
line-height: 90rpx;
font-weight: 600;
font-size: $title-size;
color: #FFFFFF;
box-shadow: 4rpx 0 10rpx rgba(155,0,19,.5);
position: relative;
}
/* canvas */
.codeImg {
position: absolute;
left: -1000%;
height: 603px;
width: 375px;
background: white;
}
</style>

View File

@@ -1,6 +1,6 @@
<template>
<view class="News-detail" v-if="loaded">
<view class="item" v-for="(item,index) in items" v-if="items.length>0"
<view class="item" v-for="(item,index) in items" :key="index" v-if="items.length>0"
@click="item.read_at === ''?read(index,item):noread(item)">
<view class="top">
<image src="/static/images/news_2_1.png" mode="widthFix"></image>

327
pages/shop/create.vue Normal file
View File

@@ -0,0 +1,327 @@
<template>
<view>
<view class="create-form">
<view class="header">
<view @click="updLogo">
<image class="logo" style="border: none;" v-if="cover.showpath" :src="cover.showpath" mode="aspectFill" />
<image class="logo" v-else src="@/static/icons/add-icon.png" mode="aspectFill" />
</view>
<view class="inputs">
<input type="text" v-model="name" placeholder="门店/部门名称" />
</view>
<view class="inputs">
<input type="number" v-model="mobile" placeholder="门店联系电话" />
</view>
</view>
<view class="info">
<view class="inputs">
<label class="inputs-label">开店时间</label>
<picker mode="time" @change="pickerTime" :value="startTime" data-key="startTime">
<view class="time-text">
{{startTime || '选择开店时间'}}
<uni-icons class="time-icon" type="arrowdown" size="18" color="#999"></uni-icons>
</view>
</picker>
</view>
<view class="inputs">
<label class="inputs-label">闭店时间</label>
<picker mode="time" @change="pickerTime" :value="endTime" data-key="endTime">
<view class="time-text">
{{endTime || '选择闭店时间'}}
<uni-icons class="time-icon" type="arrowdown" size="18" color="#999"></uni-icons>
</view>
</picker>
</view>
<view class="inputs addrss-input">
<label class="inputs-label">门店地址</label>
<textarea class="inputs-textarea" v-model="address" placeholder="输入门店地址" auto-height/>
<view class="addrss-icon" @click="onLocation">
<uni-icons type="location-filled" size="20" color="#c82626"></uni-icons>
</view>
</view>
</view>
<view class="info">
<view class="inputs">
<label class="inputs-label">门店简介</label>
<textarea class="inputs-textarea" v-model="description" placeholder="门店简介..." />
</view>
</view>
</view>
<view class="create-btns">
<button class="item-btn btn-submit" type="default" @click="createShop">{{type === 'add' ? '创建': '保存'}}</button>
<button class="item-btn btn-delete" type="default" @click="onDeleteShop" v-if="type === 'edit'">删除</button>
</view>
</view>
</template>
<script>
import { create, putShop, deleteShop, editInfo } from '@/apis/interfaces/shop'
import { uploads } from '@/apis/interfaces/uploading'
export default {
data() {
return {
type : 'add',
id : '',
cover : {
showpath: '',
path : '',
},
name : '',
mobile : '',
address : '',
startTime : '',
endTime : '',
description : '',
latitude : '',
longitude : ''
};
},
onLoad() {
if(this.$Route.query.id){
this.type = 'edit'
this.getInfo()
}
},
methods:{
// 获取编辑信息
getInfo(){
editInfo(this.$Route.query.id).then(res => {
this.id = res.store_id
this.cover = res.cover
this.name = res.name
this.mobile = res.mobile
this.address = res.address
this.startTime = res.start_time
this.endTime = res.end_time
this.description= res.description
this.latitude = res.latitude
this.longitude = res.longitude
})
},
// 获取地址
onLocation(){
uni.chooseLocation({
success: res => {
this.address = res.address
this.longitude = res.longitude
this.latitude = res.latitude
},
fail: err => {
uni.showToast({
title: err,
icon : 'none'
})
}
})
},
// 选择营业时间
pickerTime(e){
this[e.target.dataset.key] = e.detail.value
},
// 编辑创建
createShop(){
let data = {
cover : this.cover.path,
name : this.name,
mobile : this.mobile,
address : this.address,
latitude : this.latitude,
longitude : this.longitude,
description : this.description,
start_time : this.startTime,
end_time : this.endTime
}
if(this.type === 'edit'){
putShop(this.id, {...data}).then(res => {
uni.showModal({
title : '提示',
content : res,
showCancel : false,
success : modalRes => {
this.$Router.back()
}
})
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
return
}
create({...data}).then(res => {
uni.showModal({
title : '提示',
content : res,
showCancel : false,
success : modalRes => {
this.$Router.back()
}
})
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 删除门店
onDeleteShop(){
deleteShop(this.id).then(res => {
uni.showModal({
title : '提示',
content : res,
showCancel : false,
success : modalRes => {
this.$Router.back()
}
})
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
},
// 上传logo
updLogo(){
uni.chooseImage({
crop: { width: 188, height: 188 },
success: path => {
uploads([{
name: 'logo',
uri : path.tempFilePaths[0]
}]).then(res => {
this.cover = {
showpath: res.url[0],
path: res.path[0]
}
}).catch(err => {
uni.showToast({
title: err.message,
icon : 'none'
})
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
// 门店信息
.create-form{
.header{
position: relative;
background: white;
padding-left: $padding + 150;
.logo{
width: 108rpx;
height: 108rpx;
border-radius: 50%;
position: absolute;
left: $padding;
top: 26rpx;
border: dashed 2rpx $border-color;
box-sizing: border-box;
}
.inputs{
position: relative;
padding-right: $padding;
input,
.time-text{
line-height: 80rpx;
height: 80rpx;
font-size: $title-size-lg;
}
&::after{
position: absolute;
left: 0;
bottom: 0;
right: 0;
content: " ";
height: 1rpx;
background: $border-color;
}
&:last-child::after{
display: none;
}
.time-text{
padding-right: 80rpx;
.time-icon{
position: absolute;
height: 80rpx;
line-height: 80rpx;
text-align: right;
width: 80rpx;
right: $padding;
top: 0;
}
}
}
}
.info{
@extend .header;
margin-top: $margin;
padding-left: 0;
background: white;
.inputs{
padding-left: $padding + 150;
.inputs-label{
position: absolute;
left: $padding;
top: 0;
font-size: $title-size-lg;
line-height: 80rpx;
height: 80rpx;
width: 150rpx;
}
.inputs-textarea{
width: 100%;
padding: 20rpx 0;
height: 160rpx;
font-size: $title-size-lg;
line-height: 40rpx;
}
&.addrss-input{
padding-right: $padding + 100;
.addrss-icon{
position: absolute;
height: 80rpx;
line-height: 80rpx;
text-align: right;
width: 80rpx;
right: $padding;
top: 0;
}
}
}
}
}
// 按钮组
.create-btns{
padding: $padding;
.item-btn{
border-radius: 0;
background: white;
font-size: $title-size;
line-height: 90rpx;
height: 90rpx;
&::after{
border: none;
}
}
.btn-submit{
background: $text-price;
color: white;
font-weight: bold;
margin-bottom: $margin;
}
.btn-delete{
border: solid 1rpx $border-color;
color: $text-gray;
}
}
</style>

120
pages/shop/lists.vue Normal file
View File

@@ -0,0 +1,120 @@
<template>
<view class="lists">
<block v-if="lists.length > 0">
<view class="lists-item" v-for="(item, index) in lists" :key="index" @click="$Router.push({name: 'shopCreate', params: { id: item.store_id }})">
<view class="header">
<image class="logo" :src="item.cover" mode="aspectFill"></image>
<view class="title">{{item.name}}</view>
<view class="time"><text>营业时间{{item.start_time}} {{item.end_time}}</text></view>
<view class="icons">
<uni-icons type="arrowright" color="#999" size="18"></uni-icons>
</view>
</view>
<view class="address">店铺地址{{item.address}}</view>
</view>
</block>
<block v-else>
<view class="list-null">
<image class="icon" src="@/static/icons/approve-icon.png" mode="widthFix"></image>
<view class="sub-title">暂未创建店铺/部门</view>
<view class="sub-btn" @click="$Router.push({name: 'shopCreate'})">创建</view>
</view>
</block>
</view>
</template>
<script>
import { shops } from '@/apis/interfaces/shop'
export default {
data() {
return {
lists: []
};
},
onShow(){
shops().then(res => {
console.log(res)
this.lists = res.data
})
}
}
</script>
<style lang="scss">
// 空提示
.list-null{
width: 100vw;
height: 100vh;
padding-bottom: 20vh;
box-sizing: border-box;
background: white;
text-align: center;
@extend .vertical;
.sub-title{
color: $text-gray;
font-size: $title-size-m;
}
.icon{
width: 288rpx;
}
.sub-btn{
width: 200rpx;
height: 70rpx;
line-height: 70rpx;
text-align: center;
background: $mian-color;
color: white;
display: inline-block;
margin-top: $margin*2;
}
}
// 列表
.lists-item{
background: white;
margin: $margin;
border-radius: $radius/2;
padding: $padding;
.header{
position: relative;
padding-left: 128rpx;
padding-right: 100rpx;
min-height: 108rpx;
padding-bottom: $padding - 10;
.logo{
position: absolute;
top: 0;
left: 0;
width: 108rpx;
height: 108rpx;
border-radius: 50%;
}
.title{
line-height: 60rpx;
font-size: $title-size;
font-weight: bold;
}
.time{
line-height: 40rpx;
font-size: $title-size-sm;
text{
background-color: $border-color-lg;
color: $text-gray;
padding: 0 $padding/2;
}
}
.icons{
position: absolute;
right: 0;
top: 0;
line-height: 108rpx;
}
}
.address{
border-top: solid 1rpx $border-color;
padding-top: $padding - 10;
font-size: $title-size-m;
color: $text-gray;
left: 50rpx;
}
}
</style>

View File

@@ -178,7 +178,7 @@
<image class="tool-label-img" src="/static/user/userTool-01.png" mode=""></image>
<view class="tool-label-name">优惠券管理</view>
</view>
<view class="tool-label">
<view class="tool-label" @click="$Router.push({name: 'instrumentSpread'})">
<image class="tool-label-img" src="/static/user/userTool-02.png" mode=""></image>
<view class="tool-label-name">营销推广码</view>
</view>
@@ -186,14 +186,18 @@
<image class="tool-label-img" src="/static/user/userTool-03.png" mode=""></image>
<view class="tool-label-name">基础信息</view>
</view>
<view class="tool-label">
<view class="tool-label" @click="$Router.push({name: 'shopLists'})">
<image class="tool-label-img" src="/static/user/userTool-04.png" mode=""></image>
<view class="tool-label-name">部门门店</view>
</view>
<view class="tool-label" @click="$Router.push({name: 'instrumentBasics'})">
<view class="tool-label" @click="$Router.push({name: 'employeesList'})">
<image class="tool-label-img" src="/static/user/userTool-05.png" mode=""></image>
<view class="tool-label-name">店员管理</view>
</view>
<!-- <view class="tool-label" @click="$Router.push({name: 'verificationIndex'})">
<image class="tool-label-img" src="/static/user/userTool-05.png" mode=""></image>
<view class="tool-label-name">扫码核销</view>
</view> -->
</view>
</view>

View File

@@ -270,7 +270,7 @@
width: calc(100% - 60rpx);
height: 360rpx;
background-image: linear-gradient(to left, #076cff, #076cff);
box-shadow: 0 10rpx 20rpx 0rpx rgba($color: $main-color, $alpha: 0.4);
box-shadow: 0 10rpx 20rpx 0rpx rgba($color: $mian-color, $alpha: 0.4);
margin: 0 30rpx;
border-radius: 20rpx;
box-sizing: border-box;

View File

@@ -10,9 +10,12 @@ $text-color: #333;
$text-gray: #555;
$text-gray-m: #999;
$text-price: #8b64fd;
$mian-color: #b11eff;
$mian-color: #8b64fd;
$mian-color-deep: #824f9a;
// 矿机
$block-color: #2b2449;
// 边框颜色
$border-color: #ddd;
$border-color-lg: #eff4f2;
@@ -76,20 +79,6 @@ $padding: 30rpx;
-webkit-line-clamp: 2;
}
.ellipsis-1 {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.ellipsis-2 {
display: -webkit-box;
overflow: hidden;
text-overflow: ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.ellipsis-3 {
display: -webkit-box;
overflow: hidden;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 482 KiB

After

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 469 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -0,0 +1,27 @@
## 1.3.32021-08-17
- 优化 show-arrow 属性默认为true
## 1.3.22021-08-17
- 新增 show-arrow 属性,控制是否显示右侧箭头
## 1.3.12021-07-30
- 优化 vue3下小程序事件警告的问题
## 1.3.02021-07-30
- 组件兼容 vue3如何创建vue3项目详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
## 1.2.22021-07-21
- 修复 由1.2.0版本引起的 change 事件返回 undefined 的Bug
## 1.2.12021-07-21
- 优化 组件示例
## 1.2.02021-07-21
- 新增 组件折叠动画
- 新增 value\v-model 属性 ,动态修改面板折叠状态
- 新增 title 插槽 ,可定义面板标题
- 新增 border 属性 ,显示隐藏面板内容分隔线
- 新增 title-border 属性 ,显示隐藏面板标题分隔线
- 修复 resize 方法失效的Bug
- 修复 change 事件返回参数不正确的Bug
- 优化 H5、App 平台自动更具内容更新高度,无需调用 reszie() 方法
## 1.1.72021-05-12
- 新增 组件示例地址
## 1.1.62021-02-05
- 优化 组件引用关系通过uni_modules引用组件
## 1.1.52021-02-05
- 调整为uni_modules目录规范

View File

@@ -0,0 +1,402 @@
<template>
<view class="uni-collapse-item">
<!-- onClick(!isOpen) -->
<view @click="onClick(!isOpen)" class="uni-collapse-item__title"
:class="{'is-open':isOpen &&titleBorder === 'auto' ,'uni-collapse-item-border':titleBorder !== 'none'}">
<view class="uni-collapse-item__title-wrap">
<slot name="title">
<view class="uni-collapse-item__title-box" :class="{'is-disabled':disabled}">
<image v-if="thumb" :src="thumb" class="uni-collapse-item__title-img" />
<text class="uni-collapse-item__title-text">{{ title }}</text>
</view>
</slot>
</view>
<view
v-if="showArrow"
:class="{ 'uni-collapse-item__title-arrow-active': isOpen, 'uni-collapse-item--animation': showAnimation === true }"
class="uni-collapse-item__title-arrow">
<uni-icons :color="disabled?'#ddd':'#bbb'" size="14" type="arrowdown" />
</view>
</view>
<view class="uni-collapse-item__wrap" :class="{'is--transition':showAnimation}"
:style="{height: (isOpen?height:0) +'px'}">
<view :id="elId" ref="collapse--hook" class="uni-collapse-item__wrap-content"
:class="{open:isheight,'uni-collapse-item--border':border&&isOpen}">
<slot></slot>
</view>
</view>
</view>
</template>
<script>
// #ifdef APP-NVUE
const dom = weex.requireModule('dom')
// #endif
/**
* CollapseItem 折叠面板子组件
* @description 折叠面板子组件
* @property {String} title 标题文字
* @property {String} thumb 标题左侧缩略图
* @property {String} name 唯一标志符
* @property {Boolean} open = [true|false] 是否展开组件
* @property {Boolean} titleBorder = [true|false] 是否显示标题分隔线
* @property {Boolean} border = [true|false] 是否显示分隔线
* @property {Boolean} disabled = [true|false] 是否展开面板
* @property {Boolean} showAnimation = [true|false] 开启动画
* @property {Boolean} showArrow = [true|false] 是否显示右侧箭头
*/
export default {
name: 'uniCollapseItem',
props: {
// 列表标题
title: {
type: String,
default: ''
},
name: {
type: [Number, String],
default: ''
},
// 是否禁用
disabled: {
type: Boolean,
default: false
},
// #ifdef APP-PLUS
// 是否显示动画,app 端默认不开启动画,卡顿严重
showAnimation: {
type: Boolean,
default: false
},
// #endif
// #ifndef APP-PLUS
// 是否显示动画
showAnimation: {
type: Boolean,
default: true
},
// #endif
// 是否展开
open: {
type: Boolean,
default: false
},
// 缩略图
thumb: {
type: String,
default: ''
},
// 标题分隔线显示类型
titleBorder: {
type: String,
default: 'auto'
},
border: {
type: Boolean,
default: true
},
showArrow:{
type: Boolean,
default: true
}
},
data() {
// TODO 随机生生元素ID解决百度小程序获取同一个元素位置信息的bug
const elId = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
return {
isOpen: false,
isheight: null,
height: 0,
elId,
nameSync: 0
}
},
watch: {
open(val) {
this.isOpen = val
this.onClick(val,'init')
}
},
updated(e) {
this.$nextTick(()=> {
this.init(true)
})
},
created(){
this.collapse = this.getCollapse()
this.oldHeight = 0
},
// #ifndef VUE3
// TODO vue2
destroyed() {
if (this.__isUnmounted) return
this.uninstall()
},
// #endif
// #ifdef VUE3
// TODO vue3
unmounted() {
this.__isUnmounted = true
this.uninstall()
},
// #endif
mounted() {
if (!this.collapse) return
if (this.name !== '') {
this.nameSync = this.name
} else {
this.nameSync = this.collapse.childrens.length + ''
}
if (this.collapse.names.indexOf(this.nameSync) === -1) {
this.collapse.names.push(this.nameSync)
} else {
console.warn(`name 值 ${this.nameSync} 重复`);
}
if (this.collapse.childrens.indexOf(this) === -1) {
this.collapse.childrens.push(this)
}
this.init()
},
methods: {
init(type) {
// #ifndef APP-NVUE
this.getCollapseHeight(type)
// #endif
// #ifdef APP-NVUE
this.getNvueHwight(type)
// #endif
},
uninstall() {
if (this.collapse) {
this.collapse.childrens.forEach((item, index) => {
if (item === this) {
this.collapse.childrens.splice(index, 1)
}
})
this.collapse.names.forEach((item, index) => {
if (item === this.nameSync) {
this.collapse.names.splice(index, 1)
}
})
}
},
onClick(isOpen,type) {
if (this.disabled) return
this.isOpen = isOpen
if (this.isOpen && this.collapse) {
this.collapse.setAccordion(this)
}
if(type !== 'init'){
this.collapse.onChange(isOpen,this)
}
},
getCollapseHeight(type, index = 0) {
const views = uni.createSelectorQuery().in(this)
views
.select(`#${this.elId}`)
.fields({
size: true
}, data => {
// TODO 百度中可能获取不到节点信息 ,需要循环获取
if (index >= 10) return
if (!data) {
index++
this.getCollapseHeight(false, index)
return
}
// #ifdef APP-NVUE
this.height = data.height + 1
// #endif
// #ifndef APP-NVUE
this.height = data.height
// #endif
this.isheight = true
if (type) return
this.onClick(this.open,'init')
})
.exec()
},
getNvueHwight(type) {
const result = dom.getComponentRect(this.$refs['collapse--hook'], option => {
if (option && option.result && option.size) {
// #ifdef APP-NVUE
this.height = option.size.height + 1
// #endif
// #ifndef APP-NVUE
this.height = option.size.height
// #endif
this.isheight = true
if (type) return
this.onClick(this.open,'init')
}
})
},
/**
* 获取父元素实例
*/
getCollapse(name = 'uniCollapse') {
let parent = this.$parent;
let parentName = parent.$options.name;
while (parentName !== name) {
parent = parent.$parent;
if (!parent) return false;
parentName = parent.$options.name;
}
return parent;
}
}
}
</script>
<style lang="scss" scoped>
.uni-collapse-item {
/* #ifndef APP-NVUE */
box-sizing: border-box;
/* #endif */
&__title {
/* #ifndef APP-NVUE */
display: flex;
width: 100%;
box-sizing: border-box;
/* #endif */
flex-direction: row;
align-items: center;
transition: border-bottom-color .3s;
// transition-property: border-bottom-color;
// transition-duration: 5s;
&-wrap {
width: 100%;
flex: 1;
}
&-box {
padding: 0 15px;
/* #ifndef APP-NVUE */
display: flex;
width: 100%;
box-sizing: border-box;
/* #endif */
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 48px;
line-height: 48px;
background-color: #fff;
color: #303133;
font-size: 13px;
font-weight: 500;
/* #ifdef H5 */
cursor: pointer;
outline: none;
/* #endif */
&.is-disabled {
.uni-collapse-item__title-text {
color: $uni-text-color-disable;
}
}
}
&.uni-collapse-item-border {
border-bottom: 1px solid #ebeef5;
}
&.is-open {
border-bottom-color: transparent;
}
&-img {
height: $uni-img-size-base;
width: $uni-img-size-base;
margin-right: 10px;
}
&-text {
flex: 1;
font-size: $uni-font-size-base;
/* #ifndef APP-NVUE */
white-space: nowrap;
color: inherit;
/* #endif */
/* #ifdef APP-NVUE */
lines: 1;
/* #endif */
overflow: hidden;
text-overflow: ellipsis;
}
&-arrow {
/* #ifndef APP-NVUE */
display: flex;
box-sizing: border-box;
/* #endif */
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
margin-right: 10px;
transform: rotate(0deg);
&-active {
transform: rotate(180deg);
}
}
}
&__wrap {
/* #ifndef APP-NVUE */
will-change: height;
box-sizing: border-box;
/* #endif */
background-color: #fff;
overflow: hidden;
position: relative;
height: 0;
&.is--transition {
// transition: all 0.3s;
transition-property: height, border-bottom-width;
transition-duration: 0.3s;
/* #ifndef APP-NVUE */
will-change: height;
/* #endif */
}
&-content {
position: absolute;
font-size: 13px;
color: #303133;
// transition: height 0.3s;
border-bottom-color: transparent;
border-bottom-style: solid;
border-bottom-width: 0;
&.uni-collapse-item--border {
border-bottom-width: 1px;
border-bottom-color: red;
border-bottom-color: #ebeef5;
}
&.open {
position: relative;
}
}
}
&--animation {
transition-property: transform;
transition-duration: 0.3s;
transition-timing-function: ease;
}
}
</style>

View File

@@ -0,0 +1,146 @@
<template>
<view class="uni-collapse">
<slot />
</view>
</template>
<script>
/**
* Collapse 折叠面板
* @description 展示可以折叠 / 展开的内容区域
* @tutorial https://ext.dcloud.net.cn/plugin?id=23
* @property {String|Array} value 当前激活面板改变时触发(如果是手风琴模式参数类型为string否则为array)
* @property {Boolean} accordion = [true|false] 是否开启手风琴效果是否开启手风琴效果
* @event {Function} change 切换面板时触发如果是手风琴模式返回类型为string否则为array
*/
export default {
name: 'uniCollapse',
emits:['change','activeItem','input','update:modelValue'],
props: {
value: {
type: [String, Array],
default: ''
},
modelValue: {
type: [String, Array],
default: ''
},
accordion: {
// 是否开启手风琴效果
type: [Boolean, String],
default: false
},
},
data() {
return {}
},
computed: {
// TODO 兼容 vue2 和 vue3
dataValue() {
let value = (typeof this.value === 'string' && this.value === '') ||
(Array.isArray(this.value) && this.value.length === 0)
let modelValue = (typeof this.modelValue === 'string' && this.modelValue === '') ||
(Array.isArray(this.modelValue) && this.modelValue.length === 0)
if (value) {
return this.modelValue
}
if (modelValue) {
return this.value
}
return this.value
}
},
watch: {
dataValue(val) {
this.setOpen(val)
}
},
created() {
this.childrens = []
this.names = []
},
mounted() {
this.setOpen(this.dataValue)
},
methods: {
setOpen(val) {
let str = typeof val === 'string'
let arr = Array.isArray(val)
this.childrens.forEach((vm, index) => {
if (str) {
if (val === vm.nameSync) {
if (!this.accordion) {
console.warn('accordion 属性为 false ,v-model 类型应该为 array')
return
}
vm.isOpen = true
}
}
if (arr) {
val.forEach(v => {
if (v === vm.nameSync) {
if (this.accordion) {
console.warn('accordion 属性为 true ,v-model 类型应该为 string')
return
}
vm.isOpen = true
}
})
}
})
this.emit(val)
},
setAccordion(self) {
if (!this.accordion) return
this.childrens.forEach((vm, index) => {
if (self !== vm) {
vm.isOpen = false
}
})
},
resize() {
this.childrens.forEach((vm, index) => {
// #ifndef APP-NVUE
vm.getCollapseHeight()
// #endif
// #ifdef APP-NVUE
vm.getNvueHwight()
// #endif
})
},
onChange(isOpen, self) {
let activeItem = []
if (this.accordion) {
activeItem = isOpen ? self.nameSync : ''
} else {
this.childrens.forEach((vm, index) => {
if (vm.isOpen) {
activeItem.push(vm.nameSync)
}
})
}
this.$emit('change', activeItem)
this.emit(activeItem)
},
emit(val){
this.$emit('input', val)
this.$emit('update:modelValue', val)
}
}
}
</script>
<style lang="scss" scoped>
.uni-collapse {
/* #ifndef APP-NVUE */
width: 100%;
display: flex;
/* #endif */
/* #ifdef APP-NVUE */
flex: 1;
/* #endif */
flex-direction: column;
background-color: $uni-bg-color;
}
</style>

View File

@@ -0,0 +1,88 @@
{
"id": "uni-collapse",
"displayName": "uni-collapse 折叠面板",
"version": "1.3.3",
"description": "Collapse 组件,可以折叠 / 展开的内容区域。",
"keywords": [
"uni-ui",
"折叠",
"折叠面板",
"手风琴"
],
"repository": "https://github.com/dcloudio/uni-ui",
"engines": {
"HBuilderX": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"category": [
"前端组件",
"通用组件"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
},
"uni_modules": {
"dependencies": [
"uni-icons"
],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "y"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "y",
"QQ": "y"
},
"快应用": {
"华为": "u",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "u"
}
}
}
}
}

View File

@@ -0,0 +1,276 @@
## Collapse 折叠面板
> **组件名uni-collapse**
> 代码块: `uCollapse`
> 关联组件:`uni-collapse-item`、`uni-icons`。
折叠面板用来折叠/显示过长的内容或者是列表。通常是在多内容分类项使用,折叠不重要的内容,显示重要内容。点击可以展开折叠部分。
> **注意事项**
> 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
> - 组件需要依赖 `sass` 插件 ,请自行手动安装
> - `App` 端默认关闭组件动画 ,因为 `height` 动画开销比较大,会导致页面卡顿,请酌情使用动画
> - 如在使用组件过程从发现卡顿严重,请尝试停用组件动画,问题原因如上
> - 在小程序端组件内容发生变化,需要手动调用 resize() 方法,手动更新几点信息,避免出现内容错位
> - 如需自定义组件默认边框颜色等,请使用插槽自定义内容并合理使用 `border ` 和 `title-border` 属性
> - 折叠面板仅支持嵌套使用,请勿单独使用
> - 组件支持 nvue ,需要在 `manifest.json > app-plus` 节点下配置 `"nvueStyleCompiler" : "uni-app"`
> - 如使用过程中有任何问题或者您对uni-ui有一些好的建议欢迎加入 uni-ui 交流群871950839
### 安装方式
本组件符合[easycom](https://uniapp.dcloud.io/collocation/pages?id=easycom)规范,`HBuilderX 2.5.5`起,只需将本组件导入项目,在页面`template`中即可直接使用,无需在页面中`import`和注册`components`
如需通过`npm`方式使用`uni-ui`组件,另见文档:[https://ext.dcloud.net.cn/plugin?id=55](https://ext.dcloud.net.cn/plugin?id=55)
### 基本用法
使用 `title` 属性指定面板显示内容
使用 `open` 属性默认打开当前面板
使用 `disabled` 属性禁用面板
```html
<uni-collapse>
<uni-collapse-item title="默认开启" :open="true">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item title="折叠内容">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item title="禁用状态" disabled>
<text>折叠内容</text>
</uni-collapse-item>
</uni-collapse>
```
### 手风琴效果
使用 `accordion` 属性,可以仅打开一个面板并关闭其他已经打开的面板,效果类似手风琴
设置 `accordion` 属性时,`open` 属性则生效在最后一个组件
```html
<uni-collapse accordion>
<uni-collapse-item title="手风琴效果">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item title="手风琴效果">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item title="禁用状态" disabled>
<text>折叠内容</text>
</uni-collapse-item>
</uni-collapse>
```
### 动态设置折叠面板打开状态
使用 `v-model` 属性,动态设置面板的显示状态
使用 `name` 属性设置每个面板的唯一标识,如不设置使用默认索引,从字符串 `"0"` 开始记数
**注意**
- 如果 `accordion` 属性为 `true``v-model` 类型为 `String`
- 如果 `accordion` 属性为 `false``v-model` 类型为 `Array`
- 请注意 `v-model` 属性与 `open` 属性请勿一起使用 ,建议只使用 `v-model`
```html
<uni-collapse v-model="value">
<uni-collapse-item name="key1" title="默认开启">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item name="key2" title="默认开启">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item name="key3" title="默认不开启">
<text>折叠内容</text>
</uni-collapse-item>
</uni-collapse>
```
```javascript
export default {
data(){
return {
value:['key1','key2'],
// 如果设置了 accordion 属性,则使用 string 类型
// value:'key1'
}
}
}
```
### 使用动画
使用 `show-animation` 属性开启或关闭面板折叠动画,默认动画开启
**注意**
- `App` 端默认关闭组件动画 ,因为 height 动画开销比较大,会导致页面卡顿,请酌情使用动画,如出现明显卡顿,尝试关闭动画
```html
<uni-collapse>
<uni-collapse-item :show-animation="true" title="开启动画">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item :show-animation="true" title="开启动画">
<text>折叠内容</text>
</uni-collapse-item>
<uni-collapse-item :show-animation="false" title="不开启动画">
<text>折叠内容</text>
</uni-collapse-item>
</uni-collapse>
```
### 配置图片
使用 `thumb` 配置图片地址, 可在面板左侧显示一个图片
如需显示更多内容,如图标等,请见下方自定义插槽的说明
```html
<uni-collapse>
<uni-collapse-item title="标题文字"
thumb="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png">
<view class="content">
<text class="text">折叠内容主体,可自定义内容及样式</text>
</view>
</uni-collapse-item>
</uni-collapse>
```
### 自定义插槽
如果需要自定义面板显示,可以使用 `title` 插槽达成完全自定义。下面是一个使用 `uni-list` 的列表示例,需要引入 `uni-list` 组件
```html
<uni-collapse>
<!-- 因为list默认带一条分隔线所以使用 titleBorder="none" 取消面板的分隔线 -->
<uni-collapse-item title-border="none" :border="false">
<template v-slot:title>
<uni-list>
<uni-list-item title="标题使用自定义标题插槽" :show-extra-icon="true" :extra-icon="extraIcon">
</uni-list-item>
</uni-list>
</template>
<view class="content">
<text class="text">折叠内容主体,可自定义内容及样式</text>
</view>
</uni-collapse-item>
</uni-collapse>
```
**注意**
- 在折叠面板组件中使用list时在 App-Nvue 下请勿单独使用 uni-list-item会导致组件无法正常显示其他平台不做限制
- 在默认插槽里使用 uni-list 组件与上方示例一样,直接写在默认插槽里即可
## API
### Collapse Props
|属性名|类型|默认值|说明|
|:-:|:-:|:-:|:-:|
|value/v-model|String/Array|-|当前激活面板改变时触发(如果是手风琴模式参数类型为string否则为array)|
|accordion|Boolean|false|是否开启手风琴效果 |
### Collapse Event
|事件称名|说明|返回值|
|:-:|:-:|:-:|
|@change|切换面板时触发 |切换面板时触发如果是手风琴模式返回类型为string否则为array|
### Collapse Methods
|方法名称|说明|
|:-:|:-:|
|resize |更新当前列表高度|
> **提示**
> - resize 方法解决动态添加数据,带动画的折叠面板高度不更新的问题
> - 需要在数据渲染完毕之后使用 `resize` 方法。推荐在 `this.$nextTick()` 中使用
> - 当前只有小程序端需要调用此方法H5\App 端已经做了处理,不需要手动更新高度
> ```html
> <view>
> <uni-collapse ref="collapse" v-model="value">
> <uni-collapse-item title="默认开启" >
> <view class="content">
> <text class="text">{{content}}</text>
> </view>
> </uni-collapse-item>
> <uni-collapse-item title="折叠内容">
> <view class="content">
> <text class="text">折叠内容主体,这是一段比较长内容。默认折叠主要内容,只显示当前项标题。点击标题展开,才能看到这段文字。再次点击标题,折叠内容。</text>
> </view>
> </uni-collapse-item>
> </uni-collapse>
> <button class="button" type="primary" @click="add">动态修改内容</button>
> </view>
> ```
> ```javascript
> export default {
> data() {
> return {
> value:['0'],
> content: '折叠内容主体,可自定义内容及样式,点击按钮修改内容使高度发生变化。',
> }
> },
> methods: {
> add() {
> if (this.content.length > 35) {
> this.content = '折叠内容主体,可自定义内容及样式,点击按钮修改内容使高度发生变化。'
> } else {
> this.content = '折叠内容主体,这是一段比较长内容。通过点击按钮修改后内容后,使组件高度发生变化,在次点击按钮恢复之前的内容和高度。'
> }
> // TODO 小程序中不支持自动更新 需要手动resize 更新组件高度
> // #ifdef MP
> this.$nextTick(() => {
> this.$refs.collapse.resize()
> })
> // #endif
> }
> }
> }
> ```
### CollapseItem Props
|属性名|类型|默认值|说明|
|:-:|:-:|:-:|:-:|
|title|String|-|标题文字|
|thumb|String|-|标题左侧缩略图|
|disabled|Boolean|false|是否禁用|
|open|Boolean|false|是否展开面板|
|show-animation|Boolean|false|开启动画|
|border|Boolean|true|折叠面板内容分隔线|
|title-border|String|auto|折叠面板标题分隔线可选值见下方 **TitleBorder Params**|
|show-arrow|Boolean|true|是否显示右侧箭头|
#### TitleBorder Params
|参数名|说明|
|:-:|:-:|
|auto|分隔线自动显示|
|none|不显示分隔线|
|show|一直显示分隔线|
### Collapse Slots
|插槽名|说明|
|:-:| :-:|
|default|默认插槽|
|title|面板标题插槽,如使用此插槽禁用样式效果将失效|
## 组件示例
点击查看:[https://hellouniapp.dcloud.net.cn/pages/extUI/collapse/collapse](https://hellouniapp.dcloud.net.cn/pages/extUI/collapse/collapse)

View File

@@ -1,132 +1,132 @@
export default {
"pulldown": "\ue588",
"refreshempty": "\ue461",
"back": "\ue471",
"forward": "\ue470",
"more": "\ue507",
"more-filled": "\ue537",
"scan": "\ue612",
"qq": "\ue264",
"weibo": "\ue260",
"weixin": "\ue261",
"pengyouquan": "\ue262",
"loop": "\ue565",
"refresh": "\ue407",
"refresh-filled": "\ue437",
"arrowthindown": "\ue585",
"arrowthinleft": "\ue586",
"arrowthinright": "\ue587",
"arrowthinup": "\ue584",
"undo-filled": "\ue7d6",
"undo": "\ue406",
"redo": "\ue405",
"redo-filled": "\ue7d9",
"bars": "\ue563",
"chatboxes": "\ue203",
"camera": "\ue301",
"chatboxes-filled": "\ue233",
"camera-filled": "\ue7ef",
"cart-filled": "\ue7f4",
"cart": "\ue7f5",
"checkbox-filled": "\ue442",
"checkbox": "\ue7fa",
"arrowleft": "\ue582",
"arrowdown": "\ue581",
"arrowright": "\ue583",
"smallcircle-filled": "\ue801",
"arrowup": "\ue580",
"circle": "\ue411",
"eye-filled": "\ue568",
"eye-slash-filled": "\ue822",
"eye-slash": "\ue823",
"eye": "\ue824",
"flag-filled": "\ue825",
"flag": "\ue508",
"gear-filled": "\ue532",
"reload": "\ue462",
"gear": "\ue502",
"hand-thumbsdown-filled": "\ue83b",
"hand-thumbsdown": "\ue83c",
"hand-thumbsup-filled": "\ue83d",
"heart-filled": "\ue83e",
"hand-thumbsup": "\ue83f",
"heart": "\ue840",
"home": "\ue500",
"info": "\ue504",
"home-filled": "\ue530",
"info-filled": "\ue534",
"circle-filled": "\ue441",
"chat-filled": "\ue847",
"chat": "\ue263",
"mail-open-filled": "\ue84d",
"email-filled": "\ue231",
"mail-open": "\ue84e",
"email": "\ue201",
"checkmarkempty": "\ue472",
"list": "\ue562",
"locked-filled": "\ue856",
"locked": "\ue506",
"map-filled": "\ue85c",
"map-pin": "\ue85e",
"map-pin-ellipse": "\ue864",
"map": "\ue364",
"minus-filled": "\ue440",
"mic-filled": "\ue332",
"minus": "\ue410",
"micoff": "\ue360",
"mic": "\ue302",
"clear": "\ue434",
"smallcircle": "\ue868",
"close": "\ue404",
"closeempty": "\ue460",
"paperclip": "\ue567",
"paperplane": "\ue503",
"paperplane-filled": "\ue86e",
"person-filled": "\ue131",
"contact-filled": "\ue130",
"person": "\ue101",
"contact": "\ue100",
"images-filled": "\ue87a",
"phone": "\ue200",
"images": "\ue87b",
"image": "\ue363",
"image-filled": "\ue877",
"location-filled": "\ue333",
"location": "\ue303",
"plus-filled": "\ue439",
"plus": "\ue409",
"plusempty": "\ue468",
"help-filled": "\ue535",
"help": "\ue505",
"navigate-filled": "\ue884",
"navigate": "\ue501",
"mic-slash-filled": "\ue892",
"search": "\ue466",
"settings": "\ue560",
"sound": "\ue590",
"sound-filled": "\ue8a1",
"spinner-cycle": "\ue465",
"download-filled": "\ue8a4",
"personadd-filled": "\ue132",
"videocam-filled": "\ue8af",
"personadd": "\ue102",
"upload": "\ue402",
"upload-filled": "\ue8b1",
"starhalf": "\ue463",
"star-filled": "\ue438",
"star": "\ue408",
"trash": "\ue401",
"phone-filled": "\ue230",
"compose": "\ue400",
"videocam": "\ue300",
"trash-filled": "\ue8dc",
"download": "\ue403",
"chatbubble-filled": "\ue232",
"chatbubble": "\ue202",
"cloud-download": "\ue8e4",
"cloud-upload-filled": "\ue8e5",
"cloud-upload": "\ue8e6",
export default {
"pulldown": "\ue588",
"refreshempty": "\ue461",
"back": "\ue471",
"forward": "\ue470",
"more": "\ue507",
"more-filled": "\ue537",
"scan": "\ue612",
"qq": "\ue264",
"weibo": "\ue260",
"weixin": "\ue261",
"pengyouquan": "\ue262",
"loop": "\ue565",
"refresh": "\ue407",
"refresh-filled": "\ue437",
"arrowthindown": "\ue585",
"arrowthinleft": "\ue586",
"arrowthinright": "\ue587",
"arrowthinup": "\ue584",
"undo-filled": "\ue7d6",
"undo": "\ue406",
"redo": "\ue405",
"redo-filled": "\ue7d9",
"bars": "\ue563",
"chatboxes": "\ue203",
"camera": "\ue301",
"chatboxes-filled": "\ue233",
"camera-filled": "\ue7ef",
"cart-filled": "\ue7f4",
"cart": "\ue7f5",
"checkbox-filled": "\ue442",
"checkbox": "\ue7fa",
"arrowleft": "\ue582",
"arrowdown": "\ue581",
"arrowright": "\ue583",
"smallcircle-filled": "\ue801",
"arrowup": "\ue580",
"circle": "\ue411",
"eye-filled": "\ue568",
"eye-slash-filled": "\ue822",
"eye-slash": "\ue823",
"eye": "\ue824",
"flag-filled": "\ue825",
"flag": "\ue508",
"gear-filled": "\ue532",
"reload": "\ue462",
"gear": "\ue502",
"hand-thumbsdown-filled": "\ue83b",
"hand-thumbsdown": "\ue83c",
"hand-thumbsup-filled": "\ue83d",
"heart-filled": "\ue83e",
"hand-thumbsup": "\ue83f",
"heart": "\ue840",
"home": "\ue500",
"info": "\ue504",
"home-filled": "\ue530",
"info-filled": "\ue534",
"circle-filled": "\ue441",
"chat-filled": "\ue847",
"chat": "\ue263",
"mail-open-filled": "\ue84d",
"email-filled": "\ue231",
"mail-open": "\ue84e",
"email": "\ue201",
"checkmarkempty": "\ue472",
"list": "\ue562",
"locked-filled": "\ue856",
"locked": "\ue506",
"map-filled": "\ue85c",
"map-pin": "\ue85e",
"map-pin-ellipse": "\ue864",
"map": "\ue364",
"minus-filled": "\ue440",
"mic-filled": "\ue332",
"minus": "\ue410",
"micoff": "\ue360",
"mic": "\ue302",
"clear": "\ue434",
"smallcircle": "\ue868",
"close": "\ue404",
"closeempty": "\ue460",
"paperclip": "\ue567",
"paperplane": "\ue503",
"paperplane-filled": "\ue86e",
"person-filled": "\ue131",
"contact-filled": "\ue130",
"person": "\ue101",
"contact": "\ue100",
"images-filled": "\ue87a",
"phone": "\ue200",
"images": "\ue87b",
"image": "\ue363",
"image-filled": "\ue877",
"location-filled": "\ue333",
"location": "\ue303",
"plus-filled": "\ue439",
"plus": "\ue409",
"plusempty": "\ue468",
"help-filled": "\ue535",
"help": "\ue505",
"navigate-filled": "\ue884",
"navigate": "\ue501",
"mic-slash-filled": "\ue892",
"search": "\ue466",
"settings": "\ue560",
"sound": "\ue590",
"sound-filled": "\ue8a1",
"spinner-cycle": "\ue465",
"download-filled": "\ue8a4",
"personadd-filled": "\ue132",
"videocam-filled": "\ue8af",
"personadd": "\ue102",
"upload": "\ue402",
"upload-filled": "\ue8b1",
"starhalf": "\ue463",
"star-filled": "\ue438",
"star": "\ue408",
"trash": "\ue401",
"phone-filled": "\ue230",
"compose": "\ue400",
"videocam": "\ue300",
"trash-filled": "\ue8dc",
"download": "\ue403",
"chatbubble-filled": "\ue232",
"chatbubble": "\ue202",
"cloud-download": "\ue8e4",
"cloud-upload-filled": "\ue8e5",
"cloud-upload": "\ue8e6",
"cloud-download-filled": "\ue8e9",
"headphones":"\ue8bf",
"shop":"\ue609"
"shop":"\ue609"
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,24 @@
## 1.2.42021-08-20
- 优化 close-all 方法
## 1.2.32021-08-20
- 新增 close-all 方法,关闭所有已打开的组件
## 1.2.22021-08-17
- 新增 resize() 方法在非微信小程序、h5、app-vue端出现不能滑动的问题的时候重置组件
- 修复 app 端偶尔出现类似 Page[x][-x,xx;-x,xx,x,x-x] 的问题
- 优化 微信小程序、h5、app-vue 滑动逻辑,避免出现动态新增组件后不能滑动的问题
## 1.2.12021-07-30
- 组件兼容 vue3如何创建vue3项目详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
- 修复 跨页面修改组件数据 ,导致不能滑动的问题
## 1.1.102021-06-17
- 修复 按钮点击执行两次的bug
## 1.1.92021-05-12
- 新增 项目示例地址
## 1.1.82021-03-26
- 修复 微信小程序 nv_navigator is not defined 报错的bug
## 1.1.72021-02-05
- 调整为uni_modules目录规范
- 新增 左侧滑动
- 新增 插槽使用方式
- 新增 threshold 属性,可以控制滑动缺省值
- 优化 长列表滚动性能
- 修复 滚动页面时触发组件滑动的Bug

View File

@@ -0,0 +1,300 @@
// #ifdef APP-NVUE
const BindingX = uni.requireNativePlugin('bindingx');
const dom = uni.requireNativePlugin('dom');
const animation = uni.requireNativePlugin('animation');
export default {
data() {
return {}
},
watch: {
show(newVal) {
if (this.autoClose) return
if (this.stop) return
this.stop = true
if (newVal) {
this.open(newVal)
} else {
this.close()
}
},
leftOptions() {
this.getSelectorQuery()
this.init()
},
rightOptions(newVal) {
this.init()
}
},
created() {
this.swipeaction = this.getSwipeAction()
if (this.swipeaction.children !== undefined) {
this.swipeaction.children.push(this)
}
},
mounted() {
this.box = this.getEl(this.$refs['selector-box--hock'])
this.selector = this.getEl(this.$refs['selector-content--hock']);
this.leftButton = this.getEl(this.$refs['selector-left-button--hock']);
this.rightButton = this.getEl(this.$refs['selector-right-button--hock']);
this.init()
},
// beforeDestroy() {
// this.swipeaction.children.forEach((item, index) => {
// if (item === this) {
// this.swipeaction.children.splice(index, 1)
// }
// })
// },
methods: {
init() {
this.$nextTick(() => {
this.x = 0
this.button = {
show: false
}
setTimeout(() => {
this.getSelectorQuery()
}, 200)
})
},
onClick(index, item, position) {
this.$emit('click', {
content: item,
index,
position
})
},
touchstart(e) {
// 每次只触发一次,避免多次监听造成闪烁
if (this.stop) return
this.stop = true
if (this.autoClose) {
this.swipeaction.closeOther(this)
}
const leftWidth = this.button.left.width
const rightWidth = this.button.right.width
let expression = this.range(this.x, -rightWidth, leftWidth)
let leftExpression = this.range(this.x - leftWidth, -leftWidth, 0)
let rightExpression = this.range(this.x + rightWidth, 0, rightWidth)
this.eventpan = BindingX.bind({
anchor: this.box,
eventType: 'pan',
props: [{
element: this.selector,
property: 'transform.translateX',
expression
}, {
element: this.leftButton,
property: 'transform.translateX',
expression: leftExpression
}, {
element: this.rightButton,
property: 'transform.translateX',
expression: rightExpression
}, ]
}, (e) => {
// nope
if (e.state === 'end') {
this.x = e.deltaX + this.x;
this.isclick = true
this.bindTiming(e.deltaX)
}
});
},
touchend(e) {
if (this.isopen !== 'none' && !this.isclick) {
this.open('none')
}
},
bindTiming(x) {
const left = this.x
const leftWidth = this.button.left.width
const rightWidth = this.button.right.width
const threshold = this.threshold
if (!this.isopen || this.isopen === 'none') {
if (left > threshold) {
this.open('left')
} else if (left < -threshold) {
this.open('right')
} else {
this.open('none')
}
} else {
if ((x > -leftWidth && x < 0) || x > rightWidth) {
if ((x > -threshold && x < 0) || (x - rightWidth > threshold)) {
this.open('left')
} else {
this.open('none')
}
} else {
if ((x < threshold && x > 0) || (x + leftWidth < -threshold)) {
this.open('right')
} else {
this.open('none')
}
}
}
},
/**
* 移动范围
* @param {Object} num
* @param {Object} mix
* @param {Object} max
*/
range(num, mix, max) {
return `min(max(x+${num}, ${mix}), ${max})`
},
/**
* 开启swipe
*/
open(type) {
this.animation(type)
},
/**
* 关闭swipe
*/
close() {
this.animation('none')
},
/**
* 开启关闭动画
* @param {Object} type
*/
animation(type) {
const time = 300
const leftWidth = this.button.left.width
const rightWidth = this.button.right.width
if (this.eventpan && this.eventpan.token) {
BindingX.unbind({
token: this.eventpan.token,
eventType: 'pan'
})
}
switch (type) {
case 'left':
Promise.all([
this.move(this.selector, leftWidth),
this.move(this.leftButton, 0),
this.move(this.rightButton, rightWidth * 2)
]).then(() => {
this.setEmit(leftWidth, type)
})
break
case 'right':
Promise.all([
this.move(this.selector, -rightWidth),
this.move(this.leftButton, -leftWidth * 2),
this.move(this.rightButton, 0)
]).then(() => {
this.setEmit(-rightWidth, type)
})
break
default:
Promise.all([
this.move(this.selector, 0),
this.move(this.leftButton, -leftWidth),
this.move(this.rightButton, rightWidth)
]).then(() => {
this.setEmit(0, type)
})
}
},
setEmit(x, type) {
const leftWidth = this.button.left.width
const rightWidth = this.button.right.width
this.isopen = this.isopen || 'none'
this.stop = false
this.isclick = false
// 只有状态不一致才会返回结果
if (this.isopen !== type && this.x !== x) {
if (type === 'left' && leftWidth > 0) {
this.$emit('change', 'left')
}
if (type === 'right' && rightWidth > 0) {
this.$emit('change', 'right')
}
if (type === 'none') {
this.$emit('change', 'none')
}
}
this.x = x
this.isopen = type
},
move(ref, value) {
return new Promise((resolve, reject) => {
animation.transition(ref, {
styles: {
transform: `translateX(${value})`,
},
duration: 150, //ms
timingFunction: 'linear',
needLayout: false,
delay: 0 //ms
}, function(res) {
resolve(res)
})
})
},
/**
* 获取ref
* @param {Object} el
*/
getEl(el) {
return el.ref
},
/**
* 获取节点信息
*/
getSelectorQuery() {
Promise.all([
this.getDom('left'),
this.getDom('right'),
]).then((data) => {
let show = 'none'
if (this.autoClose) {
show = 'none'
} else {
show = this.show
}
if (show === 'none') {
// this.close()
} else {
this.open(show)
}
})
},
getDom(str) {
return new Promise((resolve, reject) => {
dom.getComponentRect(this.$refs[`selector-${str}-button--hock`], (data) => {
if (data) {
this.button[str] = data.size
resolve(data)
} else {
reject()
}
})
})
}
}
}
// #endif
// #ifndef APP-NVUE
export default {}
// #endif

View File

@@ -0,0 +1,12 @@
export function isPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for (let v = 0; v < Agents.length - 1; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}

View File

@@ -0,0 +1,193 @@
export default {
data() {
return {
x: 0,
transition: false,
width: 0,
viewWidth: 0,
swipeShow: 0
}
},
watch: {
show(newVal) {
if (this.autoClose) return
if (newVal && newVal !== 'none' ) {
this.transition = true
this.open(newVal)
} else {
this.close()
}
}
},
created() {
this.swipeaction = this.getSwipeAction()
if (this.swipeaction.children !== undefined) {
this.swipeaction.children.push(this)
}
},
mounted() {
this.isopen = false
setTimeout(() => {
this.getQuerySelect()
}, 50)
},
methods: {
appTouchStart(e) {
const {
clientX
} = e.changedTouches[0]
this.clientX = clientX
this.timestamp = new Date().getTime()
},
appTouchEnd(e, index, item, position) {
const {
clientX
} = e.changedTouches[0]
// fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
let diff = Math.abs(this.clientX - clientX)
let time = (new Date().getTime()) - this.timestamp
if (diff < 40 && time < 300) {
this.$emit('click', {
content: item,
index,
position
})
}
},
/**
* 移动触发
* @param {Object} e
*/
onChange(e) {
this.moveX = e.detail.x
this.isclose = false
},
touchstart(e) {
this.transition = false
this.isclose = true
this.autoClose && this.swipeaction.closeOther(this)
},
touchmove(e) {},
touchend(e) {
// 0的位置什么都不执行
if (this.isclose && this.isopen === 'none') return
if (this.isclose && this.isopen !== 'none') {
this.transition = true
this.close()
} else {
this.move(this.moveX + this.leftWidth)
}
},
/**
* 移动
* @param {Object} moveX
*/
move(moveX) {
// 打开关闭的处理逻辑不太一样
this.transition = true
// 未打开状态
if (!this.isopen || this.isopen === 'none') {
if (moveX > this.threshold) {
this.open('left')
} else if (moveX < -this.threshold) {
this.open('right')
} else {
this.close()
}
} else {
if (moveX < 0 && moveX < this.rightWidth) {
const rightX = this.rightWidth + moveX
if (rightX < this.threshold) {
this.open('right')
} else {
this.close()
}
} else if (moveX > 0 && moveX < this.leftWidth) {
const leftX = this.leftWidth - moveX
if (leftX < this.threshold) {
this.open('left')
} else {
this.close()
}
}
}
},
/**
* 打开
*/
open(type) {
this.x = this.moveX
this.animation(type)
},
/**
* 关闭
*/
close() {
this.x = this.moveX
// TODO 解决 x 值不更新的问题,所以会多触发一次 nextTick ,待优化
this.$nextTick(() => {
this.x = -this.leftWidth
if(this.isopen!=='none'){
this.$emit('change', 'none')
}
this.isopen = 'none'
})
},
/**
* 执行结束动画
* @param {Object} type
*/
animation(type) {
this.$nextTick(() => {
if (type === 'left') {
this.x = 0
} else {
this.x = -this.rightWidth - this.leftWidth
}
if(this.isopen!==type){
this.$emit('change', type)
}
this.isopen = type
})
},
getSlide(x) {},
getQuerySelect() {
const query = uni.createSelectorQuery().in(this);
query.selectAll('.movable-view--hock').boundingClientRect(data => {
this.leftWidth = data[1].width
this.rightWidth = data[2].width
this.width = data[0].width
this.viewWidth = this.width + this.rightWidth + this.leftWidth
if (this.leftWidth === 0) {
// TODO 疑似bug ,初始化的时候如果x 是0会导致移动位置错误所以让元素超出一点
this.x = -0.1
} else {
this.x = -this.leftWidth
}
this.moveX = this.x
this.$nextTick(() => {
this.swipeShow = 1
})
if (!this.buttonWidth) {
this.disabledView = true
}
if (this.autoClose) return
if (this.show !== 'none') {
this.transition = true
this.open(this.shows)
}
}).exec();
}
}
}

View File

@@ -0,0 +1,258 @@
// #ifndef APP-PLUS|| MP-WEIXIN || H5
const MIN_DISTANCE = 10;
export default {
data() {
// TODO 随机生生元素ID解决百度小程序获取同一个元素位置信息的bug
const elClass = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
return {
uniShow: false,
left: 0,
buttonShow: 'none',
ani: false,
moveLeft:'',
elClass
}
},
watch: {
show(newVal) {
if (this.autoClose) return
this.openState(newVal)
},
left(){
this.moveLeft = `translateX(${this.left}px)`
},
buttonShow(newVal){
if (this.autoClose) return
this.openState(newVal)
},
leftOptions() {
this.init()
},
rightOptions() {
this.init()
}
},
mounted() {
this.swipeaction = this.getSwipeAction()
if (this.swipeaction.children !== undefined) {
this.swipeaction.children.push(this)
}
this.init()
},
methods: {
init(){
clearTimeout(this.timer)
this.timer = setTimeout(() => {
this.getSelectorQuery()
}, 100)
// 移动距离
this.left = 0
this.x = 0
},
closeSwipe(e) {
if (!this.autoClose) return
this.swipeaction.closeOther(this)
},
appTouchStart(e) {
const {
clientX
} = e.changedTouches[0]
this.clientX = clientX
this.timestamp = new Date().getTime()
},
appTouchEnd(e, index, item, position) {
const {
clientX
} = e.changedTouches[0]
// fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
let diff = Math.abs(this.clientX - clientX)
let time = (new Date().getTime()) - this.timestamp
if (diff < 40 && time < 300) {
this.$emit('click', {
content: item,
index,
position
})
}
},
touchstart(e) {
if (this.disabled) return
this.ani = false
this.x = this.left || 0
this.stopTouchStart(e)
this.autoClose && this.closeSwipe()
},
touchmove(e) {
if (this.disabled) return
// 是否可以滑动页面
this.stopTouchMove(e);
if (this.direction !== 'horizontal') {
return;
}
this.move(this.x + this.deltaX)
return false
},
touchend() {
if (this.disabled) return
this.moveDirection(this.left)
},
/**
* 设置移动距离
* @param {Object} value
*/
move(value) {
value = value || 0
const leftWidth = this.leftWidth
const rightWidth = this.rightWidth
// 获取可滑动范围
this.left = this.range(value, -rightWidth, leftWidth);
},
/**
* 获取范围
* @param {Object} num
* @param {Object} min
* @param {Object} max
*/
range(num, min, max) {
return Math.min(Math.max(num, min), max);
},
/**
* 移动方向判断
* @param {Object} left
* @param {Object} value
*/
moveDirection(left) {
const threshold = this.threshold
const isopen = this.isopen || 'none'
const leftWidth = this.leftWidth
const rightWidth = this.rightWidth
if (this.deltaX === 0) {
this.openState('none')
return
}
if ((isopen === 'none' && rightWidth > 0 && -left > threshold) || (isopen !== 'none' && rightWidth > 0 && rightWidth +
left < threshold)) {
// right
this.openState('right')
} else if ((isopen === 'none' && leftWidth > 0 && left > threshold) || (isopen !== 'none' && leftWidth > 0 &&
leftWidth - left < threshold)) {
// left
this.openState('left')
} else {
// default
this.openState('none')
}
},
/**
* 开启状态
* @param {Boolean} type
*/
openState(type) {
const leftWidth = this.leftWidth
const rightWidth = this.rightWidth
let left = ''
this.isopen = this.isopen ? this.isopen : 'none'
switch (type) {
case "left":
left = leftWidth
break
case "right":
left = -rightWidth
break
default:
left = 0
}
if (this.isopen !== type) {
this.throttle = true
this.$emit('change', type)
}
this.isopen = type
// 添加动画类
this.ani = true
this.$nextTick(() => {
this.move(left)
})
// 设置最终移动位置,理论上只要进入到这个函数,肯定是要打开的
},
close() {
this.openState('none')
},
getDirection(x, y) {
if (x > y && x > MIN_DISTANCE) {
return 'horizontal';
}
if (y > x && y > MIN_DISTANCE) {
return 'vertical';
}
return '';
},
/**
* 重置滑动状态
* @param {Object} event
*/
resetTouchStatus() {
this.direction = '';
this.deltaX = 0;
this.deltaY = 0;
this.offsetX = 0;
this.offsetY = 0;
},
/**
* 设置滑动开始位置
* @param {Object} event
*/
stopTouchStart(event) {
this.resetTouchStatus();
const touch = event.touches[0];
this.startX = touch.clientX;
this.startY = touch.clientY;
},
/**
* 滑动中,是否禁止打开
* @param {Object} event
*/
stopTouchMove(event) {
const touch = event.touches[0];
this.deltaX = touch.clientX - this.startX;
this.deltaY = touch.clientY - this.startY;
this.offsetX = Math.abs(this.deltaX);
this.offsetY = Math.abs(this.deltaY);
this.direction = this.direction || this.getDirection(this.offsetX, this.offsetY);
},
getSelectorQuery() {
const views = uni.createSelectorQuery().in(this)
views
.selectAll('.'+this.elClass)
.boundingClientRect(data => {
if(data.length === 0) return
let show = 'none'
if (this.autoClose) {
show = 'none'
} else {
show = this.show
}
this.leftWidth = data[0].width || 0
this.rightWidth = data[1].width || 0
this.buttonShow = show
})
.exec()
}
}
}
// #endif
// #ifdef APP-PLUS|| MP-WEIXIN || H5
export default { }
// #endif

View File

@@ -0,0 +1,81 @@
// #ifdef APP-VUE|| MP-WEIXIN || H5
import { isPC } from "./isPC"
export default {
data() {
return {
is_show:'none'
}
},
watch: {
show(newVal){
this.is_show = this.show
}
},
created() {
this.swipeaction = this.getSwipeAction()
if (this.swipeaction.children !== undefined) {
this.swipeaction.children.push(this)
}
},
mounted(){
this.is_show = this.show
},
methods: {
// wxs 中调用
closeSwipe(e) {
if (!this.autoClose) return
this.swipeaction.closeOther(this)
},
change(e) {
this.$emit('change', e.open)
if (this.is_show !== e.open) {
this.is_show = e.open
}
},
appTouchStart(e) {
// #ifdef H5
if(isPC()) return
// #endif
const {
clientX
} = e.changedTouches[0]
this.clientX = clientX
this.timestamp = new Date().getTime()
},
appTouchEnd(e, index, item, position) {
// #ifdef H5
if(isPC()) return
// #endif
const {
clientX
} = e.changedTouches[0]
// fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
let diff = Math.abs(this.clientX - clientX)
let time = (new Date().getTime()) - this.timestamp
if (diff < 40 && time < 300) {
this.$emit('click', {
content: item,
index,
position
})
}
},
onClickForPC(index, item, position) {
// #ifdef H5
if(!isPC()) return
this.$emit('click', {
content: item,
index,
position
})
// #endif
}
}
}
// #endif
// #ifndef APP-VUE|| MP-WEIXIN || H5
export default {}
// #endif

View File

@@ -0,0 +1,265 @@
const MIN_DISTANCE = 10;
export default {
showWatch(newVal, oldVal, ownerInstance, instance,self) {
let state = self.state
this.getDom(instance, ownerInstance,self)
if (newVal && newVal !== 'none') {
this.openState(newVal, instance, ownerInstance,self)
return
}
if (state.left) {
this.openState('none', instance, ownerInstance,self)
}
this.resetTouchStatus(instance,self)
},
/**
* 开始触摸操作
* @param {Object} e
* @param {Object} ins
*/
touchstart(e, ownerInstance, self) {
let instance = e.instance;
let disabled = instance.getDataset().disabled
let state = self.state;
this.getDom(instance, ownerInstance, self)
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
disabled = this.getDisabledType(disabled)
if (disabled) return
// 开始触摸时移除动画类
instance.requestAnimationFrame(function() {
instance.removeClass('ani');
ownerInstance.callMethod('closeSwipe');
})
// 记录上次的位置
state.x = state.left || 0
// 计算滑动开始位置
this.stopTouchStart(e, ownerInstance, self)
},
/**
* 开始滑动操作
* @param {Object} e
* @param {Object} ownerInstance
*/
touchmove(e, ownerInstance, self) {
let instance = e.instance;
let disabled = instance.getDataset().disabled
let state = self.state
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
disabled = this.getDisabledType(disabled)
if (disabled) return
// 是否可以滑动页面
this.stopTouchMove(e, self);
if (state.direction !== 'horizontal') {
return;
}
if (e.preventDefault) {
// 阻止页面滚动
e.preventDefault()
}
let x = state.x + state.deltaX
this.move(x, instance, ownerInstance, self)
},
/**
* 结束触摸操作
* @param {Object} e
* @param {Object} ownerInstance
*/
touchend(e, ownerInstance, self) {
let instance = e.instance;
let disabled = instance.getDataset().disabled
let state = self.state
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
disabled = this.getDisabledType(disabled)
if (disabled) return
// 滑动过程中触摸结束,通过阙值判断是开启还是关闭
// fixed by mehaotian 定时器解决点击按钮touchend 触发比 click 事件时机早的问题 ,主要是 ios13
this.moveDirection(state.left, instance, ownerInstance, self)
},
/**
* 设置移动距离
* @param {Object} value
* @param {Object} instance
* @param {Object} ownerInstance
*/
move(value, instance, ownerInstance, self) {
value = value || 0
let state = self.state
let leftWidth = state.leftWidth
let rightWidth = state.rightWidth
// 获取可滑动范围
state.left = this.range(value, -rightWidth, leftWidth);
instance.requestAnimationFrame(function() {
instance.setStyle({
transform: 'translateX(' + state.left + 'px)',
'-webkit-transform': 'translateX(' + state.left + 'px)'
})
})
},
/**
* 获取元素信息
* @param {Object} instance
* @param {Object} ownerInstance
*/
getDom(instance, ownerInstance, self) {
let state = self.state
var leftDom = ownerInstance.$el.querySelector('.button-group--left')
var rightDom = ownerInstance.$el.querySelector('.button-group--right')
state.leftWidth = leftDom.offsetWidth || 0
state.rightWidth = rightDom.offsetWidth || 0
state.threshold = instance.getDataset().threshold
},
getDisabledType(value) {
return (typeof(value) === 'string' ? JSON.parse(value) : value) || false;
},
/**
* 获取范围
* @param {Object} num
* @param {Object} min
* @param {Object} max
*/
range(num, min, max) {
return Math.min(Math.max(num, min), max);
},
/**
* 移动方向判断
* @param {Object} left
* @param {Object} value
* @param {Object} ownerInstance
* @param {Object} ins
*/
moveDirection(left, ins, ownerInstance, self) {
var state = self.state
var threshold = state.threshold
var position = state.position
var isopen = state.isopen || 'none'
var leftWidth = state.leftWidth
var rightWidth = state.rightWidth
if (state.deltaX === 0) {
this.openState('none', ins, ownerInstance, self)
return
}
if ((isopen === 'none' && rightWidth > 0 && -left > threshold) || (isopen !== 'none' && rightWidth > 0 &&
rightWidth +
left < threshold)) {
// right
this.openState('right', ins, ownerInstance, self)
} else if ((isopen === 'none' && leftWidth > 0 && left > threshold) || (isopen !== 'none' && leftWidth > 0 &&
leftWidth - left < threshold)) {
// left
this.openState('left', ins, ownerInstance, self)
} else {
// default
this.openState('none', ins, ownerInstance, self)
}
},
/**
* 开启状态
* @param {Boolean} type
* @param {Object} ins
* @param {Object} ownerInstance
*/
openState(type, ins, ownerInstance, self) {
let state = self.state
let leftWidth = state.leftWidth
let rightWidth = state.rightWidth
let left = ''
state.isopen = state.isopen ? state.isopen : 'none'
switch (type) {
case "left":
left = leftWidth
break
case "right":
left = -rightWidth
break
default:
left = 0
}
// && !state.throttle
if (state.isopen !== type) {
state.throttle = true
ownerInstance.callMethod('change', {
open: type
})
}
state.isopen = type
// 添加动画类
ins.requestAnimationFrame(()=> {
ins.addClass('ani');
this.move(left, ins, ownerInstance, self)
})
},
getDirection(x, y) {
if (x > y && x > MIN_DISTANCE) {
return 'horizontal';
}
if (y > x && y > MIN_DISTANCE) {
return 'vertical';
}
return '';
},
/**
* 重置滑动状态
* @param {Object} event
*/
resetTouchStatus(instance, self) {
let state = self.state;
state.direction = '';
state.deltaX = 0;
state.deltaY = 0;
state.offsetX = 0;
state.offsetY = 0;
},
/**
* 设置滑动开始位置
* @param {Object} event
*/
stopTouchStart(event, ownerInstance, self) {
let instance = event.instance;
let state = self.state
this.resetTouchStatus(instance, self);
var touch = event.touches[0];
state.startX = touch.clientX;
state.startY = touch.clientY;
},
/**
* 滑动中,是否禁止打开
* @param {Object} event
*/
stopTouchMove(event, self) {
let instance = event.instance;
let state = self.state;
let touch = event.touches[0];
state.deltaX = touch.clientX - state.startX;
state.deltaY = touch.clientY - state.startY;
state.offsetY = Math.abs(state.deltaY);
state.offsetX = Math.abs(state.deltaX);
state.direction = state.direction || this.getDirection(state.offsetX, state.offsetY);
}
}

View File

@@ -0,0 +1,348 @@
<template>
<!-- 在微信小程序 app vue端 h5 使用wxs 实现-->
<!-- #ifdef APP-VUE || MP-WEIXIN || H5 -->
<view class="uni-swipe">
<!-- #ifdef MP-WEIXIN || VUE3 -->
<view class="uni-swipe_box" :change:prop="wxsswipe.showWatch"
:prop="is_show" :data-threshold="threshold" :data-disabled="disabled" @touchstart="wxsswipe.touchstart" @touchmove="wxsswipe.touchmove" @touchend="wxsswipe.touchend">
<!-- #endif -->
<!-- #ifndef MP-WEIXIN || VUE3 -->
<view class="uni-swipe_box" :change:prop="renderswipe.showWatch"
:prop="is_show" :data-threshold="threshold" :data-disabled="disabled+''" @touchstart="renderswipe.touchstart" @touchmove="renderswipe.touchmove" @touchend="renderswipe.touchend">
<!-- #endif -->
<!-- 在微信小程序 app vue端 h5 使用wxs 实现-->
<view class="uni-swipe_button-group button-group--left">
<slot name="left">
<view v-for="(item,index) in leftOptions" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
}" class="uni-swipe_button button-hock" @touchstart="appTouchStart"
@touchend="appTouchEnd($event,index,item,'left')" @click.stop="onClickForPC(index,item,'left')">
<text class="uni-swipe_button-text"
:style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text>
</view>
</slot>
</view>
<view class="uni-swipe_text--center">
<slot></slot>
</view>
<view class="uni-swipe_button-group button-group--right">
<slot name="right">
<view v-for="(item,index) in rightOptions" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
}" class="uni-swipe_button button-hock" @touchstart="appTouchStart"
@touchend="appTouchEnd($event,index,item,'right')"
@click.stop="onClickForPC(index,item,'right')"><text class="uni-swipe_button-text"
:style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text>
</view>
</slot>
</view>
</view>
</view>
<!-- #endif -->
<!-- app nvue端 使用 bindingx -->
<!-- #ifdef APP-NVUE -->
<view ref="selector-box--hock" class="uni-swipe" @horizontalpan="touchstart" @touchend="touchend">
<view ref='selector-left-button--hock' class="uni-swipe_button-group button-group--left">
<slot name="left">
<view v-for="(item,index) in leftOptions" :data-button="btn" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
}" class="uni-swipe_button button-hock" @click.stop="onClick(index,item,'left')"><text
class="uni-swipe_button-text"
:style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text>
</view>
</slot>
</view>
<view ref='selector-right-button--hock' class="uni-swipe_button-group button-group--right">
<slot name="right">
<view v-for="(item,index) in rightOptions" :data-button="btn" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
}" class="uni-swipe_button button-hock" @click.stop="onClick(index,item,'right')"><text
class="uni-swipe_button-text"
:style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text>
</view>
</slot>
</view>
<view ref='selector-content--hock' class="uni-swipe_box">
<slot></slot>
</view>
</view>
<!-- #endif -->
<!-- 其他平台使用 js 长列表性能可能会有影响-->
<!-- #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
<view class="uni-swipe">
<view class="uni-swipe_box" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend"
:style="{transform:moveLeft}" :class="{ani:ani}">
<view class="uni-swipe_button-group button-group--left" :class="[elClass]">
<slot name="left">
<view v-for="(item,index) in leftOptions" :data-button="btn" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
}" class="uni-swipe_button button-hock" @touchstart="appTouchStart"
@touchend="appTouchEnd($event,index,item,'left')"><text class="uni-swipe_button-text"
:style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text>
</view>
</slot>
</view>
<slot></slot>
<view class="uni-swipe_button-group button-group--right" :class="[elClass]">
<slot name="right">
<view v-for="(item,index) in rightOptions" :data-button="btn" :key="index" :style="{
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
}" @touchstart="appTouchStart" @touchend="appTouchEnd($event,index,item,'right')"
class="uni-swipe_button button-hock"><text class="uni-swipe_button-text"
:style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text>
</view>
</slot>
</view>
</view>
</view>
<!-- #endif -->
</template>
<script src="./wx.wxs" module="wxsswipe" lang="wxs"></script>
<script module="renderswipe" lang="renderjs">
import render from './render.js'
export default {
mounted(e,ins,owner) {
this.state = {}
},
methods:{
showWatch(newVal, oldVal, ownerInstance, instance){
render.showWatch(newVal, oldVal, ownerInstance, instance,this)
},
touchstart(e,ownerInstance){
render.touchstart(e,ownerInstance,this)
},
touchmove(e, ownerInstance){
render.touchmove(e,ownerInstance,this)
},
touchend(e,ownerInstance){
render.touchend(e,ownerInstance,this)
}
}
}
</script>
<script>
import mpwxs from './mpwxs'
import bindingx from './bindingx.js'
import mpother from './mpother'
/**
* SwipeActionItem 滑动操作子组件
* @description 通过滑动触发选项的容器
* @tutorial https://ext.dcloud.net.cn/plugin?id=181
* @property {Boolean} show = [left|rightnone] 开启关闭组件auto-close = false 时生效
* @property {Boolean} disabled = [true|false] 是否禁止滑动
* @property {Boolean} autoClose = [true|false] 滑动打开当前组件,是否关闭其他组件
* @property {Number} threshold 滑动缺省值
* @property {Array} leftOptions 左侧选项内容及样式
* @property {Array} rgihtOptions 右侧选项内容及样式
* @event {Function} click 点击选项按钮时触发事件e = {content,index} content点击内容、index下标)
* @event {Function} change 组件打开或关闭时触发left\right\none
*/
export default {
mixins: [mpwxs,bindingx,mpother],
emits:['click','change'],
props: {
// 控制开关
show: {
type: String,
default: 'none'
},
// 禁用
disabled: {
type: Boolean,
default: false
},
// 是否自动关闭
autoClose: {
type: Boolean,
default: true
},
// 滑动缺省距离
threshold: {
type: Number,
default: 20
},
// 左侧按钮内容
leftOptions: {
type: Array,
default () {
return []
}
},
// 右侧按钮内容
rightOptions: {
type: Array,
default () {
return []
}
}
},
// #ifndef VUE3
// TODO vue2
destroyed() {
if (this.__isUnmounted) return
this.uninstall()
},
// #endif
// #ifdef VUE3
// TODO vue3
unmounted() {
this.__isUnmounted = true
this.uninstall()
},
// #endif
methods: {
uninstall() {
if (this.swipeaction) {
this.swipeaction.children.forEach((item, index) => {
if (item === this) {
this.swipeaction.children.splice(index, 1)
}
})
}
},
/**
* 获取父元素实例
*/
getSwipeAction(name = 'uniSwipeAction') {
let parent = this.$parent;
let parentName = parent.$options.name;
while (parentName !== name) {
parent = parent.$parent;
if (!parent) return false;
parentName = parent.$options.name;
}
return parent;
}
}
}
</script>
<style lang="scss" scoped>
.uni-swipe {
position: relative;
/* #ifndef APP-NVUE */
overflow: hidden;
/* #endif */
}
.uni-swipe_box {
/* #ifndef APP-NVUE */
display: flex;
flex-shrink: 0;
// touch-action: none;
/* #endif */
position: relative;
}
.uni-swipe_content {
// border: 1px red solid;
}
.uni-swipe_text--center {
width: 100%;
/* #ifndef APP-NVUE */
cursor: grab;
/* #endif */
}
.uni-swipe_button-group {
/* #ifndef APP-NVUE */
box-sizing: border-box;
display: flex;
/* #endif */
flex-direction: row;
position: absolute;
top: 0;
bottom: 0;
/* #ifdef H5 */
cursor: pointer;
/* #endif */
}
.button-group--left {
left: 0;
transform: translateX(-100%)
}
.button-group--right {
right: 0;
transform: translateX(100%)
}
.uni-swipe_button {
/* #ifdef APP-NVUE */
flex: 1;
/* #endif */
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0 20px;
}
.uni-swipe_button-text {
/* #ifndef APP-NVUE */
flex-shrink: 0;
/* #endif */
font-size: 14px;
}
.ani {
transition-property: transform;
transition-duration: 0.3s;
transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
}
/* #ifdef MP-ALIPAY */
.movable-area {
/* width: 100%; */
height: 45px;
}
.movable-view {
display: flex;
/* justify-content: center; */
position: relative;
flex: 1;
height: 45px;
z-index: 2;
}
.movable-view-button {
display: flex;
flex-shrink: 0;
flex-direction: row;
height: 100%;
background: #C0C0C0;
}
/* .transition {
transition: all 0.3s;
} */
.movable-view-box {
flex-shrink: 0;
height: 100%;
background-color: #fff;
}
/* #endif */
</style>

View File

@@ -0,0 +1,341 @@
var MIN_DISTANCE = 10;
/**
* 判断当前是否为H5、app-vue
*/
var IS_HTML5 = false
if (typeof window === 'object') IS_HTML5 = true
/**
* 监听页面内值的变化,主要用于动态开关swipe-action
* @param {Object} newValue
* @param {Object} oldValue
* @param {Object} ownerInstance
* @param {Object} instance
*/
function showWatch(newVal, oldVal, ownerInstance, instance) {
var state = instance.getState()
getDom(instance, ownerInstance)
if (newVal && newVal !== 'none') {
openState(newVal, instance, ownerInstance)
return
}
if (state.left) {
openState('none', instance, ownerInstance)
}
resetTouchStatus(instance)
}
/**
* 开始触摸操作
* @param {Object} e
* @param {Object} ins
*/
function touchstart(e, ownerInstance) {
var instance = e.instance;
var disabled = instance.getDataset().disabled
var state = instance.getState();
getDom(instance, ownerInstance)
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
disabled = (typeof(disabled) === 'string' ? JSON.parse(disabled) : disabled) || false;
if (disabled) return
// 开始触摸时移除动画类
instance.requestAnimationFrame(function() {
instance.removeClass('ani');
ownerInstance.callMethod('closeSwipe');
})
// 记录上次的位置
state.x = state.left || 0
// 计算滑动开始位置
stopTouchStart(e, ownerInstance)
}
/**
* 开始滑动操作
* @param {Object} e
* @param {Object} ownerInstance
*/
function touchmove(e, ownerInstance) {
var instance = e.instance;
var disabled = instance.getDataset().disabled
var state = instance.getState()
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
disabled = (typeof(disabled) === 'string' ? JSON.parse(disabled) : disabled) || false;
if (disabled) return
// 是否可以滑动页面
stopTouchMove(e);
if (state.direction !== 'horizontal') {
return;
}
if (e.preventDefault) {
// 阻止页面滚动
e.preventDefault()
}
move(state.x + state.deltaX, instance, ownerInstance)
}
/**
* 结束触摸操作
* @param {Object} e
* @param {Object} ownerInstance
*/
function touchend(e, ownerInstance) {
var instance = e.instance;
var disabled = instance.getDataset().disabled
var state = instance.getState()
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
disabled = (typeof(disabled) === 'string' ? JSON.parse(disabled) : disabled) || false;
if (disabled) return
// 滑动过程中触摸结束,通过阙值判断是开启还是关闭
// fixed by mehaotian 定时器解决点击按钮touchend 触发比 click 事件时机早的问题 ,主要是 ios13
moveDirection(state.left, instance, ownerInstance)
}
/**
* 设置移动距离
* @param {Object} value
* @param {Object} instance
* @param {Object} ownerInstance
*/
function move(value, instance, ownerInstance) {
value = value || 0
var state = instance.getState()
var leftWidth = state.leftWidth
var rightWidth = state.rightWidth
// 获取可滑动范围
state.left = range(value, -rightWidth, leftWidth);
instance.requestAnimationFrame(function() {
instance.setStyle({
transform: 'translateX(' + state.left + 'px)',
'-webkit-transform': 'translateX(' + state.left + 'px)'
})
})
}
/**
* 获取元素信息
* @param {Object} instance
* @param {Object} ownerInstance
*/
function getDom(instance, ownerInstance) {
var state = instance.getState()
var leftDom = ownerInstance.selectComponent('.button-group--left')
var rightDom = ownerInstance.selectComponent('.button-group--right')
var leftStyles = {
width: 0
}
var rightStyles = {
width: 0
}
leftStyles = leftDom.getBoundingClientRect()
rightStyles = rightDom.getBoundingClientRect()
state.leftWidth = leftStyles.width || 0
state.rightWidth = rightStyles.width || 0
state.threshold = instance.getDataset().threshold
}
/**
* 获取范围
* @param {Object} num
* @param {Object} min
* @param {Object} max
*/
function range(num, min, max) {
return Math.min(Math.max(num, min), max);
}
/**
* 移动方向判断
* @param {Object} left
* @param {Object} value
* @param {Object} ownerInstance
* @param {Object} ins
*/
function moveDirection(left, ins, ownerInstance) {
var state = ins.getState()
var threshold = state.threshold
var position = state.position
var isopen = state.isopen || 'none'
var leftWidth = state.leftWidth
var rightWidth = state.rightWidth
if (state.deltaX === 0) {
openState('none', ins, ownerInstance)
return
}
if ((isopen === 'none' && rightWidth > 0 && -left > threshold) || (isopen !== 'none' && rightWidth > 0 &&
rightWidth +
left < threshold)) {
// right
openState('right', ins, ownerInstance)
} else if ((isopen === 'none' && leftWidth > 0 && left > threshold) || (isopen !== 'none' && leftWidth > 0 &&
leftWidth - left < threshold)) {
// left
openState('left', ins, ownerInstance)
} else {
// default
openState('none', ins, ownerInstance)
}
}
/**
* 开启状态
* @param {Boolean} type
* @param {Object} ins
* @param {Object} ownerInstance
*/
function openState(type, ins, ownerInstance) {
var state = ins.getState()
var leftWidth = state.leftWidth
var rightWidth = state.rightWidth
var left = ''
state.isopen = state.isopen ? state.isopen : 'none'
switch (type) {
case "left":
left = leftWidth
break
case "right":
left = -rightWidth
break
default:
left = 0
}
// && !state.throttle
if (state.isopen !== type) {
state.throttle = true
ownerInstance.callMethod('change', {
open: type
})
}
state.isopen = type
// 添加动画类
ins.requestAnimationFrame(function() {
ins.addClass('ani');
move(left, ins, ownerInstance)
})
// 设置最终移动位置,理论上只要进入到这个函数,肯定是要打开的
}
function getDirection(x, y) {
if (x > y && x > MIN_DISTANCE) {
return 'horizontal';
}
if (y > x && y > MIN_DISTANCE) {
return 'vertical';
}
return '';
}
/**
* 重置滑动状态
* @param {Object} event
*/
function resetTouchStatus(instance) {
var state = instance.getState();
state.direction = '';
state.deltaX = 0;
state.deltaY = 0;
state.offsetX = 0;
state.offsetY = 0;
}
/**
* 设置滑动开始位置
* @param {Object} event
*/
function stopTouchStart(event) {
var instance = event.instance;
var state = instance.getState();
resetTouchStatus(instance);
var touch = event.touches[0];
if (IS_HTML5 && isPC()) {
touch = event;
}
state.startX = touch.clientX;
state.startY = touch.clientY;
}
/**
* 滑动中,是否禁止打开
* @param {Object} event
*/
function stopTouchMove(event) {
var instance = event.instance;
var state = instance.getState();
var touch = event.touches[0];
if (IS_HTML5 && isPC()) {
touch = event;
}
state.deltaX = touch.clientX - state.startX;
state.deltaY = touch.clientY - state.startY;
state.offsetY = Math.abs(state.deltaY);
state.offsetX = Math.abs(state.deltaX);
state.direction = state.direction || getDirection(state.offsetX, state.offsetY);
}
function isPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length - 1; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
var movable = false
function mousedown(e, ins) {
if (!IS_HTML5) return
if (!isPC()) return
touchstart(e, ins)
movable = true
}
function mousemove(e, ins) {
if (!IS_HTML5) return
if (!isPC()) return
if (!movable) return
touchmove(e, ins)
}
function mouseup(e, ins) {
if (!IS_HTML5) return
if (!isPC()) return
touchend(e, ins)
movable = false
}
function mouseleave(e, ins) {
if (!IS_HTML5) return
if (!isPC()) return
movable = false
}
module.exports = {
showWatch: showWatch,
touchstart: touchstart,
touchmove: touchmove,
touchend: touchend,
mousedown: mousedown,
mousemove: mousemove,
mouseup: mouseup,
mouseleave: mouseleave
}

View File

@@ -0,0 +1,60 @@
<template>
<view>
<slot></slot>
</view>
</template>
<script>
/**
* SwipeAction 滑动操作
* @description 通过滑动触发选项的容器
* @tutorial https://ext.dcloud.net.cn/plugin?id=181
*/
export default {
name:"uniSwipeAction",
data() {
return {};
},
created() {
this.children = [];
},
methods: {
// 公开给用户使用,重制组件样式
resize(){
// wxs 会自己计算组件大小,所以无需执行下面代码
// #ifndef APP-VUE || H5 || MP-WEIXIN
this.children.forEach(vm=>{
vm.init()
})
// #endif
},
// 公开给用户使用,关闭全部 已经打开的组件
closeAll(){
this.children.forEach(vm=>{
// #ifdef APP-VUE || H5 || MP-WEIXIN
vm.is_show = 'none'
// #endif
// #ifndef APP-VUE || H5 || MP-WEIXIN
vm.close()
// #endif
})
},
closeOther(vm) {
if (this.openItem && this.openItem !== vm) {
// #ifdef APP-VUE || H5 || MP-WEIXIN
this.openItem.is_show = 'none'
// #endif
// #ifndef APP-VUE || H5 || MP-WEIXIN
this.openItem.close()
// #endif
}
// 记录上一个打开的 swipe-action-item ,用于 auto-close
this.openItem = vm
}
}
};
</script>
<style></style>

View File

@@ -0,0 +1,87 @@
{
"id": "uni-swipe-action",
"displayName": "uni-swipe-action 滑动操作",
"version": "1.2.4",
"description": "SwipeAction 滑动操作操作组件",
"keywords": [
"",
"uni-ui",
"uniui",
"滑动删除",
"侧滑删除"
],
"repository": "https://github.com/dcloudio/uni-ui",
"engines": {
"HBuilderX": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"category": [
"前端组件",
"通用组件"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"App": {
"app-vue": "y",
"app-nvue": "y"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "y",
"百度": "y",
"字节跳动": "y",
"QQ": "y"
},
"快应用": {
"华为": "y",
"联盟": "u"
},
"Vue": {
"vue2": "y",
"vue3": "u"
}
}
}
}
}

View File

@@ -0,0 +1,193 @@
## SwipeAction 滑动操作
> **组件名uni-swipe-action**
> 代码块: `uSwipeAction`、`uSwipeActionItem`
通过滑动触发选项的容器
> **注意事项**
> 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
> - swipeAction的跟手联动是非常考验性能的。为了提高交互体验本组件在 app 端 vue 页面、h5、微信小程序使用了wxs 技术nvue 页面使用 bindingx 技术,可以达到流畅的体验。在其他小程序平台由于底层不支持优化技术,只能使用使用普通 js ,此时性能一般。
> - `uni-swipe-action` 和 `uni-swipe-action-item` 需要同时使用
> - `uni-swipe-action` 不能嵌套在 `swiper` 中使用
> - 长列表不建议使用 autoClose属性会影响组件性能造成卡顿原因是打开之后要通知其他已经打开的组件关闭会导致多个组件重新渲染
> - 事件中传入 `$event` 获取额外参数
> - 向下兼容,需要将 `options` 属性替换成 `right-options`
> - 如使用过程中有任何问题或者您对uni-ui有一些好的建议欢迎加入 uni-ui 交流群871950839
### 安装方式
本组件符合[easycom](https://uniapp.dcloud.io/collocation/pages?id=easycom)规范,`HBuilderX 2.5.5`起,只需将本组件导入项目,在页面`template`中即可直接使用,无需在页面中`import`和注册`components`
如需通过`npm`方式使用`uni-ui`组件,另见文档:[https://ext.dcloud.net.cn/plugin?id=55](https://ext.dcloud.net.cn/plugin?id=55)
## 基本用法
在 ``template`` 中的使用
```html
<uni-swipe-action>
<!-- 基础用法 -->
<uni-swipe-action-item :right-options="options" :left-options="options" @click="onClick" @change="change">
<view>SwipeAction 基础使用场景</view>
</uni-swipe-action-item>
<!-- 使用插槽 (请自行给定插槽内容宽度)-->
<uni-swipe-action-item>
<template v-slot:left>
<view><text>置顶</text></view>
</template>
<view>
<text >使用插槽</text>
</view>
<template v-slot:right>
<view><text>删除</text></view>
</template>
</uni-swipe-action-item>
<!-- 混合用法 -->
<uni-swipe-action-item :right-options="options">
<template v-slot:left>
<view><text>置顶</text></view>
</template>
<view><text>混合使用</text></view>
</uni-swipe-action-item>
</uni-swipe-action>
<!-- 禁止滑动 -->
<uni-swipe-action>
<uni-swipe-action-item :disabled="true" :right-options="options">
<view>SwipeAction 基础使用场景</view>
</uni-swipe-action-item>
</uni-swipe-action>
<!-- 按组使用 -->
<uni-swipe-action>
<uni-swipe-action-item :right-options="options" @click="bindClick" @change="swipeChange($event, index)">
<view >item1</view>
</uni-swipe-action-item>
<uni-swipe-action-item :right-options="options" @click="bindClick" @change="swipeChange($event, index)">
<view>item2</view>
</uni-swipe-action-item>
<uni-swipe-action-item :right-options="options" @click="bindClick" @change="swipeChange($event, index)">
<view>item3</view>
</uni-swipe-action-item>
</uni-swipe-action>
```
```javascript
export default {
data(){
return {
options:[
{
text: '取消',
style: {
backgroundColor: '#007aff'
}
}, {
text: '确认',
style: {
backgroundColor: '#dd524d'
}
}
]
}
},
methods:{
onClick(e){
console.log('点击了'+(e.position === 'left' ? '左侧' : '右侧') + e.content.text + '按钮')
},
swipeChange(e,index){
console.log('当前状态:'+ e +',下标:' + index)
}
}
}
```
## API
### SwipeAciton Props
|属性名|类型|可选值|默认值|是否必填|说明|
|:-:|:-:|:-:|:-:|:-:|:-:|
|show|String|left/right/none|none |否|开启关闭组件auto-close = false 时生效|
|threshold|Number|-|20|否|滑动阙值|
|disabled|Boolean|-|false|否|是否禁止滑动|
|autoClose|Boolean|-|true|否|其他组件开启的时候,当前组件是否自动关闭,**注意:长列表使用会有性能问题**|
|left-options|Array/Object |-|-|否|左侧选项内容及样式|
|right-options|Array/Object |-|-|否|右侧选项内容及样式|
#### LeftOptions & RightOptions Options
|参数|类型|是否必填 |说明|
|:-:|:-:|:-:|:-:|
|text|String|是|按钮的文字 |
|style|Object|否|按钮样式{backgroundColor,color,fontSize}backgroundColor默认为#C7C6CDcolor默认为#FFFFFFfontSize默认为14px |
### SwipeAction Events
|事件称名 |说明|返回值|
|:-:|:-:|:-:|
|@click|点击选项按钮时触发事件|e = {content,index} content点击内容、index下标、position (位置信息) |
|@change|组件打开或关闭时触发|left:左侧 right右侧none关闭|
### SwipeAction Methods
方法通过 ref 调用
|方法称名 |说明|
|:-:|:-:|
|resize()|动态添加数据后如不能正常滑动需要主动调用此方法微信小程序、h5、app-vue 不生效|
|close-all()|关闭所有已经打开的组件|
### SwipeAction Slots
|名称|说明|
|:-:|:-:|
|-|默认插槽自定义显示内容|
|default|默认内容插槽|
|left|左侧滑动内容 ,会覆盖 leftOptions 内容|
|right|右侧滑动内容 ,会覆盖 rightOptions 内容|
> **提示**
> - iOS 端由于存在bounce效果滑动体验略差建议禁止bounce效果禁止方式如下
> ```javascript
> {
> "path": "swipe-action/swipe-action",
> "style": {
> "navigationBarTitleText": "SwipeAction 滑动操作",
> "disableScroll":true,
> "app-plus":{
> "bounce":"none"
> }
> }
> }
> ```
### Q&A
1. Q动态加载数据组件滑动失效是怎么回事
- A是因为组件会在加载的时候获取相应的节点信息数据 ,获取需要滑动的距离,所以有时候动态加载数据之后,可能是时机的问题,导致节点信息获取失败 ,那么组件就不能正常滑动。
- A如果是在其他页面通过 vuex 或者uni.$emit 等手段来更新其他页面 uni-swipe-action 数据 ,同样会发生不能滑动的现象,原因是页面隐藏后是不能获取到页面信息的,所以回到 uni-swipe-action 页面后,新增的组件节点信息获取肯定是错误的,所以不能滑动。
- A值的高兴的是在 1.2.2 版本中重构了组件滑动逻辑 在微信小程序、h5、app-vue 中使用了 wxs 优化滑动性能,并且不需要担心动态新增组件导致组件无法滑动的问题,节点信息在滑动时实时获取。
- A因为其他平台无法使用 wxs 所以还是会出现无法滑动的问题怎么处理1.2.2 版本提供了 resize() 方法,无法滑动时调用 resize() 方法重新渲染组件即可,调用方法时要保证节点已经渲染完毕。
2. Q运行到 nvue 下没有样式
- A因为 nvue 下样式默认不能使用复杂的css选择器所以需要在 manifest.json 中配置 "nvueStyleCompiler" 属性
```json
// manifest.json
{
"nvueStyleCompiler" : "uni-app",
}
```
## 组件示例
点击查看:[https://hellouniapp.dcloud.net.cn/pages/extUI/swipe-action/swipe-action](https://hellouniapp.dcloud.net.cn/pages/extUI/swipe-action/swipe-action)