2024年12月18日09:19:14

main
LeJingS 2 months ago
parent 7df01b9a0a
commit 491e1e002a

@ -30,7 +30,7 @@ const router = useRouter();
const emit = defineEmits(['destroy']); const emit = defineEmits(['destroy']);
const props = defineProps(['post_id','user_id','username','title','updated_at','Likes','showButtons']) const props = defineProps(['post_id','user_id','username','title','updated_at','Likes','showButtons'])
console.log("Likes:",props.Likes);
function handleDelete() { function handleDelete() {
ElMessageBox.confirm('您确定要删除这篇文章吗?', '提示', { ElMessageBox.confirm('您确定要删除这篇文章吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
@ -51,8 +51,11 @@ function handleDelete() {
}); });
} }
//id
function handleEdit() { function handleEdit() {
router.push({ name: 'Writing', params: { id: props.post_id } });
// r
} }
function handleClick(post_id:number) { function handleClick(post_id:number) {

@ -62,7 +62,7 @@ const dislikeIconSrc = computed(() => isDisliked.value ? abhorIcon : deabhorIcon
function getpaper(){ function getpaper(){
axios.get('/api/post/essay',{ params: {post_id:post_id}}) axios.get('http://127.0.0.1:8080/post/essay',{ params: {post_id:post_id}})
.then(res => { .then(res => {
console.log("获取文章详情数据成功", res.data.data); console.log("获取文章详情数据成功", res.data.data);
console.log("传入对象"); console.log("传入对象");

@ -21,7 +21,7 @@
// //
// //
router.push('/writing'); router.push({ name: 'Writing', params: { id: 0 } });
console.log('Custom button clicked'); console.log('Custom button clicked');
}; };
</script> </script>

@ -24,9 +24,10 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed, onMounted } from 'vue'; import { ref, computed, onMounted,nextTick } from 'vue';
import { marked } from 'marked'; import { marked } from 'marked';
import axios from 'axios'; import axios from 'axios';
import { useRoute } from 'vue-router';
import { useLoginStore } from '@/stores/Login'; import { useLoginStore } from '@/stores/Login';
// //
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
@ -34,7 +35,9 @@ import { useToast } from 'vue-toastification'
const markdownContent = ref(''); const markdownContent = ref('');
const title = ref(''); const title = ref('');
const loginStore = useLoginStore(); const loginStore = useLoginStore();
const toast = useToast() const toast = useToast();
const route = useRoute();
const post_id = route.params.id;
// 使 marked Markdown HTML // 使 marked Markdown HTML
const compiledMarkdown = computed(() => { const compiledMarkdown = computed(() => {
return marked.parse(markdownContent.value, { breaks: true }); return marked.parse(markdownContent.value, { breaks: true });
@ -42,10 +45,13 @@ const compiledMarkdown = computed(() => {
// DOM // DOM
onMounted(() => { onMounted(() => {
isChange();
const editor = document.getElementById('markdown-editor'); const editor = document.getElementById('markdown-editor');
if (editor) { if (editor) {
// //
resizeTextarea(); nextTick(() => {
resizeTextarea();
});
} }
}); });
@ -58,9 +64,27 @@ const resizeTextarea = () => {
} }
}; };
function isChange(){
//
//get
if(post_id !== '0'){
axios.get('http://localhost:8080/post/essay',{ params: {post_id:post_id}})
.then(res => {
// console.log("", res.data.data);
// console.log("");
markdownContent.value = res.data.data.content
title.value = res.data.data.title
resizeTextarea();
})
}
}
const scrollToTop = () => { const scrollToTop = () => {
// if(post_id === '0'){
console.log("正在发布中") //
console.log("正在发布中",post_id)
// //
console.log(title.value,'id',loginStore.userInfo.id) console.log(title.value,'id',loginStore.userInfo.id)
axios.post('http://localhost:8080/post/new', { axios.post('http://localhost:8080/post/new', {
@ -72,12 +96,28 @@ const scrollToTop = () => {
// //
console.log(response.data); console.log(response.data);
toast.success("发布成功"); toast.success("发布成功");
//
}) })
.catch(error => { .catch(error => {
// //
console.error(error); console.error(error);
}); });
}
else{
//
console.log("正在修改中",post_id)
//
console.log(title.value,'id',post_id)
axios.post('http://localhost:8080/post/update', {
token: loginStore.userInfo.token,
title: title.value,
content: markdownContent.value,
post_id:post_id
})
}
}; };
</script> </script>

@ -26,7 +26,7 @@
//axios //axios
// api // api
function getAll() { function getAll() {
axios.get('/api/announcements') axios.get('http://127.0.0.1:8080/announcements')
.then(res => { .then(res => {
// 使 // 使
console.log("开始存放",res.data) console.log("开始存放",res.data)

@ -67,7 +67,7 @@ let postOverviewList = reactive<postOverview[]>([]);
// //
function getAll(by: string) { function getAll(by: string) {
axios.get('/api/post/overview', { axios.get('http://127.0.0.1:8080/post/overview', {
params: { by: by }, params: { by: by },
headers: { token: '' } headers: { token: '' }
}) })

@ -40,7 +40,8 @@ const router = createRouter({
}, },
// 书写页面 // 书写页面
{ {
path:'/writing', path:'/writing/:id',
name: 'Writing',
component:Writing component:Writing
}, },
//找回密码 //找回密码

@ -7,7 +7,7 @@
<sourceOutputDir name="target/generated-sources/annotations" /> <sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<processorPath useClasspath="false"> <processorPath>
<entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/unknown/lombok-unknown.jar" /> <entry name="$MAVEN_REPOSITORY$/org/projectlombok/lombok/unknown/lombok-unknown.jar" />
</processorPath> </processorPath>
<module name="demo" /> <module name="demo" />

@ -51,4 +51,11 @@ public class PostsController {
return Result.success(); return Result.success();
} }
//修改文章
@PostMapping("/update")
public Result update(@RequestBody Posts posts){
log.info("修改文章");
postsService.postsUpdate(posts);
return Result.success("修改成功");
}
} }

@ -3,6 +3,7 @@ package top.lejings.demo.mapper;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import top.lejings.demo.pojo.Posts; import top.lejings.demo.pojo.Posts;
import java.util.List; import java.util.List;
@ -20,4 +21,7 @@ public interface PostsMapper {
@Delete("DELETE FROM posts WHERE post_id = #{post_id}") @Delete("DELETE FROM posts WHERE post_id = #{post_id}")
void deletePost(Integer post_id); void deletePost(Integer post_id);
@Update("UPDATE posts SET title = #{title}, content = #{content} WHERE post_id = #{post_id};")
void postsUpdate(Posts posts);
} }

@ -12,4 +12,6 @@ public interface PostsService {
void postsNew(Posts posts); void postsNew(Posts posts);
void deletePost(Integer postId); void deletePost(Integer postId);
void postsUpdate(Posts posts);
} }

@ -58,4 +58,10 @@ public class PostsServiceImpl implements PostsService {
public void deletePost(Integer postId) { public void deletePost(Integer postId) {
postsMapper.deletePost(postId); postsMapper.deletePost(postId);
} }
@Override
public void postsUpdate(Posts posts) {
//本来还有解析token判断逻辑。但是懒得写了
postsMapper.postsUpdate(posts);
}
} }

Loading…
Cancel
Save