添加考试看板功能
This commit is contained in:
@@ -55,7 +55,7 @@ export const kvLocalProvider = {
|
||||
* @param {number} options.limit - 每页返回的记录数,默认为 100
|
||||
* @param {number} options.skip - 跳过的记录数,默认为 0
|
||||
* @returns {Promise<Object>} 包含键名列表和分页信息的响应对象
|
||||
*
|
||||
*
|
||||
* 返回值示例:
|
||||
* {
|
||||
* keys: ["key1", "key2", "key3"],
|
||||
@@ -73,18 +73,16 @@ export const kvLocalProvider = {
|
||||
const db = await initDB();
|
||||
const transaction = db.transaction(["kv"], "readonly");
|
||||
const store = transaction.objectStore("kv");
|
||||
|
||||
|
||||
// 获取所有键名
|
||||
const allKeys = await store.getAllKeys();
|
||||
|
||||
|
||||
// 设置默认参数
|
||||
const {
|
||||
sortBy = "key",
|
||||
sortDir = "asc",
|
||||
limit = 100,
|
||||
skip = 0
|
||||
} = options;
|
||||
|
||||
// 排序键名(本地存储只支持按键名排序)
|
||||
const sortedKeys = allKeys.sort((a, b) => {
|
||||
if (sortDir === "desc") {
|
||||
@@ -92,11 +90,11 @@ export const kvLocalProvider = {
|
||||
}
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
|
||||
// 应用分页
|
||||
const totalRows = sortedKeys.length;
|
||||
const paginatedKeys = sortedKeys.slice(skip, skip + limit);
|
||||
|
||||
|
||||
// 构建响应数据
|
||||
const responseData = {
|
||||
keys: paginatedKeys,
|
||||
@@ -108,7 +106,7 @@ export const kvLocalProvider = {
|
||||
},
|
||||
load_more: null // 本地存储不需要分页URL
|
||||
};
|
||||
|
||||
|
||||
return formatResponse(responseData);
|
||||
} catch (error) {
|
||||
return formatError("获取本地键名列表失败:" + error.message);
|
||||
|
||||
Reference in New Issue
Block a user