diff --git a/src/components/settings/cards/KvDatabaseCard.vue b/src/components/settings/cards/KvDatabaseCard.vue
new file mode 100644
index 0000000..bf46db5
--- /dev/null
+++ b/src/components/settings/cards/KvDatabaseCard.vue
@@ -0,0 +1,616 @@
+
+
+
+
+
+
+
+
+ 数据库状态
+ {{ connectionStatus }}
+
+
+ 刷新
+
+
+
+
+
+
+
+
+
+
+
+ 数据条目
+ 共 {{ kvData.length }} 条记录
+
+
+
+ 加载数据
+
+
+
+ 新建
+
+
+
+
+
+
+
+
+
+
+ KV数据列表
+
+
+
+
+
+
+ {{ item.key }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 查看数据
+
+
+
+
+
+ 键名: {{ selectedItem.key }}
+
+
+
+
+
+
+
+
+
+
+ 复制数据
+
+
+ 关闭
+
+
+
+
+
+
+
+
+
+
+ 编辑数据
+
+
+
+
+
+ 键名: {{ editingItem.key }}
+
+
+
+
+
+
+
+
+
+ 取消
+
+
+ 保存
+
+
+
+
+
+
+
+
+
+
+ 新建数据
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 取消
+
+
+ 创建
+
+
+
+
+
+
+
+
+
+
+ 确认删除
+
+
+
+ 确定要删除键名为 {{ itemToDelete?.key }}
的数据吗?
+
+
+ 此操作不可撤销,请谨慎操作!
+
+
+
+
+
+
+ 取消
+
+
+ 删除
+
+
+
+
+
+
+
+
+
+
diff --git a/src/pages/index.vue b/src/pages/index.vue
index cf70d52..cb032d3 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -1194,23 +1194,26 @@ export default {
);
}
- // 加载科目配置
- try {
- const subjectsResponse = await dataProvider.loadData("classworks-config-subject");
- if (subjectsResponse && Array.isArray(subjectsResponse)) {
- // 更新科目列表
- this.state.availableSubjects = subjectsResponse;
- }
- } catch (error) {
- console.warn("Failed to load subject configuration:", error);
- // 保持默认科目列表
- }
+ await this.loadSubjects();
} catch (error) {
console.error("加载配置失败:", error);
this.$message.error("加载配置失败", error.message);
}
},
+ async loadSubjects() {
+ try {
+ const subjectsResponse = await dataProvider.loadData("classworks-config-subject");
+ if (subjectsResponse && Array.isArray(subjectsResponse)) {
+ // 更新科目列表
+ this.state.availableSubjects = subjectsResponse;
+ }
+ } catch (error) {
+ console.warn("Failed to load subject configuration:", error);
+ // 保持默认科目列表
+ }
+ },
+
showSyncMessage() {
this.$message.success("数据已同步", "数据已完成与服务器同步");
},
@@ -1358,7 +1361,7 @@ export default {
this.updateBackendUrl();
},
- handleDateSelect(newDate) {
+ async handleDateSelect(newDate) {
if (!newDate) return;
try {
@@ -1377,7 +1380,12 @@ export default {
query: { date: formattedDate },
})
.catch(() => {});
- this.downloadData();
+
+ // Load both data and subjects in parallel
+ await Promise.all([
+ this.downloadData(),
+ this.loadSubjects()
+ ]);
}
} catch (error) {
console.error("Date processing error:", error);
diff --git a/src/pages/settings.vue b/src/pages/settings.vue
index 233baa0..cd3559f 100644
--- a/src/pages/settings.vue
+++ b/src/pages/settings.vue
@@ -104,6 +104,7 @@
@saved="onSettingsSaved"
/>
+
@@ -241,6 +242,7 @@ import NamespaceSettingsCard from "@/components/settings/cards/NamespaceSettings
import RandomPickerCard from "@/components/settings/cards/RandomPickerCard.vue";
import HomeworkTemplateCard from "@/components/settings/cards/HomeworkTemplateCard.vue";
import SubjectManagementCard from "@/components/settings/cards/SubjectManagementCard.vue";
+import KvDatabaseCard from "@/components/settings/cards/KvDatabaseCard.vue";
export default {
name: "Settings",
components: {
@@ -261,6 +263,7 @@ export default {
RandomPickerCard,
HomeworkTemplateCard,
SubjectManagementCard,
+ KvDatabaseCard,
},
setup() {
const { mobile } = useDisplay();
diff --git a/src/utils/dataProvider.js b/src/utils/dataProvider.js
index 34795b3..43629e4 100644
--- a/src/utils/dataProvider.js
+++ b/src/utils/dataProvider.js
@@ -35,6 +35,57 @@ export default {
return kvLocalProvider.saveData(key, data);
}
},
+
+ /**
+ * 获取键名列表
+ * @param {Object} options - 查询选项
+ * @param {string} options.sortBy - 排序字段,默认为 "key"
+ * @param {string} options.sortDir - 排序方向,"asc" 或 "desc",默认为 "asc"
+ * @param {number} options.limit - 每页返回的记录数,默认为 100
+ * @param {number} options.skip - 跳过的记录数,默认为 0
+ * @returns {Promise