Skip to content

Commit be3ffb9

Browse files
committed
Refactor RandomPicker.vue for improved readability and maintainability. Enhance template formatting by standardizing indentation and spacing, and update button properties for consistency. Add a new button for navigating to the list page in index.vue, and adjust date handling in settings and index pages for better date management. Update dataProvider and settings utility functions for improved response handling and configuration management.
1 parent 3654e22 commit be3ffb9

File tree

8 files changed

+1062
-126
lines changed

8 files changed

+1062
-126
lines changed

src/components/RandomPicker.vue

Lines changed: 184 additions & 88 deletions
Large diffs are not rendered by default.

src/pages/index.vue

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@
149149
>
150150
随机点名
151151
</v-btn>
152+
<v-btn
153+
v-if="showListCardButton"
154+
color="primary-darken-1"
155+
prepend-icon="mdi-list-box"
156+
size="large"
157+
class="ml-2"
158+
@click="$router.push('/list')"
159+
>
160+
列表
161+
</v-btn>
152162
<v-btn
153163
v-if="showFullscreenButton"
154164
:color="state.isFullscreen ? 'blue-grey' : 'blue'"
@@ -673,8 +683,8 @@ export default {
673683
snackbarText: "",
674684
fontSize: getSetting("font.size"),
675685
datePickerDialog: false,
676-
selectedDate: new Date().toISOString().split("T")[0],
677-
selectedDateObj: new Date(this.selectedDate),
686+
selectedDate: new Date().toISOString().split("T")[0].replace(/-/g, ''),
687+
selectedDateObj: new Date(),
678688
refreshInterval: null,
679689
subjectOrder: [
680690
"语文",
@@ -849,6 +859,9 @@ export default {
849859
showRandomPickerButton() {
850860
return getSetting("randomPicker.enabled");
851861
},
862+
showListCardButton() {
863+
return getSetting("display.showListCard");
864+
},
852865
confirmNonTodaySave() {
853866
return getSetting("edit.confirmNonTodaySave");
854867
},
@@ -1066,9 +1079,26 @@ export default {
10661079
const today = this.getToday();
10671080
10681081
// 确保日期格式正确
1069-
const currentDate = dateFromUrl ? new Date(dateFromUrl) : today;
1082+
let currentDate = today;
1083+
if (dateFromUrl) {
1084+
// 处理yyyymmdd格式的日期字符串
1085+
if (/^\d{8}$/.test(dateFromUrl)) {
1086+
const year = dateFromUrl.substring(0, 4);
1087+
const month = dateFromUrl.substring(4, 6);
1088+
const day = dateFromUrl.substring(6, 8);
1089+
currentDate = new Date(`${year}-${month}-${day}`);
1090+
} else {
1091+
currentDate = new Date(dateFromUrl);
1092+
}
1093+
// 确保日期有效,无效则使用今天的日期
1094+
if (isNaN(currentDate.getTime())) {
1095+
currentDate = today;
1096+
}
1097+
}
1098+
10701099
this.state.dateString = this.formatDate(currentDate);
10711100
this.state.selectedDate = this.state.dateString;
1101+
this.state.selectedDateObj = currentDate; // 设置日期对象
10721102
this.state.isToday =
10731103
this.formatDate(currentDate) === this.formatDate(today);
10741104
// 如果没有从URL应用配置,使用本地设置
@@ -1090,7 +1120,7 @@ export default {
10901120
"classworks-data-" + this.state.dateString
10911121
);
10921122
1093-
if (!response.success) {
1123+
if (response.success == false) {
10941124
if (response.error.code === "NOT_FOUND") {
10951125
this.state.showNoDataMessage = true;
10961126
this.state.noDataMessage = response.error.message;
@@ -1105,11 +1135,11 @@ export default {
11051135
} else {
11061136
// 确保数据结构完整
11071137
this.state.boardData = {
1108-
homework: response.data.homework || {},
1138+
homework: response.homework || {},
11091139
attendance: {
1110-
absent: response.data.attendance?.absent || [],
1111-
late: response.data.attendance?.late || [],
1112-
exclude: response.data.attendance?.exclude || [],
1140+
absent: response.attendance?.absent || [],
1141+
late: response.attendance?.late || [],
1142+
exclude: response.attendance?.exclude || [],
11131143
},
11141144
};
11151145
this.state.synced = true;
@@ -1194,8 +1224,7 @@ export default {
11941224
"classworks-data-" + this.state.dateString,
11951225
this.state.boardData
11961226
);
1197-
1198-
if (!response.success) {
1227+
if (response.success == false) {
11991228
throw new Error(response.error.message);
12001229
}
12011230
@@ -1212,9 +1241,9 @@ export default {
12121241
// Try to get student list from the dedicated key
12131242
const response = await dataProvider.loadData("classworks-list-main");
12141243
1215-
if (response.success && Array.isArray(response.data)) {
1244+
if (response.success != false && Array.isArray(response)) {
12161245
// Transform the data into a simple list of names
1217-
this.state.studentList = response.data.map(
1246+
this.state.studentList = response.map(
12181247
(student) => student.name
12191248
);
12201249
return;
@@ -1390,6 +1419,7 @@ export default {
13901419
if (this.state.dateString !== formattedDate) {
13911420
this.state.dateString = formattedDate;
13921421
this.state.selectedDate = formattedDate;
1422+
this.state.selectedDateObj = selectedDate;
13931423
this.state.isToday =
13941424
formattedDate === this.formatDate(this.getToday());
13951425

0 commit comments

Comments
 (0)