点赞功能接口开发
This commit is contained in:
Binary file not shown.
@@ -4,21 +4,6 @@
|
||||
<name>Yi.Framework.ApiMicroservice</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.PageList(Yi.Framework.Model.Models.ArticleEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<param name="page"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.Add(Yi.Framework.Model.Models.ArticleEntity)">
|
||||
<summary>
|
||||
添加
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
|
||||
<summary>
|
||||
Json To Sql 类比模式,通用模型
|
||||
@@ -150,6 +135,33 @@
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AgreeController.Operate(System.Int64)">
|
||||
<summary>
|
||||
点赞操作
|
||||
</summary>
|
||||
<param name="articleId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.ArticleController">
|
||||
<summary>
|
||||
文章控制器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.PageList(Yi.Framework.Model.Models.ArticleEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<param name="page"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.Add(Yi.Framework.Model.Models.ArticleEntity)">
|
||||
<summary>
|
||||
添加
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.SkuController.PageList(Yi.Framework.Model.Models.SkuEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Org.BouncyCastle.Asn1.IsisMtt.X509;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class AgreeController : ControllerBase
|
||||
{
|
||||
[Autowired]
|
||||
public IAgreeService _iAgreeService { get; set; }
|
||||
[Autowired]
|
||||
public IArticleService _iArticleService { get; set; }
|
||||
[Autowired]
|
||||
public ILogger<AgreeEntity> _logger { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 点赞操作
|
||||
/// </summary>
|
||||
/// <param name="articleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> Operate(long articleId)
|
||||
{
|
||||
//long userId = HttpContext.GetUserIdInfo();
|
||||
long userId = 1L;
|
||||
var article = await _iArticleService._repository.GetByIdAsync(articleId);
|
||||
if (await _iAgreeService._repository.IsAnyAsync(u => u.UserId == userId && u.ArticleId == articleId))
|
||||
{
|
||||
//已点赞,取消点赞
|
||||
await _iAgreeService._repository.UseTranAsync(async () =>
|
||||
{
|
||||
await _iAgreeService._repository.DeleteAsync(u => u.UserId == userId && u.ArticleId == articleId);
|
||||
await _iArticleService._repository.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum - 1 });
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//未点赞,添加点赞记录
|
||||
await _iAgreeService._repository.UseTranAsync(async () =>
|
||||
{
|
||||
await _iAgreeService._repository.InsertAsync(new AgreeEntity { UserId = userId, ArticleId = articleId });
|
||||
await _iArticleService._repository.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum + 1 });
|
||||
});
|
||||
|
||||
}
|
||||
return Result.Success("这里业务全部拆开放service层去");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
@@ -17,6 +17,9 @@ using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章控制器
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class ArticleController : BaseSimpleCrudController<ArticleEntity>
|
||||
@@ -1,6 +1,4 @@
|
||||
using Hangfire;
|
||||
using Hangfire.MemoryStorage.Database;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
@@ -18,8 +18,6 @@ using Yi.Framework.WebCore.LogExtend;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Yi.Framework.WebCore.AutoFacExtend;
|
||||
using Hangfire;
|
||||
using Hangfire.MemoryStorage;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddCommandLine(args);
|
||||
@@ -43,14 +41,14 @@ builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ģ<EFBFBD><C4A3>
|
||||
#endregion
|
||||
//containerBuilder.RegisterModule<PropertiesAutowiredModule>();
|
||||
containerBuilder.RegisterModule<PropertiesAutowiredModule>();
|
||||
#region
|
||||
//ʹ<><CAB9>AppService<63><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĽ<C5B5><C4BD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>,<2C>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ø<EFBFBD><C3B8>ַ<EFBFBD>ʽ<EFBFBD>Զ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
containerBuilder.AddAutoIocService("Yi.Framework.Repository", "Yi.Framework.Service");
|
||||
});
|
||||
////<2F><><EFBFBD><EFBFBD>ע<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mvcģ<63><C4A3>ת<EFBFBD>Ӹ<EFBFBD>ioc
|
||||
//builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
|
||||
builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
|
||||
|
||||
builder.Host.ConfigureLogging(loggingBuilder =>
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -8,8 +8,6 @@
|
||||
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" />
|
||||
<PackageReference Include="Consul" Version="1.6.10.3" />
|
||||
<PackageReference Include="CSRedisCore" Version="3.6.9" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.32" />
|
||||
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
|
||||
|
||||
@@ -4,32 +4,32 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
{
|
||||
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; }
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
{
|
||||
/// <summary>
|
||||
/// 前端只需要这些数据即可
|
||||
@@ -0,0 +1,9 @@
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IAgreeService:IBaseService<AgreeEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 点赞表
|
||||
///</summary>
|
||||
[SugarTable("Agree")]
|
||||
public partial class AgreeEntity
|
||||
{
|
||||
public AgreeEntity()
|
||||
{
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 用户id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="UserId" )]
|
||||
public long? UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 文章id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ArticleId" )]
|
||||
public long? ArticleId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,12 @@ namespace Yi.Framework.Model.Models
|
||||
/// 文章标题
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Title" )]
|
||||
public string? Title { get; set; }
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 文章内容
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Content" )]
|
||||
public string? Content { get; set; }
|
||||
public string Content { get; set; }
|
||||
/// <summary>
|
||||
/// 用户id
|
||||
///</summary>
|
||||
@@ -72,11 +72,16 @@ namespace Yi.Framework.Model.Models
|
||||
/// 描述
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Remark" )]
|
||||
public string? Remark { get; set; }
|
||||
public string Remark { get; set; }
|
||||
/// <summary>
|
||||
/// 图片列表
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Images",IsJson = true)]
|
||||
public List<string>? Images { get; set; }
|
||||
[SugarColumn(ColumnName="Images" )]
|
||||
public string Images { get; set; }
|
||||
/// <summary>
|
||||
/// 点赞数量
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="AgreeNum" )]
|
||||
public int? AgreeNum { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class AgreeService : BaseService<AgreeEntity>, IAgreeService
|
||||
{
|
||||
public AgreeService(IRepository<AgreeEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.WebCore.Mapper
|
||||
|
||||
3
Yi.Vue3.x.Vant/components.d.ts
vendored
3
Yi.Vue3.x.Vant/components.d.ts
vendored
@@ -14,9 +14,6 @@ declare module '@vue/runtime-core' {
|
||||
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
VanActionBar: typeof import('vant/es')['ActionBar']
|
||||
VanActionBarButton: typeof import('vant/es')['ActionBarButton']
|
||||
VanActionBarIcon: typeof import('vant/es')['ActionBarIcon']
|
||||
VanActionSheet: typeof import('vant/es')['ActionSheet']
|
||||
VanButton: typeof import('vant/es')['Button']
|
||||
VanCell: typeof import('vant/es')['Cell']
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<title>大白荟</title>
|
||||
<title>意框架</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="div-top">
|
||||
<span class="title">大白荟</span>
|
||||
<span class="title">意框架</span>
|
||||
<br />
|
||||
<span class="subtitle">有幸相遇、不负未来</span>
|
||||
</div>
|
||||
@@ -19,7 +19,7 @@
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
/>
|
||||
<van-button type="primary" @click="login">进入大白荟</van-button>
|
||||
<van-button type="primary" @click="login">进入意框架</van-button>
|
||||
<p>其他方式登录<van-icon name="arrow" /></p>
|
||||
|
||||
<van-row class="row-bottom" style="margin-top: 6rem">
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<template>
|
||||
|
||||
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
||||
<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
|
||||
<van-list
|
||||
class="list"
|
||||
v-model:loading="loading"
|
||||
@@ -10,11 +9,17 @@
|
||||
>
|
||||
<van-row v-for="(item, index) in articleList" :key="index" class="row">
|
||||
<van-col span="4" class="leftCol">
|
||||
<AppUserIcon width="3rem" height="3rem" :src="item.user==null?null:(item.user.icon)"/>
|
||||
<AppUserIcon
|
||||
width="3rem"
|
||||
height="3rem"
|
||||
:src="item.user == null ? null : item.user.icon"
|
||||
/>
|
||||
</van-col>
|
||||
|
||||
<van-col span="14" class="centerTitle">
|
||||
<span class="justtitle">{{item.user==null?"-":(item.user.nick??item.user.username)}}</span>
|
||||
<span class="justtitle">{{
|
||||
item.user == null ? "-" : item.user.nick ?? item.user.username
|
||||
}}</span>
|
||||
<br />
|
||||
<app-createTime :time="item.createTime" />
|
||||
</van-col>
|
||||
@@ -25,29 +30,29 @@
|
||||
|
||||
<van-col class="rowBody" span="24">{{ item.content }}</van-col>
|
||||
|
||||
<van-col
|
||||
<van-col
|
||||
span="8"
|
||||
v-for="(image, imageIndex) in item.images"
|
||||
:key="imageIndex"
|
||||
class="imageCol"
|
||||
@click="openImage(item.images,imageIndex)"
|
||||
@click="openImage(item.images, imageIndex)"
|
||||
><van-image
|
||||
lazy-load
|
||||
fit="cover"
|
||||
lazy-load
|
||||
fit="cover"
|
||||
width="100%"
|
||||
height="7rem"
|
||||
:src="url + image+'/true'"
|
||||
:src="url + image + '/true'"
|
||||
radius="5"
|
||||
/>
|
||||
<template v-slot:loading>
|
||||
<van-loading type="spinner" size="20" />
|
||||
</template>
|
||||
</van-col>
|
||||
<van-loading type="spinner" size="20" />
|
||||
</template>
|
||||
</van-col>
|
||||
|
||||
<van-col span="24" class="bottomRow">
|
||||
<van-grid direction="horizontal" :column-num="3">
|
||||
<van-grid-item icon="share-o" text="分享" />
|
||||
<van-grid-item icon="comment-o" text="评论" />
|
||||
<van-grid-item icon="comment-o" text="评论" @click="commentShow=true" />
|
||||
<van-grid-item icon="good-job-o" text="点赞" />
|
||||
</van-grid>
|
||||
</van-col>
|
||||
@@ -72,13 +77,23 @@
|
||||
>
|
||||
<template v-slot:index>第{{ index + 1 }}页</template>
|
||||
</van-image-preview>
|
||||
|
||||
<!-- 评论面板 -->
|
||||
<van-action-sheet v-model:show="commentShow" title="共10条评论">
|
||||
|
||||
<van-row v-for="i of 10" :key="i" class="commentContent">
|
||||
<van-col span="4">头像</van-col>
|
||||
<van-col span="16">内容</van-col>
|
||||
<van-col span="4">点赞</van-col>
|
||||
</van-row>
|
||||
</van-action-sheet>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive, toRefs } from "vue";
|
||||
import { ImagePreview, Toast } from "vant";
|
||||
import AppCreateTime from "@/components/AppCreateTime.vue";
|
||||
import AppUserIcon from "@/components/AppUserIcon.vue";
|
||||
import AppUserIcon from "@/components/AppUserIcon.vue";
|
||||
import articleApi from "@/api/articleApi";
|
||||
import { ArticleEntity } from "@/type/interface/ArticleEntity";
|
||||
const VanImagePreview = ImagePreview.Component;
|
||||
@@ -97,6 +112,7 @@ const { queryParams } = toRefs(data);
|
||||
const articleList = ref<any[]>([]);
|
||||
const totol = ref<Number>(0);
|
||||
const imageShow = ref(false);
|
||||
const commentShow=ref(false)
|
||||
const index = ref(0);
|
||||
let imagesPreview = ref<string[]>([]);
|
||||
|
||||
@@ -108,7 +124,7 @@ const list = ref<Number[]>([]);
|
||||
const loading = ref(false);
|
||||
const finished = ref(false);
|
||||
const refreshing = ref(false);
|
||||
const startIndex=ref(0)
|
||||
const startIndex = ref(0);
|
||||
const show = ref(false);
|
||||
const actions = [{ name: "取消关注" }, { name: "将TA拉黑" }, { name: "举报" }];
|
||||
|
||||
@@ -125,7 +141,7 @@ const onLoad = async () => {
|
||||
finished.value = true;
|
||||
} else {
|
||||
console.log("执行");
|
||||
articleList.value.push(...(response.data.data));
|
||||
articleList.value.push(...response.data.data);
|
||||
totol.value = response.data.totol;
|
||||
queryParams.value.pageNum += 1;
|
||||
}
|
||||
@@ -144,9 +160,9 @@ const onRefresh = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
onLoad();
|
||||
};
|
||||
const openImage = (imagesUrl: string[],imageIndex:any) => {
|
||||
const openImage = (imagesUrl: string[], imageIndex: any) => {
|
||||
imagesPreview.value = imagesUrl.map((i) => url + i);
|
||||
startIndex.value=imageIndex;
|
||||
startIndex.value = imageIndex;
|
||||
imageShow.value = true;
|
||||
};
|
||||
onMounted(() => {
|
||||
@@ -156,15 +172,14 @@ onMounted(() => {
|
||||
|
||||
const getList = () => {
|
||||
articleApi.pageList(queryParams.value).then((response: any) => {
|
||||
articleList.value.push(...(response.data.data));
|
||||
articleList.value.push(...response.data.data);
|
||||
totol.value = response.data.totol;
|
||||
});
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.list {
|
||||
background-color: #F4F4F4;
|
||||
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
.row {
|
||||
background-color: white;
|
||||
@@ -210,4 +225,7 @@ const getList = () => {
|
||||
text-align: right;
|
||||
padding-right: 0.5rem;
|
||||
}
|
||||
.commentContent {
|
||||
margin-bottom: 4rem;
|
||||
}
|
||||
</style>
|
||||
@@ -9,7 +9,12 @@
|
||||
</router-link>
|
||||
</van-col>
|
||||
<van-col span="18"><span>发图文</span></van-col>
|
||||
<van-col span="3" @click="send" :style="{color: isSend?'#FE70A0':'#979797'}">发布</van-col>
|
||||
<van-col
|
||||
span="3"
|
||||
@click="send"
|
||||
:style="{ color: isSend ? '#FE70A0' : '#979797' }"
|
||||
>发布</van-col
|
||||
>
|
||||
</van-row>
|
||||
</van-sticky>
|
||||
|
||||
@@ -39,28 +44,33 @@
|
||||
<van-divider />
|
||||
<van-row>
|
||||
<van-col class="img-col" span="24">
|
||||
<van-uploader accept="image/*" :after-read="afterRead" v-model="fileList" multiple />
|
||||
<van-uploader
|
||||
accept="image/*"
|
||||
:after-read="afterRead"
|
||||
v-model="fileList"
|
||||
multiple
|
||||
/>
|
||||
</van-col>
|
||||
</van-row>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive, toRefs,watch } from "vue";
|
||||
import { ref, onMounted, reactive, toRefs, watch } from "vue";
|
||||
import { ArticleEntity } from "@/type/interface/ArticleEntity";
|
||||
import fileApi from "@/api/fileApi";
|
||||
import articleApi from "@/api/articleApi";
|
||||
import { Toast } from "vant";
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useRouter } from "vue-router";
|
||||
const router = useRouter();
|
||||
const form = reactive<any>({
|
||||
title: "",
|
||||
content: "",
|
||||
images: [],
|
||||
isDeleted: false
|
||||
isDeleted: false,
|
||||
});
|
||||
|
||||
const isSend=ref(false)
|
||||
const isSend = ref(false);
|
||||
const { images, content } = toRefs(form);
|
||||
const fileList = ref([]);
|
||||
const visible = ref<boolean>(false);
|
||||
@@ -72,60 +82,64 @@ const afterRead = (file: any) => {
|
||||
file.message = "上传中...";
|
||||
var formData = new FormData();
|
||||
//一个文件
|
||||
if(file.length==undefined)
|
||||
{
|
||||
if (file.length == undefined) {
|
||||
formData.append("file", file.file);
|
||||
} else {
|
||||
//多个文件
|
||||
file.forEach((f: any) => {
|
||||
formData.append("file", f.file);
|
||||
f.status = "uploading";
|
||||
f.message = "上传中...";
|
||||
});
|
||||
Toast({
|
||||
message: "全部文件正在上传",
|
||||
position: "bottom",
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//多个文件
|
||||
file.forEach((f:any) => {
|
||||
formData.append("file", f.file);
|
||||
});
|
||||
Toast({
|
||||
message: "全部文件正在上传",
|
||||
position: "bottom",
|
||||
});
|
||||
}
|
||||
fileApi.upload("image", formData)
|
||||
.then((response: any) => {
|
||||
images.value.push(...response.data);
|
||||
|
||||
fileApi.upload("image", formData).then((response: any) => {
|
||||
images.value.push(...response.data);
|
||||
|
||||
if (file.length == undefined) {
|
||||
file.status = "done";
|
||||
file.message = "成功";
|
||||
} else {
|
||||
//多个文件
|
||||
file.forEach((f: any) => {
|
||||
f.status = "done";
|
||||
f.message = "成功";
|
||||
});
|
||||
Toast({
|
||||
message: "文件上传成功",
|
||||
message: "全部文件上传成功",
|
||||
position: "bottom",
|
||||
});
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const send = () => {
|
||||
if(form.content.length<5)
|
||||
{
|
||||
if (form.content.length < 5) {
|
||||
Toast({
|
||||
message: "请输入至少5个字符",
|
||||
position: "bottom",
|
||||
});
|
||||
message: "请输入至少5个字符",
|
||||
position: "bottom",
|
||||
});
|
||||
} else {
|
||||
articleApi.add(form).then((response: any) => {
|
||||
router.push({ path: "/recommend" });
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
articleApi.add(form).then((response:any)=>{
|
||||
router.push({ path: '/recommend'});
|
||||
})
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
watch(()=>form.content,(newValue,oldValue)=>{
|
||||
if(newValue.length<5)
|
||||
{
|
||||
isSend.value=false
|
||||
}
|
||||
else
|
||||
{
|
||||
isSend.value=true
|
||||
}
|
||||
})
|
||||
watch(
|
||||
() => form.content,
|
||||
(newValue, oldValue) => {
|
||||
if (newValue.length < 5) {
|
||||
isSend.value = false;
|
||||
} else {
|
||||
isSend.value = true;
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<style scoped>
|
||||
.head-row {
|
||||
@@ -165,8 +179,7 @@ watch(()=>form.content,(newValue,oldValue)=>{
|
||||
.img-col {
|
||||
text-align: left;
|
||||
}
|
||||
.right-span
|
||||
{
|
||||
.right-span {
|
||||
color: #979797;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user