Merge pull request '增加json-editor-vue' (#322) from Junong/Admin.NET.Pro:v2 into v2
Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/322
This commit is contained in:
commit
ce9f5bea6f
@ -46,6 +46,7 @@
|
|||||||
"install": "^0.13.0",
|
"install": "^0.13.0",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"js-table2excel": "^1.1.2",
|
"js-table2excel": "^1.1.2",
|
||||||
|
"json-editor-vue": "^0.18.1",
|
||||||
"jsplumb": "^2.15.6",
|
"jsplumb": "^2.15.6",
|
||||||
"jwchat": "^2.0.3",
|
"jwchat": "^2.0.3",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
|
|||||||
64
Web/src/components/jsonEditor/index.vue
Normal file
64
Web/src/components/jsonEditor/index.vue
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
<!--
|
||||||
|
// JsonEditor组件,用于编辑类json格式数据,防止配置式数据的错误格式输入
|
||||||
|
// 使用示例:
|
||||||
|
<template>
|
||||||
|
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
||||||
|
<el-form-item label="内容" prop="content">
|
||||||
|
<JsonEditor ref="jsonEditorRef" v-model:jsonObj="ruleForm.content"></JsonEditor>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import JsonEditor from '/@/components/jsonEditor/index.vue';
|
||||||
|
</script>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<!-- 根据 isJsonValid 控制 JsonEditorVue 的显示 -->
|
||||||
|
<JsonEditorVue ref="jsonEditorVueRef" v-show="isJsonValid" v-model="internalJsonObj" mode="text" style="width: 100%; height: 800px" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts" name="jsonEditor">
|
||||||
|
import { ref, useTemplateRef, watch, onMounted, computed } from 'vue';
|
||||||
|
import JsonEditorVue from 'json-editor-vue';
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
jsonObj: {
|
||||||
|
type: null,
|
||||||
|
default: null, // 允许为 null
|
||||||
|
required: false, // 不是必需的
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const jsonEditorVueRef = useTemplateRef('jsonEditorVueRef');
|
||||||
|
const internalJsonObj = ref(props.jsonObj);
|
||||||
|
const emit = defineEmits(['update:jsonObj']);
|
||||||
|
|
||||||
|
// 计算属性,判断 jsonObj 是否为有效的 JSON 字符串,这里为简易判断,防止输入框失去焦点时,组件频繁隐藏和显示
|
||||||
|
const isJsonValid = computed(() => {
|
||||||
|
// try {
|
||||||
|
// if (internalJsonObj.value && (internalJsonObj.value.startsWith('{') || internalJsonObj.value.startsWith('[')) && (internalJsonObj.value.endsWith('}') || internalJsonObj.value.endsWith(']'))) {
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
// } catch {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听内部 JSON 对象变化并触发外部更新
|
||||||
|
watch(internalJsonObj, () => {
|
||||||
|
emit('update:jsonObj', internalJsonObj.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听外部字符串变化并更新内部JSON对象
|
||||||
|
watch(
|
||||||
|
() => props.jsonObj,
|
||||||
|
(newVal) => {
|
||||||
|
internalJsonObj.value = newVal;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
jsonEditorVueRef.value.jsonEditor.focus();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@ -102,9 +102,9 @@ export const setupVXETable = (app: App<Element>) => {
|
|||||||
background: true, // 带背景颜色
|
background: true, // 带背景颜色
|
||||||
perfect: false, // 配套的样式
|
perfect: false, // 配套的样式
|
||||||
autoHidden: false, // 当只有一页时自动隐藏
|
autoHidden: false, // 当只有一页时自动隐藏
|
||||||
pageSize: 50, // 每页大小
|
pageSize: 20, // 每页大小
|
||||||
pagerCount: 10, // 显示页码按钮的数量
|
pagerCount: 10, // 显示页码按钮的数量
|
||||||
pageSizes: [50, 100, 200, 500, 1000, 2000], // 每页大小选项列表
|
pageSizes: [10, 20, 50, 100, 200, 500], // 每页大小选项列表
|
||||||
layouts: ['PrevJump', 'PrevPage', 'JumpNumber', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'PageCount', 'Total'], // 自定义布局
|
layouts: ['PrevJump', 'PrevPage', 'JumpNumber', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'PageCount', 'Total'], // 自定义布局
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user