From 89395b2cfb5c7b5a6237b4df0c832c706c52df2d Mon Sep 17 00:00:00 2001 From: liteng <930372551@qq.com> Date: Sun, 7 Oct 2018 10:19:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=A8=A1=E5=9E=8B=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/MeshController.cs | 2 +- .../src/editor/window/ModelEditWindow.js | 125 ++++++++++++++++++ .../src/editor/window/ModelWindow.js | 3 +- .../src/editor/window/SceneEditWindow.js | 2 +- 4 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 ShadowEditor.Web/src/editor/window/ModelEditWindow.js diff --git a/ShadowEditor.Server/Controllers/MeshController.cs b/ShadowEditor.Server/Controllers/MeshController.cs index 40c8c68e..96c42d3f 100644 --- a/ShadowEditor.Server/Controllers/MeshController.cs +++ b/ShadowEditor.Server/Controllers/MeshController.cs @@ -95,7 +95,7 @@ namespace ShadowEditor.Server.Controllers var pinyin = PinYinHelper.GetTotalPinYin(model.Name); - var filter = Builders.Filter.Eq("ID", objectId); + var filter = Builders.Filter.Eq("_id", objectId); var update1 = Builders.Update.Set("Name", model.Name); var update2 = Builders.Update.Set("TotalPinYin", pinyin.TotalPinYin); var update3 = Builders.Update.Set("FirstPinYin", pinyin.FirstPinYin); diff --git a/ShadowEditor.Web/src/editor/window/ModelEditWindow.js b/ShadowEditor.Web/src/editor/window/ModelEditWindow.js new file mode 100644 index 00000000..4e67523c --- /dev/null +++ b/ShadowEditor.Web/src/editor/window/ModelEditWindow.js @@ -0,0 +1,125 @@ +import UI from '../../ui/UI'; +import Ajax from '../../utils/Ajax'; + +/** + * 模型编辑窗口 + * @author tengge / https://github.com/tengge1 + * @param {*} options + */ +function ModelEditWindow(options) { + UI.Control.call(this, options); + this.app = options.app; + this.callback = options.callback || null; +} + +ModelEditWindow.prototype = Object.create(UI.Control.prototype); +ModelEditWindow.prototype.constructor = ModelEditWindow; + +ModelEditWindow.prototype.render = function () { + var container = UI.create({ + xtype: 'window', + id: 'window', + scope: this.id, + parent: this.parent, + title: '编辑模型', + width: '320px', + height: '280px', + shade: true, + children: [{ + xtype: 'row', + children: [{ + xtype: 'label', + text: '名称' + }, { + xtype: 'input', + id: 'name', + scope: this.id + }] + }, { + xtype: 'row', + children: [{ + xtype: 'label', + text: '缩略图' + }, { + xtype: 'imageuploader', + id: 'image', + scope: this.id, + server: this.app.options.server + }] + }, { + xtype: 'row', + style: { + justifyContent: 'center', + marginTop: '8px' + }, + children: [{ + xtype: 'button', + text: '确定', + style: { + margin: '0 8px' + }, + onClick: this.save.bind(this) + }, { + xtype: 'button', + text: '取消', + style: { + margin: '0 8px' + }, + onClick: this.hide.bind(this) + }] + }] + }); + container.render(); +}; + +ModelEditWindow.prototype.show = function () { + UI.get('window', this.id).show(); +}; + +ModelEditWindow.prototype.hide = function () { + UI.get('window', this.id).hide(); +}; + +ModelEditWindow.prototype.setData = function (data) { + this.data = data; + this.updateUI(); +}; + +ModelEditWindow.prototype.updateUI = function () { + if (this.data === undefined) { + return; + } + + var name = UI.get('name', this.id); + var image = UI.get('image', this.id); + name.setValue(this.data.Name); + image.setValue(this.data.Thumbnail); +}; + +ModelEditWindow.prototype.save = function () { + var server = this.app.options.server; + + if (this.data === undefined) { + return; + } + + var name = UI.get('name', this.id); + var image = UI.get('image', this.id); + + Ajax.post(`${server}/api/Mesh/Edit`, { + ID: this.data.ID, + Name: name.getValue(), + Image: image.getValue() + }, json => { + var obj = JSON.parse(json); + UI.msg(obj.Msg); + if (obj.Code === 200) { + this.hide(); + if (typeof (this.callback) === 'function') { + this.callback(obj); + } + } + }); +}; + +export default ModelEditWindow; \ No newline at end of file diff --git a/ShadowEditor.Web/src/editor/window/ModelWindow.js b/ShadowEditor.Web/src/editor/window/ModelWindow.js index da6d7397..8126bc52 100644 --- a/ShadowEditor.Web/src/editor/window/ModelWindow.js +++ b/ShadowEditor.Web/src/editor/window/ModelWindow.js @@ -3,6 +3,7 @@ import Ajax from '../../utils/Ajax'; import ModelLoader from '../../loader/ModelLoader'; import AddObjectCommand from '../../command/AddObjectCommand'; import UploadUtils from '../../utils/UploadUtils'; +import ModelEditWindow from './ModelEditWindow'; /** * 模型窗口 @@ -80,7 +81,7 @@ ModelWindow.prototype.onClickModel = function (model) { ModelWindow.prototype.onEditModel = function (data) { if (this.editWindow === undefined) { - this.editWindow = new SceneEditWindow({ + this.editWindow = new ModelEditWindow({ app: this.app, parent: this.parent, callback: this.update.bind(this) diff --git a/ShadowEditor.Web/src/editor/window/SceneEditWindow.js b/ShadowEditor.Web/src/editor/window/SceneEditWindow.js index 6fb0fbbf..6fffd9f2 100644 --- a/ShadowEditor.Web/src/editor/window/SceneEditWindow.js +++ b/ShadowEditor.Web/src/editor/window/SceneEditWindow.js @@ -2,7 +2,7 @@ import UI from '../../ui/UI'; import Ajax from '../../utils/Ajax'; /** - * 编辑场景窗口 + * 场景编辑窗口 * @author tengge / https://github.com/tengge1 * @param {*} options */