From f462eed1b6acc1ea8be04ca4bff8ac7d966694e1 Mon Sep 17 00:00:00 2001 From: RB Date: Thu, 30 Nov 2023 20:31:30 +0800 Subject: [PATCH] code-viewport --- .eslintrc.js | 2 + .../web/admin/audit/RecycleBinController.java | 20 ++++++--- .../web/admin/audit/recycle-bin.html | 4 ++ .../web/admin/integration/apis-manager.html | 8 +--- src/main/resources/web/assets/css/rb-page.css | 25 +++++++++++ .../web/assets/js/admin/apis-manager.js | 41 ++++--------------- .../web/assets/js/admin/recycle-bin.js | 26 +++++++++++- .../resources/web/assets/js/rb-components.js | 35 ++++++++++++++++ src/main/resources/web/assets/js/rb-page.js | 21 +++++++++- 9 files changed, 133 insertions(+), 49 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4f247dbe2..8455e637a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -129,5 +129,7 @@ module.exports = { $escapeHtml: true, $isLight: true, RbGritter: true, + $formattedCode: true, + CodeViewport: true, }, } diff --git a/src/main/java/com/rebuild/web/admin/audit/RecycleBinController.java b/src/main/java/com/rebuild/web/admin/audit/RecycleBinController.java index 4a66a86c1..9258c04fb 100644 --- a/src/main/java/com/rebuild/web/admin/audit/RecycleBinController.java +++ b/src/main/java/com/rebuild/web/admin/audit/RecycleBinController.java @@ -8,13 +8,16 @@ package com.rebuild.web.admin.audit; import cn.devezhao.persist4j.engine.ID; +import com.rebuild.api.RespBody; +import com.rebuild.core.Application; import com.rebuild.core.service.general.recyclebin.RecycleRestore; import com.rebuild.utils.JSONUtils; import com.rebuild.web.BaseController; +import com.rebuild.web.IdParam; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; @@ -27,7 +30,7 @@ * @since 2019-08-20 */ @Slf4j -@Controller +@RestController @RequestMapping("/admin/audit/") public class RecycleBinController extends BaseController { @@ -37,7 +40,7 @@ public ModelAndView page() { } @RequestMapping("recycle-bin/restore") - public void dataList(HttpServletRequest request, HttpServletResponse response) { + public RespBody dataList(HttpServletRequest request) { boolean cascade = getBoolParameter(request, "cascade"); String ids = getParameterNotNull(request, "ids"); @@ -60,9 +63,14 @@ public void dataList(HttpServletRequest request, HttpServletResponse response) { } if (lastError != null && restored == 0) { - writeFailure(response, lastError); - } else { - writeSuccess(response, JSONUtils.toJSONObject("restored", restored)); + return RespBody.error(lastError); } + return RespBody.ok(JSONUtils.toJSONObject("restored", restored)); + } + + @GetMapping("recycle-bin/details") + public RespBody details(@IdParam ID id) { + Object[] o = Application.getQueryFactory().uniqueNoFilter(id, "recordContent"); + return RespBody.ok(o[0]); } } diff --git a/src/main/resources/web/admin/audit/recycle-bin.html b/src/main/resources/web/admin/audit/recycle-bin.html index a39d2337f..ec08b128e 100644 --- a/src/main/resources/web/admin/audit/recycle-bin.html +++ b/src/main/resources/web/admin/audit/recycle-bin.html @@ -34,6 +34,7 @@
+
@@ -51,5 +52,8 @@ + + + diff --git a/src/main/resources/web/admin/integration/apis-manager.html b/src/main/resources/web/admin/integration/apis-manager.html index 85ed17781..0c50c5d09 100644 --- a/src/main/resources/web/admin/integration/apis-manager.html +++ b/src/main/resources/web/admin/integration/apis-manager.html @@ -35,13 +35,6 @@ .logs-detail dd { color: #222; } - .code-wrap > pre { - background-color: #f5f2f0; - color: #905; - text-shadow: 0 1px #fff; - border-radius: 4px; - padding: 15px; - } .search-logs > input { appearance: none !important; outline: none !important; @@ -126,5 +119,6 @@ + diff --git a/src/main/resources/web/assets/css/rb-page.css b/src/main/resources/web/assets/css/rb-page.css index 2cc14a3cd..ccf874963 100644 --- a/src/main/resources/web/assets/css/rb-page.css +++ b/src/main/resources/web/assets/css/rb-page.css @@ -5384,3 +5384,28 @@ div.dataTables_wrapper.compact div.dataTables_oper .btn-space { .dataTables_oper.invisible2 > .btn.J_view { display: inline-block; } + +.code-viewport { + position: relative; +} + +.code-viewport > pre { + background-color: #f5f2f0; + color: #905; + text-shadow: 0 1px #fff; + border-radius: 4px; + padding: 15px; + margin: 0; + font-family: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', 'Liberation Mono', Menlo, Monaco, Consolas, monospace !important; +} + +.code-viewport > a.copy { + position: absolute; + top: 15px; + right: 15px; + display: none; +} + +.code-viewport:hover > a.copy { + display: inline-block; +} \ No newline at end of file diff --git a/src/main/resources/web/assets/js/admin/apis-manager.js b/src/main/resources/web/assets/js/admin/apis-manager.js index 3d09f02b3..7936655c2 100644 --- a/src/main/resources/web/assets/js/admin/apis-manager.js +++ b/src/main/resources/web/assets/js/admin/apis-manager.js @@ -231,19 +231,9 @@ class AppLogsViewer extends RbModal {
{$L('请求地址')}
{dataShow[3]}
{$L('请求数据')}
-
-
-
 (this._$codeReq = c)}>{JSON.stringify(dataShow[4])}
-
-
+
{dataShow[4] && }
{$L('响应数据')}
-
-
-
 (this._$codeResp = c)}>
-                        {JSON.stringify(dataShow[5])}
-                      
-
-
+
{dataShow[5] && }
) : ( @@ -265,12 +255,12 @@ class AppLogsViewer extends RbModal { this._loadNext() } - componentDidUpdate(prevProps, prevState) { - if (this._$codeReq && this._$codeResp && (this.state.dataShow || [])[6] !== (prevState || [])[6]) { - this._$codeReq.innerHTML = this._formattedCode(JSON.stringify(this.state.dataShow[4])) - this._$codeResp.innerHTML = this._formattedCode(JSON.stringify(this.state.dataShow[5])) - } - } + // componentDidUpdate(prevProps, prevState) { + // if (this._$codeReq && this._$codeResp && (this.state.dataShow || [])[6] !== (prevState || [])[6]) { + // this._$codeReq.innerHTML = $formattedCode(this.state.dataShow[4]) + // this._$codeResp.innerHTML = $formattedCode(this.state.dataShow[5]) + // } + // } _loadNext(reset, q) { if (this.__inLoading) return @@ -306,19 +296,4 @@ class AppLogsViewer extends RbModal { } return false } - - _formattedCode(c) { - try { - // eslint-disable-next-line no-undef - return prettier.format(c, { - parser: 'json', - // eslint-disable-next-line no-undef - plugins: prettierPlugins, - printWidth: 10, - }) - } catch (err) { - console.log('Cannot format :', err) - return c - } - } } diff --git a/src/main/resources/web/assets/js/admin/recycle-bin.js b/src/main/resources/web/assets/js/admin/recycle-bin.js index 725834ebe..87eaabe68 100644 --- a/src/main/resources/web/assets/js/admin/recycle-bin.js +++ b/src/main/resources/web/assets/js/admin/recycle-bin.js @@ -64,6 +64,7 @@ class DataList extends React.Component { this._$recordName = $input $('.J_restore').on('click', () => this.restore()) + $('.J_details').on('click', () => this.showDetails()) } queryList() { @@ -93,13 +94,13 @@ class DataList extends React.Component { if (!ids || ids.length === 0) return const alertMsg = ( - +
{$L('是否恢复选中的 %d 条记录?', ids.length)}
-
+ ) const that = this @@ -121,6 +122,13 @@ class DataList extends React.Component { }, }) } + + showDetails() { + const ids = this._List.getSelectedIds() + if (!ids || ids.length === 0) return + + renderRbcomp() + } } const CellRenders_renderSimple = CellRenders.renderSimple @@ -145,3 +153,17 @@ CellRenders.renderSimple = function (v, s, k) { return CellRenders_renderSimple(v, s, k) } + +// ~~ 数据详情 +class DlgDetails extends RbAlert { + renderContent() { + return this.state.code && + } + + componentDidMount() { + $.get(`/admin/audit/recycle-bin/details?id=${this.props.id}`, (res) => { + super.componentDidMount() + this.setState({ code: res.data }) + }) + } +} diff --git a/src/main/resources/web/assets/js/rb-components.js b/src/main/resources/web/assets/js/rb-components.js index b696c4687..fdf767032 100644 --- a/src/main/resources/web/assets/js/rb-components.js +++ b/src/main/resources/web/assets/js/rb-components.js @@ -1182,6 +1182,41 @@ class RbGritter extends React.Component { } } +// 代码 +class CodeViewport extends React.Component { + render() { + return ( +
+
 (this._$code = c)}>Loading
+ {window.ClipboardJS && ( + (this._$copy = c)}> + + + )} +
+ ) + } + + componentDidMount() { + this._$code.innerHTML = $formattedCode(this.props.code || '') + + if (this._$copy) { + const that = this + const $copy = $(this._$copy).on('mouseenter', () => $(this._$copy).removeClass('copied-check')) + // eslint-disable-next-line no-undef + new ClipboardJS($copy[0], { + text: function () { + return $(that._$code).text() + }, + }).on('success', () => $copy.addClass('copied-check')) + } + } + + UNSAFE_componentWillReceiveProps(newProps) { + if (newProps.code) this._$code.innerHTML = $formattedCode(newProps.code) + } +} + /** * JSX 组件渲染 * diff --git a/src/main/resources/web/assets/js/rb-page.js b/src/main/resources/web/assets/js/rb-page.js index c87586b56..5e99e816b 100644 --- a/src/main/resources/web/assets/js/rb-page.js +++ b/src/main/resources/web/assets/js/rb-page.js @@ -8,7 +8,7 @@ See LICENSE and COMMERCIAL in the project root for license information. /* !!! KEEP IT ES5 COMPATIBLE !!! */ // GA -(function () { +;(function () { var gaScript = document.createElement('script') gaScript.src = 'https://www.googletagmanager.com/gtag/js?id=G-ZCZHJPMEG7' gaScript.async = true @@ -1119,3 +1119,22 @@ var $pages = function (tp, cp) { if (end <= tp) pages.push(tp) return pages } + +// 格式化代码 +var $formattedCode = function (c, type) { + if (typeof c === 'object') c = JSON.stringify(c) + if (!window.prettier) return c + + try { + // eslint-disable-next-line no-undef + return prettier.format(c, { + parser: type || 'json', + // eslint-disable-next-line no-undef + plugins: prettierPlugins, + printWidth: 10, + }) + } catch (err) { + console.log('Cannot format code :', err) + return c + } +}