weicd
2023-02-20 6754df3c4faf22d426d45d1c4995c865cab686de
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<template>
  <div class="dashboard-container">
    <div class="dashboard-editor-container">
      <panel-group :user-info="userInfo" @handleSetLineChartData="handleSetLineChartData" />
      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <FullCalendar ref="fullCalendar" :options="calendarOptions" />
      </el-row>
    </div>
  </div>
</template>
 
<script>
import crudUser from '@/api/system/user'
import PanelGroup from './dashboard/PanelGroup'
import '@fullcalendar/core/vdom'
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
import timeGridPlugin from '@fullcalendar/timegrid'
import moment from 'moment'
 
const lineChartData = {
  // newVisitis: {
  //   expectedData: [100, 120, 161, 134, 105, 160, 165],
  //   actualData: [120, 82, 91, 154, 162, 140, 145]
  // },
  // messages: {
  //   expectedData: [200, 192, 120, 144, 160, 130, 140],
  //   actualData: [180, 160, 151, 106, 145, 150, 130]
  // },
  // purchases: {
  //   expectedData: [80, 100, 121, 104, 105, 90, 100],
  //   actualData: [120, 90, 100, 138, 142, 130, 130]
  // },
  // shoppings: {
  //   expectedData: [130, 140, 141, 142, 145, 150, 160],
  //   actualData: [120, 82, 91, 154, 162, 140, 130]
  // }
}
 
export default {
  name: 'Dashboard',
  components: {
    PanelGroup,
    FullCalendar
  },
  data() {
    return {
      // lineChartData: lineChartData.newVisitis,
      calendarOptions: {
        // 引入的插件
        plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
        // 日历头部按钮位置
        headerToolbar: {
          left: '',
          center: 'title',
          right: 'prev,today,next'
        },
        // 日历头部按钮中文转换
        buttonText: {
          today: '今天',
          month: '月',
          week: '周',
          day: '天'
        },
        initialView: 'dayGridMonth',
        locale: 'zh-ch',
        firstDay: '1',
        weekNumberCalculation: 'ISO',
        eventColor: '#3d8eec',
        timeGridEventMinHeight: '20',
        aspectRatio: '1.5',
        displayEventTime: false,
        allDaySlot: false,
        eventLimit: true,
        fixedWeekCount: false,
        eventTimeFormat: {
          hour: 'numeric',
          minute: '2-digit',
          hour12: false
        },
        slotLabelFormat: {
          hour: '2-digit',
          minute: '2-digit',
          meridiem: false,
          hour12: false
        },
        businessHours: {
          dow: [1, 2, 3, 4, 5],
          start: '9:00',
          end: '18:00'
        },
        events: [],
        // 事件
        editable: false,
        eventStartEditable: false,
        eventDurationEditable: false,
        selectable: false,
        selectMirror: true,
        selectMinDistance: 0,
        weekends: true,
        navLinks: true,
        selectHelper: false,
        selectEventOverlap: false,
        dayMaxEvents: true,
        dateClick: this.handleDateClick, // 点击日期触发
        eventsSet: this.handleEvents,
        eventClick: this.handleEventClick, // 点击日程触发
        eventDrop: this.handleEventDrop,
        eventResize: this.eventResize,
        height: 'auto',
        customButtons: {
          prev: {
            click: () => {
              this.monthClick('prev')
            }
          },
          today: {
            text: '今天',
            click: () => {
              this.monthClick('')
            }
          },
          next: {
            click: () => {
              this.monthClick('next')
            }
          }
        }
      },
      userInfo: {}
    }
  },
  mounted() {
    this.monthClick('')
    this.getUserBaseInfo()
  },
  methods: {
    handleSetLineChartData(type) {
      this.lineChartData = lineChartData[type]
    },
    // 箭头点击事件
    monthClick(type) {
      const calendarApi = this.$refs['fullCalendar'].getApi()
      if (type === 'prev') {
        calendarApi.prev()
      } else if (type === 'next') {
        calendarApi.next()
      } else {
        calendarApi.today()
      }
      // this.calendarOptions.events = [{title: '上班打卡时间', color: 'red',start: '2023-01-28',date: '2023-01-28'}]
      this.getUserCalendarInfo(moment(calendarApi.view.currentStart).format('YYYY-MM-DD').toString())
    },
    // 获取打卡信息
    getUserCalendarInfo(month) {
      crudUser.getUserCalendarInfo(month).then(res => {
        console.log('res', res)
        this.calendarOptions.events = res.map(function(obj) {
          // obj.start = obj.date
          obj.color = obj.isOk ? 'green' : 'red'
          // obj.date1 = obj.date
          return obj
        })
        setTimeout(() => {
          console.log(this.calendarOptions.events)
        }, 1000)
      }).catch(() => {
        this.calendarOptions.events = []
      })
    },
    // 日期点击
    handleDateClick(selectInfo) {
      console.log('handleDateClick.info:', selectInfo)
    },
    // 日程点击信息展示
    handleEventClick(info) {
      if (info.event._def.extendedProps.type === 1) {
        this.$router.push({
          path: '/attendance/attendance',
          query: { date: info.event._def.extendedProps.date1 }
        })
      } else {
        this.$router.push({ path: '/task/taskDaliy', query: { date: info.event._def.extendedProps.date1 }})
      }
    },
    // 获取用户信息
    getUserBaseInfo() {
      crudUser.getUserBaseInfo().then(res => {
        this.userInfo = res
      })
    }
  }
}
</script>
 
// <style rel="stylesheet/scss" lang="scss" scoped>
//   .dashboard-editor-container {
//     padding: 32px;
//     background-color: rgb(240, 242, 245);
//     position: relative;
 
//     .github-corner {
//       position: absolute;
//       top: 0;
//       border: 0;
//       right: 0;
//     }
 
//     .chart-wrapper {
//       background: #fff;
//       padding: 16px 16px 0;
//       margin-bottom: 32px;
//     }
//   }
 
//   @media (max-width:1024px) {
//     .chart-wrapper {
//       padding: 8px;
//     }
//   }
// </style>