Enhance App.vue, axios.js, MigrationTool.vue, index.vue, settings.vue, and related utilities to support namespace management and improve configuration handling. Add namespace password to axios request headers, load namespace info on App mount, and update settings structure to include namespace settings. Refactor dataProvider to utilize new kvLocalProvider and kvServerProvider for data operations, ensuring better separation of concerns and improved error handling.
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { openDB } from "idb";
|
||||
import { formatResponse, formatError } from "../dataProvider";
|
||||
|
||||
// Database initialization for local storage
|
||||
const DB_NAME = "ClassworksDB";
|
||||
const DB_VERSION = 2;
|
||||
|
||||
const initDB = async () => {
|
||||
return openDB(DB_NAME, DB_VERSION, {
|
||||
upgrade(db) {
|
||||
// Create or update stores as needed
|
||||
if (!db.objectStoreNames.contains("kv")) {
|
||||
db.createObjectStore("kv");
|
||||
}
|
||||
|
||||
// Add a system store for machine ID and other system settings
|
||||
if (!db.objectStoreNames.contains("system")) {
|
||||
db.createObjectStore("system");
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const kvLocalProvider = {
|
||||
async loadData(key) {
|
||||
try {
|
||||
const db = await initDB();
|
||||
const data = await db.get("kv", key);
|
||||
|
||||
if (!data) {
|
||||
return formatError("数据不存在", "NOT_FOUND");
|
||||
}
|
||||
|
||||
return formatResponse(JSON.parse(data));
|
||||
} catch (error) {
|
||||
return formatError("读取本地数据失败:" + error);
|
||||
}
|
||||
},
|
||||
|
||||
async saveData(key, data) {
|
||||
try {
|
||||
const db = await initDB();
|
||||
await db.put("kv", JSON.stringify(data), key);
|
||||
return formatResponse(true);
|
||||
} catch (error) {
|
||||
return formatError("保存本地数据失败:" + error);
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user