Commit 62adcaea authored by Medicean's avatar Medicean

(Add:Module:Setting) 新增默认设置

parent 03c0a0cd
......@@ -73,7 +73,7 @@ const antSword = window.antSword = {
if (!value) {
return localStorage.getItem(key) || def;
};
if (typeof(x) === "object")
if (typeof(value) === "object")
value = JSON.stringify(value);
// 设置
localStorage.setItem(key, value);
......
......@@ -664,6 +664,26 @@ module.exports = {
}
}
}
},
adefault: {
title: 'Default Setting',
success: 'Save default settings successfully!',
error: 'Failed to save the default settings!',
confirm: {
content: 'Restart the application to take effect, whether to restart?',
title: 'Change default settings'
},
toolbar: {
save: 'Save',
},
filemanager: {
title: 'FileManager',
openfileintab: {
title: 'Open File in',
window: 'Window',
tab: 'Tab',
},
}
}
},
plugin: {
......
......@@ -665,6 +665,26 @@ module.exports = {
}
}
}
},
adefault: {
title: '默认设置',
success: '保存成功',
error: '保存失败!',
confirm: {
content: '重启应用生效,是否重启?',
title: '更改默认设置'
},
toolbar: {
save: '保存',
},
filemanager: {
title: '文件管理',
openfileintab: {
title: '文件打开方式',
window: '窗口打开',
tab: '标签打开',
},
}
}
},
plugin: {
......
......@@ -383,7 +383,7 @@ class Files {
manager.previewFile(fname, fsize);
}else if(fsize <= 100 * 1024){
// 双击编辑size < 100kb 文件
manager.editFile(fname);
manager.editFile(fname, self.manager.config.openfileintab);
}else{
manager.downloadFile(fname, fsize);
}
......
......@@ -39,6 +39,11 @@ class FileManager {
antSword['modules']['filemanager'] = antSword['modules']['filemanager'] || {};
antSword['modules']['filemanager'][hash] = this;
let config = {
openfileintab: false,
};
this.config = JSON.parse(antSword['storage']("adefault_filemanager", false, JSON.stringify(config)));
this.isWin = true;
this.path = '/';
this.home = '/';
......
/**
* 设置中心::默认设置
*/
const LANG = antSword['language']['settings']['adefault'];
const LANG_T = antSword['language']['toastr'];
class ADefault {
constructor(sidebar) {
sidebar.addItem({
id: 'adefault',
text: `<i class="fa fa-television"></i> ${LANG['title']}`
});
const cell = sidebar.cells('adefault');
const default_config = {
filemanager: {
openfileintab: false,
},
};
// 读取配置
const filemanager_settings = JSON.parse(antSword['storage']("adefault_filemanager", false, JSON.stringify(default_config.filemanager)));
const toolbar = cell.attachToolbar();
toolbar.loadStruct([
{ id: 'save', type: 'button', text: LANG['toolbar']['save'], icon: 'save' }
]);
// 表单
const form = cell.attachForm([{
type: 'block', name: 'filemanager', list: [
// {type: "label", label: LANG['filemanager']['title']},
{
type: "fieldset", label: LANG['filemanager']['title'], list:[
{ type: "block", list: [
{type: "label", label: LANG['filemanager']['openfileintab']['title']},
{type: 'newcolumn', offset:20},
{
type: "radio", label: LANG['filemanager']['openfileintab']['window'], name: 'openfileintab', checked: filemanager_settings.openfileintab == false , position: "label-right", value: false,
},
{type: 'newcolumn', offset:20},
{
type: "radio", label: LANG['filemanager']['openfileintab']['tab'], name: 'openfileintab', checked: filemanager_settings.openfileintab == true , position: "label-right", value: true,
}
]},
// 后续文件管理其它设置
]
}
]},
// 后续其它模块
], true);
form.enableLiveValidation(true);
// 保存
toolbar.attachEvent('onClick', (id) => {
switch(id){
case 'save':
if(form.validate()){
var _formvals = form.getValues();
let config = default_config;
config.filemanager.openfileintab = _formvals['openfileintab'];
// save
// save 文件管理设置
antSword['storage']('adefault_filemanager', config.filemanager);
toastr.success(LANG['success'], LANG_T['success']);
// 重启应用
layer.confirm(LANG['confirm']['content'], {
icon: 2, shift: 6,
title: LANG['confirm']['title']
}, (_) => {
location.reload();
});
}else{
toastr.error(LANG['error'], LANG_T['error']);
}
break;
}
});
}
}
module.exports = ADefault;
......@@ -12,6 +12,7 @@ const Language = require('./language');
const AProxy = require('./aproxy');
const Display = require('./display');
const Encoders = require('./encoders');
const ADefault = require('./adefault');
class Settings {
......@@ -47,6 +48,7 @@ class Settings {
this.display = new Display(sidebar);
// Encoders
this.encoders = new Encoders(sidebar);
this.adefault = new ADefault(sidebar);
this.cell = cell;
this.sidebar = sidebar;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment