|
@@ -1,9 +1,9 @@
|
|
|
<template>
|
|
|
<el-form ref=formRef
|
|
|
:rules="rules"
|
|
|
- :model="props.testJson.queryParam"
|
|
|
- :inline="testJson.formConfig.inline || true">
|
|
|
- <div v-for="(value,key) in testJson.header"
|
|
|
+ :model="props.pageJson.queryParam"
|
|
|
+ :inline="pageJson.formConfig.inline || true">
|
|
|
+ <div v-for="(value,key) in pageJson.header"
|
|
|
style="display:inline-block;"
|
|
|
@click="itemClick(value,key)"
|
|
|
:class="formItemClass(key)">
|
|
@@ -27,7 +27,7 @@
|
|
|
<el-form-item :label="value.label"
|
|
|
:prop="value.key">
|
|
|
<component
|
|
|
- v-model="testJson.queryParam[value.key]"
|
|
|
+ v-model="pageJson.queryParam[value.key]"
|
|
|
v-bind="value.bind"
|
|
|
:is="el[value.name]">
|
|
|
<template v-if="value.selectData && value.name ==='ElSelect'">
|
|
@@ -42,7 +42,7 @@
|
|
|
</el-form-item>
|
|
|
</div>
|
|
|
<el-form-item>
|
|
|
- <el-button icon="Search" type="primary" @click="submit">查询</el-button>
|
|
|
+ <el-button icon="Search" type="primary" @click="submit(true)">查询</el-button>
|
|
|
<el-button icon="RefreshLeft" @click="formReset">重置</el-button>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
@@ -55,14 +55,13 @@ import {onMounted, ref, watch} from 'vue'
|
|
|
import XEUtils from 'xe-utils'
|
|
|
import {componentType, headerType} from "./page-help-type";
|
|
|
import {useVModel} from "@vueuse/core";
|
|
|
-import {getFormatDatetime, currentAndAFewDaysAgo, getDateRangeFormatDate} from '../../utils/date'
|
|
|
+import {currentAndAFewDaysAgo, getFormatDatetime} from '../../utils/date'
|
|
|
import moment from 'moment'
|
|
|
-import axios from "axios";
|
|
|
-import {pageHelpMitt} from "../../components/query-components/page-help";
|
|
|
-import {xcMessage} from "../../utils/xiaochan-element-plus";
|
|
|
+import {executeSQL, extractQueryData, pageHelpMitt} from "./page-help";
|
|
|
+import convertSql from "@/components/query-components/convert-sql";
|
|
|
|
|
|
const props = defineProps<{
|
|
|
- testJson: componentType,
|
|
|
+ pageJson: componentType,
|
|
|
currentIndex: number
|
|
|
}>()
|
|
|
|
|
@@ -73,197 +72,68 @@ const emits = defineEmits([
|
|
|
])
|
|
|
|
|
|
const formRef = ref<FormInstance | null>(null)
|
|
|
-const paramType = new Map<string, any>()
|
|
|
const rules = ref<FormRules>({})
|
|
|
|
|
|
const queryParam = ref({})
|
|
|
|
|
|
-let tempQuerySql = ''
|
|
|
-
|
|
|
-const testJson = useVModel(props, 'testJson', emits)
|
|
|
+const pageJson = useVModel(props, 'pageJson', emits)
|
|
|
const propsCurrentIndex = useVModel(props, 'currentIndex', emits)
|
|
|
|
|
|
-/**
|
|
|
- * @deprecated
|
|
|
- * @param str 字符串
|
|
|
- */
|
|
|
-function replaceTheContent(str) {
|
|
|
- if (!str) return
|
|
|
- let one = str[0]
|
|
|
- let two = str[1]
|
|
|
- let regex = /{{([\s\S]*?)}}/g;
|
|
|
- let match = regex.exec(one);
|
|
|
-
|
|
|
- function clear() {
|
|
|
- tempQuerySql = tempQuerySql.replace(one, '')
|
|
|
- }
|
|
|
-
|
|
|
- if (match) {
|
|
|
- let key = match[1]
|
|
|
- let value = testJson.value.queryParam.value[key]
|
|
|
- if (value != null) {
|
|
|
- if (XEUtils.isString(value) && XEUtils.isEmpty(value)) {
|
|
|
- clear()
|
|
|
- } else {
|
|
|
- let isString = paramType.get(key) === 'string'
|
|
|
- let temp = {}
|
|
|
- if (XEUtils.isArray(value)) {
|
|
|
- let tempStr = ''
|
|
|
- let tempLen = value.length
|
|
|
- value.forEach((item, key) => {
|
|
|
- tempStr += isString ? "'" + item + "'" : item
|
|
|
- if (key !== tempLen - 1) {
|
|
|
- tempStr += ','
|
|
|
- }
|
|
|
- })
|
|
|
- temp[key] = tempStr
|
|
|
- } else {
|
|
|
- temp[key] = isString ? "'" + value + "'" : value
|
|
|
- }
|
|
|
- tempQuerySql = tempQuerySql.replace(one, XEUtils.template(two, temp))
|
|
|
- }
|
|
|
- } else {
|
|
|
- clear()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
-/**
|
|
|
- * @deprecated
|
|
|
- * @param str 字符串
|
|
|
- */
|
|
|
-function countIfTags(str) {
|
|
|
- let regex = /<if>([\s\S]*?)<\/if>/g;
|
|
|
- let match = null
|
|
|
- do {
|
|
|
- match = regex.exec(str);
|
|
|
- if (match) {
|
|
|
- replaceTheContent(match)
|
|
|
- }
|
|
|
- } while (match)
|
|
|
-}
|
|
|
|
|
|
-/**
|
|
|
- * 把动态函数 function 前面的 注解删除
|
|
|
- * @param str 返回新的数据
|
|
|
- */
|
|
|
-function deleteFunction(str: string) {
|
|
|
- // 获取 str 中第一个 function 的下标
|
|
|
- let index = str.indexOf('function')
|
|
|
- if (index === -1) {
|
|
|
- return str;
|
|
|
- }
|
|
|
- // 获取 str 中 index 后面的字符串
|
|
|
- return str.substring(index)
|
|
|
-}
|
|
|
-
|
|
|
-function 提取查询数据() {
|
|
|
- let queryData = {}
|
|
|
- testJson.value.header.forEach((item) => {
|
|
|
- if (isDateRange(item)) {
|
|
|
- if (testJson.value.queryParam[item.key]) {
|
|
|
- let {startTime, endTime} = getDateRangeFormatDate(testJson.value.queryParam[item.key])
|
|
|
- queryData[item.dataRange.startAlias] = startTime
|
|
|
- queryData[item.dataRange.endAlias] = endTime
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (XEUtils.isArray(testJson.value.queryParam[item.key]) && item.bind.multiple) {
|
|
|
- let tempVal = ''
|
|
|
- let valueLen = testJson.value.queryParam[item.key].length
|
|
|
- // 如果是一个数组的话我就转化成为 xxx,xxx,xxx 这样的字符串
|
|
|
- testJson.value.queryParam[item.key].forEach((valueItem, key) => {
|
|
|
- if (item.keyType === 'string') {
|
|
|
- tempVal += `'${valueItem}'`
|
|
|
- } else {
|
|
|
- tempVal += `${valueItem}`
|
|
|
- }
|
|
|
- if (key !== valueLen - 1) {
|
|
|
- tempVal += ','
|
|
|
- }
|
|
|
- })
|
|
|
- if (item.multipleAlias) {
|
|
|
- queryData[item.multipleAlias] = tempVal
|
|
|
- } else {
|
|
|
- queryData[item.key] = tempVal
|
|
|
- }
|
|
|
- } else {
|
|
|
- queryData[item.key] = testJson.value.queryParam[item.key]
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- queryData['pageNo'] = testJson.value.pageConfig.currentPage
|
|
|
- return queryData
|
|
|
-}
|
|
|
|
|
|
-const submit = async () => {
|
|
|
+const submit = async (reset = false) => {
|
|
|
await formRef.value.validate()
|
|
|
|
|
|
- let queryData;
|
|
|
- queryData = 提取查询数据();
|
|
|
-
|
|
|
- let axiosConfig = {
|
|
|
- method: testJson.value.submitQuery.method,
|
|
|
- url: testJson.value.submitQuery.url,
|
|
|
+ if (reset) {
|
|
|
+ pageJson.value.pageConfig.currentPage = 1
|
|
|
+ pageJson.value.tableConfig.data = []
|
|
|
+ pageJson.value.pageConfig.total = 0
|
|
|
}
|
|
|
|
|
|
- if (axiosConfig.method === 'get') {
|
|
|
- axiosConfig['params'] = queryData
|
|
|
- } else {
|
|
|
- axiosConfig['data'] = queryData
|
|
|
- }
|
|
|
- let res = null
|
|
|
- try {
|
|
|
- res = await axios(axiosConfig)
|
|
|
- } catch (e) {
|
|
|
- console.error(e)
|
|
|
- xcMessage.error(e)
|
|
|
- throw new Error(e)
|
|
|
- }
|
|
|
- if (res === null) {
|
|
|
- throw new Error('res 为空')
|
|
|
- }
|
|
|
- if (eval('res.data.' + testJson.value.submitQuery.returnCodeSuccess)) {
|
|
|
- testJson.value.tableConfig.data = eval('res.data.' + testJson.value.submitQuery.returnsDataPath)
|
|
|
- testJson.value.pageConfig.total = eval('res.data.' + testJson.value.submitQuery.totalPath)
|
|
|
- } else {
|
|
|
- let errorMsg = eval('res.data.' + testJson.value.submitQuery.errorText)
|
|
|
- xcMessage.error(errorMsg)
|
|
|
- throw new Error(errorMsg)
|
|
|
- }
|
|
|
+ let queryData = extractQueryData(pageJson.value);
|
|
|
|
|
|
- // 动态执行函数,现在暂时不需要
|
|
|
- // let func = new Function('queryData', 'config', 'axios', 'return ' + deleteFunction(testJson.value.submitEvent))
|
|
|
- // func()(queryData, testJson.value, axios)
|
|
|
+ let res = await executeSQL(pageJson.value.submitQuerySql, queryData) as any[]
|
|
|
+ pageJson.value.tableConfig.data = res
|
|
|
+ pageJson.value.pageConfig.total = res.length
|
|
|
+
|
|
|
+ // 动态执行函数,暂时先废弃
|
|
|
+ // let func = new Function('queryData', 'config', 'axios', 'return ' + deleteFunction(pageJson.value.submitEvent))
|
|
|
+ // func()(queryData, pageJson.value, axios)
|
|
|
}
|
|
|
|
|
|
const isDateRange = (item: headerType) => {
|
|
|
return item.name === 'ElDatePicker' && item.bind.type && item.bind.type === 'daterange'
|
|
|
}
|
|
|
|
|
|
+const isSelectV2 = (item: headerType) => {
|
|
|
+ return item.name === 'ElSelectV2'
|
|
|
+}
|
|
|
+
|
|
|
const dataReset = () => {
|
|
|
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]
|
|
|
+ pageJson.value.queryParam[item.key] = [temp, temp]
|
|
|
break;
|
|
|
case '2':
|
|
|
- testJson.value.queryParam[item.key] = await currentAndAFewDaysAgo(item.dataRange.minusDays, item.bind.valueFormat)
|
|
|
+ pageJson.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')]
|
|
|
+ pageJson.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
|
|
|
+ pageJson.value.queryParam[item.key] = item.defaultValue
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
const headerFor = (iterate: (val: headerType, key: number) => void) => {
|
|
|
- for (let i = 0; i < testJson.value.header.length; i++) {
|
|
|
- iterate(testJson.value.header[i], i)
|
|
|
+ for (let i = 0; i < pageJson.value.header.length; i++) {
|
|
|
+ iterate(pageJson.value.header[i], i)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -293,7 +163,7 @@ const formItemClass = (index) => {
|
|
|
|
|
|
const upClick = (key) => {
|
|
|
if (key === 0) return
|
|
|
- swapItems(testJson.value.header, key, key - 1)
|
|
|
+ swapItems(pageJson.value.header, key, key - 1)
|
|
|
propsCurrentIndex.value = key - 1
|
|
|
}
|
|
|
|
|
@@ -303,41 +173,58 @@ const swapItems = (arr, currentIndex, newIndex) => {
|
|
|
}
|
|
|
|
|
|
const downClick = (key) => {
|
|
|
- if (key === testJson.value.header.length - 1) return
|
|
|
- swapItems(testJson.value.header, key, key + 1)
|
|
|
+ if (key === pageJson.value.header.length - 1) return
|
|
|
+ swapItems(pageJson.value.header, key, key + 1)
|
|
|
propsCurrentIndex.value = key + 1
|
|
|
}
|
|
|
|
|
|
const delClick = async (key) => {
|
|
|
await pageHelpMitt.emit('setShow', false);
|
|
|
- testJson.value.header.splice(key, 1);
|
|
|
+ pageJson.value.header.splice(key, 1);
|
|
|
propsCurrentIndex.value = -1;
|
|
|
}
|
|
|
|
|
|
-const initAttribute = () => {
|
|
|
|
|
|
- let data = {
|
|
|
- pageJson: testJson.value,
|
|
|
- axios: axios
|
|
|
+const propsFunc = (item: headerType) => {
|
|
|
+ for (const key in item.props) {
|
|
|
+ // 只有搜索是需要特殊处理的
|
|
|
+ // 因为我这是要在后端进行sql查询的
|
|
|
+ if (key === 'remoteMethod') {
|
|
|
+ item.bind[key] = XEUtils.debounce(async (val) => {
|
|
|
+ let queryList = item.props[key].query
|
|
|
+ let prepareData = {}
|
|
|
+ queryList.forEach(queryListItem => {
|
|
|
+ // 如果 queryValue 是空的那么就是自己,不是空的就用 params 里面的 key
|
|
|
+ if (XEUtils.isEmpty(queryListItem.queryValue)) {
|
|
|
+ prepareData[queryListItem.queryName] = val
|
|
|
+ } else {
|
|
|
+ prepareData[queryListItem.queryName] = pageJson.value.queryParam[queryListItem.code]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ item.bind.options = await executeSQL(item.props[key].sql, prepareData)
|
|
|
+ }, 500)
|
|
|
+ } else {
|
|
|
+ item.bind[key] = (val) => {
|
|
|
+ let func = new Function("return " + item.bind[key])
|
|
|
+ func()(item, pageJson.value, val)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
+const initAttribute = () => {
|
|
|
headerFor((item) => {
|
|
|
- if (item.bind) {
|
|
|
- for (const key in item.bind) {
|
|
|
- if (key.startsWith("_")) {
|
|
|
- let tempKey = key.substring(1);
|
|
|
- item.bind[tempKey] = XEUtils.debounce((val) => {
|
|
|
- let func = new Function('value', 'data', '...val', "return " + item.bind[key])
|
|
|
- func()(item, data, val)
|
|
|
- }, 500)
|
|
|
- }
|
|
|
- }
|
|
|
+ if (item.props) {
|
|
|
+ propsFunc(item)
|
|
|
+ }
|
|
|
+ if (!item.emits) {
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
|
|
|
|
|
|
-watch(() => testJson.value.header.length, () => {
|
|
|
+watch(() => pageJson.value.header.length, () => {
|
|
|
dataReset()
|
|
|
intiRules()
|
|
|
initAttribute()
|
|
@@ -347,10 +234,14 @@ onMounted(() => {
|
|
|
dataReset()
|
|
|
intiRules()
|
|
|
initAttribute()
|
|
|
- testJson.value.submitClickFunc = submit
|
|
|
+ pageJson.value.submitClickFunc = submit
|
|
|
console.log(el)
|
|
|
})
|
|
|
|
|
|
+defineExpose({
|
|
|
+ version: '0.1.1'
|
|
|
+})
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|