Former-commit-id: af55d2734bf023507fd17e339512b6937fefd63d
Former-commit-id: cf8afeed79e56b6ed544f2e97da1968e4f58d92e
TSXN
wanggang 5 years ago
parent 3377c05852
commit 7d8e2c4a02

@ -11,7 +11,7 @@ namespace Infrastructure.Application.Models
public string Name { get; set; } public string Name { get; set; }
[UIHint("SelectList")] [UIHint("SelectList")]
[Display(Name = "输入类")] [Display(Name = "输入类")]
public SettingType? Type { get; set; } public SettingType? Type { get; set; }
[Display(Name = "属性值")] [Display(Name = "属性值")]

@ -2,10 +2,13 @@ using Infrastructure.Application;
using Infrastructure.Application.Entites.Settings; using Infrastructure.Application.Entites.Settings;
using Infrastructure.Application.Models; using Infrastructure.Application.Models;
using Infrastructure.Application.Services.Settings; using Infrastructure.Application.Services.Settings;
using Infrastructure.Data;
using Infrastructure.Extensions; using Infrastructure.Extensions;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -15,15 +18,17 @@ namespace Infrastructure.Web.Mvc
[Area("Admin")] [Area("Admin")]
public class SettingController : BaseController public class SettingController : BaseController
{ {
private readonly IRepository<Setting> _settingRepo;
private readonly ISettingService _settingService; private readonly ISettingService _settingService;
public SettingController(ISettingService settingService) public SettingController(IRepository<Setting> settingRepo,ISettingService settingService)
{ {
this._settingRepo = settingRepo;
this._settingService = settingService; this._settingService = settingService;
} }
[Authorize(Roles = "Read-Setting")] [Authorize(Roles = "Read-Setting")]
public IActionResult Index(PagedList<Setting> model) public IActionResult Index(PagedListModel<EditSettingModel> model)
{ {
if (model is null) if (model is null)
{ {
@ -33,8 +38,18 @@ namespace Infrastructure.Web.Mvc
model.TotalCount = query.Count(); model.TotalCount = query.Count();
model.List.AddRange(query.Skip(model.PageSize * (model.PageIndex - 1)) model.List.AddRange(query.Skip(model.PageSize * (model.PageIndex - 1))
.Take(model.PageSize) .Take(model.PageSize)
.ToList()); .ToList()
return View(model); .Select(o=>o.To<EditSettingModel>()));
ViewData.SelectList(o=>model.Query.Type,()=>this.GetSelectList<SettingType>(model.Query.Type));
return Result(model);
}
[HttpGet]
public virtual IActionResult Details(Guid id)
{
var entity = this._settingRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id);
var model = entity.To<EditSettingModel>();
return Result(model);
} }
[Authorize(Roles = "Edit-Setting")] [Authorize(Roles = "Edit-Setting")]
@ -124,5 +139,20 @@ namespace Infrastructure.Web.Mvc
{ {
return PartialView("_Ajax", new EditSettingModel { Type = type }); return PartialView("_Ajax", new EditSettingModel { Type = type });
} }
[ApiExplorerSettings(IgnoreApi = true)]
private IActionResult Result(object model)
{
if (this.Request.Headers["accept"].ToString().Contains("json", StringComparison.OrdinalIgnoreCase))
{
return Json(new
{
schema = this.GetJsonSchema<EditSettingModel>(),
model,
data = ViewData
}, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
}
return View(model);
}
} }
} }

@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc; using Jint.Parser.Ast;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
@ -46,6 +48,13 @@ namespace Infrastructure.Extensions
return CreateJson(controller, metadata as DefaultModelMetadata); return CreateJson(controller, metadata as DefaultModelMetadata);
} }
public static SelectList GetSelectList<T>(this Controller controller,object selectedValue)
{
var values = from Enum e in Enum.GetValues(typeof(T))
select new { Id = e, Name = e.GetDisplayName() };
return new SelectList(values, "Id", "Name", selectedValue);
}
public static object CreateJson(this ControllerBase controller, DefaultModelMetadata metadata) public static object CreateJson(this ControllerBase controller, DefaultModelMetadata metadata)
{ {
if (metadata is null) if (metadata is null)

@ -29,7 +29,7 @@
{ {
"library": "vue@2.6.11", "library": "vue@2.6.11",
"destination": "wwwroot/lib/vue", "destination": "wwwroot/lib/vue",
"files": [ "vue.min.js" ] "files": [ "vue.min.js","vue.js" ]
}, },
{ {
"library": "vue-router@3.2.0", "library": "vue-router@3.2.0",

@ -32,7 +32,7 @@
<script src="lib/linq.js/linq.min.js"></script> <script src="lib/linq.js/linq.min.js"></script>
<script src="lib/axios/axios.min.js"></script> <script src="lib/axios/axios.min.js"></script>
<script src="lib/pubsub-js/pubsub.min.js"></script> <script src="lib/pubsub-js/pubsub.min.js"></script>
<script src="lib/vue/vue.min.js"></script> <script src="lib/vue/vue.js"></script>
<script src="lib/vuex/vuex.min.js"></script> <script src="lib/vuex/vuex.min.js"></script>
<script src="lib/vue-router/vue-router.min.js"></script> <script src="lib/vue-router/vue-router.min.js"></script>
<script src="lib/jwt-decode/build/jwt-decode.min.js"></script> <script src="lib/jwt-decode/build/jwt-decode.min.js"></script>

@ -10,6 +10,7 @@
'edit-string', 'edit-string',
'edit-boolean', 'edit-boolean',
'edit-integer', 'edit-integer',
'edit-selectlist',
]; ];
for (var i = 0; i < formComponents.length; i++) { for (var i = 0; i < formComponents.length; i++) {
var name = formComponents[i]; var name = formComponents[i];

File diff suppressed because it is too large Load Diff

@ -3,6 +3,6 @@
</template> </template>
<script> <script>
export default { export default {
props: ['key', 'value', 'data'] props: ['name', 'value', 'data']
}; };
</script> </script>

@ -3,6 +3,6 @@
</template> </template>
<script> <script>
export default { export default {
props: ['key', 'value', 'data'] props: ['name', 'value', 'data']
}; };
</script> </script>

@ -0,0 +1,26 @@
<template>
<div>
<select class="form-control" :name="name">
<option value="">请选择</option>
<template v-for="item in list">
<option v-if="item.value===value" :value="item.value" selected>{{item.text}}</option>
<option v-else :value="item.value">{{item.text}}</option>
</template>
</select>
</div>
</template>
<script>
export default {
props: ['name', 'value', 'data','prefix'],
computed:{
list:function(){
var key=this.name;
if(this.prefix)
{
key=this.name.substring(this.prefix.length+1);
}
return this.data[key+'SelectList'];
}
}
};
</script>

@ -9,7 +9,7 @@
<router-link :to="{path:'/'}" class="nav-link">首页</router-link> <router-link :to="{path:'/'}" class="nav-link">首页</router-link>
</li> </li>
</ul> </ul>
<ul class="navbar-nav ml-auto"> <ul class="navbar-nav ml-auto" v-if="model.username">
<li class="nav-item"> <li class="nav-item">
<router-link class="nav-link" to="/router/user.html">{{model.username}}</router-link> <router-link class="nav-link" to="/router/user.html">{{model.username}}</router-link>
</li> </li>

@ -12,7 +12,7 @@
<div class="form-group row"> <div class="form-group row">
<label class="col-sm-3 col-form-label" :for="key">{{value.title}}:</label> <label class="col-sm-3 col-form-label" :for="key">{{value.title}}:</label>
<div class="col-sm-9"> <div class="col-sm-9">
<component :is="getQueryComponent(value)" :title="value.title" :name="'query.'+key" :value="data.model.query[key]" v-if="data.model.query" /> <component :is="getQueryComponent(value)" :title="value.title" :name="'query.'+key" :value="data.model.query[key]" v-bind:data="data.data" v-bind:prefix="'query'" v-if="data.model.query" />
</div> </div>
</div> </div>
</div> </div>
@ -50,7 +50,7 @@
<input type="checkbox" name="list[]" :value="item.id" /> <input type="checkbox" name="list[]" :value="item.id" />
</td> </td>
<td v-for="(value,key,index) in data.schema.properties" v-if="showForList(key,value)"> <td v-for="(value,key,index) in data.schema.properties" v-if="showForList(key,value)">
<component :is="getDisplayComponent(key)" v-bind:key="key" v-bind:value="item[key]" v-bind:data="data.data" :mode="'list'" /> <component :is="getDisplayComponent(key)" v-bind:name="key" v-bind:value="item[key]" v-bind:data="data.data" :mode="'list'" />
</td> </td>
<td v-if="hasPermission('Edit')"> <td v-if="hasPermission('Edit')">
<a href="javascript:;" class="btn btn-sm btn-info">编辑</a> <a href="javascript:;" class="btn btn-sm btn-info">编辑</a>
@ -130,7 +130,7 @@
return template; return template;
}, },
getQueryComponent: function (value) { getQueryComponent: function (value) {
var template = 'edit-' + (value.format || value.type); var template = 'edit-' + (value.ui || value.format || value.type);
console.log(template); console.log(template);
return template; return template;
}, },

@ -1,7 +1,7 @@
<template> <template>
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-5"> <div class="col-sm-12 col-md-5">
<div class="dataTables_info">共{{total}}条 当前数据{{(index-1)*size+1}}-{{index*size}} 当前页{{index}}/{{getPageCount()}}</div> <div class="dataTables_info">共{{total}}条 当前数据{{(index-1)*size+1}}-{{index*size>total?total:index*size}} 当前页{{index}}/{{getPageCount()}}</div>
</div> </div>
<div class="col-sm-12 col-md-7"> <div class="col-sm-12 col-md-7">
<div class="dataTables_paginate paging_simple_numbers"> <div class="dataTables_paginate paging_simple_numbers">
@ -44,7 +44,7 @@
}, },
sizeList: { sizeList: {
type: Array, type: Array,
default: [20, 50, 100] default: ()=>[20, 50, 100]
}, },
nav: { nav: {
type: Function, type: Function,

Loading…
Cancel
Save