修复页面加载不出的问题

This commit is contained in:
陈淳
2022-10-13 14:04:48 +08:00
parent edde5f8a88
commit ea4ddb68f3
17 changed files with 122 additions and 52 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization; using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
@@ -6,6 +7,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Models; using Yi.Framework.Common.Models;
using Yi.Framework.DTOModel;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Model.Models; using Yi.Framework.Model.Models;
using Yi.Framework.Repository; using Yi.Framework.Repository;
@@ -20,9 +22,11 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public class ArticleController : BaseSimpleCrudController<ArticleEntity> public class ArticleController : BaseSimpleCrudController<ArticleEntity>
{ {
private IArticleService _iArticleService; private IArticleService _iArticleService;
public ArticleController(ILogger<ArticleEntity> logger, IArticleService iArticleService) : base(logger, iArticleService) private IMapper _mapper;
public ArticleController(ILogger<ArticleEntity> logger, IArticleService iArticleService, IMapper mapper) : base(logger, iArticleService)
{ {
_iArticleService = iArticleService; _iArticleService = iArticleService;
_mapper = mapper;
} }
/// <summary> /// <summary>
@@ -34,7 +38,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpGet] [HttpGet]
public async Task<Result> PageList([FromQuery] ArticleEntity entity, [FromQuery] PageParModel page) public async Task<Result> PageList([FromQuery] ArticleEntity entity, [FromQuery] PageParModel page)
{ {
return Result.Success().SetData(await _iArticleService.SelctPageList(entity, page)); var pageData= await _iArticleService.SelctPageList(entity, page);
return Result.Success().SetData(new PageModel() { Data = _mapper.Map<List<ArticleVo>>(pageData.Data), Total = pageData.Total }) ;
} }
/// <summary> /// <summary>
@@ -44,7 +49,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
/// <returns></returns> /// <returns></returns>
public override Task<Result> Add(ArticleEntity entity) public override Task<Result> Add(ArticleEntity entity)
{ {
entity.UserId=HttpContext.GetUserIdInfo(); entity.UserId = HttpContext.GetUserIdInfo();
return base.Add(entity); return base.Add(entity);
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.DTOModel
{
public class ArticleVo
{
public long Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public long? UserId { get; set; }
public long? CreateUser { get; set; }
public DateTime? CreateTime { get; set; }
public long? ModifyUser { get; set; }
public DateTime? ModifyTime { get; set; }
public bool? IsDeleted { get; set; }
public long? TenantId { get; set; }
public int? OrderNum { get; set; }
public string Remark { get; set; }
public List<string> Images { get; set; }
public UserVo User { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.DTOModel
{
/// <summary>
/// 前端只需要这些数据即可
/// </summary>
public class UserVo
{
public string Name { get; set; }
public int? Age { get; set; }
public string UserName { get; set; }
public string Icon { get; set; }
public string Nick { get; set; }
//public string Email { get; set; }
//public string Ip { get; set; }
//public string Address { get; set; }
//public string Phone { get; set; }
public string Introduction { get; set; }
public int? Sex { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using SqlSugar;
namespace Yi.Framework.Model.Models
{
public partial class ArticleEntity:IBaseModelEntity
{
[Navigate(NavigateType.OneToOne,nameof(UserId))]
public UserEntity User { get; set; }
}
}

View File

@@ -14,6 +14,7 @@ namespace Yi.Framework.Service
{ {
RefAsync<int> total = 0; RefAsync<int> total = 0;
var data = await _repository._DbQueryable var data = await _repository._DbQueryable
.Includes(x => x.User)
//.WhereIF(!string.IsNullOrEmpty(config.ConfigName), u => u.ConfigName.Contains(config.ConfigName)) //.WhereIF(!string.IsNullOrEmpty(config.ConfigName), u => u.ConfigName.Contains(config.ConfigName))
//.WhereIF(!string.IsNullOrEmpty(config.ConfigKey), u => u.ConfigKey.Contains(config.ConfigKey)) //.WhereIF(!string.IsNullOrEmpty(config.ConfigKey), u => u.ConfigKey.Contains(config.ConfigKey))
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime) .WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)

View File

@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.DTOModel;
using Yi.Framework.Model.Models;
namespace Yi.Framework.WebCore.Mapper namespace Yi.Framework.WebCore.Mapper
{ {
@@ -12,7 +14,8 @@ namespace Yi.Framework.WebCore.Mapper
// 添加你的实体映射关系. // 添加你的实体映射关系.
public AutoMapperProfile() public AutoMapperProfile()
{ {
//CreateMap<DBPoundSheet, PoundSheetViewModel>(); CreateMap<ArticleEntity, ArticleVo > ();
CreateMap<UserEntity, UserVo>();
} }
} }

View File

@@ -856,7 +856,7 @@
<script setup name="Index"> <script setup name="Index">
import useSocketStore from '@/store/modules/socket' import useSocketStore from '@/store/modules/socket'
import { ref } from 'vue-demi'; import { ref } from 'vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
const socketStore=useSocketStore(); const socketStore=useSocketStore();
const {onlineNum}=storeToRefs(socketStore); const {onlineNum}=storeToRefs(socketStore);

View File

@@ -3,9 +3,11 @@ import './style.css'
import 'vant/es/image-preview/style'; import 'vant/es/image-preview/style';
import 'vant/es/toast/style'; import 'vant/es/toast/style';
import 'vant/es/dialog/style'; import 'vant/es/dialog/style';
import 'vant/es/notify/style';
import router from './router' import router from './router'
import store from './store' import store from './store'
import './permission' import './permission'
import App from './App.vue' import App from './App.vue'
const app=createApp(App) const app=createApp(App)

View File

@@ -7,8 +7,7 @@ const useUserStore = defineStore(
{ {
state: () => ({ state: () => ({
token: getToken(), token: getToken(),
name: '', user:{username:"",nick:""},
avatar: '',
roles: [], roles: [],
permissions: [] permissions: []
}), }),
@@ -49,7 +48,8 @@ const useUserStore = defineStore(
} }
// this.roles = ["admin"]; // this.roles = ["admin"];
// this.permissions=["*:*:*"] // this.permissions=["*:*:*"]
this.name = user.userName this.user.username = user.userName;
this.user.nick=user.nick
this.avatar = avatar; this.avatar = avatar;
resolve(res) resolve(res)
}).catch(error => { }).catch(error => {

View File

@@ -5,6 +5,7 @@ import JsonBig from 'json-bigint'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import { Notify } from 'vant';
// import VuetifyDialogPlugin from 'vuetify-dialog/nuxt/index'; // import VuetifyDialogPlugin from 'vuetify-dialog/nuxt/index';
export let isRelogin = { show: false }; export let isRelogin = { show: false };
const myaxios = axios.create({ const myaxios = axios.create({
@@ -40,37 +41,7 @@ myaxios.interceptors.request.use(function(config) {
myaxios.interceptors.response.use(async function(response) { myaxios.interceptors.response.use(async function(response) {
//成功 //成功
const resp = response.data const resp = response.data
// if (resp.code == undefined && resp.message == undefined) {
// alert("直接爆炸")
// // vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
// // position: "top-right",
// // timeout: 5000,
// // });
// } else if (resp.code == 401) {
// alert("登录过期!重新登录");
// const router = useRouter();
// router.push({ path:"/login" });
// // const res = await vm.$dialog.error({
// // text: `错误代码:${resp.code},原因:${resp.message}<br>是否重新进行登录?`,
// // title: '错误',
// // actions: {
// // 'false': '取消',
// // 'true': '跳转'
// // }
// // });
// // if (res) {
// // vm.$router.push({ path: "/login" });
// // }
// } else if (resp.code !== 200) {
// // vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
// // position: "top-right",
// // timeout: 5000,
// // });
// }
// store.dispatch("closeLoad"); // store.dispatch("closeLoad");
return resp; return resp;
}, async function(error) { }, async function(error) {
@@ -79,17 +50,13 @@ const resp = error.response.data
if (resp.code == undefined && resp.message == undefined) { if (resp.code == undefined && resp.message == undefined) {
alert("直接爆炸") Notify({ type: 'danger', message: '未知错误' });
// vm.$dialog.notify.error("错误代码:无,原因:与服务器失去连接", {
// position: "top-right",
// timeout: 5000,
// });
} else if (resp.code == 401) { } else if (resp.code == 401) {
if (!isRelogin.show) { if (!isRelogin.show) {
alert("登录过期!重新登录"); Notify({ type: 'warning', message: '登录过期' });
//登出 //登出
useUserStore().logOut().then(() => { useUserStore().logOut().then(() => {
location.href = '/'; location.href = '/';
@@ -113,7 +80,7 @@ if (resp.code == undefined && resp.message == undefined) {
// } // }
} else if (resp.code !== 200) { } else if (resp.code !== 200) {
alert("服务器内部错误") Notify({ type: 'danger', message: `错误代码:${resp.code},原因:${resp.message}` });
// vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, { // vm.$dialog.notify.error(`错误代码:${resp.code},原因:${resp.message}`, {
// position: "top-right", // position: "top-right",
// timeout: 5000, // timeout: 5000,

View File

@@ -19,7 +19,7 @@
</van-col> </van-col>
<van-col span="14" class="centerTitle"> <van-col span="14" class="centerTitle">
<span class="justtitle"> 大白</span> <span class="justtitle">{{item.user==null?"-":(item.user.nick??item.user.username)}}</span>
<br /> <br />
<app-createTime :time="item.createTime" /> <app-createTime :time="item.createTime" />
</van-col> </van-col>
@@ -30,7 +30,7 @@
<van-col class="rowBody" span="24">{{ item.content }}</van-col> <van-col class="rowBody" span="24">{{ item.content }}</van-col>
<!-- <van-col <van-col
span="8" span="8"
v-for="(image, imageIndex) in item.images" v-for="(image, imageIndex) in item.images"
:key="imageIndex" :key="imageIndex"
@@ -42,7 +42,7 @@
:src="url + image" :src="url + image"
radius="5" radius="5"
/> />
</van-col> --> </van-col>
<van-col span="24" class="bottomRow"> <van-col span="24" class="bottomRow">
<van-grid direction="horizontal" :column-num="3"> <van-grid direction="horizontal" :column-num="3">

View File

@@ -16,7 +16,7 @@
src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg" src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/> />
</van-col> </van-col>
<van-col span="12" class="title"><span>大白不在家</span></van-col> <van-col span="12" class="title"><span>{{user.nick}}</span></van-col>
<van-col span="6" class="subtitle" <van-col span="6" class="subtitle"
><span>个人主页<van-icon name="arrow" /></span ><span>个人主页<van-icon name="arrow" /></span
></van-col> ></van-col>
@@ -99,6 +99,7 @@ import { AppGridData } from "@/type/class/AppGridData.ts";
import { ref } from "vue"; import { ref } from "vue";
import { Dialog } from "vant"; import { Dialog } from "vant";
import useUserStore from "@/store/modules/user"; import useUserStore from "@/store/modules/user";
import { storeToRefs } from 'pinia';
const show = ref<boolean>(false); const show = ref<boolean>(false);
let data1: AppGridData = { let data1: AppGridData = {
head: "个人中心", head: "个人中心",
@@ -159,13 +160,15 @@ let data3: AppGridData = {
}, },
], ],
}; };
const userStore=useUserStore();
const {user}=storeToRefs(useUserStore());
const outLog = () => { const outLog = () => {
Dialog.confirm({ Dialog.confirm({
title: "提示", title: "提示",
message: "确定退出当前用户吗?", message: "确定退出当前用户吗?",
}) })
.then(() => { .then(() => {
useUserStore() userStore
.logOut() .logOut()
.then((response: any) => { .then((response: any) => {
location.href = "/"; location.href = "/";
@@ -175,6 +178,7 @@ const outLog = () => {
// on cancel // on cancel
}); });
}; };
</script> </script>
<style scoped> <style scoped>
.grid { .grid {