|
@@ -2,28 +2,45 @@
|
|
|
<el-form ref=formRef
|
|
|
:rules="rules"
|
|
|
:model="props.testJson.queryParam"
|
|
|
- :inline="testJson.inline || true">
|
|
|
- <el-form-item :label="value.label"
|
|
|
- :prop="value.key"
|
|
|
- @click="itemClick(value,key)"
|
|
|
- v-for="(value,key) in testJson.header">
|
|
|
- <component
|
|
|
- v-model="testJson.queryParam[value.key]"
|
|
|
- v-bind="value.bind"
|
|
|
- :remote-method="(val)=> {remoteMethod(val,value)}"
|
|
|
- :style="{width: value.width + 'px' }"
|
|
|
- :is="el[value.name]">
|
|
|
- <template v-if="value.selectData && value.name ==='ElSelect'">
|
|
|
- <el-option :label="select.label"
|
|
|
- :value="select.value"
|
|
|
- v-for="select in value.selectData"/>
|
|
|
- </template>
|
|
|
- <template v-if="value.text">
|
|
|
- {{ value.text }}
|
|
|
- </template>
|
|
|
-
|
|
|
- </component>
|
|
|
- </el-form-item>
|
|
|
+ :inline="testJson.formConfig.inline || true">
|
|
|
+ <div v-for="(value,key) in testJson.header"
|
|
|
+ style="display:inline-block;"
|
|
|
+ @click="itemClick(value,key)"
|
|
|
+ :class="formItemClass(key)">
|
|
|
+ <div v-if="props.currentIndex === key" class="tool">
|
|
|
+ <div class="tool_item" @click="upClick(key)">
|
|
|
+ <el-icon>
|
|
|
+ <ArrowLeft/>
|
|
|
+ </el-icon>
|
|
|
+ </div>
|
|
|
+ <div class="tool_item" @click="downClick(key)">
|
|
|
+ <el-icon>
|
|
|
+ <ArrowRight/>
|
|
|
+ </el-icon>
|
|
|
+ </div>
|
|
|
+ <div class="tool_item" @click="delClick(key)">
|
|
|
+ <el-icon>
|
|
|
+ <DeleteFilled/>
|
|
|
+ </el-icon>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <el-form-item :label="value.label"
|
|
|
+ :prop="value.key">
|
|
|
+ <component
|
|
|
+ v-model="testJson.queryParam[value.key]"
|
|
|
+ v-bind="value.bind"
|
|
|
+ :is="el[value.name]">
|
|
|
+ <template v-if="value.selectData && value.name ==='ElSelect'">
|
|
|
+ <el-option :label="select.label"
|
|
|
+ :value="select.value"
|
|
|
+ v-for="select in value.selectData"/>
|
|
|
+ </template>
|
|
|
+ <template v-if="value.text">
|
|
|
+ {{ value.text }}
|
|
|
+ </template>
|
|
|
+ </component>
|
|
|
+ </el-form-item>
|
|
|
+ </div>
|
|
|
<el-form-item>
|
|
|
<el-button icon="Search" type="primary" @click="submit">查询</el-button>
|
|
|
<el-button icon="RefreshLeft" @click="formReset">重置</el-button>
|
|
@@ -34,19 +51,25 @@
|
|
|
<script setup lang="ts">
|
|
|
import * as el from "element-plus";
|
|
|
import {FormInstance, FormRules} from "element-plus";
|
|
|
-import {onMounted, ref} from 'vue'
|
|
|
+import {nextTick, onMounted, ref, watch} from 'vue'
|
|
|
import XEUtils from 'xe-utils'
|
|
|
import {componentType, headerType} from "./page-help-type";
|
|
|
import {useVModel} from "@vueuse/core";
|
|
|
-import {watch} from "@vue/runtime-core";
|
|
|
-import {callAxios} from "../../components/query-components/page-help";
|
|
|
-
|
|
|
+import {getFormatDatetime, currentAndAFewDaysAgo, getDateRangeFormatDate} from '../../utils/date'
|
|
|
+import moment from 'moment'
|
|
|
+import axios from "axios";
|
|
|
|
|
|
const props = defineProps<{
|
|
|
- testJson: componentType
|
|
|
+ testJson: componentType,
|
|
|
+ currentIndex: number
|
|
|
}>()
|
|
|
|
|
|
-const emits = defineEmits(['submit', 'itemClick'])
|
|
|
+const emits = defineEmits([
|
|
|
+ 'submit',
|
|
|
+ 'itemClick',
|
|
|
+ 'update:currentIndex',
|
|
|
+ 'delClick'
|
|
|
+])
|
|
|
|
|
|
const formRef = ref<FormInstance | null>(null)
|
|
|
const paramType = new Map<string, any>()
|
|
@@ -57,10 +80,7 @@ const queryParam = ref({})
|
|
|
let tempQuerySql = ''
|
|
|
|
|
|
const testJson = useVModel(props, 'testJson', emits)
|
|
|
-
|
|
|
-watch(() => testJson.value, async () => {
|
|
|
- intiRules()
|
|
|
-}, {deep: true})
|
|
|
+const propsCurrentIndex = useVModel(props, 'currentIndex', emits)
|
|
|
|
|
|
function replaceTheContent(str) {
|
|
|
if (!str) return
|
|
@@ -120,12 +140,46 @@ const submit = async () => {
|
|
|
tempQuerySql = testJson.value.querySql
|
|
|
countIfTags(tempQuerySql)
|
|
|
}
|
|
|
+
|
|
|
+ let tempData = {}
|
|
|
+
|
|
|
+ testJson.value.header.forEach((item) => {
|
|
|
+ if (isDateRange(item)) {
|
|
|
+ let {startTime, endTime} = getDateRangeFormatDate(testJson.value.queryParam[item.key])
|
|
|
+ tempData[item.dataRange.startAlias] = startTime
|
|
|
+ tempData[item.dataRange.endAlias] = endTime
|
|
|
+ } else {
|
|
|
+ tempData[item.key] = testJson.value.queryParam[item.key]
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ console.log('查询条件', tempData)
|
|
|
emits('submit', testJson.value.queryParam)
|
|
|
}
|
|
|
|
|
|
+const isDateRange = (item: headerType) => {
|
|
|
+ return item.name === 'ElDatePicker' && item.bind.type && item.bind.type === 'daterange'
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
const dataReset = () => {
|
|
|
- headerFor((item, key) => {
|
|
|
- testJson.value.queryParam[item.key] = item.defaultValue
|
|
|
+ headerFor(async (item, key) => {
|
|
|
+ if (isDateRange(item)) {
|
|
|
+ switch (item.dataRange.defaultValue) {
|
|
|
+ case '1':
|
|
|
+ let temp = getFormatDatetime(new Date, item.bind.valueFormat)
|
|
|
+ testJson.value.queryParam[item.key] = [temp, temp]
|
|
|
+ break;
|
|
|
+ case '2':
|
|
|
+ testJson.value.queryParam[item.key] = await currentAndAFewDaysAgo(item.dataRange.minusDays, item.bind.valueFormat)
|
|
|
+ break
|
|
|
+ case '3':
|
|
|
+ testJson.value.queryParam[item.key] = [moment().startOf('month').format('YYYY-MM-DD'), moment().endOf('month').format('YYYY-MM-DD')]
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ testJson.value.queryParam[item.key] = item.defaultValue
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -153,17 +207,94 @@ const itemClick = (data, key) => {
|
|
|
emits('itemClick', data, key)
|
|
|
}
|
|
|
|
|
|
-const remoteMethod = async (val, key: headerType) => {
|
|
|
- let {networkRequests} = key
|
|
|
- if (networkRequests && networkRequests.url) {
|
|
|
- key.bind.options = await callAxios(testJson.value, key, val)
|
|
|
+const formItemClass = (index) => {
|
|
|
+ if (index === props.currentIndex) {
|
|
|
+ return 'activation_item'
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const upClick = (key) => {
|
|
|
+ if (key === 0) return
|
|
|
+ swapItems(testJson.value.header, key, key - 1)
|
|
|
+ propsCurrentIndex.value = key - 1
|
|
|
+}
|
|
|
+
|
|
|
+const swapItems = (arr, currentIndex, newIndex) => {
|
|
|
+ arr[currentIndex] = arr.splice(newIndex, 1, arr[currentIndex])[0]
|
|
|
+ return arr
|
|
|
+}
|
|
|
+
|
|
|
+const downClick = (key) => {
|
|
|
+ if (key === testJson.value.header.length - 1) return
|
|
|
+ swapItems(testJson.value.header, key, key + 1)
|
|
|
+ propsCurrentIndex.value = key + 1
|
|
|
+}
|
|
|
+
|
|
|
+const delClick = async (key) => {
|
|
|
+ await emits('delClick')
|
|
|
+ await nextTick()
|
|
|
+ testJson.value.header.splice(key, 1)
|
|
|
+ propsCurrentIndex.value = -1
|
|
|
+}
|
|
|
+
|
|
|
+const initAttribute = () => {
|
|
|
+ let data = {
|
|
|
+ pageJson: testJson.value,
|
|
|
+ axios: axios
|
|
|
}
|
|
|
+
|
|
|
+ headerFor((item) => {
|
|
|
+ if (item.bind) {
|
|
|
+ for (const key in item.bind) {
|
|
|
+ if (key.startsWith("_")) {
|
|
|
+ let tempKey = key.substr(1);
|
|
|
+ item.bind[tempKey] = (val) => {
|
|
|
+ let func = new Function('value', 'data', '...val', "return " + item.bind[key])
|
|
|
+ func()(item, data, val)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
+watch(() => testJson.value.header.length, () => {
|
|
|
+ dataReset()
|
|
|
+ intiRules()
|
|
|
+ initAttribute()
|
|
|
+}, {deep: true})
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
dataReset()
|
|
|
intiRules()
|
|
|
+ initAttribute()
|
|
|
console.log(el)
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+.activation_item {
|
|
|
+ border: 1px solid #000;
|
|
|
+ position: relative;
|
|
|
+ display: inline-block;
|
|
|
+}
|
|
|
+
|
|
|
+.tool {
|
|
|
+ width: inherit;
|
|
|
+ height: inherit;
|
|
|
+ z-index: 99;
|
|
|
+ position: absolute;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ display: flex;
|
|
|
+
|
|
|
+ div {
|
|
|
+ padding: 0 5px;
|
|
|
+ border: 1px solid #0000fa;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|