Browse Source

文章详情pdf读取

zxm
zhangxiaomeng 7 months ago
parent
commit
a20376f879
  1. 2
      gyxtp/package.json
  2. 14
      gyxtp/src/api/api/article.js
  3. 12
      gyxtp/src/api/api/upload.js
  4. 34
      gyxtp/src/view/Home.vue
  5. 46
      gyxtp/src/view/articleInfo.vue
  6. 12
      gyxtp/src/view/graphPageCopy.vue
  7. 11
      ruoyi-api/src/main/java/com/ruoyi/api/controller/ZhyArticleController.java
  8. 63
      ruoyi-api/src/main/java/com/ruoyi/api/controller/uploadApiController.java
  9. 15
      ruoyi-system/src/main/java/com/ruoyi/system/domain/ZhyArticle.java
  10. 7
      ruoyi-system/src/main/resources/mapper/system/ZhyArticleMapper.xml

2
gyxtp/package.json

@ -17,10 +17,12 @@
"element-plus": "^2.8.8", "element-plus": "^2.8.8",
"fabric": "^6.4.3", "fabric": "^6.4.3",
"neovis.js": "^2.1.0", "neovis.js": "^2.1.0",
"pdfjs-dist": "^5.4.149",
"relation-graph-vue3": "^2.2.11", "relation-graph-vue3": "^2.2.11",
"view-ui-plus": "^1.3.7", "view-ui-plus": "^1.3.7",
"vue": "^3.2.13", "vue": "^3.2.13",
"vue-i18n": "9.0.0", "vue-i18n": "9.0.0",
"vue-pdf-embed": "^2.1.3",
"vue-router": "^4.4.5", "vue-router": "^4.4.5",
"vue3-treeselect": "^0.1.10" "vue3-treeselect": "^0.1.10"
}, },

14
gyxtp/src/api/api/article.js

@ -12,4 +12,16 @@ export const getArticleInfo = (id) => {
url: '/api/article/getArticleInfo/'+id, url: '/api/article/getArticleInfo/'+id,
method: 'get', method: 'get',
}); });
}; };
export const updateArticle = (params) => {
return request({
url: '/api/article/updateArticle',
method: 'post',
data:params,
headers:{
'token':localStorage.getItem('token')
}
})
}

12
gyxtp/src/api/api/upload.js

@ -8,3 +8,15 @@ export const uploadInfo = (params) => {
data: params, data: params,
}); });
}; };
export const getFileByUrl = (params) => {
return request({
url: '/api/updateload/file/info', // 你的接口路径
method: 'post',
data: params, // 使用 data 发送 JSON
headers:{
'token':localStorage.getItem('token')
}
});
};

34
gyxtp/src/view/Home.vue

@ -14,25 +14,15 @@
<div class="rightInfo"> <div class="rightInfo">
<div class="searchInfo"> <div class="searchInfo">
<input class="input" @keyup.enter="goSearch" v-model="searchWord" placeholder="请输入要检索的关键字"/> <input class="input" @keyup.enter="goSearch" v-model="searchWord" placeholder="请输入要检索的关键字"/>
<img
src="../assets/img2/photo.png" @click="openPhoto" <div class="searchQuan" @click="goSearch" style="cursor: pointer;">
style="position: absolute;right: 29%;top: 53.5%;height: 28%;object-fit: contain;cursor: pointer;"
alt=""
/>
<div class="searchQuan" @click="goSearch" v-if="type=='word'" style="cursor: pointer;">
<img
src="../assets/img2/search.png"
style="height: 100%;object-fit: contain;"
alt=""
/>
</div>
<div class="searchQuan" @click="goSearchPhoto" v-if="type=='photo'">
<img <img
src="../assets/img2/search.png" src="../assets/img2/search.png"
style="height: 100%;object-fit: contain;" style="height: 100%;object-fit: contain;"
alt="" alt=""
/> />
</div> </div>
</div> </div>
<div class="historyInfo" style="cursor: pointer;"> <div class="historyInfo" style="cursor: pointer;">
<div class="lsjl"> <div class="lsjl">
@ -68,25 +58,7 @@
</div> </div>
<div style="width: 50vw;height: 9vw;position: relative;margin: 0 auto;margin-left: 21vw" v-if="type=='photo'">
<img src="../assets/img2/imgBorder.png " style="width: 100%;object-fit: contain;"/>
<div style="height: 5vw;width: 5vw;position: absolute;top: 5%;left: 40%;">
<el-upload
style="width: 100%;height: 100%;"
:action="updateUrl"
:on-success="handleSuccess"
:on-remove="handleRemove"
list-type="picture-card"
:auto-upload="true">
<!-- <img style="height: 8vw;width: 8vw;" v-if="imageUrl!=''" :src="imageUrl" class="avatar">-->
<el-icon v-if="imageUrl==''" class="avatar-uploader-icon"><Plus /></el-icon>
</el-upload>
</div>
</div>
</div> </div>
</div> </div>

46
gyxtp/src/view/articleInfo.vue

@ -36,7 +36,8 @@
<!-- <div class="tcontent">知识内容:</div>--> <!-- <div class="tcontent">知识内容:</div>-->
<!-- </div>--> <!-- </div>-->
<!-- </div>--> <!-- </div>-->
<div class="yuanwen" v-html="content.content"></div> <vue-pdf-embed class="yuanwen" :source=" this.content.uploadUrl" />
<!-- <div class="yuanwen" v-html="content.content"></div>-->
</div> </div>
</div> </div>
@ -61,8 +62,9 @@ import RelationGraph from 'relation-graph-vue3';
import HeaderInfo from '../components/UseAll/headerInfo' import HeaderInfo from '../components/UseAll/headerInfo'
import LeftInfo from "../components/UseAll/leftInfo"; import LeftInfo from "../components/UseAll/leftInfo";
import {ElMessage} from 'element-plus' import {ElMessage} from 'element-plus'
import {getArticleInfo} from "@/api/api/article"; import {getArticleInfo, updateArticle} from "@/api/api/article";
import VuePdfEmbed from 'vue-pdf-embed'
import {getFileByUrl, uploadPdf} from "@/api/api/upload";
const graphOptions = { const graphOptions = {
debug: true, debug: true,
backgrounImageNoRepeat: true, backgrounImageNoRepeat: true,
@ -103,7 +105,8 @@ export default {
name: 'articleInfo', name: 'articleInfo',
components: { components: {
LeftInfo, LeftInfo,
HeaderInfo HeaderInfo,
VuePdfEmbed
}, },
data() { data() {
@ -936,8 +939,39 @@ export default {
mounted() { mounted() {
// this.getInfoInit(); // this.getInfoInit();
this.id = this.$route.query.id; this.id = this.$route.query.id;
getArticleInfo(this.id).then(res=>{ getArticleInfo(this.id).then(async res => {
this.content=res this.content = res
if(this.content.uploadUrl==null && this.content.uploadUrl==''){
const localFilePath = this.content.localUrl;
try {
const response = await getFileByUrl({
filePath: localFilePath
});
if (response.code === 200) {
this.pdfInfo = response;
this.content.uploadUrl = this.pdfInfo.url
updateArticle(this.content).then((res)=>{
console.log(res)
})
console.log('PDF 可访问地址:', this.pdfInfo.url);
this.content.uploadUrl = this.pdfInfo.url
} else {
this.$message.error('获取文件失败:' + response.msg);
}
} catch (error) {
console.error('请求异常:', error);
this.$message.error('网络错误或文件不存在');
}
}
// this.content.content=this.content.content.replace(/\n/g, '<br>'); // this.content.content=this.content.content.replace(/\n/g, '<br>');
}) })
// this.level = this.$route.query.level; // this.level = this.$route.query.level;

12
gyxtp/src/view/graphPageCopy.vue

@ -197,10 +197,10 @@
<el-drawer v-model="drawer" title="相关文档" direction="rtl" size="30%" :modal="false" :wrapperClosable="false" <el-drawer v-model="drawer" title="相关文档" direction="rtl" size="30%" :modal="false" :wrapperClosable="false"
:append-to-body="true" @opened="onDrawerOpened" @closed="onDrawerClosed" :append-to-body="true" @opened="onDrawerOpened" @closed="onDrawerClosed"
style="position: fixed;right: 0;background-color: rgba(76, 100, 233, 0.71);top: 5.35vw;height: 91%;color: #fff"> style="position: fixed;right: 0;background-color: rgba(76, 100, 233, 0.71);top: 5.35vw;height: 91%;color: #fff;font-size: 2vw;">
<el-table :data="tableData" style="width: 95%;margin-left: 2.5%;height: 97%; background: transparent;" <el-table :data="tableData" style="width: 100%;margin-left: 3.25%;height: 97%; background: transparent;"
v-if="drawer"> v-if="drawer">
<el-table-column label="文档名称" width="300"> <el-table-column label="文档名称" width="500">
<template #default="scope"> <template #default="scope">
<div @click="goArticle(scope.row)" style="cursor: pointer; padding: 8px;"> <div @click="goArticle(scope.row)" style="cursor: pointer; padding: 8px;">
{{ scope.row.name }} {{ scope.row.name }}
@ -959,7 +959,7 @@ export default {
line.num <= 5 ? 'rgb(255, 255, 255)' : // line.num <= 5 ? 'rgb(255, 255, 255)' : //
line.num <= 10 ? 'rgb(0, 255, 0)' : // 绿 line.num <= 10 ? 'rgb(0, 255, 0)' : // 绿
line.num <= 15 ? 'rgb(255, 255, 0)' : // line.num <= 15 ? 'rgb(255, 255, 0)' : //
'rgb(255, 0, 0)', // line.num <= 2020 'rgb(178,246,255)', // line.num <= 2020
lineWidth:1, lineWidth:1,
lineShape: 1, lineShape: 1,
}) })
@ -2051,4 +2051,8 @@ tr {
.el-tree--highlight-current { .el-tree--highlight-current {
background: no-repeat; background: no-repeat;
} }
.el-icon{
color: #FFFFFF !important;
font-size: 1vw;
}
</style> </style>

11
ruoyi-api/src/main/java/com/ruoyi/api/controller/ZhyArticleController.java

@ -1,5 +1,6 @@
package com.ruoyi.api.controller; package com.ruoyi.api.controller;
import com.ruoyi.api.domain.ZhyDocStudentTestApi;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
@ -12,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -33,7 +35,7 @@ public class ZhyArticleController extends BaseController
/** /**
* 查询文献管理列表 * 查询文献管理列表
*/ */
@PreAuthorize("@ss.hasPermi('system:article:list')")
@GetMapping("/list") @GetMapping("/list")
public TableDataInfo list(ZhyArticle zhyArticle) public TableDataInfo list(ZhyArticle zhyArticle)
{ {
@ -170,10 +172,9 @@ public class ZhyArticleController extends BaseController
/** /**
* 修改文献管理 * 修改文献管理
*/ */
@PreAuthorize("@ss.hasPermi('system:article:edit')") @PostMapping("/updateArticle")
@Log(title = "文献管理", businessType = BusinessType.UPDATE) public AjaxResult updateArticle(HttpServletRequest request, @RequestBody ZhyArticle zhyArticle)
@PutMapping
public AjaxResult edit(@RequestBody ZhyArticle zhyArticle)
{ {
return toAjax(zhyArticleService.updateZhyArticle(zhyArticle)); return toAjax(zhyArticleService.updateZhyArticle(zhyArticle));
} }

63
ruoyi-api/src/main/java/com/ruoyi/api/controller/uploadApiController.java

@ -8,11 +8,15 @@ import com.ruoyi.framework.config.ServerConfig;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Map;
@RestController @RestController
@RequestMapping("/api/updateload") @RequestMapping("/api/updateload")
@ -51,4 +55,57 @@ public class uploadApiController {
return AjaxResult.error(e.getMessage()); return AjaxResult.error(e.getMessage());
} }
} }
@PostMapping("/file/info")
public AjaxResult getFileByUrl(@RequestBody Map<String, String> params) {
try {
String filePath = params.get("filePath");
if (filePath == null || filePath.trim().isEmpty()) {
return AjaxResult.error("缺少参数:filePath 不能为空");
}
// 检查文件是否存在
Path path = Paths.get(filePath.trim());
if (!Files.exists(path)) {
return AjaxResult.error("文件不存在:" + filePath);
}
if (Files.isDirectory(path)) {
return AjaxResult.error("路径不是一个文件:" + filePath);
}
// 获取原始文件名
String originalFilename = path.getFileName().toString();
// 定义上传目录和服务器访问前缀
String uploadDir = RuoYiConfig.getUploadPath(); // 例如 D:/update/upload/
String serverUrlPrefix = serverConfig.getUrl(); // 例如 http://localhost:8080/profile/upload/
// 定义目标相对路径(可自定义规则)
String relativePath = "/profile/upload/pdf/" + originalFilename;
Path targetPath = Paths.get(uploadDir, relativePath);
System.out.println(targetPath);
// 确保目标目录存在
Files.createDirectories(targetPath.getParent());
// 复制文件到可访问目录(关键:让 Spring 能通过静态资源访问)
Files.copy(path, targetPath, StandardCopyOption.REPLACE_EXISTING);
// 构建可访问的 URL
String accessibleUrl = serverUrlPrefix + relativePath;
AjaxResult ajax = AjaxResult.success();
ajax.put("url", accessibleUrl);
ajax.put("fileName", relativePath);
ajax.put("newFileName", FileUtils.getName(relativePath));
ajax.put("originalFilename", originalFilename);
return ajax;
} catch (Exception e) {
return AjaxResult.error("文件处理失败:" + e.getMessage());
}
}
} }

15
ruoyi-system/src/main/java/com/ruoyi/system/domain/ZhyArticle.java

@ -66,8 +66,22 @@ public class ZhyArticle extends BaseEntity
@Excel(name = "urls") @Excel(name = "urls")
private String urls; private String urls;
private String uploadUrl;
public String getUploadUrl() {
return uploadUrl;
}
public void setUploadUrl(String uploadUrl) {
this.uploadUrl = uploadUrl;
}
private String content; private String content;
public String getContent() { public String getContent() {
return content; return content;
} }
@ -92,6 +106,7 @@ public class ZhyArticle extends BaseEntity
", agencies='" + agencies + '\'' + ", agencies='" + agencies + '\'' +
", summary='" + summary + '\'' + ", summary='" + summary + '\'' +
", urls='" + urls + '\'' + ", urls='" + urls + '\'' +
", uploadUrl='" + uploadUrl + '\'' +
", content='" + content + '\'' + ", content='" + content + '\'' +
'}'; '}';
} }

7
ruoyi-system/src/main/resources/mapper/system/ZhyArticleMapper.xml

@ -18,10 +18,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="agencies" column="agencies" /> <result property="agencies" column="agencies" />
<result property="summary" column="summary" /> <result property="summary" column="summary" />
<result property="urls" column="urls" /> <result property="urls" column="urls" />
<result property="uploadUrl" column="upload_url" />
</resultMap> </resultMap>
<sql id="selectZhyArticleVo"> <sql id="selectZhyArticleVo">
select id, name, open_url, local_url, source_id, source_name, target_id, tagert_name, authors, keywords, agencies, summary, urls from zhy_article select id, name, open_url, local_url, source_id, source_name, target_id, tagert_name, authors, keywords, agencies, summary, urls,upload_url from zhy_article
</sql> </sql>
<select id="selectZhyArticleList" parameterType="ZhyArticle" resultMap="ZhyArticleResult"> <select id="selectZhyArticleList" parameterType="ZhyArticle" resultMap="ZhyArticleResult">
@ -39,6 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="agencies != null and agencies != ''"> and agencies = #{agencies}</if> <if test="agencies != null and agencies != ''"> and agencies = #{agencies}</if>
<if test="summary != null and summary != ''"> and summary = #{summary}</if> <if test="summary != null and summary != ''"> and summary = #{summary}</if>
<if test="urls != null and urls != ''"> and urls = #{urls}</if> <if test="urls != null and urls != ''"> and urls = #{urls}</if>
<if test="uploadUrl != null and uploadUrl != ''"> and upload_url = #{uploadUrl}</if>
</where> </where>
</select> </select>
@ -62,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="agencies != null">agencies,</if> <if test="agencies != null">agencies,</if>
<if test="summary != null">summary,</if> <if test="summary != null">summary,</if>
<if test="urls != null">urls,</if> <if test="urls != null">urls,</if>
<if test="uploadUrl != null">upload_url,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if> <if test="name != null">#{name},</if>
@ -76,6 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="agencies != null">#{agencies},</if> <if test="agencies != null">#{agencies},</if>
<if test="summary != null">#{summary},</if> <if test="summary != null">#{summary},</if>
<if test="urls != null">#{urls},</if> <if test="urls != null">#{urls},</if>
<if test="uploadUrl != null">#{uploadUrl},</if>
</trim> </trim>
</insert> </insert>
@ -94,6 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="agencies != null">agencies = #{agencies},</if> <if test="agencies != null">agencies = #{agencies},</if>
<if test="summary != null">summary = #{summary},</if> <if test="summary != null">summary = #{summary},</if>
<if test="urls != null">urls = #{urls},</if> <if test="urls != null">urls = #{urls},</if>
<if test="uploadUrl != null">upload_url = #{uploadUrl},</if>
</trim> </trim>
where id = #{id} where id = #{id}
</update> </update>

Loading…
Cancel
Save