From 064fcbf6cfbd4721df0c334f481de11b76fc95cb Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Sun, 27 Oct 2019 14:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E7=94=A8=E6=88=B7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShadowEditor.Model/System/ConfigModel.cs | 5 + .../Controllers/System/ConfigController.cs | 43 ++++++- .../System/InitializeController.cs | 11 +- ShadowEditor.Web/locales/zh-CN.json | 4 +- .../src/editor/menu/SystemMenu.jsx | 45 +++++-- .../src/editor/system/LoginWindow.jsx | 17 ++- .../src/editor/system/SystemSettingWindow.jsx | 110 ++++++++++++++++++ .../editor/system/css/SystemSettingWindow.css | 3 + 8 files changed, 221 insertions(+), 17 deletions(-) create mode 100644 ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx create mode 100644 ShadowEditor.Web/src/editor/system/css/SystemSettingWindow.css diff --git a/ShadowEditor.Model/System/ConfigModel.cs b/ShadowEditor.Model/System/ConfigModel.cs index f708ffe3..60c1d967 100644 --- a/ShadowEditor.Model/System/ConfigModel.cs +++ b/ShadowEditor.Model/System/ConfigModel.cs @@ -15,5 +15,10 @@ namespace ShadowEditor.Model.System /// ID /// public string ID { get; set; } + + /// + /// 默认注册用户ID + /// + public string DefaultRegisterRole { get; set; } } } diff --git a/ShadowEditor.Server/Controllers/System/ConfigController.cs b/ShadowEditor.Server/Controllers/System/ConfigController.cs index 16e32dc5..2f2a7434 100644 --- a/ShadowEditor.Server/Controllers/System/ConfigController.cs +++ b/ShadowEditor.Server/Controllers/System/ConfigController.cs @@ -43,7 +43,8 @@ namespace ShadowEditor.Server.Controllers.System config = new BsonDocument { ["ID"] = ObjectId.GenerateNewId(), - ["Initialized"] = false + ["Initialized"] = false, + ["DefaultRegisterRole"] = "" }; mongo.InsertOne(Constant.ConfigCollectionName, config); } @@ -53,6 +54,7 @@ namespace ShadowEditor.Server.Controllers.System ["ID"] = config["ID"].ToString(), ["EnableAuthority"] = ConfigurationManager.AppSettings["EnableAuthority"] == "true", ["Initialized"] = config.Contains("Initialized") ? config["Initialized"].ToBoolean() : false, + ["DefaultRegisterRole"] = config.Contains("DefaultRegisterRole") ? config["DefaultRegisterRole"].ToString() : "", ["IsLogin"] = false, ["Username"] = "", ["Name"] = "", @@ -100,5 +102,44 @@ namespace ShadowEditor.Server.Controllers.System Data = model, }); } + + /// + /// 保存系统设置 + /// + /// + /// + [HttpPost] + public JsonResult Save(ConfigModel model) + { + var mongo = new MongoHelper(); + + var filter = Builders.Filter.Empty; + + // 获取配置 + var doc = mongo.FindOne(Constant.ConfigCollectionName, filter); + + if (doc == null) + { + doc = new BsonDocument + { + ["ID"] = ObjectId.GenerateNewId(), + ["Initialized"] = false, + ["DefaultRegisterRole"] = model.DefaultRegisterRole + }; + mongo.InsertOne(Constant.ConfigCollectionName, doc); + } + else + { + var update = Builders.Update.Set("DefaultRegisterRole", model.DefaultRegisterRole); + mongo.UpdateOne(Constant.ConfigCollectionName, filter, update); + } + + return Json(new + { + Code = 200, + Msg = "Save Successfully.", + Data = model, + }); + } } } diff --git a/ShadowEditor.Server/Controllers/System/InitializeController.cs b/ShadowEditor.Server/Controllers/System/InitializeController.cs index 47e27bd7..8cff7f31 100644 --- a/ShadowEditor.Server/Controllers/System/InitializeController.cs +++ b/ShadowEditor.Server/Controllers/System/InitializeController.cs @@ -56,12 +56,15 @@ namespace ShadowEditor.Server.Controllers.System }); } + var defaultRegisterRoleID = ObjectId.GenerateNewId(); + if (doc == null) { doc = new BsonDocument { ["ID"] = ObjectId.GenerateNewId(), - ["Initialized"] = true + ["Initialized"] = true, + ["DefaultRegisterRole"] = defaultRegisterRoleID }; mongo.InsertOne(Constant.ConfigCollectionName, doc); } @@ -69,7 +72,9 @@ namespace ShadowEditor.Server.Controllers.System { var filter11 = Builders.Filter.Eq("_id", doc["_id"].AsObjectId); var update11 = Builders.Update.Set("Initialized", true); - mongo.UpdateOne(Constant.ConfigCollectionName, filter11, update11); + var update12 = Builders.Update.Set("DefaultRegisterRole", defaultRegisterRoleID); + var update13 = Builders.Update.Combine(update11, update12); + mongo.UpdateOne(Constant.ConfigCollectionName, filter11, update13); } // 初始化角色 @@ -95,7 +100,7 @@ namespace ShadowEditor.Server.Controllers.System var role2 = new BsonDocument { - ["ID"] = ObjectId.GenerateNewId(), + ["ID"] = defaultRegisterRoleID, ["Name"] = "User", ["CreateTime"] = now, ["UpdateTime"] = now, diff --git a/ShadowEditor.Web/locales/zh-CN.json b/ShadowEditor.Web/locales/zh-CN.json index f5d8a66a..e9e272f6 100644 --- a/ShadowEditor.Web/locales/zh-CN.json +++ b/ShadowEditor.Web/locales/zh-CN.json @@ -886,5 +886,7 @@ "Pleast select a department.": "请选择机构。", "Delete this department?": "删除这个机构?", "PDept Name": "父机构名称", - "Not allowed.": "不允许。" + "Not allowed.": "不允许。", + "System Setting": "系统设置", + "Register Default Role": "注册默认角色" } \ No newline at end of file diff --git a/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx b/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx index 6e5afd36..dc9a0b44 100644 --- a/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx +++ b/ShadowEditor.Web/src/editor/menu/SystemMenu.jsx @@ -1,8 +1,9 @@ -import { classNames, PropTypes, MenuBar, MenuItem, MenuItemSeparator } from '../../third_party'; +import { MenuItem, MenuItemSeparator } from '../../third_party'; import DepartmentManagementWindow from '../system/DepartmentManagementWindow.jsx'; import UserManageWindow from '../system/UserManageWindow.jsx'; import RoleManageWindow from '../system/RoleManageWindow.jsx'; import AuthorityManagementWindow from '../system/AuthorityManagementWindow.jsx'; +import SystemSettingWindow from '../system/SystemSettingWindow.jsx'; /** * 系统菜单 @@ -18,23 +19,46 @@ class SystemMenu extends React.Component { this.handleUser = this.handleUser.bind(this); this.handleRole = this.handleRole.bind(this); this.handleAuthority = this.handleAuthority.bind(this); + this.handleSystemSetting = this.handleSystemSetting.bind(this); this.handleResetSystem = this.handleResetSystem.bind(this); this.commitResetSystem = this.commitResetSystem.bind(this); } render() { - const { enableAuthority, initialized, login } = app.config; + const { initialized } = app.config; return - + - - + + - - + + - + + ; } @@ -86,6 +110,11 @@ class SystemMenu extends React.Component { app.addElement(win); } + handleSystemSetting() { + const win = app.createElement(SystemSettingWindow); + app.addElement(win); + } + handleResetSystem() { app.confirm({ title: _t('Query'), diff --git a/ShadowEditor.Web/src/editor/system/LoginWindow.jsx b/ShadowEditor.Web/src/editor/system/LoginWindow.jsx index 28ba7919..73d5df31 100644 --- a/ShadowEditor.Web/src/editor/system/LoginWindow.jsx +++ b/ShadowEditor.Web/src/editor/system/LoginWindow.jsx @@ -29,17 +29,26 @@ class LoginWindow extends React.Component { style={{ width: '320px', height: '200px' }} mask={false} onClose={this.handleClose} - > + >
- - + + - +
diff --git a/ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx b/ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx new file mode 100644 index 00000000..fd31c825 --- /dev/null +++ b/ShadowEditor.Web/src/editor/system/SystemSettingWindow.jsx @@ -0,0 +1,110 @@ +import './css/SystemSettingWindow.css'; +import { Window, Content, Buttons, Form, FormControl, Label, Button, Select } from '../../third_party'; + +/** + * 系统设置窗口 + * @author tengge / https://github.com/tengge1 + */ +class SystemSettingWindow extends React.Component { + constructor(props) { + super(props); + + this.state = { + roles: {}, + registerRole: '' + }; + + this.handleChange = this.handleChange.bind(this); + this.handleSave = this.handleSave.bind(this); + this.handleClose = this.handleClose.bind(this); + } + + render() { + const { roles, registerRole } = this.state; + + return + +
+ + +