|
@@ -9,12 +9,14 @@ d'une api)
|
|
|
<UiInputAutocomplete
|
|
<UiInputAutocomplete
|
|
|
:field="field"
|
|
:field="field"
|
|
|
:label="label"
|
|
:label="label"
|
|
|
- :data="data"
|
|
|
|
|
|
|
+ :data="remoteData ? remoteData : data"
|
|
|
:items="items"
|
|
:items="items"
|
|
|
:isLoading="isLoading"
|
|
:isLoading="isLoading"
|
|
|
:item-text="itemText"
|
|
:item-text="itemText"
|
|
|
:slotText="slotText"
|
|
:slotText="slotText"
|
|
|
:item-value="itemValue"
|
|
:item-value="itemValue"
|
|
|
|
|
+ :multiple="multiple"
|
|
|
|
|
+ :chips="chips"
|
|
|
prependIcon="mdi-magnify"
|
|
prependIcon="mdi-magnify"
|
|
|
:return-object="returnObject"
|
|
:return-object="returnObject"
|
|
|
@research="search"
|
|
@research="search"
|
|
@@ -25,7 +27,9 @@ d'une api)
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
|
-import {defineComponent, ref, Ref, watch, onUnmounted, toRefs} from '@nuxtjs/composition-api'
|
|
|
|
|
|
|
+import {defineComponent, ref, Ref, watch, onUnmounted, toRefs, useContext, useFetch} from '@nuxtjs/composition-api'
|
|
|
|
|
+import {QUERY_TYPE} from "~/types/enums";
|
|
|
|
|
+import ModelsUtils from "~/services/utils/modelsUtils";
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
|
props: {
|
|
props: {
|
|
@@ -48,6 +52,16 @@ export default defineComponent({
|
|
|
required: false,
|
|
required: false,
|
|
|
default: null
|
|
default: null
|
|
|
},
|
|
},
|
|
|
|
|
+ remoteUri: {
|
|
|
|
|
+ type: [Array],
|
|
|
|
|
+ required: false,
|
|
|
|
|
+ default: null
|
|
|
|
|
+ },
|
|
|
|
|
+ remoteUrl: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ required: false,
|
|
|
|
|
+ default: null
|
|
|
|
|
+ },
|
|
|
readonly: {
|
|
readonly: {
|
|
|
type: Boolean,
|
|
type: Boolean,
|
|
|
required: false
|
|
required: false
|
|
@@ -71,24 +85,57 @@ export default defineComponent({
|
|
|
noFilter: {
|
|
noFilter: {
|
|
|
type: Boolean,
|
|
type: Boolean,
|
|
|
default: false
|
|
default: false
|
|
|
|
|
+ },
|
|
|
|
|
+ multiple: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: false
|
|
|
|
|
+ },
|
|
|
|
|
+ chips: {
|
|
|
|
|
+ type: Boolean,
|
|
|
|
|
+ default: false
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
setup(props) {
|
|
setup(props) {
|
|
|
const {data} = toRefs(props)
|
|
const {data} = toRefs(props)
|
|
|
- const items:Ref<Array<any>> = ref([data.value])
|
|
|
|
|
|
|
+ const items = ref([])
|
|
|
|
|
+ const remoteData:Ref<Array<string> | null> = ref(null)
|
|
|
const isLoading = ref(false)
|
|
const isLoading = ref(false)
|
|
|
|
|
+ const {$dataProvider} = useContext()
|
|
|
|
|
+
|
|
|
|
|
+ if(props.data){
|
|
|
|
|
+ items.value = props.multiple ? (data.value ?? []) : [data.value]
|
|
|
|
|
+ }else if(props.remoteUri){
|
|
|
|
|
+ const ids:Array<any> = []
|
|
|
|
|
+ for(const uri of props.remoteUri){
|
|
|
|
|
+ ids.push(ModelsUtils.extractIdFromUri(uri as string))
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ useFetch(async () => {
|
|
|
|
|
+ isLoading.value = true
|
|
|
|
|
+ const r = await $dataProvider.invoke({
|
|
|
|
|
+ type: QUERY_TYPE.DEFAULT,
|
|
|
|
|
+ url: props.remoteUrl,
|
|
|
|
|
+ listArgs: {
|
|
|
|
|
+ filters:[
|
|
|
|
|
+ {key: 'id', value: ids.join(',')}
|
|
|
|
|
+ ]
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ isLoading.value = false
|
|
|
|
|
+ remoteData.value = r.data
|
|
|
|
|
+ items.value = r.data
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const search = async (research:string) => {
|
|
const search = async (research:string) => {
|
|
|
isLoading.value = true
|
|
isLoading.value = true
|
|
|
-
|
|
|
|
|
const func: Function = props.searchFunction
|
|
const func: Function = props.searchFunction
|
|
|
- items.value = await func(research, props.field)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ items.value = items.value.concat(await func(research, props.field))
|
|
|
isLoading.value = false
|
|
isLoading.value = false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const unwatch = watch(data,(d) => {
|
|
const unwatch = watch(data,(d) => {
|
|
|
- items.value = [d]
|
|
|
|
|
|
|
+ items.value = props.multiple ? d : [d]
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
@@ -99,6 +146,7 @@ export default defineComponent({
|
|
|
label_field: props.label ?? props.field,
|
|
label_field: props.label ?? props.field,
|
|
|
isLoading,
|
|
isLoading,
|
|
|
items,
|
|
items,
|
|
|
|
|
+ remoteData,
|
|
|
search
|
|
search
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|