mirror of
https://gitee.com/dromara/electron-egg.git
synced 2026-05-15 04:02:10 +08:00
jsondb demo
This commit is contained in:
@@ -10,7 +10,7 @@ module.exports = (appInfo) => {
|
||||
* 开发者工具
|
||||
*/
|
||||
config.openDevTools = {
|
||||
mode: 'bottom'
|
||||
mode: 'undocked'
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ module.exports = (appInfo) => {
|
||||
* 开发者工具
|
||||
*/
|
||||
config.openDevTools = {
|
||||
mode: 'bottom'
|
||||
mode: 'undocked'
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ class FrameworkController extends Controller {
|
||||
* json数据库操作
|
||||
*/
|
||||
async jsondbOperation(args) {
|
||||
const { action, info, delete_name, update_name, update_age, search_age } = args;
|
||||
const { action, info, delete_name, update_name, update_age, search_age, data_dir } = args;
|
||||
|
||||
const data = {
|
||||
action,
|
||||
@@ -54,6 +54,12 @@ class FrameworkController extends Controller {
|
||||
case 'get' :
|
||||
data.result = await Services.get('database.jsondb').getTestData(search_age);
|
||||
break;
|
||||
case 'getDataDir' :
|
||||
data.result = await Services.get('database.jsondb').getDataDir();
|
||||
break;
|
||||
case 'setDataDir' :
|
||||
data.result = await Services.get('database.jsondb').setCustomDataDir(data_dir);
|
||||
break;
|
||||
}
|
||||
|
||||
data.all_list = await Services.get('database.jsondb').getAllTestData();
|
||||
@@ -65,7 +71,7 @@ class FrameworkController extends Controller {
|
||||
* sqlite数据库操作
|
||||
*/
|
||||
async sqlitedbOperation(args) {
|
||||
const { action, info, delete_name, update_name, update_age, search_age } = args;
|
||||
const { action, info, delete_name, update_name, update_age, search_age, data_dir } = args;
|
||||
|
||||
const data = {
|
||||
action,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const { Service } = require('ee-core');
|
||||
const Storage = require('ee-core/storage');
|
||||
const _ = require('lodash');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* json数据存储
|
||||
@@ -14,7 +15,8 @@ class JsondbService extends Service {
|
||||
super(ctx);
|
||||
|
||||
// jsondb数据库
|
||||
this.demoDB = Storage.connection('demo');
|
||||
this.jsonFile = 'demo';
|
||||
this.demoDB = Storage.connection(this.jsonFile);
|
||||
this.demoDBKey = {
|
||||
test_data: 'test_data'
|
||||
};
|
||||
@@ -106,6 +108,30 @@ class JsondbService extends Service {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/*
|
||||
* get data dir (sqlite)
|
||||
*/
|
||||
async getDataDir() {
|
||||
const dir = this.demoDB.getStorageDir();
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
/*
|
||||
* set custom data dir (sqlite)
|
||||
*/
|
||||
async setCustomDataDir(dir) {
|
||||
if (_.isEmpty(dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// the absolute path of the db file
|
||||
const dbFile = path.join(dir, this.jsonFile);
|
||||
this.demoDB = Storage.connection(dbFile);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
JsondbService.toString = () => '[class JsondbService]';
|
||||
|
||||
@@ -20,7 +20,31 @@
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
2. 测试数据
|
||||
2. 数据目录
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
<a-row>
|
||||
<a-col :span="12">
|
||||
<a-input v-model="data_dir" :value="data_dir" addon-before="数据目录" />
|
||||
</a-col>
|
||||
<a-col :span="2">
|
||||
</a-col>
|
||||
<a-col :span="5">
|
||||
<a-button @click="selectDir">
|
||||
修改目录
|
||||
</a-button>
|
||||
</a-col>
|
||||
<a-col :span="5">
|
||||
<a-button @click="openDir">
|
||||
打开目录
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
3. 测试数据
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
@@ -32,7 +56,7 @@
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
3. 添加数据
|
||||
4. 添加数据
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
@@ -56,7 +80,7 @@
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
4. 获取数据
|
||||
5. 获取数据
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
@@ -84,7 +108,7 @@
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
5. 修改数据
|
||||
6. 修改数据
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
@@ -108,7 +132,7 @@
|
||||
</div>
|
||||
<div class="one-block-1">
|
||||
<span>
|
||||
6. 删除数据
|
||||
7. 删除数据
|
||||
</span>
|
||||
</div>
|
||||
<div class="one-block-2">
|
||||
@@ -145,13 +169,23 @@ export default {
|
||||
update_name: '张三',
|
||||
update_age: 21,
|
||||
delete_name: '张三',
|
||||
all_list: ['空']
|
||||
all_list: ['空'],
|
||||
data_dir: ''
|
||||
};
|
||||
},
|
||||
mounted () {
|
||||
this.getAllTestData();
|
||||
this.init();
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
const params = {
|
||||
action: 'getDataDir',
|
||||
}
|
||||
ipc.invoke(ipcApiRoute.jsondbOperation, params).then(res => {
|
||||
this.data_dir = res.result;
|
||||
this.getAllTestData();
|
||||
})
|
||||
},
|
||||
getAllTestData () {
|
||||
const params = {
|
||||
action: 'all',
|
||||
@@ -164,6 +198,28 @@ export default {
|
||||
this.all_list = res.all_list;
|
||||
})
|
||||
},
|
||||
selectDir() {
|
||||
ipc.invoke(ipcApiRoute.selectFolder, '').then(r => {
|
||||
this.data_dir = r;
|
||||
// 修改数据目录
|
||||
this.modifyDataDir(r);
|
||||
})
|
||||
},
|
||||
openDir() {
|
||||
// console.log('data_dir:', this.data_dir);
|
||||
ipc.invoke(ipcApiRoute.openDirectory, {id: this.data_dir}).then(res => {
|
||||
//
|
||||
})
|
||||
},
|
||||
modifyDataDir(dir) {
|
||||
const params = {
|
||||
action: 'setDataDir',
|
||||
data_dir: dir
|
||||
}
|
||||
ipc.invoke(ipcApiRoute.jsondbOperation, params).then(res => {
|
||||
this.all_list = res.all_list;
|
||||
})
|
||||
},
|
||||
dbOperation (ac) {
|
||||
const params = {
|
||||
action: ac,
|
||||
|
||||
@@ -175,7 +175,6 @@ export default {
|
||||
},
|
||||
mounted () {
|
||||
this.init();
|
||||
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
@@ -193,7 +192,6 @@ export default {
|
||||
})
|
||||
},
|
||||
getAllTestData () {
|
||||
const self = this;
|
||||
const params = {
|
||||
action: 'all',
|
||||
}
|
||||
@@ -201,7 +199,7 @@ export default {
|
||||
if (res.all_list.length == 0) {
|
||||
return false;
|
||||
}
|
||||
self.all_list = res.all_list;
|
||||
this.all_list = res.all_list;
|
||||
})
|
||||
},
|
||||
selectDir() {
|
||||
|
||||
Reference in New Issue
Block a user