click suffix icon to show options
This commit is contained in:
@ -1,17 +1,9 @@
|
||||
<script setup>
|
||||
import {
|
||||
nextTick,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
ref,
|
||||
toRefs,
|
||||
watch,
|
||||
watchEffect,
|
||||
} from "vue";
|
||||
import {nextTick, onMounted, onUnmounted, ref, toRefs, watch, watchEffect,} from "vue";
|
||||
import InfiniteLoading from "v3-infinite-loading";
|
||||
import "v3-infinite-loading/lib/style.css";
|
||||
import { debounce } from "lodash-es"; //required if you're not going to override default slots
|
||||
import { ElInput, ElPopover, ElScrollbar } from "element-plus";
|
||||
import {debounce} from "lodash-es"; //required if you're not going to override default slots
|
||||
import {ElInput, ElPopover, ElScrollbar} from "element-plus";
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {},
|
||||
@ -25,7 +17,7 @@ const props = defineProps({
|
||||
width: {
|
||||
type: Number,
|
||||
},
|
||||
prefixIcon: { type: String },
|
||||
prefixIcon: {type: String},
|
||||
query: {
|
||||
type: Object,
|
||||
required: true,
|
||||
@ -43,13 +35,14 @@ const props = defineProps({
|
||||
},
|
||||
});
|
||||
|
||||
const { modelValue } = toRefs(props);
|
||||
const {modelValue} = toRefs(props);
|
||||
const loadKey = ref(0);
|
||||
const emit = defineEmits(["update:modelValue", "change", "confirm"]);
|
||||
|
||||
const showPopOver = ref(false);
|
||||
|
||||
const inputRefWhenShowPop = ref();
|
||||
const inputRefWhenNotShowPop = ref()
|
||||
const placeholderWhenShowPop = ref("");
|
||||
const placeholderWhenNotShowPop = ref("");
|
||||
const optionLabelWhenShowPop = ref("");
|
||||
@ -57,7 +50,6 @@ const optionLabelWhenNotShowPop = ref("");
|
||||
const echoLabel = ref("");
|
||||
const options = ref([]);
|
||||
const page = ref(0);
|
||||
|
||||
const initOptions = (keyword) => {
|
||||
props
|
||||
.remoteMethod({
|
||||
@ -93,7 +85,8 @@ const loadMore = async ($state) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleInputClick = () => {
|
||||
const handleInputClick = (event) => {
|
||||
event.stopPropagation()
|
||||
showPopOver.value = true;
|
||||
placeholderWhenShowPop.value = optionLabelWhenNotShowPop.value;
|
||||
nextTick(() => {
|
||||
@ -146,7 +139,7 @@ watchEffect(() => {
|
||||
options.value.find((el) => el[props.prop.value] === modelValue.value)?.[
|
||||
props.prop.label
|
||||
] ??
|
||||
echoLabel.value ??
|
||||
(echoLabel.value.length ? echoLabel.value : null) ??
|
||||
props.defaultLabel ??
|
||||
"...";
|
||||
} else {
|
||||
@ -159,6 +152,7 @@ watch(modelValue, (value) => {
|
||||
emit("change", value);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* 点击空白关闭弹出选项列表
|
||||
* @param event
|
||||
@ -179,6 +173,17 @@ onMounted(() => {
|
||||
page.value++;
|
||||
initOptions();
|
||||
document.body.addEventListener("click", handleBodyClick);
|
||||
watch(showPopOver, (show) => {
|
||||
if (show) {
|
||||
inputRefWhenNotShowPop.value?.input?.parentNode?.removeEventListener('click', handleInputClick)
|
||||
} else {
|
||||
nextTick(() => {
|
||||
inputRefWhenNotShowPop.value?.input?.parentNode?.addEventListener('click', handleInputClick)
|
||||
})
|
||||
|
||||
}
|
||||
}, {immediate: true})
|
||||
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
@ -211,12 +216,13 @@ onUnmounted(() => {
|
||||
@click.stop
|
||||
>
|
||||
<template #prefix>
|
||||
<slot name="prefix" />
|
||||
<slot name="prefix"/>
|
||||
</template>
|
||||
</el-input>
|
||||
<!--选项隐藏时-->
|
||||
<el-input
|
||||
v-else
|
||||
ref="inputRefWhenNotShowPop"
|
||||
v-model="optionLabelWhenNotShowPop"
|
||||
:placeholder="placeholderWhenNotShowPop"
|
||||
:prefix-icon="prefixIcon"
|
||||
@ -225,11 +231,10 @@ onUnmounted(() => {
|
||||
clearable
|
||||
suffix-icon="ArrowDown"
|
||||
@clear="handleClearSeletion"
|
||||
@click.stop="handleInputClick"
|
||||
>
|
||||
<!-- @blur="handleInputBlur"-->
|
||||
<!-- @click.stop="handleFocus"-->
|
||||
<template #prefix>
|
||||
<slot name="prefix" />
|
||||
<slot name="prefix"/>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
|
@ -224,7 +224,8 @@
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<template v-if="tenantSettingForm.mode==='3'">
|
||||
<div class="data-source-item">
|
||||
<div v-for="item in tenantSettingForm.datasourceList" :key="`${item.ip}-${item.port}-${item.name}`"
|
||||
class="data-source-item">
|
||||
<div class="left">
|
||||
<div class="database-type">{{ "MySQL" }}</div>
|
||||
<div class="database-url">{{ "127.0.0.1" }} : {{ 3306 }}</div>
|
||||
@ -285,6 +286,7 @@ const total = ref(0);
|
||||
const title = ref("");
|
||||
const showTenantSetting = ref(false) /*是否显示租户设置对话框*/
|
||||
const tenantSettingRef = ref()
|
||||
const editDatasourceIndex = ref(-1)
|
||||
const data = reactive({
|
||||
form: {},
|
||||
queryParams: {
|
||||
@ -310,17 +312,17 @@ const data = reactive({
|
||||
},
|
||||
tenantSettingForm: {
|
||||
// TODO:
|
||||
dataSource: [
|
||||
{
|
||||
type: "MySQL",
|
||||
ip: "127.0.0.1",
|
||||
port: "",
|
||||
name: "",
|
||||
username: "",
|
||||
password: ""
|
||||
}
|
||||
],
|
||||
mode: '3'
|
||||
// dataSource: [
|
||||
// {
|
||||
// type: "MySQL",
|
||||
// ip: "127.0.0.1",
|
||||
// port: "",
|
||||
// name: "",
|
||||
// username: "",
|
||||
// password: ""
|
||||
// }
|
||||
// ],
|
||||
// mode: '3'
|
||||
}
|
||||
,
|
||||
tenantSettingRules: {
|
||||
@ -383,7 +385,14 @@ function reset() {
|
||||
const resetSettingTenant = () => {
|
||||
form.value = {
|
||||
/*TODO:*/
|
||||
datasourceList: []
|
||||
datasourceList: [{
|
||||
type: null,
|
||||
ip: null,
|
||||
port: null,
|
||||
name: null,
|
||||
username: null,
|
||||
password: null,
|
||||
}]
|
||||
}
|
||||
tenantSettingRef.value?.resetFields()
|
||||
}
|
||||
@ -430,6 +439,7 @@ function handleUpdate(row) {
|
||||
* @param row
|
||||
*/
|
||||
const handleSetting = (row) => {
|
||||
// editDatasourceIndex.value = 0
|
||||
resetSettingTenant()
|
||||
getSetting(row.tenantId).then(resp => {
|
||||
tenantSettingForm.value = resp.data
|
||||
|
Reference in New Issue
Block a user