Skip to content

Commit 443fad7

Browse files
committed
feat: add new house data to month calendar
1 parent 2b6a797 commit 443fad7

File tree

2 files changed

+126
-7
lines changed

2 files changed

+126
-7
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@commitlint/config-conventional": "^18.6.3",
8282
"@iconify-json/ep": "^1.1.15",
8383
"@types/color": "^3.0.6",
84+
"@types/jquery": "^3.5.30",
8485
"@types/lodash": "^4.17.6",
8586
"@types/node": "^20.14.10",
8687
"@types/nprogress": "^0.2.3",

src/views/house/resold-calendar/index.vue

+125-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { format } from "date-fns";
2+
import { format, addDays, compareAsc } from "date-fns";
33
import { defineComponent, onMounted, reactive, ref, onBeforeMount } from "vue";
44
import FullCalendar from "@fullcalendar/vue3";
55
import dayGridPlugin from "@fullcalendar/daygrid";
@@ -10,6 +10,7 @@ import HouseAPI from "@/api/house";
1010
import { ChartHouseDataVO } from "@/api/house/model";
1111
import { log } from "console";
1212
13+
// install bootstrap@4 @fortawesome/fontawesome-free
1314
import "bootstrap/dist/css/bootstrap.css";
1415
import "@fortawesome/fontawesome-free/css/all.css"; // needs additional webpack config!
1516
@@ -19,18 +20,22 @@ defineOptions({
1920
2021
interface eventItem {
2122
id: String;
23+
groupId?: String;
2224
title: String;
2325
start: String;
2426
end?: String;
2527
allDay?: boolean;
28+
borderColor?: String;
29+
backgroundColor?: String;
30+
classNames?: Array<String>;
2631
// other properties...
2732
}
2833
2934
const loading = ref(true); // 加载状态
3035
const chartHousedataList = ref<ChartHouseDataVO>();
3136
// const monthCalendar = ref() as Ref<InstanceType<typeof FullCalendar>>
3237
const currentMonthData = ref(0);
33-
38+
const currentMonthNewData = ref(0);
3439
const createEventId = (date: any): String => {
3540
return format(date, "yyyy-MM-dd");
3641
// return String(eventGuid++)
@@ -48,6 +53,10 @@ function handleDateSet(info: any) {
4853
}
4954
}
5055
56+
function getLastDayOfMonth(year: number, month: number): Date {
57+
return new Date(year, month + 1, 0);
58+
}
59+
5160
const handleDateClick = (info: any) => {
5261
// alert('Clicked on: ' + info.dateStr);
5362
// alert('Coordinates: ' + info.jsEvent.pageX + ',' + info.jsEvent.pageY);
@@ -90,17 +99,27 @@ async function initialEventsFromRemote(date: Date) {
9099
chartHousedataList.value = data as ChartHouseDataVO;
91100
//initialEventsData.length = 0
92101
currentMonthData.value = 0;
102+
currentMonthNewData.value = 0;
103+
let currentLastDay: Date | null = null;
93104
chartHousedataList.value.xaxis.forEach((val, idx) => {
105+
currentLastDay = new Date(val);
106+
// 当月二手房销量
94107
currentMonthData.value += chartHousedataList.value?.series[0].chatData[
95108
idx
96109
] as number;
110+
// 当月新房总销量
111+
currentMonthNewData.value += chartHousedataList.value?.series[1]
112+
.chatData[idx] as number;
97113
let event: eventItem = {
98114
id: createEventId(val),
99115
title: String(
100116
chartHousedataList.value?.series[0].chatData[idx].toString()
101117
),
102-
start: val,
118+
start: val, //.toString().replace(/T.*$/, '') + ' 00:00:00',
119+
//backgroundColor: "red",
120+
// other properties...
103121
};
122+
//console.log(event);
104123
// 检查该数据是否已经存在
105124
if (
106125
initialEventsData.findIndex((val) => {
@@ -109,7 +128,85 @@ async function initialEventsFromRemote(date: Date) {
109128
) {
110129
initialEventsData.push(event);
111130
}
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+
}
112149
});
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+
113210
calendarOptions.initialEvents = initialEventsData;
114211
calendarOptions.initialDate = date;
115212
calendarOptions.customButtons.myCustomButton.text =
@@ -151,10 +248,10 @@ const calendarOptions: any = reactive({
151248
right: "today prev next",
152249
},
153250
footerToolbar: {
154-
right: "myCustomButton",
251+
//right: "myCustomButton",
155252
},
156253
buttonText: {
157-
today: "今日",
254+
today: "当月",
158255
},
159256
views: {
160257
dayGridMonth: {
@@ -166,7 +263,8 @@ const calendarOptions: any = reactive({
166263
initialDate: new Date(),
167264
themeSystem: "bootstrap",
168265
showNonCurrentDates: false,
169-
eventColor: "#52bb0c",
266+
eventColor: "#00aa66",
267+
eventOrder: "start",
170268
height: "auto",
171269
// contentHeight: 350,
172270
// eventDisplay: 'none',
@@ -197,7 +295,7 @@ const calendarOptions: any = reactive({
197295
onBeforeMount(() => {
198296
// 异步读取当前显示日历对应的数据
199297
initialEventsFromRemote(new Date());
200-
298+
// $(".fc-center").append('<input type="text" id="datepicker"></input>');
201299
// let event: eventItem = {
202300
// id: createEventId("2024-07-12"),
203301
// title: "test",
@@ -228,6 +326,11 @@ onMounted(() => {
228326
</div>
229327
</template>
230328
</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> -->
231334
</div>
232335
</div>
233336
</template>
@@ -277,6 +380,21 @@ b {
277380
font-size: 14px;
278381
}
279382
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+
280398
.demo-app-sidebar {
281399
width: 300px;
282400
line-height: 1.5;

0 commit comments

Comments
 (0)