Former-commit-id: 95b00cb4c9411e7d18ac728ac5cebb282fcb367a
TangShanKaiPing
wanggang 6 years ago
parent 288551c6e2
commit cb88bdb378

@ -252,7 +252,7 @@ namespace Infrastructure.Web
{
context.Token = context.Request.Query["access_token"];
}
if (context.Request.Cookies.Keys.Contains("jwt"))
if (!context.Request.Headers.ContainsKey("Authorization") && context.Request.Cookies.Keys.Contains("jwt"))
{
context.Token = context.Request.Cookies["jwt"];
}

@ -24,6 +24,9 @@ namespace Application.Domain.Entities
[Display(Name = "ApiJson")]
public string ApiJson { get; set; }
[Display(Name = "序号")]
public int DisplayOrder { get; set; }
[Display(Name = "产品分类")]
public Guid CategoryId { get; set; }

@ -24,6 +24,9 @@ namespace Application.Models
[Display(Name = "路径")]
public string Path { get; set; }
[Display(Name = "序号")]
public int DisplayOrder { get; set; }
[Display(Name = "ApiJson")]
[DataType(DataType.MultilineText)]
public string ApiJson { get; set; }

@ -0,0 +1,53 @@
using Application.Domain.Entities;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.Linq;
namespace UserCenter.Controllers
{
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
public class DeviceController : ControllerBase
{
private readonly IConfiguration _cfg;
private readonly IRepository<Product> _productRepo;
private readonly IRepository<Category> _categoryRepo;
public DeviceController(IConfiguration cfg,
IRepository<Product> productRepo,
IRepository<Category> categoryRepo)
{
this._cfg = cfg;
this._productRepo = productRepo;
this._categoryRepo = categoryRepo;
}
[HttpPost]
public ActionResult GetProducts()
{
try
{
var model = this._productRepo.ReadOnlyTable()
.OrderBy(o => o.DisplayOrder)
.Select(o => new
{
o.Name,
o.Number,
o.Image,
o.DisplayOrder,
Count = o.Devices.Count()
});
return Ok(model);
}
catch (Exception ex)
{
ex.PrintStack();
return Problem(ex.Message);
}
}
}
}

@ -32,15 +32,24 @@ namespace UserCenter.Controllers
{
try
{
var model = this._nodeCategoryRepo.ReadOnlyTable()
.Include(o => o.CategoryNodes)
.ThenInclude(o => o.Node)
.OrderBy(o => o.DisplayOrder)
//var model = this._nodeCategoryRepo.ReadOnlyTable()
// .Include(o => o.CategoryNodes)
// .ThenInclude(o => o.Node)
// .OrderBy(o => o.DisplayOrder)
// .Select(o => new
// {
// o.Name,
// o.DisplayOrder,
// Nodes = o.CategoryNodes.Select(o => o.Node)
// });
var model = this._nodeRepo.ReadOnlyTable()
.Select(o => new
{
o.Name,
o.Number,
o.Image,
o.DisplayOrder,
Nodes = o.CategoryNodes.Select(o => o.Node)
Count = o.Devices.Count()
});
return Ok(model);
}

@ -0,0 +1,80 @@
using Application.Domain.Entities;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace UserCenter.Controllers
{
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
public class ProductController : ControllerBase
{
private readonly IConfiguration _cfg;
private readonly IRepository<Product> _productRepo;
private readonly IRepository<Device> _deviceRepo;
public ProductController(IConfiguration cfg,
IRepository<Product> productRepo,
IRepository<Device> deviceRepo)
{
this._cfg = cfg;
this._productRepo = productRepo;
this._deviceRepo = deviceRepo;
}
[HttpPost]
public ActionResult GetProducts()
{
try
{
var model = this._productRepo.ReadOnlyTable()
.OrderBy(o => o.DisplayOrder)
.Select(o => new
{
o.Name,
o.Number,
o.Image,
o.DisplayOrder,
Count = o.Devices.Count()
});
return Ok(model);
}
catch (Exception ex)
{
ex.PrintStack();
return Problem(ex.Message);
}
}
[HttpPost]
public ActionResult GetDevices([Required]string number)
{
try
{
var model = this._deviceRepo.ReadOnlyTable()
.Where(o => o.Product.Number == number)
.OrderBy(o => o.DisplayOrder)
.Select(o => new
{
o.Name,
o.Number,
o.DisplayName,
Image = o.Product.Image,
o.DisplayOrder,
o.Data
});
return Ok(model);
}
catch (Exception ex)
{
ex.PrintStack();
return Problem(ex.Message);
}
}
}
}

@ -0,0 +1,19 @@
<div class="page js_show">
<mt-header title="智慧教室">
<router-link to="/" slot="left">
<mt-button icon="back">back</mt-button>
</router-link>
</mt-header>
<div class="weui-panel__bd">
<div class="weui-grids">
<template v-if="model" v-for="node in model">
<router-link to="/IoTCenter/node" class="weui-grid">
<div class="weui-grid__icon">
<img :src="'/IoTCenter'+node.image" />
</div>
<p class="weui-grid__label">{{node.name}}</p>
</router-link>
</template>
</div>
</div>
</div>

@ -0,0 +1,29 @@
function IoTCenter_nodes() {
return Vue.component('IoTCenter_nodes', function (resolve, reject) {
axios.get("/IoTCenter/nodes.html").then(function (response) {
resolve({
template: response.data,
data() {
return {
model: null
};
},
mounted: function () {
var url = '/IoTCenter/api/v1/node/getNodes';
var component = this;
axios.post(url)
.then(function (response) {
component.model = response.data;
})
.catch(function (error) {
})
.finally(function () {
});
},
methods: {
}
})
});
});
}

@ -0,0 +1,19 @@
<div class="page js_show">
<mt-header title="设备">
<router-link to="/IoTCenter/products" slot="left">
<mt-button icon="back">back</mt-button>
</router-link>
</mt-header>
<div class="weui-panel__bd">
<div class="weui-grids">
<template v-if="model" v-for="device in model">
<router-link :to="{path:'/IoTCenter/device',query:{number:device.number}}" class="weui-grid">
<div class="weui-grid__icon">
<img :src="'/IoTCenter'+device.image" />
</div>
<p class="weui-grid__label">{{device.displayName}}</p>
</router-link>
</template>
</div>
</div>
</div>

@ -0,0 +1,31 @@
function IoTCenter_product() {
return Vue.component('IoTCenter_product', function (resolve, reject) {
axios.get("/IoTCenter/product.html").then(function (response) {
resolve({
template: response.data,
data() {
return {
model: null
};
},
mounted: function () {
console.log('当前路由:');
console.log(this.$route);
var url = '/IoTCenter/api/v1/product/getDevices?number='+this.$route.query.number;
var component = this;
axios.post(url)
.then(function (response) {
component.model = response.data;
})
.catch(function (error) {
})
.finally(function () {
});
},
methods: {
}
})
});
});
}

@ -0,0 +1,19 @@
<div class="page js_show">
<mt-header title="产品">
<router-link to="/" slot="left">
<mt-button icon="back">back</mt-button>
</router-link>
</mt-header>
<div class="weui-panel__bd">
<div class="weui-grids">
<template v-if="model" v-for="product in model">
<router-link :to="{path:'/IoTCenter/product',query:{number:product.number}}" class="weui-grid">
<div class="weui-grid__icon">
<img :src="'/IoTCenter'+product.image" />
</div>
<p class="weui-grid__label">{{product.name}}</p>
</router-link>
</template>
</div>
</div>
</div>

@ -0,0 +1,29 @@
function IoTCenter_products() {
return Vue.component('IoTCenter_products', function (resolve, reject) {
axios.get("/IoTCenter/products.html").then(function (response) {
resolve({
template: response.data,
data() {
return {
model: null
};
},
mounted: function () {
var url = '/IoTCenter/api/v1/product/getProducts';
var component = this;
axios.post(url)
.then(function (response) {
component.model = response.data;
})
.catch(function (error) {
})
.finally(function () {
});
},
methods: {
}
})
});
});
}

@ -100,7 +100,7 @@ router.beforeEach((to, from, next) => {
var path = to.path === '/' ? '/pchome' : to.path;
var url = path + '.js';
var method = path.replace(/\//g, '_').substr(1) + "()";
console.log('preRoute:' + path + '|' + url + '|' + method);
console.log('preRoute:from ' + from.path + ' to path ' + to.path);
$.getScript(url, function () {
var route = {
path: to.path,

@ -1,25 +1,24 @@
<div class="weui-tab" id="tab">
<div class="weui-tab__panel">
<div class="weui-tab__content">
<h2>消息</h2>
</div>
<div class="weui-tab__content">
<div class="weui-panel weui-panel_access">
<div class="weui-panel__hd">物联网</div>
<div class="weui-panel__bd">
<div class="weui-grids">
<router-link to="/IoTCenter/products" class="weui-grid">
<div class="weui-grid__icon">
<i class="ion ion-md-laptop weui-tabbar__icon"></i>
</div>
<p class="weui-grid__label">设备</p>
</router-link>
<router-link to="/IoTCenter/nodes" class="weui-grid">
<div class="weui-grid__icon">
<i class="ion ion-md-share weui-tabbar__icon"></i>
</div>
<p class="weui-grid__label">房间</p>
</router-link>
</div>
<div class="weui-panel__hd">物联网</div>
<div class="weui-panel__bd">
<div class="weui-grids">
<router-link to="/IoTCenter/products" class="weui-grid">
<div class="weui-grid__icon">
<i class="ion ion-md-laptop weui-tabbar__icon"></i>
</div>
<p class="weui-grid__label">设备</p>
</router-link>
<router-link to="/IoTCenter/nodes" class="weui-grid">
<div class="weui-grid__icon">
<i class="ion ion-md-share weui-tabbar__icon"></i>
</div>
<p class="weui-grid__label">智慧教室</p>
</router-link>
</div>
</div>
</div>
@ -35,7 +34,7 @@
</div>
</div>
</div>
<div class="weui-btn-area"> <a href="javascript:" class="weui-btn weui-btn_primary" v-on:click="logout">退出</a> </div>
<a href="javascript:;" class="weui-btn_cell weui-btn_cell-default" style="margin-top:16px;" v-on:click="logout">退出</a>
</div>
</div>
<div class="weui-tabbar">

Loading…
Cancel
Save