mirror of
				https://github.com/continew-org/continew-admin-ui.git
				synced 2025-11-04 10:57:08 +08:00 
			
		
		
		
	feat: 操作日志新增复制功能
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/components/JsonPretty/index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/components/JsonPretty/index.vue
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <div class="json_prettt_container">
 | 
				
			||||||
 | 
					    <vue-json-pretty
 | 
				
			||||||
 | 
					              :path="'res'"
 | 
				
			||||||
 | 
					              :data="JSONObject"
 | 
				
			||||||
 | 
					              :show-length="true"
 | 
				
			||||||
 | 
					            />
 | 
				
			||||||
 | 
					    <icon-copy class="copy_icon" @click="onCopy(JSONObject)"/>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					<script setup lang="ts">
 | 
				
			||||||
 | 
					import VueJsonPretty from 'vue-json-pretty'
 | 
				
			||||||
 | 
					import 'vue-json-pretty/lib/styles.css'
 | 
				
			||||||
 | 
					import {copyText} from '@/utils'
 | 
				
			||||||
 | 
					defineOptions({ name: 'JsonPretty', inheritAttrs: false })
 | 
				
			||||||
 | 
					const props = defineProps<{
 | 
				
			||||||
 | 
					  josn: string
 | 
				
			||||||
 | 
					}>()
 | 
				
			||||||
 | 
					const JSONObject = computed(()=>JSON.parse(props?.josn))
 | 
				
			||||||
 | 
					const onCopy =(data:object)=>{
 | 
				
			||||||
 | 
					  copyText(JSON.stringify(data))
 | 
				
			||||||
 | 
					  console.log('copyObject',data)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					<style lang="scss" scoped>
 | 
				
			||||||
 | 
					.json_prettt_container{
 | 
				
			||||||
 | 
					  width: 100%;
 | 
				
			||||||
 | 
					  height: 100%;
 | 
				
			||||||
 | 
					  overflow: auto;
 | 
				
			||||||
 | 
					  position: relative;
 | 
				
			||||||
 | 
					  .copy_icon{
 | 
				
			||||||
 | 
					    position: absolute;
 | 
				
			||||||
 | 
					    right: 10px;
 | 
				
			||||||
 | 
					    top: 10px;
 | 
				
			||||||
 | 
					    font-size: 20px;
 | 
				
			||||||
 | 
					    cursor: pointer;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
							
								
								
									
										1
									
								
								src/types/components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								src/types/components.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -34,6 +34,7 @@ declare module 'vue' {
 | 
				
			|||||||
    IconTableSize: typeof import('./../components/icons/IconTableSize.vue')['default']
 | 
					    IconTableSize: typeof import('./../components/icons/IconTableSize.vue')['default']
 | 
				
			||||||
    IconTreeAdd: typeof import('./../components/icons/IconTreeAdd.vue')['default']
 | 
					    IconTreeAdd: typeof import('./../components/icons/IconTreeAdd.vue')['default']
 | 
				
			||||||
    IconTreeReduce: typeof import('./../components/icons/IconTreeReduce.vue')['default']
 | 
					    IconTreeReduce: typeof import('./../components/icons/IconTreeReduce.vue')['default']
 | 
				
			||||||
 | 
					    JsonPretty: typeof import('./../components/JsonPretty/index.vue')['default']
 | 
				
			||||||
    ParentView: typeof import('./../components/ParentView/index.vue')['default']
 | 
					    ParentView: typeof import('./../components/ParentView/index.vue')['default']
 | 
				
			||||||
    RouterLink: typeof import('vue-router')['RouterLink']
 | 
					    RouterLink: typeof import('vue-router')['RouterLink']
 | 
				
			||||||
    RouterView: typeof import('vue-router')['RouterView']
 | 
					    RouterView: typeof import('vue-router')['RouterView']
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
import { isExternal } from "@/utils/validate";
 | 
					import { isExternal } from "@/utils/validate";
 | 
				
			||||||
import { browse, mapTree } from "xe-utils";
 | 
					import { browse, mapTree } from "xe-utils";
 | 
				
			||||||
import _ from "lodash";
 | 
					import _ from "lodash";
 | 
				
			||||||
 | 
					import { Message } from "@arco-design/web-vue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
 | 
					export function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
 | 
				
			||||||
  return obj[key]
 | 
					  return obj[key]
 | 
				
			||||||
@@ -242,3 +243,12 @@ export const formatFileSize = (fileSize: number) => {
 | 
				
			|||||||
  const size = srcSize / 1024 ** index
 | 
					  const size = srcSize / 1024 ** index
 | 
				
			||||||
  return `${size.toFixed(2)} ${unitArr[index]}`
 | 
					  return `${size.toFixed(2)} ${unitArr[index]}`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					export const copyText =(text:any) =>{
 | 
				
			||||||
 | 
					  const textarea = document.createElement('textarea');
 | 
				
			||||||
 | 
					  textarea.value = text;
 | 
				
			||||||
 | 
					  document.body.appendChild(textarea);
 | 
				
			||||||
 | 
					  textarea.select();
 | 
				
			||||||
 | 
					  document.execCommand('copy');
 | 
				
			||||||
 | 
					  document.body.removeChild(textarea);
 | 
				
			||||||
 | 
					  Message.success('复制成功')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -38,21 +38,11 @@
 | 
				
			|||||||
      <a-descriptions-item :span="2">
 | 
					      <a-descriptions-item :span="2">
 | 
				
			||||||
        <a-tabs type="card">
 | 
					        <a-tabs type="card">
 | 
				
			||||||
          <a-tab-pane key="1" title="响应头">
 | 
					          <a-tab-pane key="1" title="响应头">
 | 
				
			||||||
            <VueJsonPretty
 | 
					            <JsonPretty v-if="operationLog?.responseHeaders" :josn="operationLog?.responseHeaders"/>
 | 
				
			||||||
              v-if="operationLog?.responseHeaders"
 | 
					 | 
				
			||||||
              :path="'res'"
 | 
					 | 
				
			||||||
              :data="JSON.parse(operationLog?.responseHeaders)"
 | 
					 | 
				
			||||||
              :show-length="true"
 | 
					 | 
				
			||||||
            />
 | 
					 | 
				
			||||||
            <span v-else>无</span>
 | 
					            <span v-else>无</span>
 | 
				
			||||||
          </a-tab-pane>
 | 
					          </a-tab-pane>
 | 
				
			||||||
          <a-tab-pane key="2" title="响应体">
 | 
					          <a-tab-pane key="2" title="响应体">
 | 
				
			||||||
            <VueJsonPretty
 | 
					            <JsonPretty v-if="operationLog?.responseBody" :josn="operationLog?.responseBody"/>
 | 
				
			||||||
              v-if="operationLog?.responseBody"
 | 
					 | 
				
			||||||
              :path="'res'"
 | 
					 | 
				
			||||||
              :data="JSON.parse(operationLog?.responseBody)"
 | 
					 | 
				
			||||||
              :show-length="true"
 | 
					 | 
				
			||||||
            />
 | 
					 | 
				
			||||||
            <span v-else>无</span>
 | 
					            <span v-else>无</span>
 | 
				
			||||||
          </a-tab-pane>
 | 
					          </a-tab-pane>
 | 
				
			||||||
        </a-tabs>
 | 
					        </a-tabs>
 | 
				
			||||||
@@ -68,21 +58,11 @@
 | 
				
			|||||||
      <a-descriptions-item :span="2">
 | 
					      <a-descriptions-item :span="2">
 | 
				
			||||||
        <a-tabs type="card">
 | 
					        <a-tabs type="card">
 | 
				
			||||||
          <a-tab-pane key="1" title="请求头">
 | 
					          <a-tab-pane key="1" title="请求头">
 | 
				
			||||||
            <VueJsonPretty
 | 
					            <JsonPretty v-if="operationLog?.requestHeaders" :josn="operationLog?.requestHeaders"/>
 | 
				
			||||||
              v-if="operationLog?.requestHeaders"
 | 
					 | 
				
			||||||
              :path="'res'"
 | 
					 | 
				
			||||||
              :data="JSON.parse(operationLog?.requestHeaders)"
 | 
					 | 
				
			||||||
              :show-length="true"
 | 
					 | 
				
			||||||
            />
 | 
					 | 
				
			||||||
            <span v-else>无</span>
 | 
					            <span v-else>无</span>
 | 
				
			||||||
          </a-tab-pane>
 | 
					          </a-tab-pane>
 | 
				
			||||||
          <a-tab-pane key="2" title="请求体">
 | 
					          <a-tab-pane key="2" title="请求体">
 | 
				
			||||||
            <VueJsonPretty
 | 
					            <JsonPretty v-if="operationLog?.requestBody" :josn="operationLog?.requestBody"/>
 | 
				
			||||||
              v-if="operationLog?.requestBody"
 | 
					 | 
				
			||||||
              :path="'res'"
 | 
					 | 
				
			||||||
              :data="JSON.parse(operationLog?.requestBody)"
 | 
					 | 
				
			||||||
              :show-length="true"
 | 
					 | 
				
			||||||
            />
 | 
					 | 
				
			||||||
            <span v-else>无</span>
 | 
					            <span v-else>无</span>
 | 
				
			||||||
          </a-tab-pane>
 | 
					          </a-tab-pane>
 | 
				
			||||||
        </a-tabs>
 | 
					        </a-tabs>
 | 
				
			||||||
@@ -93,8 +73,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script lang="ts" setup>
 | 
					<script lang="ts" setup>
 | 
				
			||||||
import { getLog, type LogDetailResp } from '@/apis'
 | 
					import { getLog, type LogDetailResp } from '@/apis'
 | 
				
			||||||
import VueJsonPretty from 'vue-json-pretty'
 | 
					import JsonPretty from '@/components/JsonPretty/index.vue'
 | 
				
			||||||
import 'vue-json-pretty/lib/styles.css'
 | 
					 | 
				
			||||||
const logId = ref('')
 | 
					const logId = ref('')
 | 
				
			||||||
const operationLog = ref<LogDetailResp | null>()
 | 
					const operationLog = ref<LogDetailResp | null>()
 | 
				
			||||||
// 查询详情
 | 
					// 查询详情
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user