You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.1 KiB

import calander from '@/minix/calander.js';
import websockt from '@/utils/websocket.js';
//日历写入模块
var calanderURL = 'content://com.android.calendar/calendars';
var calanderEventURL = 'content://com.android.calendar/events';
var calanderRemiderURL = 'content://com.android.calendar/reminders';
var calId;
/**
* 写入日历混入js
*/
export default {
data() {
return {
i: 0,
title: ''
};
},
onShow() {
// this.getUserId();
},
methods: {
/**
* 获取用户id
* */
getUserId() {
let websocket = new websockt('ws://192.168.0.103:8070/websocket/message/274264305126605109', 5000);
// 发送消息;
let data = { value: 'HHHHHHH ', method: 'post' };
websocket.send(JSON.stringify(data));
// 接收消息
websocket.getMessage(res => {
this.i++;
this.title = JSON.parse(res.data).title;
console.log(JSON.parse(res.data), 'webxiaoxi');
});
},
/**
* // 获取手机平台
* 传入开始结束时间---时间戳格式
* startstime, endtime, title, description
* */
getplatform(startstime, endtime, title, description) {
console.log(startstime, endtime, title, description);
uni.getSystemInfo({
success: res => {
// console.log(res, '调用');
if (res.platform === 'android') {
this.addEvent(startstime, endtime, title, description);
}
}
});
},
/**
* 删除日历
*/
delEvent() {
},
/**
* 写入日历
*/
addEvent(startstime, endtime, title, description) {
let that = this;
var Uri = plus.android.importClass('android.net.Uri');
var main = plus.android.runtimeMainActivity();
var userCursor = plus.android.invoke(main.getContentResolver(), 'query', Uri.parse(calanderURL), null, null,
null, null);
plus.android.invoke(userCursor, 'moveToLast');
calId = plus.android.invoke(userCursor, 'getString', plus.android.invoke(userCursor, 'getColumnIndex',
'_id'));
var ContentValues = plus.android.importClass('android.content.ContentValues');
var events = new ContentValues();
events.put('title', title);
events.put('description', description);
// 插入账户
events.put('calendar_id', calId);
//位置 可不填
// events.put("eventLocation", "位置");
events.put('dtstart', startstime); //时间戳 到毫秒的时间戳
events.put('dtend', endtime); //时间戳 到毫秒的时间戳
events.put('hasAlarm', 1); //是否有闹钟提醒
events.put('eventTimezone', 'Asia/Shanghai'); // 这个是时区,必须有,这个就是中国标准时区,在中国境内的不必再改
// 添加事件
var newEvent = plus.android.invoke(plus.android.runtimeMainActivity().getContentResolver(), 'insert', Uri
.parse(calanderEventURL), events);
// 事件提醒的设定
var id = plus.android.invoke(newEvent, 'getLastPathSegment');
var values = new ContentValues();
values.put('event_id', id);
// 提前30分钟有提醒
values.put('minutes', '15');
values.put('method', '1'); //提醒次数
plus.android.invoke(main.getContentResolver(), 'insert', Uri.parse(calanderRemiderURL), values);
uni.showModal({
content: '任务日历完成',
showCancel: false
});
}
}
};