实例、代码、资料
实例1
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
X-WR-CALNAME:阿斯顿发
X-APPLE-CALENDAR-COLOR:#540EB9
BEGIN:VEVENT
UID:1668753387035
SUMMARY:修改
DTSTART;VALUE=DATE-TIME:20231124T04:30:00Z
DTEND;VALUE=DATE-TIME:20231124T14:30:00Z
DESCRIPTION:主要内容中文修改
LOCATION:地点
END:VEVENT
END:VCALENDAR
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
X-WR-CALNAME:百融云创
X-APPLE-CALENDAR-COLOR:#540EB9
BEGIN:VEVENT
UID:
SUMMARY:11月工作计划
DTSTART;VALUE=DATE:20221118T084000Z
DTEND;VALUE=DATE:20221118T085000Z
DESCRIPTION:阿斯顿发
LOCATION:阿斯顿发
END:VEVENT
END:VCALENDAR
实例2
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
<script>
const icsMeg2 = `
BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
X-WR-CALNAME:阿斯顿发
X-APPLE-CALENDAR-COLOR:#540EB9
BEGIN:VEVENT
UID:${Date.now()}
SUMMARY:${Date.now()}
DTSTART;VALUE=DATE:20221118T084000Z
DTEND;VALUE=DATE:20221118T085000Z
DESCRIPTION:阿斯顿发
LOCATION:阿斯顿发
END:VEVENT
END:VCALENDAR`;
const blob = new Blob([icsMSG], { type: 'text/calendar' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = 'Calendar2.ics';
link.click();
</script>
</head>
<body>
<div>
asdfasdfsfd
<a href="">阿斯顿发送到发</a>
</div>
</body>
</html>
- 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
项目中代码实现
handleAddCalendar(item) {
const startTime = item.startTime ? moment(item.meetingDate + ' ' + item.startTime).format('YYYYMMDDTHH:mm:ss') + 'Z' : moment(item.meetingDate).format('YYYYMMDDTHH:mm:ss') + 'Z';
const endTime = item.endTime ? moment(item.meetingDate + ' ' + item.endTime).format('YYYYMMDDTHH:mm:ss') + 'Z' : moment(item.meetingDate).format('YYYYMMDDTHH:mm:ss') + 'Z';
const title = this.language === 'e' ? `${item.enMeetingTitle}` : `${item.cnMeetingTitle}`;
const content = this.language === 'e' ? `${item.enContent}` : `${item.cnContent}`;
const place = this.language === 'e' ? `${item.enMeetingPlace}` : `${item.cnMeetingPlace}`;
const icsMsg = 'BEGIN:VCALENDAR\n' +
'METHOD:PUBLISH\n' +
'VERSION:2.0\n' +
'X-WR-CALNAME:百融云创\n' +
'X-APPLE-CALENDAR-COLOR:#540EB9\n' +
'BEGIN:VEVENT\n' +
`UID:${Date.now()}\n` +
`SUMMARY:${title}\n` +
`DTSTART;VALUE=DATE-TIME:${startTime}\n` +
`DTEND;VALUE=DATE-TIME:${endTime}\n` +
`DESCRIPTION:${content}\n` +
`LOCATION:${place}\n` +
'END:VEVENT\n' +
'END:VCALENDAR';
const blob = new Blob([icsMsg], { type: 'text/calendar' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `${title}.ics`;
link.click();
}
- 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
参考资料