You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.3 KiB
33 lines
1.3 KiB
import { name, version } from '@/config';
|
|
|
|
// 创建表
|
|
const createTable = (Vue, db) => {
|
|
// projects项目表
|
|
Vue.prototype.$db.projects = db.createObjectStore('projects', { keyPath: 'id' });
|
|
// roles 角色表
|
|
Vue.prototype.$db.roles = db.createObjectStore('roles', { keyPath: 'id' });
|
|
// plan_tasks 定期任务
|
|
Vue.prototype.$db.plan_tasks = db.createObjectStore('plan_tasks', { keyPath: 'id' });
|
|
// fixed_tasks 固定全局任务
|
|
Vue.prototype.$db.fixed_tasks = db.createObjectStore('fixed_tasks', { keyPath: 'id' });
|
|
// variable_tasks 可变全局任务
|
|
Vue.prototype.$db.variable_tasks = db.createObjectStore('variable_tasks', { keyPath: 'id' });
|
|
// plugins 插件表
|
|
Vue.prototype.$db.plugins = db.createObjectStore('plugins', { keyPath: 'id' });
|
|
};
|
|
|
|
const install = Vue => {
|
|
Vue.prototype.$db.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
|
const request = window.indexedDB.open(name, version); // IDBRequest 对象
|
|
request.onerror = error => console.error('打开数据库失败', error);
|
|
request.onsuccess = event => {
|
|
Vue.prototype.$db.db = event.target.result;
|
|
};
|
|
request.onupgradeneeded = event => {
|
|
Vue.prototype.$db.db = event.target.result;
|
|
// 创建表
|
|
createTable(Vue, Vue.prototype.$db.db);
|
|
};
|
|
};
|
|
|
|
export default { install };
|
|
|