1
1
<script setup lang="ts">
2
- import { format } from " date-fns" ;
2
+ import { format , addDays , compareAsc } from " date-fns" ;
3
3
import { defineComponent , onMounted , reactive , ref , onBeforeMount } from " vue" ;
4
4
import FullCalendar from " @fullcalendar/vue3" ;
5
5
import dayGridPlugin from " @fullcalendar/daygrid" ;
@@ -10,6 +10,7 @@ import HouseAPI from "@/api/house";
10
10
import { ChartHouseDataVO } from " @/api/house/model" ;
11
11
import { log } from " console" ;
12
12
13
+ // install bootstrap@4 @fortawesome/fontawesome-free
13
14
import " bootstrap/dist/css/bootstrap.css" ;
14
15
import " @fortawesome/fontawesome-free/css/all.css" ; // needs additional webpack config!
15
16
@@ -19,18 +20,22 @@ defineOptions({
19
20
20
21
interface eventItem {
21
22
id: String ;
23
+ groupId? : String ;
22
24
title: String ;
23
25
start: String ;
24
26
end? : String ;
25
27
allDay? : boolean ;
28
+ borderColor? : String ;
29
+ backgroundColor? : String ;
30
+ classNames? : Array <String >;
26
31
// other properties...
27
32
}
28
33
29
34
const loading = ref (true ); // 加载状态
30
35
const chartHousedataList = ref <ChartHouseDataVO >();
31
36
// const monthCalendar = ref() as Ref<InstanceType<typeof FullCalendar>>
32
37
const currentMonthData = ref (0 );
33
-
38
+ const currentMonthNewData = ref ( 0 );
34
39
const createEventId = (date : any ): String => {
35
40
return format (date , " yyyy-MM-dd" );
36
41
// return String(eventGuid++)
@@ -48,6 +53,10 @@ function handleDateSet(info: any) {
48
53
}
49
54
}
50
55
56
+ function getLastDayOfMonth(year : number , month : number ): Date {
57
+ return new Date (year , month + 1 , 0 );
58
+ }
59
+
51
60
const handleDateClick = (info : any ) => {
52
61
// alert('Clicked on: ' + info.dateStr);
53
62
// alert('Coordinates: ' + info.jsEvent.pageX + ',' + info.jsEvent.pageY);
@@ -90,17 +99,27 @@ async function initialEventsFromRemote(date: Date) {
90
99
chartHousedataList .value = data as ChartHouseDataVO ;
91
100
// initialEventsData.length = 0
92
101
currentMonthData .value = 0 ;
102
+ currentMonthNewData .value = 0 ;
103
+ let currentLastDay: Date | null = null ;
93
104
chartHousedataList .value .xaxis .forEach ((val , idx ) => {
105
+ currentLastDay = new Date (val );
106
+ // 当月二手房销量
94
107
currentMonthData .value += chartHousedataList .value ?.series [0 ].chatData [
95
108
idx
96
109
] as number ;
110
+ // 当月新房总销量
111
+ currentMonthNewData .value += chartHousedataList .value ?.series [1 ]
112
+ .chatData [idx ] as number ;
97
113
let event: eventItem = {
98
114
id: createEventId (val ),
99
115
title: String (
100
116
chartHousedataList .value ?.series [0 ].chatData [idx ].toString ()
101
117
),
102
- start: val ,
118
+ start: val , // .toString().replace(/T.*$/, '') + ' 00:00:00',
119
+ // backgroundColor: "red",
120
+ // other properties...
103
121
};
122
+ // console.log(event);
104
123
// 检查该数据是否已经存在
105
124
if (
106
125
initialEventsData .findIndex ((val ) => {
@@ -109,7 +128,85 @@ async function initialEventsFromRemote(date: Date) {
109
128
) {
110
129
initialEventsData .push (event );
111
130
}
131
+ // 当月新房销量
132
+ let newHouseEvent: eventItem = {
133
+ id: createEventId (val ) + " new" ,
134
+ title: String (
135
+ chartHousedataList .value ?.series [1 ].chatData [idx ].toString ()
136
+ ),
137
+ start: val ,
138
+ borderColor: " #ff666600" ,
139
+ backgroundColor: " #ff666666" ,
140
+ };
141
+ // 检查该数据是否已经存在
142
+ if (
143
+ initialEventsData .findIndex ((val ) => {
144
+ return val .id === newHouseEvent .id ;
145
+ }) === - 1
146
+ ) {
147
+ initialEventsData .push (newHouseEvent );
148
+ }
112
149
});
150
+
151
+ if (currentMonthData .value != 0 ) {
152
+ let lastDayofMonth = getLastDayOfMonth (
153
+ date .getFullYear (),
154
+ date .getMonth ()
155
+ );
156
+ // 当月有数据的最后一天+1
157
+ if (
158
+ currentLastDay &&
159
+ compareAsc (addDays (currentLastDay , 1 ), lastDayofMonth ) == - 1
160
+ ) {
161
+ lastDayofMonth = addDays (currentLastDay , 1 );
162
+ }
163
+ let monthTotalNumberEvent: eventItem = {
164
+ id: createEventId (lastDayofMonth ) + " total" ,
165
+ title: " 总:" + currentMonthData .value .toString (),
166
+ start: createEventId (lastDayofMonth ),
167
+ // backgroundColor: '#00cc66',
168
+ // other properties...
169
+ };
170
+ // 检查该数据是否已经存在
171
+ if (
172
+ initialEventsData .findIndex ((val ) => {
173
+ return val .id === monthTotalNumberEvent .id ;
174
+ }) === - 1
175
+ ) {
176
+ initialEventsData .push (monthTotalNumberEvent );
177
+ }
178
+ }
179
+ if (currentMonthNewData .value != 0 ) {
180
+ let lastDayofMonth = getLastDayOfMonth (
181
+ date .getFullYear (),
182
+ date .getMonth ()
183
+ );
184
+ // 当月有数据的最后一天+1
185
+ if (
186
+ currentLastDay &&
187
+ compareAsc (addDays (currentLastDay , 1 ), lastDayofMonth ) == - 1
188
+ ) {
189
+ lastDayofMonth = addDays (currentLastDay , 1 );
190
+ }
191
+ let monthTotalNumberEvent: eventItem = {
192
+ id: createEventId (lastDayofMonth ) + " newTotal" ,
193
+ title: " 总:" + currentMonthNewData .value .toString ().padEnd (5 , " " ),
194
+ start: createEventId (lastDayofMonth ),
195
+ borderColor: " #ff666600" ,
196
+ backgroundColor: " #ff666666" ,
197
+ // classNames: ['total-data'],
198
+ // other properties...
199
+ };
200
+ // 检查该数据是否已经存在
201
+ if (
202
+ initialEventsData .findIndex ((val ) => {
203
+ return val .id === monthTotalNumberEvent .id ;
204
+ }) === - 1
205
+ ) {
206
+ initialEventsData .push (monthTotalNumberEvent );
207
+ }
208
+ }
209
+
113
210
calendarOptions .initialEvents = initialEventsData ;
114
211
calendarOptions .initialDate = date ;
115
212
calendarOptions .customButtons .myCustomButton .text =
@@ -151,10 +248,10 @@ const calendarOptions: any = reactive({
151
248
right: " today prev next" ,
152
249
},
153
250
footerToolbar: {
154
- right: " myCustomButton" ,
251
+ // right: "myCustomButton",
155
252
},
156
253
buttonText: {
157
- today: " 今日 " ,
254
+ today: " 当月 " ,
158
255
},
159
256
views: {
160
257
dayGridMonth: {
@@ -166,7 +263,8 @@ const calendarOptions: any = reactive({
166
263
initialDate: new Date (),
167
264
themeSystem: " bootstrap" ,
168
265
showNonCurrentDates: false ,
169
- eventColor: " #52bb0c" ,
266
+ eventColor: " #00aa66" ,
267
+ eventOrder: " start" ,
170
268
height: " auto" ,
171
269
// contentHeight: 350,
172
270
// eventDisplay: 'none',
@@ -197,7 +295,7 @@ const calendarOptions: any = reactive({
197
295
onBeforeMount (() => {
198
296
// 异步读取当前显示日历对应的数据
199
297
initialEventsFromRemote (new Date ());
200
-
298
+ // $(".fc-center").append('<input type="text" id="datepicker"></input>');
201
299
// let event: eventItem = {
202
300
// id: createEventId("2024-07-12"),
203
301
// title: "test",
@@ -228,6 +326,11 @@ onMounted(() => {
228
326
</div >
229
327
</template >
230
328
</FullCalendar >
329
+ <!-- <div class="fc-dayGridMonth-view fc-view fc-daygrid">
330
+ <div class="fc-daygrid-day-frame fc-scrollgrid-sync-inner">
331
+ sss
332
+ </div>
333
+ </div> -->
231
334
</div >
232
335
</div >
233
336
</template >
277
380
font-size : 14px ;
278
381
}
279
382
383
+ /* .fc-event-main {
384
+ text-align: center;
385
+ color: red;
386
+ }
387
+
388
+ .total-data {
389
+ text-align: center;
390
+ color: red;
391
+ }
392
+
393
+ a.fc-h-event a.fc-event-main {
394
+ color: blue;
395
+ text-align: center;
396
+ } */
397
+
280
398
.demo-app-sidebar {
281
399
width : 300px ;
282
400
line-height : 1.5 ;
0 commit comments