编辑场景名称。

This commit is contained in:
liteng 2018-10-06 16:51:46 +08:00
parent 8c8b870118
commit d74bca252d
5 changed files with 106 additions and 3 deletions

View File

@ -99,6 +99,56 @@ namespace ShadowEditor.Server.Controllers
});
}
/// <summary>
/// 编辑场景信息
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost]
public JsonResult Edit(EditSceneModel model)
{
var objectId = ObjectId.GenerateNewId();
if (!string.IsNullOrEmpty(model.ID) && !ObjectId.TryParse(model.ID, out objectId))
{
return Json(new
{
Code = 300,
Msg = "场景ID不合法。"
});
}
if (string.IsNullOrEmpty(model.Name))
{
return Json(new
{
Code = 300,
Msg = "场景名称不允许为空。"
});
}
if (model.Name.StartsWith("_"))
{
return Json(new
{
Code = 300,
Msg = "场景名称不允许以下划线开头。"
});
}
var mongo = new MongoHelper();
var filter = Builders<BsonDocument>.Filter.Eq("ID", objectId);
var update = Builders<BsonDocument>.Update.Set("Name", model.Name);
mongo.UpdateOne(Constant.SceneCollectionName, filter, update);
return Json(new
{
Code = 200,
Msg = "编辑场景成功!"
});
}
/// <summary>
/// 保存场景
/// </summary>

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShadowEditor.Server.Scene
{
/// <summary>
/// 场景编辑数据模型
/// </summary>
public class EditSceneModel
{
/// <summary>
/// 场景ID
/// </summary>
public string ID { get; set; }
/// <summary>
/// 场景名称
/// </summary>
public string Name { get; set; }
}
}

View File

@ -125,6 +125,7 @@
<Compile Include="MMD\MMDSaver.cs" />
<Compile Include="MMD\MMDType.cs" />
<Compile Include="Result.cs" />
<Compile Include="Scene\EditSceneModel.cs" />
<Compile Include="Scene\SaveSceneModel.cs" />
<Compile Include="Scene\SceneModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -9,6 +9,7 @@ import Ajax from '../../utils/Ajax';
function SceneEditWindow(options) {
UI.Control.call(this, options);
this.app = options.app;
this.callback = options.callback || null;
}
SceneEditWindow.prototype = Object.create(UI.Control.prototype);
@ -46,13 +47,15 @@ SceneEditWindow.prototype.render = function () {
text: '确定',
style: {
margin: '0 8px'
}
},
onClick: this.save.bind(this)
}, {
xtype: 'button',
text: '取消',
style: {
margin: '0 8px'
}
},
onClick: this.hide.bind(this)
}]
}]
});
@ -81,4 +84,28 @@ SceneEditWindow.prototype.updateUI = function () {
name.setValue(this.data.Name);
};
SceneEditWindow.prototype.save = function () {
var server = this.app.options.server;
if (this.data === undefined) {
return;
}
var name = UI.get('name', this.id);
Ajax.post(`${server}/api/Scene/Edit`, {
ID: this.data.ID,
Name: name.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 SceneEditWindow;

View File

@ -181,7 +181,8 @@ SceneWindow.prototype.onEditScene = function (data) {
if (this.editWindow === undefined) {
this.editWindow = new SceneEditWindow({
app: this.app,
parent: this.parent
parent: this.parent,
callback: this.update.bind(this)
});
this.editWindow.render();
}