<template>
<gracePage :customHeader="false" :isLoading="pageLoading">
<!-- 页面主体 -->
<view slot="gBody" id="gBody" class="grace-flex-v1">
<view class="grace-title grace-margin grace-margin-top">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">组件演示</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-margin-top">
<graceSwipeList :msgs="msgs" @itemTap="itemTap" @btnTap="btnTap" :height="mainHeight"></graceSwipeList>
</view>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceSwipeList from "../../graceUI/components/graceSwipeList.vue";
var graceJS = require('@/Grace.JS/grace.js');
// 模拟个 api 请求的数据
var msgsFromApi = [
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
];
export default {
data() {
return {
msgs : [],
pageLoading : true,
mainHeight : 200
}
},
onLoad:function(){
// 此处动态计算列表可以占据的最大高度
setTimeout(()=>{
graceJS.select('#gBody', (res)=>{
// 200 代表页面其他元素的高度 包含 margin padding 等
this.mainHeight = res.height - uni.upx2px(200);
console.log(this.mainHeight);
});
},1000);
setTimeout(()=>{this.pageLoading = false;}, 1500);
// 模拟 api 请求,因为请求数据里没有按钮信息我们利用js进行按钮补充
setTimeout(() => {
for(let i = 0; i < msgsFromApi.length; i++){
// 具体几个按钮及按钮文本根据项目需求来,格式 {name:按钮文本, bgColor:按钮背景色}
msgsFromApi[i].btns = [{'name':'标为已读', bgColor:'#323232'}, {'name':'删除消息', bgColor:'#FF0036'}];
}
this.msgs = msgsFromApi;
}, 500);
},
methods:{
btnTap : function(index, btnIndex){
console.log(index, btnIndex);
// 第一个按钮被点击 [ 标记已读 ]
if(btnIndex == 0){
if(this.msgs[index].btns[0].name == '标为已读'){
this.msgs[index].btns = [{'name':'标为未读', bgColor:'#888888'}, {'name':'删除消息', bgColor:'#FF0036'}];
this.msgs[index].msgnumber = 0;
}else{
this.msgs[index].btns = [{'name':'标为已读', bgColor:'#323232'}, {'name':'删除消息', bgColor:'#FF0036'}];
this.msgs[index].msgnumber = 1;
}
setTimeout(()=>{this.msgs.splice(index, 1, this.msgs[index]);}, 300);
}
// 第二个按钮被打开 [ 删除消息 ]
else if(btnIndex == 1){
uni.showModal({
title:"确定要删除吗?",
success: (e) => {
if(e.confirm){this.msgs.splice(index, 1);}
}
});
}
},
// 列表本身被点击
itemTap : function (e) {
console.log(e);
uni.showToast({title:"索引"+e});
}
},
components:{
gracePage, graceSwipeList
}
}
</script>
<style>
</style>
<template>
<gracePage :customHeader="false" :isLoading="pageLoading" flexVal="1">
<!-- 页面主体 -->
<view slot="gBody" ref="gBody" class="grace-flex-v1">
<view class="grace-title grace-margin grace-margin-top">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">组件演示</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-margin-top">
<graceSwipeList :msgs="msgs" @itemTap="itemTap" @btnTap="btnTap" :height="mainHeight"></graceSwipeList>
</view>
<!-- 对话框 -->
<graceDialog :isTitle="false" :show="showDialog" @closeDialog="closeDialog">
<view slot="content">
<text class="contentDialog">确定要删除吗?</text>
</view>
<view slot="btns" class="grace-space-between">
<text class="grace-dialog-buttons" @tap="closeDialog">关闭</text>
<text class="grace-dialog-buttons grace-blue" @tap="confirm">确认</text>
</view>
</graceDialog>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceSwipeList from "../../graceUI/weexComponents/graceSwipeList.nvue";
import graceDialog from '../../graceUI/weexComponents/graceDialog.nvue';
const dom = weex.requireModule('dom');
// 模拟个 api 请求的数据
var msgsFromApi = [
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
];
export default {
data() {
return {
msgs : [],
showDialog : false,
doIndex : -1,
pageLoading : true,
mainHeight : 200
}
},
onLoad:function(){
// 此处动态计算列表可以占据的最大高度
setTimeout(()=>{
var el = this.$refs.gBody;
dom.getComponentRect(el, (res) => {
console.log(res);
this.mainHeight = res.size.height - uni.upx2px(200);
});
},1000);
setTimeout(()=>{this.pageLoading = false;}, 1500);
// 模拟 api 请求,因为请求数据里没有按钮信息我们利用js进行按钮补充
setTimeout(() => {
for(let i = 0; i < msgsFromApi.length; i++){
// 具体几个按钮及按钮文本根据项目需求来,格式 {name:按钮文本, bgColor:按钮背景色}
msgsFromApi[i].btns = [{'name':'标为已读', bgColor:'#323232'}, {'name':'删除消息', bgColor:'#FF0036'}];
}
this.msgs = msgsFromApi;
}, 500);
},
methods:{
btnTap : function(index, btnIndex){
console.log(index, btnIndex);
// 第一个按钮被点击 [ 标记已读 ]
if(btnIndex === 0){
if(this.msgs[index].btns[0].name == '标为已读'){
this.msgs[index].btns = [{'name':'标为未读', bgColor:'#888888'}, {'name':'删除消息', bgColor:'#FF0036'}];
this.msgs[index].msgnumber = 0;
}else{
this.msgs[index].btns = [{'name':'标为已读', bgColor:'#323232'}, {'name':'删除消息', bgColor:'#FF0036'}];
this.msgs[index].msgnumber = 1;
}
setTimeout(()=>{this.msgs.splice(index, 1, this.msgs[index]);}, 300);
}
// 第二个按钮被打开 [ 删除消息 ]
else if(btnIndex === 1){
this.doIndex = index;
this.showDialog = true;
}
},
closeDialog : function(){this.showDialog = false;},
confirm : function(){
this.showDialog = false;
this.msgs.splice(this.doIndex, 1);
},
// 列表本身被点击
itemTap : function (e) {
console.log(e);
uni.showToast({title:"索引"+e});
}
},
components:{
gracePage, graceSwipeList,graceDialog
}
}
</script>
<style>
.contentDialog{padding:30rpx; padding-right:80rpx; line-height:100rpx; font-size:26rpx; text-align:center;}
</style>
.wxml
<gracePage customHeader="{{false}}" isLoading="{{pageLoading}}">
<!-- 页面主体 -->
<view slot="gBody" id="gBody" class="grace-flex-v1">
<view class="grace-title grace-margin grace-margin-top">
<view class="grace-title-border"></view>
<text class="grace-title-text grace-blue">组件演示</text>
<text class="grace-text-small grace-gray">grace.hcoder.net</text>
</view>
<view class="grace-margin-top">
<graceSwipeList msgs="{{msgs}}" bind:itemTap="itemTap" bind:btnTap="btnTap" height="{{mainHeight}}"></graceSwipeList>
</view>
</view>
</gracePage>.js
// 模拟个 api 请求的数据
var graceJS = require('../../Grace.JS/grace.js');
var msgsFromApi = [
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 8,
title : "优惠促销",
time : "昨天",
content : "兰叶春葳蕤,桂华秋皎洁。"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882db43842c.png',
msgnumber : 0,
title : "账户通知",
time : "2019-08-11",
content : "您的账户入账 *** 元"
},
{
img : 'https://fudezao.oss-cn-qingdao.aliyuncs.com/statics/uper/201909/23/5d882ce3900b7.png',
msgnumber : 12,
title : "优惠促销",
time : "昨天",
content : "草木有本心,何求美人折?"
},
];
Page({
data:{
msgs : [],
mainHeight: 300,
pageLoading : true
},
onLoad:function(){
setTimeout(() => {
// 此处动态计算列表可以占据的最大高度
graceJS.select('#gBody', (res)=>{
// 80 代表页面其他元素的高度 包含 margin padding 等
this.setData({mainHeight : res.height - 80});
});
}, 1000);
setTimeout(()=>{ this.setData({ pageLoading: false });}, 1500);
// 模拟 api 请求,因为请求数据里没有按钮信息我们利用js进行按钮补充
setTimeout(() => {
for(let i = 0; i < msgsFromApi.length; i++){
// 具体几个按钮及按钮文本根据项目需求来,格式 {name:按钮文本, bgColor:按钮背景色}
msgsFromApi[i].btns = [{'name':'标为已读', bgColor:'#323232'}, {'name':'删除消息', bgColor:'#FF0036'}];
}
this.setData({msgs : msgsFromApi});
}, 500);
},
btnTap : function(e){
var index = e.detail[0];
var btnIndex = e.detail[1];
// 第一个按钮被点击 [ 标记已读 ]
if(btnIndex == 0){
if(this.data.msgs[index].btns[0].name == '标为已读'){
this.data.msgs[index].btns = [{'name':'标为未读', bgColor:'#888888'}, {'name':'删除消息', bgColor:'#FF0036'}];
this.data.msgs[index].msgnumber = 0;
}else{
this.data.msgs[index].btns = [{'name':'标为已读', bgColor:'#323232'}, {'name':'删除消息', bgColor:'#FF0036'}];
this.data.msgs[index].msgnumber = 1;
}
setTimeout(()=>{
this.data.msgs.splice(index, 1, this.data.msgs[index]);
this.setData({msgs:this.data.msgs});
}, 300);
}
// 第二个按钮被打开 [ 删除消息 ]
else if(btnIndex == 1){
wx.showModal({
title:"确定要删除吗?",
success: (e) => {
if(e.confirm){
this.data.msgs.splice(index, 1);
this.setData({msgs:this.data.msgs});
}
}
});
}
},
// 列表本身被点击
itemTap : function (e) {
console.log(e);
wx.showToast({title:"索引"+e.detail});
}
}).json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceSwipeList": "../../graceUI/components/graceSwipeList"
}
}