代码格式修改
This commit is contained in:
@@ -3,16 +3,16 @@
|
||||
<div>
|
||||
<!--输入框-->
|
||||
<el-autocomplete
|
||||
v-bind="$attrs"
|
||||
v-on="$listeners"
|
||||
v-model="childValue"
|
||||
clearable
|
||||
v-if="filterable"
|
||||
ref="autoRef"
|
||||
v-model="childValue"
|
||||
v-bind="$attrs"
|
||||
clearable
|
||||
:fetch-suggestions="querySuggestions"
|
||||
:trigger-on-focus="false"
|
||||
v-on="$listeners"
|
||||
@select="handleSelectSuggestion"
|
||||
@clear="handleClear"
|
||||
ref="autoRef"
|
||||
>
|
||||
<template slot-scope="{ item }">
|
||||
{{ item.text }}
|
||||
@@ -20,45 +20,45 @@
|
||||
<i
|
||||
slot="suffix"
|
||||
class="el-input__icon el-icon-search"
|
||||
@click="handleSelector"
|
||||
:class="$attrs.disabled ? 'disabled' : ''"
|
||||
></i>
|
||||
@click="handleSelector"
|
||||
/>
|
||||
</el-autocomplete>
|
||||
<el-input
|
||||
v-else-if="showLabel"
|
||||
ref="inputLabel"
|
||||
v-model="childLabel"
|
||||
class="input-cursor"
|
||||
v-bind="$attrs"
|
||||
v-on="$listeners"
|
||||
v-model="childLabel"
|
||||
@focus="onInputFocus"
|
||||
:clearable="clearable"
|
||||
v-on="$listeners"
|
||||
@focus="onInputFocus"
|
||||
@clear="handleClear"
|
||||
v-else-if="showLabel"
|
||||
>
|
||||
<i
|
||||
slot="suffix"
|
||||
class="el-input__icon el-icon-search"
|
||||
@click="handleSelector"
|
||||
:class="$attrs.disabled ? 'disabled' : ''"
|
||||
></i>
|
||||
@click="handleSelector"
|
||||
/>
|
||||
</el-input>
|
||||
<el-input
|
||||
v-else
|
||||
ref="inputValue"
|
||||
v-model="childValue"
|
||||
class="input-cursor"
|
||||
v-bind="$attrs"
|
||||
v-on="$listeners"
|
||||
v-model="childValue"
|
||||
@focus="onInputFocus"
|
||||
clearable
|
||||
v-on="$listeners"
|
||||
@focus="onInputFocus"
|
||||
@clear="handleClear"
|
||||
v-else
|
||||
>
|
||||
<i
|
||||
slot="suffix"
|
||||
class="el-input__icon el-icon-search"
|
||||
@click="handleSelector"
|
||||
:class="$attrs.disabled ? 'disabled' : ''"
|
||||
></i>
|
||||
@click="handleSelector"
|
||||
/>
|
||||
</el-input>
|
||||
<!--弹出框-->
|
||||
<vxe-modal
|
||||
@@ -68,15 +68,15 @@
|
||||
:width="dialogWidth"
|
||||
:height="dialogHeight"
|
||||
:transfer="true"
|
||||
:zIndex="3044"
|
||||
:z-index="3044"
|
||||
resize
|
||||
show-zoom
|
||||
show-footer
|
||||
>
|
||||
<template #default>
|
||||
<vxe-grid
|
||||
ref="xGrid"
|
||||
id="dataTableValueHelper"
|
||||
ref="xGrid"
|
||||
class="grid-scrollbar"
|
||||
:border="true"
|
||||
:stripe="true"
|
||||
@@ -114,11 +114,11 @@
|
||||
>
|
||||
<!--使用 form 插槽-->
|
||||
<template #form>
|
||||
<el-form :model="queryParams" ref="dialogQueryForm" :inline="true">
|
||||
<el-form ref="dialogQueryForm" :model="queryParams" :inline="true">
|
||||
<el-form-item
|
||||
v-for="domain in dynamicDomains"
|
||||
:label="domain.label"
|
||||
:key="domain.key"
|
||||
:label="domain.label"
|
||||
:prop="domain.prop"
|
||||
>
|
||||
<el-input
|
||||
@@ -126,15 +126,14 @@
|
||||
:disabled="domain.disabled"
|
||||
clearable
|
||||
@keyup.enter.native="handleQuery"
|
||||
></el-input>
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
icon="el-icon-search"
|
||||
@click="handleQuery"
|
||||
>{{ $t("generic.search") }}</el-button
|
||||
>
|
||||
>{{ $t("generic.search") }}</el-button>
|
||||
<el-button icon="el-icon-refresh" @click="resetQuery">{{
|
||||
$t("generic.reset")
|
||||
}}</el-button>
|
||||
@@ -155,7 +154,7 @@
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "ValueHelper",
|
||||
name: 'ValueHelper',
|
||||
components: {},
|
||||
props: {
|
||||
//值
|
||||
@@ -182,7 +181,7 @@ export default {
|
||||
valueProps: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return { value: "value", label: "label" };
|
||||
return { value: 'value', label: 'label' }
|
||||
},
|
||||
},
|
||||
//对话框标题
|
||||
@@ -193,17 +192,17 @@ export default {
|
||||
//对话框宽度
|
||||
dialogWidth: {
|
||||
type: String,
|
||||
default: "700px",
|
||||
default: '700px',
|
||||
},
|
||||
//对话框高度
|
||||
dialogHeight: {
|
||||
type: String,
|
||||
default: "470px",
|
||||
default: '470px',
|
||||
},
|
||||
//对话框高度
|
||||
tableHeight: {
|
||||
type: [String, Number],
|
||||
default: "auto",
|
||||
default: 'auto',
|
||||
},
|
||||
//搜索条件,例子[{key:0,label:'货币编码',prop:'currencyCode'},{key:1,label:'货币名称', prop:'currencyName'},]
|
||||
searchCriteria: {
|
||||
@@ -239,7 +238,7 @@ export default {
|
||||
//选项分隔符
|
||||
separator: {
|
||||
type: String,
|
||||
default: "/",
|
||||
default: '/',
|
||||
},
|
||||
},
|
||||
data() {
|
||||
@@ -264,8 +263,8 @@ export default {
|
||||
autoLoad: false, //是否自动加载查询数据
|
||||
sort: true, // 启用排序代理
|
||||
props: {
|
||||
result: "rows", // 配置响应结果列表字段
|
||||
total: "total", // 配置响应结果总页数字段
|
||||
result: 'rows', // 配置响应结果列表字段
|
||||
total: 'total', // 配置响应结果总页数字段
|
||||
},
|
||||
ajax: {
|
||||
// 接收 Promise 对象
|
||||
@@ -273,26 +272,26 @@ export default {
|
||||
//查询
|
||||
return this.searchMethod(
|
||||
this.buildParams(page, sorts, filters)
|
||||
).then((response) => response);
|
||||
).then((response) => response)
|
||||
},
|
||||
},
|
||||
},
|
||||
// 动态查询参数
|
||||
dynamicDomains: [],
|
||||
};
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
//父组件值变更
|
||||
value(val) {
|
||||
if (this.childValue !== val) {
|
||||
// console.log("value change0:", val, this.childValue, this.childLabel);
|
||||
this.childValue = val;
|
||||
this.childValue = val
|
||||
//有值,非Filterable模式,且是Show label时,获取文本
|
||||
if (val && !this.filterable && this.showLabel) {
|
||||
// console.log("value change1:", val, this.childValue, this.childLabel);
|
||||
this.queryMappingLabel(val);
|
||||
this.queryMappingLabel(val)
|
||||
} else {
|
||||
this.childLabel = undefined;
|
||||
this.childLabel = undefined
|
||||
}
|
||||
// console.log("value change2:", val, this.childValue, this.childLabel);
|
||||
} else {
|
||||
@@ -302,17 +301,17 @@ export default {
|
||||
//搜索条件变更
|
||||
searchCriteria(val, oldVal) {
|
||||
if (JSON.stringify(val) !== JSON.stringify(oldVal)) {
|
||||
this.criteriaToDynamicDomain(val);
|
||||
this.criteriaToDynamicDomain(val)
|
||||
}
|
||||
},
|
||||
},
|
||||
created() {
|
||||
//当显示文本模式时,通过初始值获取初始文本
|
||||
if (this.value && !this.filterable && this.showLabel) {
|
||||
this.queryMappingLabel(this.value);
|
||||
this.queryMappingLabel(this.value)
|
||||
}
|
||||
//搜索条件转为动态输入框
|
||||
this.criteriaToDynamicDomain(this.searchCriteria);
|
||||
this.criteriaToDynamicDomain(this.searchCriteria)
|
||||
},
|
||||
methods: {
|
||||
//构建查询条件
|
||||
@@ -322,38 +321,38 @@ export default {
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
reasonable: true,
|
||||
};
|
||||
}
|
||||
//查询条件
|
||||
const selectParams = this.addDynamicDomains(
|
||||
pageParams,
|
||||
this.dynamicDomains
|
||||
);
|
||||
)
|
||||
// 处理排序条件
|
||||
if (sorts && sorts.length > 0) {
|
||||
const firstSort = sorts[0];
|
||||
const firstSort = sorts[0]
|
||||
if (firstSort) {
|
||||
selectParams.orderByColumn = firstSort.property;
|
||||
selectParams.isAsc = firstSort.order;
|
||||
selectParams.orderByColumn = firstSort.property
|
||||
selectParams.isAsc = firstSort.order
|
||||
}
|
||||
}
|
||||
// 处理筛选条件
|
||||
if (filters) {
|
||||
filters.forEach(({ property, values }) => {
|
||||
selectParams[property] = values.join(",");
|
||||
});
|
||||
selectParams[property] = values.join(',')
|
||||
})
|
||||
}
|
||||
//额外的参数
|
||||
if (this.otherParam) {
|
||||
for (let key in this.otherParam) {
|
||||
selectParams[key] = this.otherParam[key];
|
||||
selectParams[key] = this.otherParam[key]
|
||||
}
|
||||
}
|
||||
//模糊查询Code
|
||||
selectParams.params = { fuzzyQueryCode: true };
|
||||
selectParams.params = { fuzzyQueryCode: true }
|
||||
|
||||
console.log("buildQueryParams: ", selectParams);
|
||||
console.log('buildQueryParams: ', selectParams)
|
||||
|
||||
return selectParams;
|
||||
return selectParams
|
||||
},
|
||||
/**
|
||||
* 输入条件转为动态输入框
|
||||
@@ -366,18 +365,18 @@ export default {
|
||||
prop: item.prop,
|
||||
value: item.value,
|
||||
disabled: item.disabled || false,
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
//获取值对应的文本
|
||||
queryMappingLabel(val) {
|
||||
var conditions = { pageNum: 1, pageSize: 1, reasonable: true };
|
||||
conditions[this.valueProps.value] = val;
|
||||
var conditions = { pageNum: 1, pageSize: 1, reasonable: true }
|
||||
conditions[this.valueProps.value] = val
|
||||
this.searchMethod(conditions).then((response) => {
|
||||
if (response.rows && response.rows.length > 0) {
|
||||
this.childLabel = response.rows[0][this.valueProps.label]; //文本
|
||||
this.childLabel = response.rows[0][this.valueProps.label] //文本
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
//根据用户输入远程搜索(暂时不支持Label)
|
||||
querySuggestions(queryString, callback) {
|
||||
@@ -386,115 +385,115 @@ export default {
|
||||
orderByColumn: this.defaultSort.field,
|
||||
isAsc: this.defaultSort.order,
|
||||
params: { fuzzyQueryCode: true }, //模糊查询Code
|
||||
};
|
||||
conditions[this.valueProps.value] = queryString; //暂时不支持Label
|
||||
}
|
||||
conditions[this.valueProps.value] = queryString //暂时不支持Label
|
||||
//远程查询
|
||||
this.searchMethod(conditions).then((response) => {
|
||||
//结果转换
|
||||
var results = response.rows.map((item, i) => {
|
||||
var values = [];
|
||||
var values = []
|
||||
if (this.columns && this.columns.length > 0) {
|
||||
for (var index = 0; index < this.columns.length; index++) {
|
||||
values.push(item[this.columns[index].field]);
|
||||
values.push(item[this.columns[index].field])
|
||||
}
|
||||
} else {
|
||||
values.push(item[this.valueProps.value]);
|
||||
values.push(item[this.valueProps.label]);
|
||||
values.push(item[this.valueProps.value])
|
||||
values.push(item[this.valueProps.label])
|
||||
}
|
||||
return {
|
||||
value: item[this.valueProps.value], //暂时不支持Label
|
||||
text: values.join(this.separator),
|
||||
raw: item,
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
//结果回调
|
||||
callback(results);
|
||||
});
|
||||
callback(results)
|
||||
})
|
||||
},
|
||||
//选择建议
|
||||
handleSelectSuggestion(item) {
|
||||
this.$emit("selectSubmit", item.raw); //提交事件,传递值给父组件
|
||||
this.$emit('selectSubmit', item.raw) //提交事件,传递值给父组件
|
||||
},
|
||||
//不允许输入框输入,但又支持Clear事件
|
||||
onInputFocus(event) {
|
||||
if (this.showLabel) {
|
||||
this.$refs.inputLabel.blur();
|
||||
this.$refs.inputLabel.blur()
|
||||
} else {
|
||||
this.$refs.inputValue.blur();
|
||||
this.$refs.inputValue.blur()
|
||||
}
|
||||
this.handleSelector();
|
||||
this.handleSelector()
|
||||
},
|
||||
//增加动态查询字段
|
||||
addDynamicDomains(params, domains) {
|
||||
let search = params;
|
||||
let search = params
|
||||
if (domains && domains.length > 0) {
|
||||
for (var i = 0; i < domains.length; i++) {
|
||||
search[domains[i].prop] = domains[i].value;
|
||||
search[domains[i].prop] = domains[i].value
|
||||
}
|
||||
}
|
||||
return search;
|
||||
return search
|
||||
},
|
||||
//弹出选择框
|
||||
handleSelector() {
|
||||
this.open = true;
|
||||
this.open = true
|
||||
this.$nextTick(() => {
|
||||
// console.log(this.$refs.xGrid);
|
||||
this.$refs.xGrid.commitProxy("query");
|
||||
});
|
||||
this.$refs.xGrid.commitProxy('query')
|
||||
})
|
||||
},
|
||||
//关闭选择框
|
||||
cancel() {
|
||||
this.open = false;
|
||||
this.open = false
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
console.log(this.$refs.xGrid);
|
||||
console.log(this.$refs.xGrid)
|
||||
// this.queryParams.pageNum = 1;
|
||||
this.$refs.xGrid.commitProxy("query");
|
||||
this.$refs.xGrid.commitProxy('query')
|
||||
},
|
||||
/** 重置按钮操作 */
|
||||
resetQuery() {
|
||||
if (this.dynamicDomains && this.dynamicDomains.length > 0) {
|
||||
for (var i = 0; i < this.dynamicDomains.length; i++) {
|
||||
this.dynamicDomains[i].value = undefined;
|
||||
this.dynamicDomains[i].value = undefined
|
||||
}
|
||||
}
|
||||
this.handleQuery();
|
||||
this.handleQuery()
|
||||
},
|
||||
/**
|
||||
* 双击选择
|
||||
*/
|
||||
handleDbSelected({ row }) {
|
||||
this.childValue = row[this.valueProps.value]; //值
|
||||
this.childLabel = row[this.valueProps.label]; //文本
|
||||
this.$emit("input", row[this.valueProps.value]); //传递值给父组件
|
||||
this.$emit("selectSubmit", row); //提交事件,传递值给父组件
|
||||
this.cancel();
|
||||
this.childValue = row[this.valueProps.value] //值
|
||||
this.childLabel = row[this.valueProps.label] //文本
|
||||
this.$emit('input', row[this.valueProps.value]) //传递值给父组件
|
||||
this.$emit('selectSubmit', row) //提交事件,传递值给父组件
|
||||
this.cancel()
|
||||
},
|
||||
/**
|
||||
* 点击确定提交
|
||||
*/
|
||||
handleSelectionSubmit() {
|
||||
const selectionObject = this.$refs.xGrid.getRadioRecord();
|
||||
const selectionObject = this.$refs.xGrid.getRadioRecord()
|
||||
if (selectionObject) {
|
||||
this.childValue = selectionObject[this.valueProps.value]; //值
|
||||
this.childLabel = selectionObject[this.valueProps.label]; //文本
|
||||
this.$emit("input", selectionObject[this.valueProps.value]); //传递值给父组件
|
||||
this.$emit("selectSubmit", selectionObject); //提交事件,传递值给父组件
|
||||
this.cancel();
|
||||
this.childValue = selectionObject[this.valueProps.value] //值
|
||||
this.childLabel = selectionObject[this.valueProps.label] //文本
|
||||
this.$emit('input', selectionObject[this.valueProps.value]) //传递值给父组件
|
||||
this.$emit('selectSubmit', selectionObject) //提交事件,传递值给父组件
|
||||
this.cancel()
|
||||
} else {
|
||||
this.$message.info("请选择任意一行");
|
||||
this.$message.info('请选择任意一行')
|
||||
}
|
||||
},
|
||||
//清空事件
|
||||
handleClear() {
|
||||
if (this.filterable) {
|
||||
this.$refs.autoRef.activated = true; //使用clearable清除,点击输入框下拉条件不再显示
|
||||
this.$refs.autoRef.activated = true //使用clearable清除,点击输入框下拉条件不再显示
|
||||
}
|
||||
this.$emit("clearSelect");
|
||||
this.$emit('clearSelect')
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.disabled {
|
||||
|
||||
Reference in New Issue
Block a user