mirror of
https://github.com/fugary/simple-element-plus-template.git
synced 2025-12-31 03:17:49 +00:00
自动完成控件
This commit is contained in:
@@ -105,14 +105,19 @@ const emit = defineEmits(['update:modelValue', 'onSelectData', 'update:page', 'u
|
|||||||
|
|
||||||
const keywords = ref(props.autocompleteLabel)
|
const keywords = ref(props.autocompleteLabel)
|
||||||
const lastAutocompleteLabel = ref(props.autocompleteLabel)
|
const lastAutocompleteLabel = ref(props.autocompleteLabel)
|
||||||
const pageAttrs = { layout: 'total, prev, pager, next' }
|
const pageAttrs = { layout: 'total, prev, pager, next', small: true }
|
||||||
const dataList = ref([])
|
const dataList = ref([])
|
||||||
const popoverVisible = ref(false)
|
const popoverVisible = ref(false)
|
||||||
const autocompletePopover = ref()
|
const autocompletePopover = ref()
|
||||||
const pageConfig = useVModel(props, 'page', emit)
|
const pageConfig = useVModel(props, 'page', emit)
|
||||||
|
/**
|
||||||
const onInputKeywords = debounce((click) => {
|
* @type {function(boolean?)}
|
||||||
|
*/
|
||||||
|
const onInputKeywords = debounce((input) => {
|
||||||
if (!props.disabled && !props.readonly) {
|
if (!props.disabled && !props.readonly) {
|
||||||
|
if (input && pageConfig.value) {
|
||||||
|
pageConfig.value = { ...pageConfig.value, pageNumber: 1 }
|
||||||
|
}
|
||||||
const val = keywords.value
|
const val = keywords.value
|
||||||
if (val || props.emptySearchEnabled) {
|
if (val || props.emptySearchEnabled) {
|
||||||
popoverVisible.value = true
|
popoverVisible.value = true
|
||||||
@@ -123,7 +128,7 @@ const onInputKeywords = debounce((click) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (!val && !click) {
|
if (!val && input) {
|
||||||
onSelectData()
|
onSelectData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,8 +233,8 @@ onKeyStroke('Enter', e => {
|
|||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
v-bind="inputAttrs"
|
v-bind="inputAttrs"
|
||||||
@input="onInputKeywords()"
|
@input="onInputKeywords(true)"
|
||||||
@click="onInputKeywords(true)"
|
@click="onInputKeywords(false)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #default>
|
<template #default>
|
||||||
@@ -243,7 +248,7 @@ onKeyStroke('Enter', e => {
|
|||||||
:data="dataList"
|
:data="dataList"
|
||||||
:page-attrs="pageAttrs"
|
:page-attrs="pageAttrs"
|
||||||
@row-click="onSelectData($event)"
|
@row-click="onSelectData($event)"
|
||||||
@current-page-change="onInputKeywords()"
|
@current-page-change="onInputKeywords(false)"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-for="column in autocompleteConfig.columns"
|
v-for="column in autocompleteConfig.columns"
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* 配置信息
|
* 配置信息
|
||||||
|
* @property {CommonTableColumn[]} columns 表格显示列配置
|
||||||
|
* @buttonSize {''|'large'|'small'|'default'}
|
||||||
*/
|
*/
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +42,7 @@ const props = defineProps({
|
|||||||
<el-table-column
|
<el-table-column
|
||||||
v-if="!column.isOperation"
|
v-if="!column.isOperation"
|
||||||
:label="column.label || $t(column.labelKey)"
|
:label="column.label || $t(column.labelKey)"
|
||||||
:property="column.property"
|
:prop="column.prop||column.property"
|
||||||
:width="column.width"
|
:width="column.width"
|
||||||
v-bind="column.attrs"
|
v-bind="column.attrs"
|
||||||
:formatter="column.formatter"
|
:formatter="column.formatter"
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { useDefaultPage } from '@/config'
|
import { useDefaultPage } from '@/config'
|
||||||
import { loadUsersResult } from '@/services/user/UserService'
|
import { loadUsersResult } from '@/services/user/UserService'
|
||||||
|
import { $i18nMsg } from '@/messages'
|
||||||
|
|
||||||
const modelIcon = ref('Apple')
|
const modelIcon = ref('Apple')
|
||||||
const modelAuto = ref('99999')
|
const modelAuto = ref('99999')
|
||||||
const modelAutoLabel = ref('Gary Fu')
|
const modelAutoLabel = ref('Gary Fu')
|
||||||
const autoPage = ref(useDefaultPage(8))
|
const autoPage = ref(useDefaultPage(8))
|
||||||
const autocompleteConfig = {
|
const autocompleteConfig = computed(() => {
|
||||||
|
return {
|
||||||
columns: [{
|
columns: [{
|
||||||
label: '中文名',
|
label: $i18nMsg('姓名', 'Name'),
|
||||||
property: 'nameCn'
|
property: $i18nMsg('nameCn', 'nameEn')
|
||||||
}, {
|
}, {
|
||||||
label: '性别',
|
label: $i18nMsg('性别', 'Gender'),
|
||||||
property: 'gender',
|
property: 'gender',
|
||||||
slot: 'gender'
|
slot: 'gender'
|
||||||
}, {
|
}, {
|
||||||
label: '地址',
|
label: $i18nMsg('地址', 'Address'),
|
||||||
property: 'address'
|
property: 'address'
|
||||||
}],
|
}],
|
||||||
searchMethod (query, cb) {
|
searchMethod (query, cb) {
|
||||||
@@ -29,7 +31,8 @@ const autocompleteConfig = {
|
|||||||
cb(data)
|
cb(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -46,7 +49,7 @@ const autocompleteConfig = {
|
|||||||
v-model:page="autoPage"
|
v-model:page="autoPage"
|
||||||
id-key="id"
|
id-key="id"
|
||||||
:label-key="$i18nMsg('nameCn', 'nameEn')"
|
:label-key="$i18nMsg('nameCn', 'nameEn')"
|
||||||
empty-search-enabled
|
:empty-search-enabled="false"
|
||||||
title="请选择用户"
|
title="请选择用户"
|
||||||
:autocomplete-config="autocompleteConfig"
|
:autocomplete-config="autocompleteConfig"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user