Browse Source

Merge branch 'zxm' of http://124.70.32.114:3100/zhangxiaomeng/kechengfuzhu into wzx

# Conflicts:
#	kcui/src/view/SpInfo.vue
wzx
linsheng0116 1 year ago
parent
commit
e060254975
  1. 5
      kcui/package.json
  2. 15
      kcui/src/api/kcInfo.js
  3. 8
      kcui/src/api/upload.js
  4. BIN
      kcui/src/assets/img/delete.png
  5. 221
      kcui/src/components/Video1.vue
  6. 6
      kcui/src/router/router.js
  7. 251
      kcui/src/view/SpInfo.vue
  8. 9
      kcui/src/view/TWInfo.vue
  9. 2
      src/main/java/com/main/woka/Filter/SaTokenFilter.java
  10. 35
      src/main/java/com/main/woka/Web/Controller/FileUpdateController.java
  11. 169
      src/main/java/com/main/woka/Web/Controller/KcInfoController.java

5
kcui/package.json

@ -25,7 +25,10 @@
"@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"vue-template-compiler": "^2.6.14"
"vue-template-compiler": "^2.6.14",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"node-sass": "^9.0.0"
},
"eslintConfig": {
"root": true,

15
kcui/src/api/kcInfo.js

@ -12,6 +12,17 @@ export function getDocList(data) {
}
})
}
export function getSpList(data) {
return request({
url: '/kcDoc/getSpList',
method: 'post',
data:data,
headers: {
'Authorization': 'Bearer '+ getToken() // 将 token 放在请求头中
}
})
}
export function editInfo(data) {
return request({
@ -26,9 +37,9 @@ export function editInfo(data) {
export function getTwInfo(params) {
export function getInfo(params) {
return request({
url: '/kcDoc/getTwInfo',
url: '/kcDoc/getInfo',
method: 'get',
params,
headers: {

8
kcui/src/api/upload.js

@ -8,3 +8,11 @@ export const uploadInfo = (params) => {
data: params,
});
};
export const uploadVideo = (params) => {
return request({
url: '/api/updateload/uploadVideo',
method: 'post',
data: params,
});
};

BIN
kcui/src/assets/img/delete.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

221
kcui/src/components/Video1.vue

@ -0,0 +1,221 @@
<template>
<div class="m-video" :class="{'u-video-hover': !hidden}" :style="`width: ${veoWidth}; height: ${veoHeight};`">
<video
ref="veoRef"
class="u-video"
:style="`object-fit: ${zoom};`"
:src="src"
:poster="veoPoster"
:autoplay="autoplay"
:controls="!originPlay&&controls"
:loop="loop"
:muted="autoplay || muted"
:preload="preload"
crossorigin="anonymous"
@loadeddata="poster ? () => false : getPoster()"
@pause="showPlay ? onPause() : () => false"
@playing="showPlay ? onPlaying() : () => false"
@click.prevent.once="onPlay"
v-bind="$attrs">
您的浏览器不支持video标签
</video>
<svg v-show="originPlay || showPlay" class="u-play" :class="{'hidden': hidden}" :style="`width: ${playWidth}px; height: ${playWidth}px;`" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4.75 6.75C4.75 5.64543 5.64543 4.75 6.75 4.75H17.25C18.3546 4.75 19.25 5.64543 19.25 6.75V17.25C19.25 18.3546 18.3546 19.25 17.25 19.25H6.75C5.64543 19.25 4.75 18.3546 4.75 17.25V6.75Z"></path>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M15.25 12L9.75 8.75V15.25L15.25 12Z"></path>
</svg>
</div>
</template>
<script>
export default {
// eslint-disable-next-line vue/multi-word-component-names
name: 'Video1',
props: {
src: { // url https require('@/assets/files/Bao.mp4')
type: String,
required: true,
default: ''
},
poster: { // url https require('@/assets/images/Bao.jpg')
type: String,
default: ''
},
second: { // second
type: Number,
default: 0.5
},
width: { // px
type: [String, Number],
default: 800
},
height: { // px
type: [String, Number],
default: 450
},
/*
参考 MDN 自动播放指南https://developer.mozilla.org/zh-CN/docs/Web/Media/Autoplay_guide
Autoplay 功能
据新政策媒体内容将在满足以下至少一个的条件下自动播放
1.音频被静音或其音量设置为 0
2.用户和网页已有交互行为包括点击触摸按下某个键等等
3.网站已被列入白名单如果浏览器确定用户经常与媒体互动这可能会自动发生也可能通过首选项或其他用户界面功能手动发生
4.自动播放策略应用到<iframe>或者其文档上
autoplay由于目前在最新版的Chrome浏览器以及所有以Chromium为内核的浏览器
已不再允许自动播放音频和视频就算你为video或audio标签设置了autoplay属性也一样不能自动播放
解决方法设置视频 autoplay 视频必须设置为静音 muted: true 即可实现自动播放
然后用户可以使用控制栏开启声音类似某宝商品自动播放的宣传视频逻辑
*/
autoplay: { // preload
type: Boolean,
default: false
},
controls: { //
type: Boolean,
default: true
},
loop: { //
type: Boolean,
default: false
},
muted: { //
type: Boolean,
default: false
},
preload: { // autoplaypreload
type: String,
default: 'metadata' // auto:; metadata: none:
},
showPlay: { //
type: Boolean,
default: true
},
playWidth: { //
type: Number,
default: 96
},
zoom: { // videoposter
type: String,
default: 'contain' // none:(); fill:; contain:; cover:
}
},
data () {
return {
veoPoster: this.poster,
originPlay: true,
hidden: false
}
},
computed: {
veoWidth () {
if (typeof this.width === 'number') {
return this.width + 'px'
}
return this.width
},
veoHeight () {
if (typeof this.height === 'number') {
return this.height + 'px'
}
return this.height
}
},
mounted () {
if (this.autoplay) {
this.hidden = true
this.originPlay = false
}
/*
自定义设置播放速度经测试
在vue2中需设置this.$refs.veoRef.playbackRate = 2
在vue3中需设置veo.value.defaultPlaybackRate = 2
*/
// this.$refs.veoRef.playbackRate = 2
},
methods: {
/*
loadedmetadata 事件在元数据metadata被加载完成后触发
loadeddata 事件在媒体当前播放位置的视频帧通常是第一帧加载完成后触发
若在移动/平板设备的浏览器设置中开启了流量节省data-saver模式该事件则不会被触发
preload none 时不会触发
*/
getPoster () { // 0.5s
// 0.5s
this.$refs.veoRef.currentTime = this.second
// canvas
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
// canvas
canvas.width = this.$refs.veoRef.videoWidth
canvas.height = this.$refs.veoRef.videoHeight
ctx.drawImage(this.$refs.veoRef, 0, 0, canvas.width, canvas.height)
// canvasbase64
this.veoPoster = canvas.toDataURL('image/png')
},
onPlay () {
if (this.originPlay) {
this.$refs.veoRef.currentTime = 0
this.originPlay = false
}
if (this.autoplay) {
this.$refs.veoRef.pause()
} else {
this.hidden = true
this.$refs.veoRef.play()
}
},
onPause () {
this.hidden = false
},
onPlaying () {
this.hidden = true
}
}
}
</script>
<style lang="less" scoped>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.m-video {
display: inline-block;
position: relative;
background: #000;
cursor: pointer;
border-radius: 2vw;
.u-video {
display: inline-block;
width: 100%;
height: 100%;
vertical-align: bottom;
}
.u-play {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
fill: none;
color: #FFF;
pointer-events: none;
opacity: 0.7;
transition: opacity .3s;
path {
stroke: #FFF;
}
}
.hidden {
opacity: 0;
}
}
.u-video-hover {
&:hover {
.u-play {
opacity: 0.9;
}
}
}
</style>

6
kcui/src/router/router.js

@ -9,6 +9,7 @@ import SpInfo from '@/view/SpInfo.vue'
import DhInfo from '@/view/DhInfo.vue'
import JsInfo from '@/view/JsInfo.vue'
import TwInfoXq from '@/view/TWInfoXq.vue'
import SpnfoXq from '@/view/SpInfoXq.vue'
import Login from '@/view/Login.vue'
import Mulu from '@/view/Mulu.vue'
//2.调用vue.use() 函数,把 VueRouter 安装为 Vue 的插件
@ -59,6 +60,11 @@ export default new VueRouter({
component: SpInfo //对应的组件模板
},
{ //每一个链接都是一个对象
path: '/SpInfoXq', //链接路径
name: 'SpInfoXq', //路由名称,
component: SpnfoXq //对应的组件模板
},
{ //每一个链接都是一个对象
path: '/DhInfo', //链接路径
name: 'DhInfo', //路由名称,
component: DhInfo //对应的组件模板

251
kcui/src/view/SpInfo.vue

@ -36,8 +36,6 @@
</div>
</div>
<div class="rightContent">
<div class="rigthHeadInfo" style="position: relative;">
<div style="width: 30%;height: 2vw;position: absolute;top: 2.5vw;right: 1vw;">
<div class="password-input-container">
@ -60,7 +58,7 @@
<div v-for="item in typeList" :key="item" style="position: relative;margin-right: 1vw;"
@click="changeType(item)">
<img v-if="twType==item" src="../assets/img/typeHeadChoose.png" style="width: 7vw;object-fit: contain;">
<img v-if="spType==item" src="../assets/img/typeHeadChoose.png" style="width: 7vw;object-fit: contain;">
<img v-else src="../assets/img/typeHead.png" style="width: 7vw;object-fit: contain;">
<div style="position: absolute;z-index: 12121;width: 100%;text-align: center;color: white;top: 15%;">
{{ item }}
@ -100,10 +98,8 @@
<div style="width: 8%;">{{ item.id }}</div>
<div style="width: 22%;">{{ item.name }}</div>
<div style="width: 60%;display: flex;flex-direction: row;">
<div v-for="item1 in item.imgList" :key="item1">
<img :src="item1.imgUrl"
style="height: 5vw;object-fit: contain;justify-content: flex-start;margin-left: 1vw;border-radius: 1vw;">
</div>
<Video1 style="height: 100%; object-fit:contain" :src="item.spUrl"
:second="3"/>
</div>
<div style="width: 10%;text-decoration: underline;font-style: italic;" @click="goXq(item.id)">
点击查看详情
@ -114,11 +110,10 @@
<div class="oneRight" v-for="item in contentList" :key="item">
<div style="width: 8%;">{{ item.id }}</div>
<div style="width: 22%;">{{ item.name }}</div>
<div style="width: 60%;display: flex;flex-direction: row;">
<div v-for="item1 in item.imgList" :key="item1">
<img :src="item1.imgUrl"
style="height: 5vw;object-fit: contain;justify-content: flex-start;margin-left: 1vw;border-radius: 1vw;">
</div>
<div style="width: 60%;display: flex;flex-direction: row;justify-content: space-around;">
<Video1 style="height: 100%; object-fit:contain" :src="item.spUrl"
:second="3"/>
</div>
<div style="width: 10%;text-decoration: underline;font-style: italic;" @click="goXq(item.id)">
点击查看详情
@ -150,28 +145,44 @@
<foot></foot>
</div>
<el-dialog :visible.sync="openInfo" title="文章修改">
<el-dialog :visible.sync="openInfo" title="视频">
<el-form :model="form" label-width="80px">
<el-form-item label="活动名称">
<el-form-item label="视频名称">
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
<el-form-item style="position: relative ;" label="知识内容">
<Editor v-if="form.contentInfo!=''" v-model="TxtValue" style="height: 15vw;"></Editor>
</el-form-item>
<el-form-item style="position: relative;margin-top: 5vw;" label="相关图片">
<el-form-item label="上传视频" prop="courseUrl">
<el-upload
action="http://127.0.0.1:10031/fileUpdate/upload"
list-type="picture-card"
:on-remove="handleRemove"
:file-list="fileList"
:multiple="true"
:limit="9"
:on-exceed="handleExceed"
:before-upload="beforeUpload"
:on-success="handleSuccess"
:on-error="handleError">
<i class="el-icon-plus"></i>
class="avatar-uploader el-upload--text"
multiple
:headers="videoUpload.headers"
:action="videoUpload.url"
:file-list="videoFileList"
:show-file-list="false"
accept=".mp4"
:on-success="handleVideoSuccess"
:before-upload="beforeUploadVideo"
:on-progress="uploadVideoProcess"
:on-remove="handleVideoRemove"
>
<div v-if="!videoFlag && showVideoPath" style="display: flex; flex-wrap: wrap; gap: 10px;">
<div v-for="(url, index) in showVideoPath.split(',')" :key="url"
style="position: relative; flex: 1 1 calc(33.333% - 20px); min-width: 200px; margin-bottom: 10px;">
<video :src="`${videoUpload.url2}${url}`" style="width:90%; height: auto;border-radius: 0.5vw;" class="avatar video-avatar" controls>
您的浏览器不支持视频播放
</video>
<img
src="../assets/img/delete.png"
@click.stop="handleVideoRemove(videoFileList[index])"
style="width: 35px; height: 35px;position: absolute; top: 5px; left: 5px; cursor: pointer; z-index: 999;"
alt="删除"
/>
</div>
</div>
<el-progress :stroke-width="10" class="progressType" v-if="videoFlag"
type="circle" :percentage="videoUploadPercent" style="margin-top:30px;"></el-progress>
<el-button style="z-index: 999;" class="video-btn" slot="trigger" size="small" type="primary">点击上传视频</el-button>
</el-upload>
</el-form-item>
</el-form>
@ -189,15 +200,17 @@
<script>
import headInfo from '@/components/Head.vue';
import Foot from "@/components/Foot.vue";
import {editInfo, getDocList, getTwInfo} from "@/api/kcInfo";
import Editor from "@/components/Editor.vue";
import {twdelete} from "@/api/twdelete";
import {editInfo, getSpList, getInfo} from "@/api/kcInfo";
import {getToken} from "@/utils/auth";
import Video1 from "@/components/Video1.vue";
export default {
// eslint-disable-next-line vue/multi-word-component-names
name: 'SpInfo',
components: {
Editor,
Video1,
Foot, headInfo
},
data() {
@ -212,7 +225,6 @@ export default {
{id: 4, name: "知识图谱", info: "Graph"},
{id: 4, name: "帮助文档", info: "Help"}
],
type:"2",//
page: "视频资源",
typeList: ["起降", "飞行", "通信载荷使用", "探测载荷使用", "攻击载荷使用"],
contentList: [],
@ -235,6 +247,22 @@ export default {
id: 0,
fileList: [], //
isUpload:0,
//
videoUpload: {
//
headers: {Authorization: "Bearer " + getToken()},
//
url: "http://127.0.0.1:10031/fileUpdate/upload",
url2: "http://127.0.0.1:10031",
},
videoFlag: false, //
videoUploadPercent: "", //
isShowUploadVideo: false, //
videoFileList:[],
showVideoPath: "",
uploadUrl: "",//
}
},
@ -244,7 +272,7 @@ export default {
this.$router.push('/' + info)
},
changeType(item) {
this.twType = item;
this.spType = item;
this.getContentList();
},
choosePage(item) {
@ -253,15 +281,14 @@ export default {
this.getContentList();
},
getContentList() {
console.log("djaksjdklajsdk")
var data = {
name: this.selectName,
type: this.type,
spType: this.spType,
pageNum: this.pageNum,
pageSize: this.pageSize
}
getDocList(data).then((res) => {
getSpList(data).then((res) => {
console.log(res);
this.contentList = res.data.list;
this.total = res.data.total;
@ -284,23 +311,19 @@ export default {
}
}
console.log(this.onePagesList,)
console.log(this.onePagesList)
})
},
goXq(id) {
var data = {
id: id
}
getTwInfo(data).then((res) => {
this.$router.push({path: '/TwInfoXq', query: {id: id, level: res.data.level, type: "tw"}})
})
this.$router.push({path: '/SpInfoXq', query: {id: id,type: "sp"}})
},
//
deleteTw(id){
twdelete(id);
deleteTw() {
console.log("这是删除操作")
},
editTw(id) {
@ -308,23 +331,12 @@ export default {
var data = {
id: id
}
getTwInfo(data).then((res) => {
getInfo(data).then((res) => {
this.openInfo = true;
this.form.contentInfo = res.data.data.contentInfo
this.form.name = res.data.data.name
this.TxtValue = res.data.data.contentInfo;
this.id = id;
var imgs = res.data.data.imgList;
console.log(imgs)
for (let j = 0; j < imgs.length; j++) {
var ii = {
uuid:imgs[j].imgId,
url:imgs[j].imgUrl
}
this.fileList.push(ii)
}
console.log(res);
@ -333,37 +345,75 @@ export default {
},
//
//
handleRemove(file, fileList) {
console.log('File removed:', file);
console.log('Current fileList:', fileList);
//
beforeUploadVideo(file) {
const isLt1024M = (file.size / 1024 / 1024) < 1024;
this.form.videoSize = file.size / 1024 / 1024;
//MP4
if (['video/mp4'].indexOf(file.type) === -1) {
this.$message.error('请上传正确的视频格式');
return false;
}
//1024M
if (!isLt1024M) {
this.$message.error('上传视频大小不能超过1024MB哦!');
return false;
}
return true;
},
//
handleExceed(files, fileList) {
this.$message.warning(`当前限制选择 9 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
// eslint-disable-next-line no-unused-vars
uploadVideoProcess(event, file, fileList) {
this.videoFlag = true;
this.videoUploadPercent = file.percentage.toFixed(0) * 1;
},
updateCourseUrl() {
this.form.courseUrl = this.showVideoPath;
console.log('Updated courseUrl:', this.form.courseUrl);
},
//
beforeUpload(file) {
const isJPGorPNG = file.type === 'image/jpeg' || file.type === 'image/png';
const isLt2M = file.size / 1024 / 1024 < 10; // 2MB
if (!isJPGorPNG) {
this.$message.error('上传图片只能是 JPG/PNG 格式!');
}
if (!isLt2M) {
this.$message.error('上传图片大小不能超过 2MB!');
//
// eslint-disable-next-line no-unused-vars
handleVideoSuccess(response, file, fileList) {
console.log(response.data.url)
try {
// res
if (!response.data.url || typeof response.data.url !== 'string') {
this.$message.error('视频上传失败,请检查服务器响应');
return;
}
const videoUrl = response.data.url.trim();
if (videoUrl === '') {
this.$message.error('收到无效的视频URL,请检查服务器响应');
return;
}
//
if (this.videoFileList.some(video => video.url === videoUrl)) {
this.$message.warning('该视频已存在于列表中');
return;
}
this.videoFileList.push({ url: videoUrl, name: file.name });
this.showVideoPath = this.videoFileList.map(f => f.url).join(',');
this.updateCourseUrl();
this.$message.success('视频上传成功');
console.log('Updated videoFileList:', this.videoFileList);
console.log('Updated showVideoPath:', this.showVideoPath);
this.$nextTick(() => {
this.videoFlag = false;
});
} catch (error) {
this.$message.error('处理上传响应时发生错误:' + error.message);
console.error('Error in handleVideoSuccess:', error);
}
return isJPGorPNG && isLt2M;
},
//
handleSuccess(response, file, fileList) {
console.log('Upload success:', response);
// fileList
console.log(fileList)
this.fileList = fileList;
this.isUpload = 1;
handleVideoRemove(video) {
if (!video) return;
// 使uid
const index = this.videoFileList.findIndex(item => item.uid === video.uid);
if (index > -1) { // UI
this.videoFileList.splice(index, 1);
this.showVideoPath = this.videoFileList.map(f => f.url).join(',');
this.updateCourseUrl();
}
},
//
// eslint-disable-next-line no-unused-vars
@ -372,29 +422,12 @@ export default {
this.$message.error('上传失败,请重试!');
},
submitInfo() {
console.log(this.fileList);
var urlStr = "";
for (let f = 0; f < this.fileList.length; f++) {
if (f == 0) {
if(this.fileList[f].response!=null){
urlStr = this.fileList[f].response.data.url
}else {
urlStr = this.fileList[f].url
}
} else {
if(this.fileList[f].response!=null){
urlStr = urlStr + "," + this.fileList[f].response.data.url
}else {
urlStr = urlStr + "," + this.fileList[f].url
}
}
}
console.log(this.videoFileList);
var urlStr = this.videoFileList[0];
var data = {
name: this.form.name,
contentInfo: this.TxtValue,
imgs: urlStr,
spUrl:urlStr.url,
type:2,
id: this.id
}
editInfo(data).then((res) => {
@ -518,7 +551,7 @@ export default {
.oneRight {
width: 98%;
height: 4.6vw;
height: 5vw;
line-height: 5vw;
//background-color: #42b983;
margin: 0 1%;
@ -567,4 +600,8 @@ input::placeholder {
opacity: 1; /* Firefox 默认将 placeholder 的透明度设置为 0.54 */
}
.m-video{
width: 12vw !important;
background: none !important;
}
</style>

9
kcui/src/view/TWInfo.vue

@ -197,7 +197,7 @@
<script>
import headInfo from '@/components/Head.vue';
import Foot from "@/components/Foot.vue";
import {editInfo, getDocList, getTwInfo} from "@/api/kcInfo";
import {editInfo, getDocList, getInfo} from "@/api/kcInfo";
import Editor from "@/components/Editor.vue";
import {twdelete} from "@/api/twdelete";
@ -307,7 +307,7 @@ export default {
var data = {
id: id
}
getTwInfo(data).then((res) => {
getInfo(data).then((res) => {
this.$router.push({path: '/TwInfoXq', query: {id: id, level: res.data.level, type: "tw"}})
})
},
@ -324,7 +324,7 @@ export default {
var data = {
id: id
}
getTwInfo(data).then((res) => {
getInfo(data).then((res) => {
this.openInfo = true;
this.form.contentInfo = res.data.data.contentInfo
@ -411,7 +411,8 @@ export default {
name: this.form.name,
contentInfo: this.TxtValue,
imgs: urlStr,
id: this.id
id: this.id,
type:1,
}
editInfo(data).then((res) => {
console.log(res);

2
src/main/java/com/main/woka/Filter/SaTokenFilter.java

@ -20,7 +20,7 @@ public class SaTokenFilter implements WebMvcConfigurer {
// SaRouter.match("/admin/**", r -> StpUtil.checkRoleOr("admin", "super-admin"));
// // 权限校验 -- 不同模块校验不同权限
// SaRouter.match("/user/**", r -> StpUtil.checkPermission("user"));
})).excludePathPatterns("/user/doLogin").excludePathPatterns("/file/**").excludePathPatterns("/login/**").excludePathPatterns("/fileUpdate/**"); //开放
})).excludePathPatterns("/user/doLogin").excludePathPatterns("/file/**").excludePathPatterns("/login/**").excludePathPatterns("/fileUpdate/**").excludePathPatterns("/profile/**"); //开放
}
}

35
src/main/java/com/main/woka/Web/Controller/FileUpdateController.java

@ -74,4 +74,39 @@ public class FileUpdateController extends BaseController {
return timestamp + "_" + Math.abs(originalFileName.hashCode()) + extension;
}
@RequestMapping("/uploadVideo")
public AjaxResult uploadVideo(@RequestParam(value = "file", required = true) MultipartFile file) throws Exception {
if (file.isEmpty()) {
return AjaxResult.error();
}
try {
// 确保上传目录存在
File uploadDir = new File(UPLOAD_DIR);
if (!uploadDir.exists()) {
uploadDir.mkdirs();
}
// 获取文件名并生成唯一的文件名
String fileName = generateUniqueFileName(file.getOriginalFilename());
Path filePath = Paths.get(UPLOAD_DIR, fileName);
// 将文件写入磁盘
Files.copy(file.getInputStream(), filePath);
// 返回文件访问路径
String fileAccessPath = "http://127.0.0.1:10031/profile/" + fileName;
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.put("fileName",fileName);
ajaxResult.put("url",fileAccessPath);
return AjaxResult.success(ajaxResult);
} catch (IOException e) {
e.printStackTrace();
return AjaxResult.error();
}
}
}

169
src/main/java/com/main/woka/Web/Controller/KcInfoController.java

@ -37,6 +37,7 @@ public class KcInfoController extends BaseController {
int offset = (pageNum - 1) * pageSize;
kcInfo.setOffset(offset);
kcInfo.setType(1l);
Long total = kcFileMapper.getKcCount(kcInfo);
List<KcInfo> list = kcFileMapper.getkcList(kcInfo);
for(int i=0;i<list.size();i++){
@ -59,83 +60,151 @@ public class KcInfoController extends BaseController {
}
@PostMapping(value = "/getSpList")
public AjaxResult getSpList(@RequestBody KcInfo kcInfo) {
int pageNum = kcInfo.getPageNum() == null ? 1 : kcInfo.getPageNum();
int pageSize = kcInfo.getPageSize() == null ? 10 : kcInfo.getPageSize();
int offset = (pageNum - 1) * pageSize;
kcInfo.setOffset(offset);
kcInfo.setType(2l);
Long total = kcFileMapper.getKcCount(kcInfo);
List<KcInfo> list = kcFileMapper.getkcList(kcInfo);
int totalPages = (int) Math.ceil((double) total / pageSize);
AjaxResult ajax = new AjaxResult();
ajax.put("list", list);
ajax.put("total", total);
ajax.put("totalPages", totalPages);
ajax.put("pageSize", pageSize);
return AjaxResult.success(ajax);
// return null;
}
//管理员修改文件
@GetMapping("/getTwInfo")
public AjaxResult editTwInfo(@RequestParam("id") Long id) {
@GetMapping("/getInfo")
public AjaxResult editInfo(@RequestParam("id") Long id) {
System.out.println(id);
AjaxResult ajax = new AjaxResult();
KcInfo aa = kcFileMapper.selectById(id);
List<KcTwImg> list = twImgMapper.getKcTwImgList(aa.getId());
aa.setImgList(list);
//判断这个实体是什么类型
if(aa.getType()==1){
List<KcTwImg> list = twImgMapper.getKcTwImgList(aa.getId());
aa.setImgList(list);
String path = aa.getTwUrl();
File file = new File(path);
String string = txt2String(file);
aa.setContentInfo(string);
ajax.put("data", aa);
return AjaxResult.success(ajax);
}
if(aa.getType()==2){
System.out.println(aa);
ajax.put("data", aa);
return AjaxResult.success(ajax);
}
return AjaxResult.error();
String path = aa.getTwUrl();
File file = new File(path);
String string = txt2String(file);
aa.setContentInfo(string);
ajax.put("data", aa);
return AjaxResult.success(ajax);
}
@PostMapping(value = "/editInfo")
public AjaxResult editInfo(@RequestBody KcInfo kcInfo) throws IOException {
Long id = kcInfo.getId();
String name = kcInfo.getName();
String contentInfo = kcInfo.getContentInfo();
String imgs = kcInfo.getImgs();
String[] imgList = imgs.split(",");
//判断这个info是什么
if(kcInfo.getType()==1){
Long id = kcInfo.getId();
String name = kcInfo.getName();
String contentInfo = kcInfo.getContentInfo();
String imgs = kcInfo.getImgs();
String[] imgList = imgs.split(",");
KcInfo aa = kcFileMapper.selectById(id);
KcInfo aa = kcFileMapper.selectById(id);
int d = twImgMapper.deleteImgs(id);
int d = twImgMapper.deleteImgs(id);
List<KcTwImg> list = new ArrayList<>();
if (imgList.length!=0){
for (int a = 0; a < imgList.length; a++) {
List<KcTwImg> list = new ArrayList<>();
if (imgList.length!=0){
for (int a = 0; a < imgList.length; a++) {
KcTwImg twimg = new KcTwImg();
twimg.setTwId(id);
twimg.setImgUrl(imgList[a]);
list.add(twimg);
}
}else {
KcTwImg twimg = new KcTwImg();
twimg.setTwId(id);
twimg.setImgUrl(imgList[a]);
twimg.setImgUrl(imgs);
list.add(twimg);
}
}else {
KcTwImg twimg = new KcTwImg();
twimg.setTwId(id);
twimg.setImgUrl(imgs);
list.add(twimg);
}
twImgMapper.insertTwImg(list);
twImgMapper.insertTwImg(list);
if (aa.getTwUrl() == null || aa.getTwUrl().isEmpty() || contentInfo == null) {
return AjaxResult.error("File path or content is missing");
if (aa.getTwUrl() == null || aa.getTwUrl().isEmpty() || contentInfo == null) {
return AjaxResult.error("File path or content is missing");
}
Path currentPath = Paths.get(aa.getTwUrl());
String aurl = aa.getTwUrl();
String[] urls = aurl.split("\\\\");
aurl = urls[urls.length - 1];
Path newPath = currentPath.getParent().resolve(aurl);
// Rename the file
Files.move(currentPath, newPath, StandardCopyOption.REPLACE_EXISTING);
// Update the file with new content
Files.write(newPath, contentInfo.getBytes(StandardCharsets.UTF_8));
KcInfo info = new KcInfo();
info.setId(id);
info.setName(name);
info.setTwUrl(String.valueOf(newPath));
int a = kcFileMapper.updateDocById(info);
if (a>0){
return AjaxResult.success();
}else {
return AjaxResult.error();
}
}
Path currentPath = Paths.get(aa.getTwUrl());
String aurl = aa.getTwUrl();
String[] urls = aurl.split("\\\\");
aurl = urls[urls.length - 1];
Path newPath = currentPath.getParent().resolve(aurl);
// Rename the file
Files.move(currentPath, newPath, StandardCopyOption.REPLACE_EXISTING);
// Update the file with new content
Files.write(newPath, contentInfo.getBytes(StandardCharsets.UTF_8));
KcInfo info = new KcInfo();
info.setId(id);
info.setName(name);
info.setTwUrl(String.valueOf(newPath));
int a = kcFileMapper.updateDocById(info);
if (a>0){
return AjaxResult.success();
}else {
return AjaxResult.error();
//视频
if(kcInfo.getType()==2){
Long id = kcInfo.getId();
String name = kcInfo.getName();
String spUrl = kcInfo.getSpUrl();
KcInfo aa = kcFileMapper.selectById(id);
aa.setSpUrl(spUrl);
aa.setName(name);
int a = kcFileMapper.updateDocById(aa);
if (a>0){
return AjaxResult.success();
}else {
return AjaxResult.error();
}
}
return AjaxResult.error();
}

Loading…
Cancel
Save