uniapp 监听推送

<template>
	<view class="page">
		<view class="uni-list">
			<block v-if="listData.length>0">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(value,key) in listData" :key="key" @click="goDetail(value)"
				 @longpress="show_m(value)">
					<view class="uni-media-list">
						<image class="uni-media-list-logo" :src="value.face"></image>
						<view v-if="value.stotal>0" class="tip">{{value.stotal}}</view>
						<view class="uni-media-list-body">
							<view class="uni-media-list-text-top"  >{{value.cont}}</view>
							<view class="uni-media-list-text-bottom">
								<block v-if="value.type=='agent'">
									<block v-for="(s,k) in agentarr" :key="k">
										<text v-if="value.id==s.id">{{s.name}}</text>
									</block>
								</block>
								<block v-else>
									<text>{{value.name}}</text>
								</block>
								<text>{{value.optdts}}</text>
							</view>
						</view>
					</view>
				</view>
			</block>
			<block v-else>
				<view class="page-share-title">
					<text>暂无数据</text>
				</view>
			</block>

		</view>
	</view>
</template>
<script>
	import {
		Base64
	} from '../../utils/base64.min.js';
	import service from '../../utils/service.js';

	export default {
		data: {
			listData:'',
			agentarr: '',
			Loop: '',
			ck: true,
			provider: '',
			cont:''
		},

		onLoad() {
			if (!uni.getStorageSync('$APPLOGIN')) {
				uni.reLaunch({
					url: '../login/login'
				});
				return;
			}
			
			this.get_reimarr();
			this.listenTranMsg();
		},
		onShow() {
			//this.get_reimarr();
		},
		methods: {
			listenTranMsg: function() {
				var that = this;
				var provider=uni.getStorageSync('$provider');
				uni.subscribePush({
					provider: provider[0],
					success: (e) => {
// 						uni.showToast({
// 							title: "已开启push接收"
// 						})
					}
				});
				uni.onPush({
					provider: provider[0],
					success: (e) => {
// 						uni.showToast({
// 							title: "开始监听透传数据"
// 						})
					},
					receive: (e) => {
						//that.get_reimarr()
					},
					
				})
				
			},

			get_reimarr: function() {
				uni.showLoading({
					title: '加载中...'
				});
				const data = uni.getStorageSync('$APPLOGIN');
				var that = this;
				service.getURL('?m=index&a=indexapp',data,function(res){
					if (res.data.data.reimarr.length > 0) {
						var da = res.data.data.reimarr;
						that.listData = da;
						that.agentarr = res.data.data.agentarr;
					}
				})
				uni.hideLoading();
			},
			show_m: function(value) {

				var that = this;
				uni.showActionSheet({
					itemList: ['删除记录', '取消'],
					success: function(res) {
						if (res.tapIndex == 0) {
							uni.showModal({
								title: '提示',
								content: '确定要删除会话记录吗?',
								success: function(res) {
									if (res.confirm) {
										const server ='?m=reim&a=delhistory&gid=' + value.receid + '&type=' + value.type;
										const data = uni.getStorageSync('$APPLOGIN');
										
										service.getURL(server,data,function(res){
											
											that.get_reimarr();
											uni.showToast({
												title: '删除成功!',
												duration: 2000
											});
											
										})
									}
								}
							});
						}

					}
				});
			},
			goDetail: function(value) {
				var agentarr = this.agentarr;


				if (value.type == 'user') {
					uni.navigateTo({
						url: 'main-msg?value=' + JSON.stringify(value)
					})
				}
				if (value.type == 'group') {
					uni.showToast({
						title: '没有',
						duration: 2000
					});
				}
				if (value.type == 'agent') {
					for (var i = 0; i < agentarr.length; i++) {
						if (value.receid === agentarr[i]['id']) {
							value.num = agentarr[i]['num'];
							break;
						}
					}
					uni.navigateTo({
						url: 'main-agent?value=' + JSON.stringify(value)
					})
				}
			},
			clearLoop: function() {
				clearInterval(this.Loop);
			}

		}
	}
</script>

<style>
	.tip {
		min-width: 30upx;
		height: 30upx;
		background: red;
		box-sizing: border-box;
		color: white;
		font-size: 16upx;
		text-align: center;
		line-height: 30px;
		padding: 0 0;
		border-radius: 30px;

		position: absolute;
		left: 85upx
	}

	.uni-media-list-logo {
		width: 80upx;
		height: 80upx;
		border-radius: 40upx;
	}

	.uni-media-list-body {
		height: auto;
		justify-content: space-around;
	}

	.uni-media-list-text-top {
		height: 50upx;
		font-size: 28upx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.page-share-title {
		text-align: center;
		font-size: 30upx;
		color: #BEBEBE;
		padding: 20upx 0;
	}

	.uni-media-list-text-bottom {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
</style>

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逍遥596607010

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值