diff --git a/projects/Infrastructure/Web/Mvc/CrudController.cs b/projects/Infrastructure/Web/Mvc/CrudController.cs index 6fea2fe4..61eb2f0e 100644 --- a/projects/Infrastructure/Web/Mvc/CrudController.cs +++ b/projects/Infrastructure/Web/Mvc/CrudController.cs @@ -140,6 +140,12 @@ namespace Infrastructure.Web.Mvc return Result(model); } + [HttpPost] + public virtual IActionResult EditApi([FromBody] TEditModel model) + { + return this.Edit(model); + } + [HttpPost] public virtual IActionResult Remove(List list) { @@ -181,7 +187,7 @@ namespace Infrastructure.Web.Mvc entity.IsDeleted = null; this.Repo.SaveChanges(); } - return RedirectTo(); + return Success(); } catch (DbUpdateException ex) { @@ -286,7 +292,7 @@ namespace Infrastructure.Web.Mvc } [ApiExplorerSettings(IgnoreApi = true)] - private IActionResult Result(object model) + protected IActionResult Result(object model) { if (this.Request.Headers["accept"].ToString().Contains("json", StringComparison.OrdinalIgnoreCase)) { @@ -300,5 +306,15 @@ namespace Infrastructure.Web.Mvc } return View(model); } + + [ApiExplorerSettings(IgnoreApi = true)] + protected IActionResult Success() + { + if (this.Request.Headers["accept"].ToString().Contains("json", StringComparison.OrdinalIgnoreCase)) + { + return this.NoContent(); + } + return RedirectTo(); + } } } \ No newline at end of file diff --git a/projects/IoT.Shared/Areas/Admin/Controlls/SharedController.cs b/projects/IoT.Shared/Areas/Admin/Controlls/SharedController.cs index e61fddb1..c7035713 100644 --- a/projects/IoT.Shared/Areas/Admin/Controlls/SharedController.cs +++ b/projects/IoT.Shared/Areas/Admin/Controlls/SharedController.cs @@ -54,7 +54,7 @@ namespace IoT.Shared.Areas.Admin.Controlls var dataService = scope.ServiceProvider.GetService(); dataService.Edit(model); } - return RedirectTo(); + return Success(); } catch (Exception ex) { @@ -63,7 +63,7 @@ namespace IoT.Shared.Areas.Admin.Controlls } } this.ToEditModel(null, model); - return View(model); + return Result(model); } public override IActionResult Delete(List list) diff --git a/projects/WebMVC/wwwroot/js/common.js b/projects/WebMVC/wwwroot/js/common.js index ac41feaa..dfbd5def 100644 --- a/projects/WebMVC/wwwroot/js/common.js +++ b/projects/WebMVC/wwwroot/js/common.js @@ -19,7 +19,7 @@ Vue.directive('valid', { }, update: function (el, binding) { if (binding.value !== binding.oldValue) { - console.log('value changed:' + el.innerHTML); + console.log('value changed:' + el.value); } } }); diff --git a/projects/WebMVC/wwwroot/router/shared/details.html b/projects/WebMVC/wwwroot/router/shared/details.html index 4472148b..7684241c 100644 --- a/projects/WebMVC/wwwroot/router/shared/details.html +++ b/projects/WebMVC/wwwroot/router/shared/details.html @@ -54,7 +54,7 @@ }, hasPermission: function (cmd) { var permission = cmd + '-' + this.entity; - return Enumerable.from(store.state.site.permissions).any(o => o === permission); + return Enumerable.from(store.state.permissions).any(o => o === permission); }, getComponent: function (key) { var property = this.data.schema.properties[key]; diff --git a/projects/WebMVC/wwwroot/router/shared/edit.html b/projects/WebMVC/wwwroot/router/shared/edit.html index 1e338694..6ce3a496 100644 --- a/projects/WebMVC/wwwroot/router/shared/edit.html +++ b/projects/WebMVC/wwwroot/router/shared/edit.html @@ -3,14 +3,16 @@

{{title}}

-
-
-
-
-
权限不足
-
-
-
+ +
+
+
@@ -20,24 +22,25 @@ +
{{value.description}}
- -
- +
@@ -64,6 +67,9 @@ this.$route.query.entity + '/' + this.$route.query.mode + (this.mode === 'Edit' ? ('?id=' + this.$route.query.id) : ''); + }, + action: function () { + return '/IoTCenter/Admin/' + this.$route.query.entity + '/' + this.$route.query.mode + 'Api'; } }, mounted: function () { @@ -75,11 +81,14 @@ var url = this.baseUrl + this.url; axios.get(url).then(function (response) { vm.data = response.data; - vm.$nextTick(function () { - $(vm.$refs.form).removeData('validator'); - $(vm.$refs.form).removeData('unobtrusiveValidation'); - $.validator.unobtrusive.parse(vm.$refs.form); - }); + this.validInit(); + }); + }, + validInit: function () { + vm.$nextTick(function () { + $(vm.$refs.form).removeData('validator'); + $(vm.$refs.form).removeData('unobtrusiveValidation'); + $.validator.unobtrusive.parse(vm.$refs.form); }); }, hasPermission: function () { @@ -110,8 +119,22 @@ } return result; }, - onSubmit: function () { - + onSubmit: function (e) { + if ($(e.target).validate()) { + var vm = this; + axios.post(e.target.action, this.data.model).then(function (response) { + if (response.status === 204) { + var url = '/router/shared/list.html?entity=' + vm.entity; + setTimeout(function () { + router.push(url); + }, 1000); + } + else { + vm.data = response.data; + vm.validInit(); + } + }); + } } } } diff --git a/projects/WebMVC/wwwroot/router/shared/edit/boolean.html b/projects/WebMVC/wwwroot/router/shared/edit/boolean.html index 84e54f7a..94b7442e 100644 --- a/projects/WebMVC/wwwroot/router/shared/edit/boolean.html +++ b/projects/WebMVC/wwwroot/router/shared/edit/boolean.html @@ -5,6 +5,10 @@ \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/router/shared/edit/cron.html b/projects/WebMVC/wwwroot/router/shared/edit/cron.html index b6157993..e5bef5d5 100644 --- a/projects/WebMVC/wwwroot/router/shared/edit/cron.html +++ b/projects/WebMVC/wwwroot/router/shared/edit/cron.html @@ -6,6 +6,11 @@ \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/router/shared/edit/multilinetext.html b/projects/WebMVC/wwwroot/router/shared/edit/multilinetext.html index cefc1639..445e5693 100644 --- a/projects/WebMVC/wwwroot/router/shared/edit/multilinetext.html +++ b/projects/WebMVC/wwwroot/router/shared/edit/multilinetext.html @@ -5,7 +5,11 @@ \ No newline at end of file diff --git a/projects/WebMVC/wwwroot/router/shared/list.html b/projects/WebMVC/wwwroot/router/shared/list.html index e7dda1f1..415107f5 100644 --- a/projects/WebMVC/wwwroot/router/shared/list.html +++ b/projects/WebMVC/wwwroot/router/shared/list.html @@ -12,7 +12,7 @@
- +
@@ -50,7 +50,7 @@ - + 编辑