|
@@ -0,0 +1,290 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <div style="
|
|
|
+ border: 1px solid #cccccc;
|
|
|
+ padding: 0px 0px 0px 0px;
|
|
|
+ margin: 0px 0px 0px 0px;
|
|
|
+ width: 1000px;
|
|
|
+ overflow: visible;">
|
|
|
+ <span style="margin-left:10px;margin-right:10px;">📅</span>
|
|
|
+ <select
|
|
|
+ v-model="selectedView"
|
|
|
+ class="view-select"
|
|
|
+ >
|
|
|
+ <option
|
|
|
+ v-for="view in viewOptions"
|
|
|
+ :key="view.value"
|
|
|
+ :value="view.value"
|
|
|
+ >
|
|
|
+ {{ view.title }}
|
|
|
+ </option>
|
|
|
+ </select>
|
|
|
+ <div class="buttons">
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ @click="onClickTodayButton"
|
|
|
+ >
|
|
|
+ 今天
|
|
|
+ </button>
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-d-arrow-left"
|
|
|
+ @click="onClickMoveButton(-1)"
|
|
|
+ ></el-button>
|
|
|
+ <span class="date-range">{{ dateRangeText }}</span>
|
|
|
+ <el-button
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-d-arrow-right"
|
|
|
+ @click="onClickMoveButton(1)"
|
|
|
+ ></el-button>
|
|
|
+ </div>
|
|
|
+ <ToastUICalendar
|
|
|
+ ref="calendar"
|
|
|
+ style="height:500px;"
|
|
|
+ :view="'month'"
|
|
|
+ :use-form-popup="true"
|
|
|
+ :use-detail-popup="true"
|
|
|
+ :week="uioption.week"
|
|
|
+ :month="uioption.month"
|
|
|
+ :timezone="{ zones }"
|
|
|
+ :theme="theme"
|
|
|
+ :template="{
|
|
|
+ milestone: getTemplateForMilestone,
|
|
|
+ allday: getTemplateForAllday,
|
|
|
+ monthGridHeader: monthGridHeader,
|
|
|
+ }"
|
|
|
+ :grid-selection="true"
|
|
|
+ :calendars="calendars"
|
|
|
+ :notices="notices"
|
|
|
+ :events="events"
|
|
|
+ @selectDateTime="onSelectDateTime"
|
|
|
+ @beforeCreateEvent="onBeforeCreateEvent"
|
|
|
+ @beforeUpdateEvent="onBeforeUpdateEvent"
|
|
|
+ @beforeDeleteEvent="onBeforeDeleteEvent"
|
|
|
+ @afterRenderEvent="onAfterRenderEvent"
|
|
|
+ @clickDayName="onClickDayName"
|
|
|
+ @clickEvent="onClickEvent"
|
|
|
+ @clickTimezonesCollapseBtn="onClickTimezonesCollapseBtn"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+/* eslint-disable no-console */
|
|
|
+import ToastUICalendar from './Calendar.js';
|
|
|
+import './tuical/toastui-calendar.css';
|
|
|
+import 'tui-date-picker/dist/tui-date-picker.min.css';
|
|
|
+import 'tui-time-picker/dist/tui-time-picker.min.css';
|
|
|
+
|
|
|
+import { events, calendars } from './mock-data';
|
|
|
+import { theme } from './theme';
|
|
|
+import './calendar.css';
|
|
|
+
|
|
|
+export default {
|
|
|
+ components: {
|
|
|
+ ToastUICalendar,
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ calendars: calendars,
|
|
|
+ notices: [
|
|
|
+ {
|
|
|
+ id: "n1",
|
|
|
+ name: "notice1"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: "n2",
|
|
|
+ name: "notice2"
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ events,
|
|
|
+ zones: [
|
|
|
+ {
|
|
|
+ timezoneName: 'Asia/Shanghai',
|
|
|
+ displayLabel: 'Beijing',
|
|
|
+ tooltip: 'UTC+08:00',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ theme,
|
|
|
+ selectedView: 'month',
|
|
|
+ viewOptions: [
|
|
|
+ {
|
|
|
+ title: '月',
|
|
|
+ value: 'month',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '周',
|
|
|
+ value: 'week',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '天',
|
|
|
+ value: 'day',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ uioption: {
|
|
|
+ month: {
|
|
|
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
|
|
|
+ startDayOfWeek: 1,
|
|
|
+ },
|
|
|
+ week: {
|
|
|
+ dayNames: ['日', '一', '二', '三', '四', '五', '六'],
|
|
|
+ showTimezoneCollapseButton: true,
|
|
|
+ timezonesCollapsed: false,
|
|
|
+ eventView: true,
|
|
|
+ taskView: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ dateRangeText: '',
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ calendarInstance() {
|
|
|
+ return this.$refs.calendar.getInstance();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ selectedView(newView) {
|
|
|
+ this.calendarInstance.changeView(newView);
|
|
|
+ this.setDateRangeText();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+
|
|
|
+ m3.callFS("/matrix/calendar/load.js").then( (res)=>{
|
|
|
+ //console.log(res)
|
|
|
+ if (res.status == "ok" && res.message && res.message.data && res.message.data.length > 0) {
|
|
|
+ var cals = [];
|
|
|
+ for(var i in calendars) {
|
|
|
+ cals.push(calendars[i]);
|
|
|
+ }
|
|
|
+ for(var i in res.message.calendars) {
|
|
|
+ cals.push(res.message.calendars[i]);
|
|
|
+ }
|
|
|
+ this.calendarInstance.setCalendars(cals);
|
|
|
+ }
|
|
|
+ }).catch( (err)=>{
|
|
|
+ console.error(err);
|
|
|
+ } );
|
|
|
+
|
|
|
+ this.setDateRangeText();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getTemplateForMilestone(event) {
|
|
|
+ return `<span style="color: #fff; background-color: ${event.backgroundColor};">${event.title}</span>`;
|
|
|
+ },
|
|
|
+ getTemplateForAllday(event) {
|
|
|
+ return `[All day] ${event.title}`;
|
|
|
+ },
|
|
|
+ monthGridHeader(model) {
|
|
|
+ const date = parseInt(model.date.split('-')[2], 10);
|
|
|
+ var cls = "toastui-calendar-weekday-grid-date";
|
|
|
+ if(model.isToday){
|
|
|
+ cls += " toastui-calendar-weekday-grid-date-decorator";
|
|
|
+ }
|
|
|
+ cls += " toastui-calendar-template-monthGridHeader";
|
|
|
+ return `<span class="${cls}">${date}</span>`
|
|
|
+ },
|
|
|
+ onSelectDateTime({ start, end }) {
|
|
|
+ console.group('onSelectDateTime');
|
|
|
+ console.log(`Date : ${start} ~ ${end}`);
|
|
|
+ console.groupEnd();
|
|
|
+ },
|
|
|
+ onBeforeCreateEvent(eventData) {
|
|
|
+ const event = {
|
|
|
+ calendarId: eventData.calendarId || '',
|
|
|
+ id: String(Math.random()),
|
|
|
+ title: eventData.title,
|
|
|
+ isAllday: eventData.isAllday,
|
|
|
+ start: eventData.start,
|
|
|
+ end: eventData.end,
|
|
|
+ category: eventData.isAllday ? 'allday' : 'time',
|
|
|
+ dueDateClass: '',
|
|
|
+ location: eventData.location,
|
|
|
+ state: eventData.state,
|
|
|
+ isPrivate: eventData.isPrivate,
|
|
|
+ };
|
|
|
+
|
|
|
+ this.calendarInstance.createEvents([event]);
|
|
|
+ },
|
|
|
+ onBeforeUpdateEvent(updateData) {
|
|
|
+ console.group('onBeforeUpdateEvent');
|
|
|
+ console.log(updateData);
|
|
|
+ console.groupEnd();
|
|
|
+
|
|
|
+ const targetEvent = updateData.event;
|
|
|
+ const changes = { ...updateData.changes };
|
|
|
+
|
|
|
+ this.calendarInstance.updateEvent(targetEvent.id, targetEvent.calendarId, changes);
|
|
|
+ },
|
|
|
+
|
|
|
+ onBeforeDeleteEvent({ title, id, calendarId }) {
|
|
|
+ console.group('onBeforeDeleteEvent');
|
|
|
+ console.log('Event Info : ', title);
|
|
|
+ console.groupEnd();
|
|
|
+
|
|
|
+ this.calendarInstance.deleteEvent(id, calendarId);
|
|
|
+ },
|
|
|
+ onAfterRenderEvent({ title }) {
|
|
|
+ console.group('onAfterRenderEvent');
|
|
|
+ console.log('Event Info : ', title);
|
|
|
+ console.groupEnd();
|
|
|
+ },
|
|
|
+ onClickDayName({ date }) {
|
|
|
+ console.group('onClickDayName');
|
|
|
+ console.log('Date : ', date);
|
|
|
+ console.groupEnd();
|
|
|
+ },
|
|
|
+ onClickEvent({ nativeEvent, event }) {
|
|
|
+ console.group('onClickEvent');
|
|
|
+ console.log('MouseEvent : ', nativeEvent);
|
|
|
+ console.log('Event Info : ', event);
|
|
|
+ console.groupEnd();
|
|
|
+ },
|
|
|
+ onClickTimezonesCollapseBtn(timezoneCollapsed) {
|
|
|
+ console.group('onClickTimezonesCollapseBtn');
|
|
|
+ console.log('Is Timezone Collapsed?: ', timezoneCollapsed);
|
|
|
+ console.groupEnd();
|
|
|
+
|
|
|
+ const newTheme = {
|
|
|
+ 'week.daygridLeft.width': '100px',
|
|
|
+ 'week.timegridLeft.width': '100px',
|
|
|
+ };
|
|
|
+
|
|
|
+ this.calendarInstance.setTheme(newTheme);
|
|
|
+ },
|
|
|
+ onClickTodayButton() {
|
|
|
+ this.calendarInstance.today();
|
|
|
+ this.setDateRangeText();
|
|
|
+ },
|
|
|
+ onClickMoveButton(offset) {
|
|
|
+ this.calendarInstance.move(offset);
|
|
|
+ this.setDateRangeText();
|
|
|
+ },
|
|
|
+ setDateRangeText() {
|
|
|
+ const date = this.calendarInstance.getDate();
|
|
|
+ const start = this.calendarInstance.getDateRangeStart();
|
|
|
+ const end = this.calendarInstance.getDateRangeEnd();
|
|
|
+
|
|
|
+ const startYear = start.getFullYear();
|
|
|
+ const endYear = end.getFullYear();
|
|
|
+
|
|
|
+ switch (this.selectedView) {
|
|
|
+ case 'month':
|
|
|
+ this.dateRangeText = `${date.getFullYear()}年${date.getMonth() + 1}月`;
|
|
|
+
|
|
|
+ return;
|
|
|
+ case 'day':
|
|
|
+ this.dateRangeText = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`;
|
|
|
+ return;
|
|
|
+ default:
|
|
|
+ this.dateRangeText = `${startYear}年${start.getMonth() + 1}月${start.getDate()}日 - ${
|
|
|
+ startYear !== endYear ? `${endYear}年` : ''
|
|
|
+ }${end.getMonth() + 1}月${end.getDate()}日`;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped>
|
|
|
+</style>
|