12 changed files with 454 additions and 122 deletions
@ -1,56 +1,57 @@ |
|||||
# 0.1.0 (2021-07-19) |
# 0.1.0 (2021-07-20) |
||||
|
|
||||
### 🌟 新功能 |
### 🌟 新功能 |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
- | 标题栏角色栏全局任务组件新建 | [0500cb4](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/0500cb4) |
- | db store | [6414c4f](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/6414c4f) |
||||
- | db store | [6414c4f](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/6414c4f) |
- | indexedDB | [687394e](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/687394e) |
||||
- | indexedDB | [687394e](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/687394e) |
- | 标题栏角色栏全局任务组件新建 | [0500cb4](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/0500cb4) |
||||
富文本插件 | 富文本插件demo测试 | [ed3d644](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/ed3d644) |
pinch | alloy finger实现图片的pinch放大缩小 | [de01343](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/de01343) |
||||
pinch | alloy finger实现图片的pinch放大缩小 | [de01343](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/de01343) |
富文本插件 | 富文本插件demo测试 | [ed3d644](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/ed3d644) |
||||
|
|
||||
|
|
||||
### 🎨 代码样式 |
### 🎨 代码样式 |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
- | 组件新建 | [89c0035](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/89c0035) |
- | 组件新建 | [89c0035](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/89c0035) |
||||
|
|
||||
|
|
||||
### 🐛 Bug 修复 |
### 🐛 Bug 修复 |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
- | 修改main | [749ae9a](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/749ae9a) |
- | 修改main | [749ae9a](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/749ae9a) |
||||
|
|
||||
|
|
||||
### 📝 文档 |
### 📝 文档 |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
- | README.md | [ab0eb05](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/ab0eb05) |
- | README.md | [ab0eb05](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/ab0eb05) |
||||
|
|
||||
|
|
||||
### 🔨 代码重构 |
### 🔨 代码重构 |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
template | eslint prettier sass uview tailwindcss | [9c966a1](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/9c966a1) |
template | eslint prettier sass uview tailwindcss | [9c966a1](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/9c966a1) |
||||
|
|
||||
|
|
||||
### 🚀 性能优化 |
### 🚀 性能优化 |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
- | 组件文件夹新建 | [17bb8c9](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/17bb8c9) |
- | 组件文件夹新建 | [22bfe7b](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/22bfe7b) |
||||
- | 组件文件夹新建 | [1421504](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/1421504) |
- | 组件文件夹新建 | [17bb8c9](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/17bb8c9) |
||||
|
- | 组件文件夹新建 | [1421504](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/1421504) |
||||
|
|
||||
|
|
||||
### chore |
### chore |
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
pwa 小程序 | 移除了pwa,alloyFinger添加平台判断 | [875fab4](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/875fab4) |
pwa 小程序 | 移除了pwa,alloyFinger添加平台判断 | [875fab4](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/875fab4) |
||||
- | uview-ui | [a9ea34b](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/a9ea34b) |
- | uview-ui | [a9ea34b](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/a9ea34b) |
||||
信息配置 | 配置eslint等配置 | [7421443](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/7421443) |
信息配置 | 配置eslint等配置 | [7421443](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/7421443) |
||||
|
|
||||
|
|
||||
范围|描述|commitId |
范围|描述|commitId |
||||
--|--|-- |
--|--|-- |
||||
- | !2 基础模板v1.1.0 | [f5e61dd](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/f5e61dd) |
- | !2 基础模板v1.1.0 | [f5e61dd](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/f5e61dd) |
||||
- | init | [c0f1deb](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/c0f1deb) |
- | init | [c0f1deb](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/c0f1deb) |
||||
|
|
||||
|
@ -0,0 +1,21 @@ |
|||||
|
<template> |
||||
|
<view class="container p-3"> |
||||
|
<u-button type="primary" @click="add">add</u-button> |
||||
|
</view> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
export default { |
||||
|
components: {}, |
||||
|
data: () => ({}), |
||||
|
computed: {}, |
||||
|
methods: { |
||||
|
add() { |
||||
|
this.$db.create('projects', { id: '123' }); |
||||
|
}, |
||||
|
}, |
||||
|
watch: {}, |
||||
|
}; |
||||
|
</script> |
||||
|
|
||||
|
<style></style> |
@ -1,33 +1,185 @@ |
|||||
import { name, version } from '@/config'; |
import { name } from '@/config/db'; |
||||
|
import { curry } from 'lodash'; |
||||
|
|
||||
// 创建表
|
// 创建表
|
||||
const createTable = (Vue, db) => { |
const createCollection = (Vue, db) => { |
||||
// projects项目表
|
// projects项目表
|
||||
Vue.prototype.$db.projects = db.createObjectStore('projects', { keyPath: 'id' }); |
!db.objectStoreNames.contains('projects') && db.createObjectStore('projects', { keyPath: 'id' }); |
||||
// roles 角色表
|
// roles 角色表
|
||||
Vue.prototype.$db.roles = db.createObjectStore('roles', { keyPath: 'id' }); |
!db.objectStoreNames.contains('roles') && db.createObjectStore('roles', { keyPath: 'id' }); |
||||
// plan_tasks 定期任务
|
// plan_tasks 定期任务
|
||||
Vue.prototype.$db.plan_tasks = db.createObjectStore('plan_tasks', { keyPath: 'id' }); |
!db.objectStoreNames.contains('plan_tasks') && db.createObjectStore('plan_tasks', { keyPath: 'id' }); |
||||
// fixed_tasks 固定全局任务
|
// fixed_tasks 固定全局任务
|
||||
Vue.prototype.$db.fixed_tasks = db.createObjectStore('fixed_tasks', { keyPath: 'id' }); |
Vue.prototype.$db.fixed_tasks = !db.objectStoreNames.contains('fixed_tasks') && db.createObjectStore('fixed_tasks', { keyPath: 'id' }); |
||||
// variable_tasks 可变全局任务
|
// variable_tasks 可变全局任务
|
||||
Vue.prototype.$db.variable_tasks = db.createObjectStore('variable_tasks', { keyPath: 'id' }); |
Vue.prototype.$db.variable_tasks = |
||||
|
!db.objectStoreNames.contains('variable_tasks') && db.createObjectStore('variable_tasks', { keyPath: 'id' }); |
||||
// plugins 插件表
|
// plugins 插件表
|
||||
Vue.prototype.$db.plugins = db.createObjectStore('plugins', { keyPath: 'id' }); |
Vue.prototype.$db.plugins = !db.objectStoreNames.contains('plugins') && db.createObjectStore('plugins', { keyPath: 'id' }); |
||||
}; |
}; |
||||
|
|
||||
|
/** |
||||
|
* 新增数据 |
||||
|
* |
||||
|
* @param {object} db 数据库database |
||||
|
* @param {string} collection 集合/表 |
||||
|
* @param {object} data 数据 |
||||
|
*/ |
||||
|
const create = (db, collection, data) => { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const request = db.transaction([collection], 'readwrite').objectStore(collection).add(data); |
||||
|
|
||||
|
request.onsuccess = event => { |
||||
|
console.log(event); |
||||
|
// FIXME:
|
||||
|
resolve(event); |
||||
|
}; |
||||
|
|
||||
|
request.onerror = event => { |
||||
|
console.log(event); |
||||
|
// FIXME:
|
||||
|
reject(event); |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 找到1条数据 |
||||
|
* |
||||
|
* @param {object} db 数据库database |
||||
|
* @param {string} collection 集合/表 |
||||
|
* @param {string} key 索引关键字 一般是id |
||||
|
*/ |
||||
|
const findOne = (db, collection, key) => { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const request = db.transaction([collection]).objectStore(collection).get(key); |
||||
|
request.onerror = event => { |
||||
|
console.log('indexedDB findOne error:', event); |
||||
|
// FIXME:
|
||||
|
reject(event); |
||||
|
}; |
||||
|
request.onsuccess = event => { |
||||
|
console.log('indexedDB findOne success:', event); |
||||
|
// FIXME:
|
||||
|
resolve(event); |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 找到所有数据 |
||||
|
* |
||||
|
* @param {object} db 数据库database |
||||
|
* @param {string} collection 集合/表 |
||||
|
*/ |
||||
|
const find = (db, collection) => { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const request = db.transaction(collection).objectStore(collection).openCursor(); |
||||
|
request.onerror = event => { |
||||
|
console.log('indexedDB find error:', event); |
||||
|
reject(event); |
||||
|
}; |
||||
|
request.onsuccess = event => { |
||||
|
const cursor = event.target.result; |
||||
|
if (cursor) { |
||||
|
console.log('indexedDB find success:', cursor); |
||||
|
cursor.continue(); |
||||
|
// FIXME:
|
||||
|
resolve(event.target.result); |
||||
|
} else { |
||||
|
console.log('没有更多数据了'); |
||||
|
} |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 更新数据 |
||||
|
* |
||||
|
* @param {object} db 数据库database |
||||
|
* @param {string} collection 集合/表 |
||||
|
* @param {object} newData 新数据 |
||||
|
*/ |
||||
|
const update = (db, collection, newData) => { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const request = db.transaction([collection], 'readwrite').objectStore(collection).put(newData); |
||||
|
request.onerror = event => { |
||||
|
console.log('indexedDB UPDATE error:', event); |
||||
|
reject(event); |
||||
|
}; |
||||
|
request.onsuccess = event => { |
||||
|
console.log('indexedDB UPDATE success:', event); |
||||
|
// FIXME:
|
||||
|
resolve(event); |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 移除数据 通过关键字 |
||||
|
* |
||||
|
* @param {object} db 数据库database |
||||
|
* @param {string} collection 集合/表 |
||||
|
* @param {string} key 关键字 |
||||
|
*/ |
||||
|
const remove = (db, collection, key) => { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const request = db.transaction([collection], 'readwrite').objectStore(collection).delete(key); |
||||
|
request.onerror = event => { |
||||
|
console.log('indexedDB REMOVE error:', event); |
||||
|
reject(event); |
||||
|
}; |
||||
|
request.onsuccess = event => { |
||||
|
console.log('indexedDB REMOVE success:', event); |
||||
|
resolve(event); |
||||
|
}; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* 创建索引 |
||||
|
* |
||||
|
* @param {object} db 数据库database |
||||
|
* @param {string} collection 集合/表 |
||||
|
* @param {string} field 创建索引的字段名称 |
||||
|
* @param {string} key 关键字 |
||||
|
*/ |
||||
|
const createIndexAndFind = (db, collection, field, key) => { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const index = db.transaction([collection], 'readonly').objectStore(collection).index(field); |
||||
|
const request = index.get(key); |
||||
|
// FIXME:
|
||||
|
request.onerror = event => reject(event); |
||||
|
request.onsuccess = event => resolve(event); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
const curriedCreate = curry(create); |
||||
|
export const curriedFindOne = curry(findOne); |
||||
|
export const curriedFind = curry(find); |
||||
|
export const curriedRemove = curry(remove); |
||||
|
export const curriedUpdate = curry(update); |
||||
|
export const curriedIndex = curry(createIndexAndFind); |
||||
|
|
||||
const install = Vue => { |
const install = Vue => { |
||||
|
Vue.prototype.$db = {}; |
||||
Vue.prototype.$db.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; |
Vue.prototype.$db.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; |
||||
const request = window.indexedDB.open(name, version); // IDBRequest 对象
|
const request = Vue.prototype.$db.indexedDB.open(name, Date.now()); // IDBRequest 对象
|
||||
request.onerror = error => console.error('打开数据库失败', error); |
request.onerror = error => console.error('打开数据库失败', error); |
||||
request.onsuccess = event => { |
request.onsuccess = event => { |
||||
|
console.log('INDEXED_DB OPEN SUCCESS'); |
||||
Vue.prototype.$db.db = event.target.result; |
Vue.prototype.$db.db = event.target.result; |
||||
}; |
}; |
||||
request.onupgradeneeded = event => { |
request.onupgradeneeded = event => { |
||||
|
console.log('INDEXED_DB OPEN onupgradeneeded'); |
||||
Vue.prototype.$db.db = event.target.result; |
Vue.prototype.$db.db = event.target.result; |
||||
// 创建表
|
// 创建表
|
||||
createTable(Vue, Vue.prototype.$db.db); |
createCollection(Vue, Vue.prototype.$db.db); |
||||
}; |
}; |
||||
|
|
||||
|
// create
|
||||
|
console.log(curriedCreate(Vue.prototype.$db.db)); |
||||
|
Vue.prototype.$db.create = curriedCreate(Vue.prototype.$db.db); |
||||
}; |
}; |
||||
|
|
||||
export default { install }; |
export default { install }; |
||||
|
Loading…
Reference in new issue