当前位置: 首页 > wzjs >正文

高水平高职院校 建设网站网上开店铺需要什么流程

高水平高职院校 建设网站,网上开店铺需要什么流程,网站百度地图怎么做,网页设计规范的主要内容文章目录 oonlyoffice历史版本功能实现 (编辑器功能实现)springbootvue2前提 需要注意把这个 (改成自己服务器的ip或者域名) 改成 自己服务器的域名或者地址1. onloyoffice 服务器部署 搜索其他文章2. 前段代码 vue 22.1 需要注意把这个 (改成自己服务器…

文章目录

  • oonlyoffice历史版本功能实现 (编辑器功能实现)springboot+vue2
  • 前提 需要注意把这个 (改成自己服务器的ip或者域名) 改成 自己服务器的域名或者地址
  • 1. onloyoffice 服务器部署 搜索其他文章
  • 2. 前段代码 vue 2
    • 2.1 需要注意把这个 (改成自己服务器的ip或者域名) 改成 自己服务器的域名或者地址
    • 2.2. openedit getHistoryData 这两个 是调用后端的 接口 改成自己项目的写法 都是 post 请求
    • 2.3 下面是整个页面代码 需要 别的页面进入下面这个页面 入参是 文件id
    • 举例
    • 进入editer.vue 页面的 页面代码 row.id 是文件id 也就是 onloyoffice 文件id
      • 文件名字 editer.vue
  • 3. 后端java 代码
    • 3.1 controller 代码
    • 3.2 service 代码
    • 3.3 serviceImpl 代码
    • 3.3公共方法代码
  • 4.效果图
  • 5.可以参考此文章优化代码

oonlyoffice历史版本功能实现 (编辑器功能实现)springboot+vue2

前提 需要注意把这个 (改成自己服务器的ip或者域名) 改成 自己服务器的域名或者地址

1. onloyoffice 服务器部署 搜索其他文章

2. 前段代码 vue 2

2.1 需要注意把这个 (改成自己服务器的ip或者域名) 改成 自己服务器的域名或者地址

2.2. openedit getHistoryData 这两个 是调用后端的 接口 改成自己项目的写法 都是 post 请求

2.3 下面是整个页面代码 需要 别的页面进入下面这个页面 入参是 文件id

举例

进入editer.vue 页面的 页面代码 row.id 是文件id 也就是 onloyoffice 文件id

//row.id 是文件id 也就是 onloyoffice 文件id
//  /only/editer/   这是页面路由的地址需要在路由里面配置
//页面
openFile(row) {window.open('#/only/editer/' + row.id,'_blank');},

文件名字 editer.vue

<template><div><div id="onlyoffice-container" ref="editorContainer"></div></div>
</template><script>export default {name: 'OnlyOfficeEditor',props: {isEdit: {type: Boolean,default: true}},data() {return {docEditor: null,currentVersion: null,fileToken: null,historyData: null,historys: [],historyList: []};},mounted() {this.loadScript().then(() => {this.initEditor();});},methods: {async loadScript() {return new Promise((resolve, reject) => {const scriptId = "onlyoffice-api-script";if (!document.getElementById(scriptId)) {const script = document.createElement('script');script.id = scriptId;script.src = "https://(改成自己服务器的ip或者域名)/ds-vpath/web-apps/apps/api/documents/api.js"; // 替换为你的 ONLYOFFICE 服务器地址script.type = "text/javascript";script.onload = resolve;script.onerror = reject;document.head.appendChild(script);} else {resolve();}});},initEditor() {if (this.docEditor) {this.docEditor.destroyEditor();this.docEditor = null;}openedit({"fileId": this.$route.params.id}).then(res  => {if (res.code  === 200) {//这是主编辑器获取的数据  config let config = res.data.openedit;//处理后端返回的历史版本数据const historyList = res.data.historyList;const fileToken = res.data.fileToken;const currentVersion  = historyList[0].version; // 假设最新版本为第一个元素// 添加版本历史事件处理config.events  = {//这里拿到的是 左侧版本的 数据 比如 版本1 版本2onRequestHistory: () => {this.docEditor.refreshHistory({currentVersion: currentVersion,token: fileToken,history: historyList});},//这里是 左侧关闭历史记录 按钮调用这个方法onRequestHistoryClose: () => {document.location.reload();},//这是左侧 点击版本  对应的版本内容onRequestHistoryData: (event) => {const version = event.datagetHistoryData({"fileId": this.$route.params.id,"version": version}).then(res  => {const historyData = res.data.historyData;this.docEditor.setHistoryData(historyData);}).catch(err => {console.log(err);});},//版本恢复功能onRequestRestore: (event) => {//待实现}};this.docEditor  = new window.DocsAPI.DocEditor(this.$refs.editorContainer.id,  config);}}).catch(err => {console.log(err);});}},beforeDestroy() {if (this.docEditor)  {this.docEditor.destroyEditor();this.docEditor  = null;}if (this.DocsAPIInterval) {clearInterval(this.DocsAPIInterval);}},beforeRouteLeave(to, from, next) {if (this.docEditor)  {this.docEditor.destroyEditor();this.docEditor  = null;}if (this.DocsAPIInterval) {clearInterval(this.DocsAPIInterval);}next();}
};
</script><style>
iframe {border: none;width: 100%;height: 100vh;
}
</style>

3. 后端java 代码

3.1 controller 代码

    @PostMapping("/openedit")public RestResultDTO openedit(HttpServletRequest request, @RequestBody OnlyofficeRequestDTO params) {try {if (CommonFunctions.isEmpty(params.getFileId())) {throw new BusinessServiceException("非空校验失败");}Map<String, Object> resultMap  = onlyofficeService.openedit(params);return RestResultDTO.success(resultMap);} catch (Exception e) {LOGGER.error("openedit 方法发生异常: ", e);return RestResultDTO.error(ResponseCodeDTO.INTERNAL_SERVER_ERROR, e.getMessage());}}
@PostMapping("/getHistoryData")public RestResultDTO getHistoryData(HttpServletRequest request, @RequestBody OnlyofficeRequestDTO params) {try {if (CommonFunctions.isEmpty(params.getFileId()) || CommonFunctions.isEmpty(params.getVersion())) {throw new BusinessServiceException("非空校验失败");}Map<String, Object> resultMap  = onlyofficeService.getHistoryData(params);return RestResultDTO.success(resultMap);} catch (Exception e) {LOGGER.error("openedit 方法发生异常: ", e);return RestResultDTO.error(ResponseCodeDTO.INTERNAL_SERVER_ERROR, e.getMessage());}}

3.2 service 代码

    Map<String, Object> openedit(OnlyofficeRequestDTO params);
 //获取文件的初始化配置Map<String, Object> getHistoryData(OnlyofficeRequestDTO params);

3.3 serviceImpl 代码

       @Overridepublic Map<String, Object> openedit(OnlyofficeRequestDTO params) {String fileId = params.getFileId();String permissionType = "";JSONObject onlyOfficeConfig = null;try {String result = HttpUtils.executeRequestOnlyoffice(HttpUtils.O_SHAREFILE_URL + fileId + "/openedit", null, null, "UTF-8", "get");JSONObject resJsonObject = JSONObject.parseObject(result);if (CollectionUtils.isEmpty(resJsonObject)) {throw new BusinessServiceException("获取配置文件异常");} else if (resJsonObject.getInteger("statusCode") == 200) {onlyOfficeConfig = resJsonObject.getJSONObject("response");} else if (resJsonObject.getInteger("statusCode") == 500) {throw new BusinessServiceException(resJsonObject.getJSONObject("error").getString("message"));} else {throw new BusinessServiceException("获取配置文件异常");}//只读if ("4".equals(permissionType)) {onlyOfficeConfig.getJSONObject("editorConfig").put("mode", "view");}} catch (Exception e) {LOGGER.error("解析JSON响应失败", e);throw new BusinessServiceException("", e);}JSONArray responseArray = null;try {String result = HttpUtils.executeRequestOnlyoffice(HttpUtils.O_FILES_URL  + "/edit-history?fileId=" + fileId, null, null, "UTF-8", "get");// 尝试解析为 JSONArrayJSONArray resJsonArray = JSONArray.parseArray(result);if (CollectionUtils.isEmpty(resJsonArray))  {throw new BusinessServiceException("获取配置文件异常");}responseArray = resJsonArray;} catch (Exception e) {LOGGER.error(" 解析JSON响应失败", e);throw new BusinessServiceException("", e);}// 使用 Map 封装多个 JSON 对象Map<String, Object> resultMap = new HashMap<>();resultMap.put("openedit", onlyOfficeConfig);resultMap.put("historyList", responseArray);try {resultMap.put("fileToken",HttpUtils.renovateAuthorizationToken());} catch (Exception e) {LOGGER.error(" 获取token失败", e);throw new BusinessServiceException("", e);}return resultMap;}
    @Overridepublic Map<String, Object> getHistoryData(OnlyofficeRequestDTO params) {String fileId = params.getFileId();String version = params.getVersion();JSONObject responseArray = null;try {String result = HttpUtils.executeRequestOnlyoffice(HttpUtils.O_FILES_URL + "/edit-diff-url?fileId=" + fileId + "&version=" + version, null, null, "UTF-8", "get");responseArray = JSONObject.parseObject(result);if (CollectionUtils.isEmpty(responseArray))  {throw new BusinessServiceException("获取配置文件异常");}} catch (Exception e) {LOGGER.error("解析JSON响应失败", e);throw new BusinessServiceException("", e);}// 使用 Map 封装多个 JSON 对象Map<String, Object> resultMap = new HashMap<>();resultMap.put("historyData", responseArray);return resultMap;}

3.3公共方法代码

  /*** 根据请求类型执行POST或PUT请求*/public static String executeRequestOnlyoffice(String url, Map<String, Object> params, Map<String, String> headers, String encoding, String requestType) throws Exception {Map<String, String> headersCover = new HashMap<>();String authorizationToken = getAuthorizationToken();//覆盖默认请求头headersCover.put("Authorization", authorizationToken);headersCover.put("Accept", "application/json");headersCover.put("Content-Type", "application/json");if (headers != null) {for (Map.Entry<String, String> entry : headers.entrySet()) {headersCover.put(entry.getKey(), entry.getValue());}}switch (requestType.toLowerCase()) {case "get":return executeGetRequestCommon(url, params, headersCover, encoding);case "post":return executePostRequestCommon(url, params, headersCover, encoding);case "put":return executePutRequestCommon(url, params, headersCover, encoding);case "delete":return executeDeleteRequestCommon(url, params, headersCover, encoding);default:throw new IllegalArgumentException("Unsupported request type: " + requestType);}}
 /*** 获取授权Token*/public static synchronized void refreshAuthorizationToken() throws Exception {Map<String, Object> params = new HashMap<>();params.put("userName", "");//输入onloyoffice 登录用户名params.put("password", "");//输入onloyoffice登录密码Map<String, String> headers = new HashMap<>();headers.put("Accept", "application/json");headers.put("Content-Type", "application/json");String result = executePostRequestCommon(HttpUtils.O_AUTH_URL, params, headers, "UTF-8");JSONObject jsonObject = JSONObject.parseObject(result);HttpUtils.authorizationToken = "Bearer " + jsonObject.getJSONObject("response").getString("token");}// 获取Token的方法@PostConstructpublic static String getAuthorizationToken() throws Exception {if (CommonFunctions.isEmpty(HttpUtils.authorizationToken)) {refreshAuthorizationToken();}return HttpUtils.authorizationToken;}
    /*** 执行GET通用请求*/public static String executeGetRequestCommon(String url, Map<String, Object> params, Map<String, String> headers, String encoding) throws Exception {// 创建一个带有默认配置的HttpClient,并设置超时时间RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000) // 连接超时时间.setSocketTimeout(10000) // 读取超时时间.build();try (CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build()) {// 构建带有查询参数的URLif (params != null && !params.isEmpty()) {StringBuilder queryString = new StringBuilder(url);if (!url.contains("?")) {queryString.append("?");} else {queryString.append("&");}for (String key : params.keySet()) {queryString.append(key).append("=").append(params.get(key)).append("&");}// 去掉最后一个多余的&if (queryString.toString().endsWith("&")) {queryString.setLength(queryString.length() - 1);}url = queryString.toString();}HttpGet httpGet = new HttpGet(url);// 添加自定义头信息if (headers != null) {for (Map.Entry<String, String> entry : headers.entrySet()) {httpGet.addHeader(entry.getKey(), entry.getValue());}}// 执行请求并获取响应try (CloseableHttpResponse response = httpClient.execute(httpGet)) {HttpEntity entity = response.getEntity();return entity != null ? EntityUtils.toString(entity, encoding != null ? encoding : "UTF-8") : null;}} catch (IOException e) {logger.error("Error executing GET request to URL: {}. Exception: {}", url, e.getMessage(), e);throw e;}}
public static String O_FILES_URL = "https://(自己服务器ip或者域名)/Products/Files/Services/WCFService/service.svc"public static String O_SHAREFILE_URL = "https://(自己服务器ip或者域名)/api/2.0/files/file/"
/*** 获取授权Token* @return 授权Token字符串* @throws Exception 如果请求或解析失败*/public static String renovateAuthorizationToken() throws Exception {// 构造请求参数Map<String, Object> params = new HashMap<>();params.put("userName", "");//输入onloyoffice 登录用户名params.put("password", "");//输入onloyoffice登录密码// 构造请求头Map<String, String> headers = new HashMap<>();headers.put("Accept", "application/json");headers.put("Content-Type", "application/json");// 执行POST请求并获取结果String result = executePostRequestCommon(HttpUtils.O_AUTH_URL, params, headers, "UTF-8");// 解析JSON结果JSONObject jsonObject = JSONObject.parseObject(result);return jsonObject.getJSONObject("response").getString("token");}

4.效果图

在这里插入图片描述
在这里插入图片描述

5.可以参考此文章优化代码

https://www.cnblogs.com/gamepen/p/17849005.html

文章转载自:

http://ZYqoUCOV.hmjns.cn
http://5jQu5j3E.hmjns.cn
http://RPiCTkxE.hmjns.cn
http://3rz37maz.hmjns.cn
http://P1jdxh2U.hmjns.cn
http://qtKRjdDo.hmjns.cn
http://KZ7HFA8V.hmjns.cn
http://fMdyAFGv.hmjns.cn
http://qwNFu9Tp.hmjns.cn
http://XuLxJrYF.hmjns.cn
http://J8EozQDg.hmjns.cn
http://r1rQ9h88.hmjns.cn
http://dx5XOi7H.hmjns.cn
http://wzdeMFom.hmjns.cn
http://eMrzFBQI.hmjns.cn
http://pdw0pyoY.hmjns.cn
http://xL0belMu.hmjns.cn
http://wFBAsAEq.hmjns.cn
http://7XhZw1qD.hmjns.cn
http://SBUMOmdw.hmjns.cn
http://d7oHvlj4.hmjns.cn
http://b0enxoYU.hmjns.cn
http://600QXuDr.hmjns.cn
http://sauE5dnz.hmjns.cn
http://z2u24LGq.hmjns.cn
http://r54hvD4d.hmjns.cn
http://c5bACKcg.hmjns.cn
http://2FTWCaHv.hmjns.cn
http://Yr45rbEg.hmjns.cn
http://CQLbsBbC.hmjns.cn
http://www.dtcms.com/wzjs/672812.html

相关文章:

  • 无锡企业如何建网站网站集约化建设项目内容
  • 上海青浦网站建设公司物流网络优化
  • 网站开发网页制作薪资建设什么网站可以上传视频
  • 在线阅读网站建设方案长沙有哪些做网站的
  • 葫芦岛建设网站石家庄城市建设档案馆网站
  • 电脑做服务器搭建网站最近一周的热点新闻
  • 什么网站做电子元器件网站建设背景及意义
  • 伍佰亿网站线上平面设计培训
  • google建站推广如何快速被百度收录
  • 涉密资质 网站建设沈阳制作网站
  • 网站建设方案范文2000字专业的定制型网站建设
  • 哪家公司建网站最好婚庆公司网站搭建
  • 没有网站怎么做cpa赚钱移动公司营销网站设计
  • 织梦模板网站源码企业网络的设计与实现
  • 做公司网站哪里好芜湖公司做网站
  • 中建二局核电建设分公司网站整站优化是什么意思
  • 南京市住房和城乡建设部网站推荐个做淘宝主图视频的网站
  • 商场网站设计企业网站优化电话
  • 网站排名优化工薪待遇成都代做网站
  • 个人网站设计首页深入解析wordpress 下载
  • 黑彩网站充值就给你做单子辽宁省建设信息网
  • 网站建设存在哪些问题做个企业网站 优帮云
  • 受欢迎的集团网站建设南充 网站建设
  • 公司网站怎么做站外链接网络平台建设公司
  • 深圳做网站找哪家好全国新农村建设中心网站
  • 做百度网站接到多少客户电话怎样网站建设
  • 上海技术网站建设苏州优化哪家公司好
  • 做外贸网站那个好有的网站网速慢
  • 上海哪里有做网站的wordpress无法点上传图片
  • 大连网站制作姚喜运宁国做网站的公司