diff --git a/electron/config/config.local.js b/electron/config/config.local.js index a79eff2..9b63737 100644 --- a/electron/config/config.local.js +++ b/electron/config/config.local.js @@ -10,7 +10,7 @@ module.exports = (appInfo) => { * 开发者工具 */ config.openDevTools = { - mode: 'bottom' + mode: 'undocked' }; /** diff --git a/electron/config/config.prod.js b/electron/config/config.prod.js index 09b5d36..cc58f5b 100644 --- a/electron/config/config.prod.js +++ b/electron/config/config.prod.js @@ -10,7 +10,7 @@ module.exports = (appInfo) => { * 开发者工具 */ config.openDevTools = { - mode: 'bottom' + mode: 'undocked' }; /** diff --git a/electron/controller/framework.js b/electron/controller/framework.js index acc9fa2..c60993c 100644 --- a/electron/controller/framework.js +++ b/electron/controller/framework.js @@ -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, diff --git a/electron/service/database/jsondb.js b/electron/service/database/jsondb.js index 724123b..7c6cc6d 100644 --- a/electron/service/database/jsondb.js +++ b/electron/service/database/jsondb.js @@ -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]'; diff --git a/frontend/src/views/framework/jsondb/Index.vue b/frontend/src/views/framework/jsondb/Index.vue index 7b3105f..4e86563 100644 --- a/frontend/src/views/framework/jsondb/Index.vue +++ b/frontend/src/views/framework/jsondb/Index.vue @@ -20,7 +20,31 @@
- 2. 测试数据 + 2. 数据目录 + +
+
+ + + + + + + + + 修改目录 + + + + + 打开目录 + + + +
+
+ + 3. 测试数据
@@ -32,7 +56,7 @@
- 3. 添加数据 + 4. 添加数据
@@ -56,7 +80,7 @@
- 4. 获取数据 + 5. 获取数据
@@ -84,7 +108,7 @@
- 5. 修改数据 + 6. 修改数据
@@ -108,7 +132,7 @@
- 6. 删除数据 + 7. 删除数据
@@ -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, diff --git a/frontend/src/views/framework/sqlitedb/Index.vue b/frontend/src/views/framework/sqlitedb/Index.vue index fb420a5..156b1c5 100644 --- a/frontend/src/views/framework/sqlitedb/Index.vue +++ b/frontend/src/views/framework/sqlitedb/Index.vue @@ -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() {