|
@@ -0,0 +1,303 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import {defineExpose, ref, h} from 'vue'
|
|
|
+import {callAxios, elComponent} from "../../../components/query-components/page-help";
|
|
|
+import {useVModel} from "@vueuse/core";
|
|
|
+import {bindType, componentType, CompType, headerType} from "../../../components/query-components/page-help-type";
|
|
|
+import XEUtils from "xe-utils";
|
|
|
+import {ElInput, ElOption, ElSelect, ElSwitch} from 'element-plus'
|
|
|
+import * as el from 'element-plus'
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ data: headerType,
|
|
|
+ pageJson: componentType
|
|
|
+}>()
|
|
|
+
|
|
|
+const emits = defineEmits(['update:data'])
|
|
|
+const dataVal = useVModel(props, 'data', emits)
|
|
|
+
|
|
|
+const comp = ref<CompType>({bind: null})
|
|
|
+const show = ref(false)
|
|
|
+
|
|
|
+const editComp = (data: headerType) => {
|
|
|
+ comp.value = elComponent[data.name]
|
|
|
+ if (typeof comp.value === 'undefined') {
|
|
|
+ comp.value = {bind: null}
|
|
|
+ }
|
|
|
+ show.value = true
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+const selectRender = (data: bindType, key) => {
|
|
|
+ let optionList = [];
|
|
|
+ data.selectData?.forEach(item => {
|
|
|
+ let hTemp = h(ElOption,
|
|
|
+ {
|
|
|
+ label: item,
|
|
|
+ value: item
|
|
|
+ },
|
|
|
+ null)
|
|
|
+ optionList.push(hTemp)
|
|
|
+ })
|
|
|
+ return h(ElSelect,
|
|
|
+ {
|
|
|
+ modelValue: dataVal.value['bind'][key],
|
|
|
+ "onUpdate:modelValue": (val) => {
|
|
|
+ dataVal.value['bind'][key] = val
|
|
|
+ }
|
|
|
+ },
|
|
|
+ () => optionList)
|
|
|
+}
|
|
|
+
|
|
|
+let elComp = {
|
|
|
+ boolean: 'ElSwitch',
|
|
|
+ number: 'ElInputNumber',
|
|
|
+ input: 'ElInput'
|
|
|
+}
|
|
|
+
|
|
|
+const bindRendering = (data: bindType, key: any) => {
|
|
|
+ if (typeof dataVal.value['bind'][key] === 'undefined') {
|
|
|
+ if (data.defaultValue) {
|
|
|
+ dataVal.value['bind'][key] = data.defaultValue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (data.renderName === 'select') {
|
|
|
+ return selectRender(data, key)
|
|
|
+ } else {
|
|
|
+ let temp = elComp[data.renderName]
|
|
|
+ if (temp) {
|
|
|
+ return h(
|
|
|
+ el[temp],
|
|
|
+ {
|
|
|
+ modelValue: dataVal.value['bind'][key],
|
|
|
+ "onUpdate:modelValue": (val) => {
|
|
|
+ dataVal.value['bind'][key] = val
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ return h('span', {}, '没有找到组件');
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const isSelect = () => {
|
|
|
+ return dataVal.value.name === 'ElSelect'
|
|
|
+}
|
|
|
+const isSelectV2 = () => {
|
|
|
+ return dataVal.value['name'] === 'ElSelectV2'
|
|
|
+}
|
|
|
+
|
|
|
+const addSelectData = () => {
|
|
|
+ dataVal.value['selectData'].push({
|
|
|
+ value: '',
|
|
|
+ label: ''
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const addNetParams = () => {
|
|
|
+ dataVal.value['networkRequests'].params.push({
|
|
|
+ queryName: '',
|
|
|
+ queryValue: ''
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+const interfaceDisplay = ref({
|
|
|
+ dialog: false,
|
|
|
+ data: []
|
|
|
+})
|
|
|
+
|
|
|
+const callTheInterface = async () => {
|
|
|
+ interfaceDisplay.value.dialog = true
|
|
|
+ interfaceDisplay.value.data = await callAxios(props.pageJson, dataVal.value)
|
|
|
+}
|
|
|
+
|
|
|
+const clearSelectData = () => {
|
|
|
+ if (dataVal.value['bind'].multiple) {
|
|
|
+ dataVal.value['defaultValue'] = []
|
|
|
+ } else {
|
|
|
+ dataVal.value['defaultValue'] = ''
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const state = (path, data) => {
|
|
|
+ dataVal.value[path] = data
|
|
|
+}
|
|
|
+
|
|
|
+const test = (value, el) => {
|
|
|
+ if (el.func) {
|
|
|
+ let unboundFunc = new Function('value', 'state', el.func);
|
|
|
+ unboundFunc(value, state)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const interFaced = {
|
|
|
+ 创智中台: () => {
|
|
|
+ return 'data.rows'
|
|
|
+ },
|
|
|
+ 工作集成平台: () => {
|
|
|
+ return 'data.data'
|
|
|
+ },
|
|
|
+ 其他: () => {
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const changeInterFaced = (val) => {
|
|
|
+ dataVal.value.networkRequests.returnsVolumeResolutionDetail = interFaced[val]()
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+defineExpose({
|
|
|
+ editComp
|
|
|
+})
|
|
|
+
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+
|
|
|
+ <el-dialog v-model="interfaceDisplay.dialog" title="接口测试">
|
|
|
+ <div>
|
|
|
+ <JsonViewer :value="interfaceDisplay.data"
|
|
|
+ copyable
|
|
|
+ :expandDepth="3"/>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
+ <el-form label-width="80px">
|
|
|
+
|
|
|
+ <template v-if="show">
|
|
|
+ <el-divider content-position="center">
|
|
|
+ 基本设置
|
|
|
+ </el-divider>
|
|
|
+
|
|
|
+ <el-form-item label="唯一名称 ">
|
|
|
+ <el-input v-model="dataVal.key"/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="前缀">
|
|
|
+ <el-input v-model="dataVal['label']"/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="默认值"
|
|
|
+ v-if="!isSelect() && !isSelectV2()">
|
|
|
+ <el-input
|
|
|
+ v-model="dataVal.defaultValue"
|
|
|
+ v-if="XEUtils.isString(dataVal.defaultValue)"
|
|
|
+ />
|
|
|
+ <el-input-number v-model="dataVal.defaultValue"
|
|
|
+ v-if="XEUtils.isNumber(dataVal.defaultValue)"/>
|
|
|
+
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="必填">
|
|
|
+ <el-switch v-model="dataVal.required"/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="宽度:">
|
|
|
+ <el-input-number v-model="dataVal.width"/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="comp.bind">
|
|
|
+ <el-divider content-position="center">
|
|
|
+ 内置信息
|
|
|
+ </el-divider>
|
|
|
+
|
|
|
+ <template v-for="(item,key) in comp.bind">
|
|
|
+ <el-form-item :label="item.label + ':'">
|
|
|
+ <component :is="bindRendering(item,key)" @change=" (value) =>{test(value,item )}"/>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="isSelect()">
|
|
|
+ <el-divider content-position="center">
|
|
|
+ 内置信息
|
|
|
+ </el-divider>
|
|
|
+ <div style="max-height: 200px; overflow-y: auto">
|
|
|
+ <template v-if="dataVal.bind.multiple">
|
|
|
+ <el-checkbox-group v-model="dataVal.defaultValue">
|
|
|
+ <template v-for="selectItem in dataVal.selectData">
|
|
|
+ <el-checkbox :label="selectItem.value">
|
|
|
+ <el-input v-model="selectItem.value" style="width: 100px"/>
|
|
|
+ <el-input v-model="selectItem.label" style="width: 100px"/>
|
|
|
+ <el-button icon="Minus" type="danger" style="margin-left: 5px" circle/>
|
|
|
+ </el-checkbox>
|
|
|
+ </template>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <el-radio-group v-model="dataVal.defaultValue">
|
|
|
+ <template v-for="selectItem in dataVal.selectData">
|
|
|
+ <el-radio :label="selectItem.value">
|
|
|
+ <el-input v-model="selectItem.value" style="width: 100px"/>
|
|
|
+ <el-input v-model="selectItem.label" style="width: 100px"/>
|
|
|
+ <el-button icon="Minus" type="danger" style="margin-left: 5px" circle/>
|
|
|
+ </el-radio>
|
|
|
+ </template>
|
|
|
+ </el-radio-group>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <div style=" margin-top:5px">
|
|
|
+ <el-button text type="primary" @click="addSelectData">新增</el-button>
|
|
|
+ <el-button text type="primary" @click="clearSelectData">清空默认</el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <template v-if="comp.networkRequests">
|
|
|
+ <el-divider content-position="center">
|
|
|
+ 远程请求
|
|
|
+ </el-divider>
|
|
|
+
|
|
|
+ <el-form-item label="请求方式">
|
|
|
+ <el-select v-model="dataVal.networkRequests.method">
|
|
|
+ <el-option label="get" value="get"/>
|
|
|
+ <el-option label="post" value="post"/>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="请求接口">
|
|
|
+ <el-select v-model="dataVal.networkRequests.requestInterfaced"
|
|
|
+ @change="changeInterFaced">
|
|
|
+ <el-option label="创智中台" value="创智中台"/>
|
|
|
+ <el-option label="工作集成平台" value="工作集成平台"/>
|
|
|
+ <el-option label="其他" value="其他"/>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="返回体">
|
|
|
+ <el-input type="textarea"
|
|
|
+ :autosize="{ minRows: 4, maxRows: 10 }"
|
|
|
+ v-model="dataVal.networkRequests.returnsVolumeResolutionDetail"/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="请求地址">
|
|
|
+ <el-input type="textarea"
|
|
|
+ :autosize="{ minRows: 4, maxRows: 10 }"
|
|
|
+ v-model="dataVal.networkRequests.url"/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+
|
|
|
+ <el-form-item label="请求参数">
|
|
|
+ <template v-for="item in dataVal.networkRequests.params">
|
|
|
+ <el-input v-model="item.queryName" style="width: 100px"/>
|
|
|
+ <el-input v-model="item.queryValue" style="width: 100px"/>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <div style=" margin-top:5px">
|
|
|
+ <el-button text type="primary" @click="addNetParams">新增</el-button>
|
|
|
+ <el-button text type="primary" @click="callTheInterface">测试调用</el-button>
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </el-form>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+
|
|
|
+</style>
|