Commit 35144d69 authored by Facius's avatar Facius

feat: 推送

parent 4437fd5d
Pipeline #3329 canceled with stages
...@@ -4,6 +4,7 @@ unpackage/* ...@@ -4,6 +4,7 @@ unpackage/*
!/unpackage/res/ !/unpackage/res/
npm-debug.log* npm-debug.log*
**/*.log **/*.log
uniCloud-*
tests/**/coverage/ tests/**/coverage/
tests/e2e/reports tests/e2e/reports
......
<script> <script>
// import{setToken,setRefreshToken} from "@/utils/common.js" // import{setToken,setRefreshToken} from "@/utils/common.js"
export default { export default {
onLaunch: function() { onLaunch: function() {
// setToken("eyJ0eXAiOiJKc29uV2ViVG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJ1bmlvbklkIjoib1gtVEs2VmVTWmNVbUx0cWhodk15NU1mYk9IMCIsIm9wZW5JZCI6Im9aZk5VNUVhSEF3bGdrbm8yQno3Y1Q0X0JRVUUiLCJuYW1lIjoi6Ze7562gIiwibW9iaWxlIjoiMTM0MjM4MzExOTEiLCJ0b2tlbl90eXBlIjoidG9rZW4iLCJ1c2VyaWQiOiIxNTUyNDg2NzEyMzY4NjkzMjQ4IiwiYWNjb3VudCI6IjEzNDIzODMxMTkxIiwiaWF0IjoxNjYwNzA4MzYyLCJuYmYiOjE2NjA3MDgzNjIsImV4cCI6MTY2MjAwNDM2Mn0.9hBVwqmYDxL4Q0S05JXQqteOWI9kda_UXxX5-eNO1LY") // setToken("eyJ0eXAiOiJKc29uV2ViVG9rZW4iLCJhbGciOiJIUzI1NiJ9.eyJ1bmlvbklkIjoib1gtVEs2VmVTWmNVbUx0cWhodk15NU1mYk9IMCIsIm9wZW5JZCI6Im9aZk5VNUVhSEF3bGdrbm8yQno3Y1Q0X0JRVUUiLCJuYW1lIjoi6Ze7562gIiwibW9iaWxlIjoiMTM0MjM4MzExOTEiLCJ0b2tlbl90eXBlIjoidG9rZW4iLCJ1c2VyaWQiOiIxNTUyNDg2NzEyMzY4NjkzMjQ4IiwiYWNjb3VudCI6IjEzNDIzODMxMTkxIiwiaWF0IjoxNjYwNzA4MzYyLCJuYmYiOjE2NjA3MDgzNjIsImV4cCI6MTY2MjAwNDM2Mn0.9hBVwqmYDxL4Q0S05JXQqteOWI9kda_UXxX5-eNO1LY")
...@@ -10,6 +11,10 @@ ...@@ -10,6 +11,10 @@
this.updateApp(); this.updateApp();
console.log('App Launch') console.log('App Launch')
this.$store.dispatch('Get_system_info') this.$store.dispatch('Get_system_info')
// #ifdef APP-PLUS
this.settingPush()
// #endif
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')
...@@ -63,6 +68,31 @@ ...@@ -63,6 +68,31 @@
}); });
} }
}, },
settingPush() {
uni.getPushClientId({
success: (res) => {
console.log('--------getPushClientId--------', res.cid);
uni.setStorageSync('pushClientId', res.cid)
},
fail(err) {
console.log(err)
}
})
//监听push推送通知
uni.onPushMessage('receive', ({type,data})=>{ //console.log(type,title,content,payload);
console.log('-------receive----------', type,title,content,payload);
if(type=='receive' || uni.getSystemInfoSync().platform != "ios"){ //如果type!='receive'是自己本地插件的push消息栏,“拦截”避免死循环',安卓系统没有这个问题
uni.createPushMessage(data);
}
});
//监听点击通知栏
uni.onPushMessage('click', ({type,data}) => {
console.log('-------click----------',data)
uni.switchTab({
url: '/pages/index/schedule/schedule'
});
});
}
} }
} }
</script> </script>
......
<template> <template>
<view class="checkbox-group"> <view class="checkbox-group">
<view class="checkbox-group-item" :style="[customStyle]" :class="{ active: item.value === checked }" v-for="(item, index) in options" :key="index" @click="handleCheck(item)"> <view class="checkbox-group-item" :style="[customStyle]" :class="{ active: item.value == checked }" v-for="(item, index) in options" :key="index" @click="handleCheck(item)">
{{ item.label }} {{ item.label }}
</view> </view>
</view> </view>
......
{ {
"name" : "account-book", "name" : "account-book",
"appid" : "__UNI__C731E8B", "appid" : "__UNI__EDB8C7C",
"description" : "", "description" : "",
"versionName" : "1.0.1", "versionName" : "1.0.1",
"versionCode" : 101, "versionCode" : 101,
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
"Payment" : {}, "Payment" : {},
"Share" : {}, "Share" : {},
"Geolocation" : {}, "Geolocation" : {},
"Maps" : {} "Maps" : {},
"Push" : {}
}, },
/* 应用发布信息 */ /* 应用发布信息 */
"distribute" : { "distribute" : {
...@@ -108,6 +109,18 @@ ...@@ -108,6 +109,18 @@
"appkey_ios" : "dFMUnxGBq8mB8CSotGMELp4EGUq9qlwo", "appkey_ios" : "dFMUnxGBq8mB8CSotGMELp4EGUq9qlwo",
"appkey_android" : "32HwrFwjGUFno8GddnqSZtP72sDFucG1" "appkey_android" : "32HwrFwjGUFno8GddnqSZtP72sDFucG1"
} }
},
"push" : {
"unipush" : {
"version" : "2",
"offline" : true,
"hms" : {},
"oppo" : {},
"vivo" : {},
"mi" : {},
"meizu" : {},
"fcm" : {}
}
} }
}, },
"icons" : { "icons" : {
...@@ -159,7 +172,10 @@ ...@@ -159,7 +172,10 @@
"desc" : "你的位置信息将用于小程序获取所在城市和天气状况" "desc" : "你的位置信息将用于小程序获取所在城市和天气状况"
} }
}, },
"requiredPrivateInfos" : [ "getLocation", "chooseLocation" ] "requiredPrivateInfos" : [ "getLocation", "chooseLocation" ],
"unipush" : {
"enable" : true
}
}, },
"mp-alipay" : { "mp-alipay" : {
"usingComponents" : true "usingComponents" : true
...@@ -168,7 +184,10 @@ ...@@ -168,7 +184,10 @@
"usingComponents" : true "usingComponents" : true
}, },
"mp-toutiao" : { "mp-toutiao" : {
"usingComponents" : true "usingComponents" : true,
"unipush" : {
"enable" : true
}
}, },
"uniStatistics" : { "uniStatistics" : {
"enable" : false "enable" : false
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<ab-button content="添加" :customStyle="customStyle" left-icon="plus" @click="toAdd"></ab-button> <ab-button content="添加" :customStyle="customStyle" left-icon="plus" @click="toAdd"></ab-button>
</view> </view>
<view class="time-line"> <view class="time-line">
<block v-if="list.length"><plan-step :list="list" @handleClick="handleClick" @handleRemind="handleRemind"></plan-step></block> <block v-if="list.length"><plan-step :list="list" @handleClick="handleClick" @handleRemind="handleClickRemind"></plan-step></block>
<block v-else-if="afterGetList"><no-data :imageName="imageName" text="当前暂无待办计划"></no-data></block> <block v-else-if="afterGetList"><no-data :imageName="imageName" text="当前暂无待办计划"></no-data></block>
</view> </view>
</view> </view>
...@@ -33,6 +33,12 @@ export default { ...@@ -33,6 +33,12 @@ export default {
EmptyPage, EmptyPage,
NoData NoData
}, },
props: {
day: {
type: String,
default: '',
}
},
data() { data() {
return { return {
imageName: 'plan/wudaibanjihua@3x.png', imageName: 'plan/wudaibanjihua@3x.png',
...@@ -79,14 +85,25 @@ export default { ...@@ -79,14 +85,25 @@ export default {
toAdd() { toAdd() {
uni.navigateTo({ uni.navigateTo({
animationType:'pop-in', animationType:'pop-in',
url: 'pages/schedule/create-schedule/create-schedule' url: 'pages/schedule/create-schedule/create-schedule?date=' + this.day
}); });
}, },
// 拉起订阅
async handleRemind(item) { handleClickRemind(item) {
if (item.status !== '1') { if (item.status !== '1') {
return false; return false;
} }
// #ifdef MP-WEIXIN
this.handleRemind(item);
// #endif
// #ifdef APP-PLUS
// 推送不能重复创建,直接提示成功
this.showToast('订阅成功');
// #endif
},
// 拉起订阅
async handleRemind(item) {
try{ try{
await this.getSubscribeMessage(this.scene.trip); // 拉起订阅 await this.getSubscribeMessage(this.scene.trip); // 拉起订阅
this.saveSubscribe(item) this.saveSubscribe(item)
......
...@@ -11,6 +11,25 @@ ...@@ -11,6 +11,25 @@
</u-cell-item> </u-cell-item>
</u-cell-group> </u-cell-group>
</view> </view>
<view class="push-setting-view" v-if="platform == '4'">
<view class="cell-view" hover-class="u-cell-hover" @click.stop="$u.throttle(gotoSetting, 500)" >
<view class="left-view">行程通知</view>
<view class="right-view">
<u-icon color="#D8D8D8" size="24" name="play-right-fill"></u-icon>
<!-- <u-icon v-if="isIOS" color="#D8D8D8" size="24" name="play-right-fill"></u-icon>
<view class="switch-view" v-else>
<u-switch
v-model="pushState"
active-color="#02A074"
inactive-color="#8D8D8D"
@change="handleChange"
>
</u-switch>
</view> -->
</view>
</view>
</view>
<u-toast ref="uToast" />
</view> </view>
</template> </template>
...@@ -20,6 +39,7 @@ import { mineBaseUrl,UPLOAD_FILE_HOST } from '@/utils/config.js'; ...@@ -20,6 +39,7 @@ import { mineBaseUrl,UPLOAD_FILE_HOST } from '@/utils/config.js';
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import { getQiNiuToken } from '@/api/common/index.js' import { getQiNiuToken } from '@/api/common/index.js'
import { update } from '@/api/user/index.js'; import { update } from '@/api/user/index.js';
import permision from "@/js_sdk/wa-permission/permission.js"
export default { export default {
data() { data() {
return { return {
...@@ -37,13 +57,16 @@ export default { ...@@ -37,13 +57,16 @@ export default {
fontSize: '28rpx', fontSize: '28rpx',
color: '#333', color: '#333',
marginRight: '16rpx' marginRight: '16rpx'
} },
}; };
}, },
computed: { computed: {
...mapGetters(['userInfo']), ...mapGetters(['userInfo','platform']),
avatar() { avatar() {
return this.mineBaseUrl + 'toxuiang@3x.png'; return this.mineBaseUrl + 'toxuiang@3x.png';
},
isIOS() {
return uni.getSystemInfoSync().platform === "ios" || 1
} }
}, },
onLoad(options) { onLoad(options) {
...@@ -121,6 +144,21 @@ export default { ...@@ -121,6 +144,21 @@ export default {
//TODO handle the exception //TODO handle the exception
} }
},
// handleChange(value) {
// plus.push.setAutoNotification( value )
// this.$refs.uToast.show({
// title: '设置成功',
// type: 'success',
// duration: 1500,
// callback: () => {},
// })
// },
gotoSetting() {
// if (this.isIOS) {
permision.gotoAppPermissionSetting()
// }
} }
} }
}; };
...@@ -139,6 +177,29 @@ export default { ...@@ -139,6 +177,29 @@ export default {
background-color: #f6f7fa; background-color: #f6f7fa;
border-radius: 50%; border-radius: 50%;
} }
.push-setting-view {
background-color: #ffffff;
margin-top: 24rpx;
border-radius: 16rpx;
.cell-view {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 32rpx;
height: 106rpx;
.left-view {
font-size: 28rpx;
color: #8D8D8D;
}
.right-view {
display: flex;
align-items: center;
justify-content: flex-end;
.switch-view {
}
}
}
}
} }
</style> </style>
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
</view> </view>
</u-form> </u-form>
<view class="submit" v-loading="loading"><ab-button :disabled="disabled" :customStyle="customStyle" @click="submit"></ab-button></view> <view class="submit"><ab-button :disabled="disabled" :customStyle="customStyle" @click="submit"></ab-button></view>
<u-popup v-model="soundShow" mode="bottom" border-radius="14" safe-area-inset-bottom> <u-popup v-model="soundShow" mode="bottom" border-radius="14" safe-area-inset-bottom>
<sound-recording ref="sound-recording" @cancel="soundCancel" @confirm="soundConfirm"></sound-recording> <sound-recording ref="sound-recording" @cancel="soundCancel" @confirm="soundConfirm"></sound-recording>
</u-popup> </u-popup>
...@@ -75,6 +75,7 @@ import { baseUrl } from '@/utils/config.js'; ...@@ -75,6 +75,7 @@ import { baseUrl } from '@/utils/config.js';
import { scheduleTypeOptions, scheduleSettingOptions } from '@/utils/options/schedule'; import { scheduleTypeOptions, scheduleSettingOptions } from '@/utils/options/schedule';
import { get, add, deleteById, saveTripSubscribe } from '@/api/schedule/index.js'; import { get, add, deleteById, saveTripSubscribe } from '@/api/schedule/index.js';
import subscribeMixin from '@/utils/subscribeMixin'; import subscribeMixin from '@/utils/subscribeMixin';
export default { export default {
components: { NavbarRight, PopInput, SoundRecording, CheckboxGroups, CalendarPopup, SoundPlayer, AbButton }, components: { NavbarRight, PopInput, SoundRecording, CheckboxGroups, CalendarPopup, SoundPlayer, AbButton },
mixins: [subscribeMixin], mixins: [subscribeMixin],
...@@ -111,7 +112,8 @@ export default { ...@@ -111,7 +112,8 @@ export default {
remindMinute: '', remindMinute: '',
name: '', // 标题 name: '', // 标题
content: '', content: '',
attach: '' attach: '',
taskId: ''
}, },
errorType: ['toast', 'border-bottom'], errorType: ['toast', 'border-bottom'],
rules: { rules: {
...@@ -138,7 +140,11 @@ export default { ...@@ -138,7 +140,11 @@ export default {
} }
}, },
onLoad(options) { onLoad(options) {
if (options && options.date) {
this.form.createdTime = options.date
} else {
this.form.createdTime = this.parseTime(new Date(), '{y}-{m}-{d}'); this.form.createdTime = this.parseTime(new Date(), '{y}-{m}-{d}');
}
this.form.time = this.parseTime(new Date(), '{h}:{i}'); this.form.time = this.parseTime(new Date(), '{h}:{i}');
if (options && options.id) { if (options && options.id) {
this.id = options.id; this.id = options.id;
...@@ -151,8 +157,20 @@ export default { ...@@ -151,8 +157,20 @@ export default {
methods: { methods: {
async geDetail() { async geDetail() {
try { try {
let { code, data, msg } = await get({ id: this.id }); let { code, data, msg } = await get({ id: this.id })
this.form = { ...this.form, ...data }; var array = data.startTime.split(' ')
var timeArray = array[1].split(':')
this.form = {
type: data.type.code,
createdTime: array[0],
time: timeArray[0] + ':' + timeArray[1],
remindMinute: data.remindMinute,
attach: data.attach,
name: data.name,
content: data.content,
id: data.id,
taskId: data.taskId
}
} catch (e) { } catch (e) {
//TODO handle the exception //TODO handle the exception
} }
...@@ -163,7 +181,22 @@ export default { ...@@ -163,7 +181,22 @@ export default {
if (valid) { if (valid) {
let { createdTime, time } = this.form; let { createdTime, time } = this.form;
this.form.startTime = createdTime + ' ' + time + ':00'; this.form.startTime = createdTime + ' ' + time + ':00';
// #ifdef MP-WEIXIN
// 新建或更新服务端行程,拉起小程序订阅
this.save(); this.save();
// #endif
// #ifdef APP-PLUS
// 创建推送
if (this.form.id) {
// 删除旧的推送,建新的推送,更新推送taskid, 调用this.save()更新服务端行程
this.deleteMessage(false)
} else {
// 建新的推送,更新推送taskid, 调用this.save()新建服务端行程
this.createMessage()
}
// #endif
} else { } else {
this.loading = false; this.loading = false;
console.log('验证失败'); console.log('验证失败');
...@@ -175,8 +208,15 @@ export default { ...@@ -175,8 +208,15 @@ export default {
try { try {
let { data } = await add(this.form); let { data } = await add(this.form);
this.showToast(title + '成功', true); this.showToast(title + '成功', true);
// #ifdef MP-WEIXIN
// 订阅
this.handleRemind(data); this.handleRemind(data);
// #endif
// #ifdef APP-PLUS
setTimeout(() => {
this.navigateTo();
}, 1500);
// #endif
} catch (error) { } catch (error) {
console.log(error); console.log(error);
this.showToast(title + '失败'); this.showToast(title + '失败');
...@@ -258,7 +298,50 @@ export default { ...@@ -258,7 +298,50 @@ export default {
handlClickDelete() { handlClickDelete() {
this.showConfirm = true; this.showConfirm = true;
}, },
async handleConfirm() { async createMessage() {
var pushClientId = uni.getStorageSync('pushClientId')
const push = uniCloud.importObject('account-book-push')
let {res} = await push.sendMessage({...this.form,pushClientId: pushClientId})
console.log('-----sendMessage---------', res)
if (res.errCode == 0) {
// 注意taskId 和 taskid 大小写
this.form.taskId = res.data.taskid
console.log('------form---------', this.form)
// 创建推送成功
this.save()
}
},
// 删除推送
async deleteMessage(isDelete) {
console.log('---------------', this.form.taskId)
if (!this.form.taskId) {
this.handleDelete()
return
}
const push = uniCloud.importObject('account-book-push')
let {res} = await push.deleteMessage(this.form.taskId)
console.log('-----deleteMessage---------', res)
if (res.errCode == 0) {
console.log('删除推送成功')
if (isDelete) {
this.handleDelete()
} else {
this.createMessage()
}
}
},
handleConfirm() {
// #ifdef MP-WEIXIN
this.handleDelete();
// #endif
// #ifdef APP-PLUS
// 删除推送,删除行程
this.deleteMessage(true)
// #endif
},
async handleDelete() {
if (!this.form.id) { if (!this.form.id) {
this.showToast('行程不存在'); this.showToast('行程不存在');
return false; return false;
...@@ -288,6 +371,7 @@ export default { ...@@ -288,6 +371,7 @@ export default {
}, },
// 提交行程订阅给服务器 // 提交行程订阅给服务器
async saveSubscribe(item) { async saveSubscribe(item) {
console.log('------saveSubscribe----------')
try { try {
let params = { let params = {
id: item.id, id: item.id,
......
...@@ -122,7 +122,30 @@ export default { ...@@ -122,7 +122,30 @@ export default {
handlClickDelete() { handlClickDelete() {
this.showConfirm = true; this.showConfirm = true;
}, },
async handleConfirm() { // 删除推送
async deleteMessage() {
console.log('---------------', this.detail.taskId)
if (!this.detail.taskId) {
this.handleDelete()
return
}
const push = uniCloud.importObject('account-book-push')
let {res} = await push.deleteMessage(this.detail.taskId)
console.log('-----deleteMessage---------', res)
if (res.errCode == 0) {
console.log('删除推送成功')
this.handleDelete()
}
},
handleConfirm() {
// #ifdef MP-WEIXIN
this.handleDelete();
// #endif
// #ifdef APP-PLUS
this.deleteMessage()
// #endif
},
async handleDelete() {
if (!this.detail.id) { if (!this.detail.id) {
this.showToast('行程不存在'); this.showToast('行程不存在');
return false; return false;
......
...@@ -228,7 +228,6 @@ export function getSetting(scope, text, block, errBlock = () => {}) { ...@@ -228,7 +228,6 @@ export function getSetting(scope, text, block, errBlock = () => {}) {
// #ifdef APP-PLUS // #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform === "ios") { if (uni.getSystemInfoSync().platform === "ios") {
var result = permision.judgeIosPermission(scope) var result = permision.judgeIosPermission(scope)
console.log('------------------', result)
if (result) { if (result) {
block() block()
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment