index.uvue 2.0 KB
Newer Older
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
<template>
	<view class="content">
		<button class="normal-button" type="default" @click="handleCreateChannel">创建通知渠道</button>
		<button class="normal-button" type="default" @click="handleGetAllChannels">获取所有通知渠道信息</button>
		<button class="normal-button" type="default" @click="handleCreateLocalNotification">创建本地通知消息</button>
		<button class="normal-button" type="default" @click="handleGetClientId">获取cid</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isXM: false
			}
		},
		onLoad() {
			uni.onPushMessage((res) => {
				console.log("onpushmessage1 : " + JSON.stringify(res));
			})
		},
		methods: {
			handleCreateChannel() {
				const manager = uni.getChannelManager()
				manager.setPushChannel({
					channelId: this.isXM ? "112735" : "msg-pass",
					channelDesc: "留言审核通过",
					soundName: "pushsound"
				} as SetPushChannelOptions)
			},
			handleGetAllChannels() {
				const manager = uni.getChannelManager()
				console.log("channels : " + manager.getAllChannels());
			},
			handleCreateLocalNotification() {
				uni.createPushMessage({
					title: "halo",
					content: "world",
					// cover:true,
					channelId: this.isXM ? "112735" : "msg-pass",
					when: Date.now() + 10000,
					icon: "/static/xxxx.jpeg",
					// delay:5,
					payload: {
						pkey: "pvalue1"
					},
					category: "IM",
					success(res) {
						console.log("res: " + res);
					},
					fail(e) {
						console.log("fail :" + e);
					}
				})
			},
			handleGetClientId() {
				uni.getPushClientId({
					complete(e : any) {
						console.log(e);
					}
				})
			},
		}
	}
</script>

<style>
	.normal-button {
		width: 100%;
	}

	.content {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-bottom: 50rpx;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>