demo
This commit is contained in:
@@ -21,8 +21,8 @@ function appendBuffer(buffer1, buffer2) {
|
||||
// 读取本地音乐列表并标识为缓存状态(本地缓存)
|
||||
const database = new IndexedDB('musicDatabase', 1)
|
||||
await database.store('musicObjectStore') // 音乐(为什么会用这么丑的格式呢)
|
||||
await database.store('imageObjectStore') // 图像(为什么会用这么丑的格式呢)
|
||||
await database.store('chatsObjectStore') // 聊天室
|
||||
//await database.store('imageObjectStore') // 图像(为什么会用这么丑的格式呢)
|
||||
//await database.store('chatsObjectStore') // 聊天室
|
||||
|
||||
// 读取本地音乐列表并标识为缓存状态(本地缓存)
|
||||
const list = (await database.getAll('musicObjectStore')).map(item => {
|
||||
|
16
src/store.js
16
src/store.js
@@ -1,4 +1,12 @@
|
||||
import { v4 } from 'uuid'
|
||||
// 使用封装为支持异步的 IndexedDB
|
||||
import { openDB, deleteDB, wrap, unwrap } from 'idb'
|
||||
const storenames = ['music', 'chat', 'user']
|
||||
const database = await openDB('database', 1, {
|
||||
upgrade(db) {
|
||||
storenames.forEach(name => db.createObjectStore(name, { keyPath: 'id' }))
|
||||
console.log('store created:', storenames)
|
||||
}
|
||||
})
|
||||
|
||||
export class Store {
|
||||
constructor(data) {
|
||||
@@ -7,7 +15,7 @@ export class Store {
|
||||
}
|
||||
|
||||
create(data) {
|
||||
const id = v4()
|
||||
const id = window.crypto.randomUUID()
|
||||
return { id, ...data }
|
||||
}
|
||||
|
||||
@@ -16,7 +24,7 @@ export class Store {
|
||||
query() {}
|
||||
}
|
||||
|
||||
export const music = new Store({
|
||||
export const musicStore = new Store({
|
||||
name: '音乐(资源类型)',
|
||||
info: '音乐(类型说明)',
|
||||
存储时间: 1000 * 60 * 60 * 24 * 7, // 7天不使用的资源将被删除
|
||||
@@ -30,7 +38,7 @@ export const music = new Store({
|
||||
}]
|
||||
})
|
||||
|
||||
export const chat = new Store({
|
||||
export const chatStore = new Store({
|
||||
name: '聊天(资源类型)',
|
||||
info: '聊天(类型说明)',
|
||||
存储时间: 1000 * 60 * 60 * 24 * 7, // 7天不使用的资源将被删除
|
||||
|
Reference in New Issue
Block a user