|
| 1 | +<template> |
| 2 | + |
| 3 | + <SuggestionInput |
| 4 | + class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 |
| 5 | + focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 |
| 6 | + dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500 whitespace-normal" |
| 7 | + v-model="currentValue" |
| 8 | + :type="column.type" |
| 9 | + :completionRequest="complete" |
| 10 | + :debounceTime="meta.debounceTime" |
| 11 | + /> |
| 12 | +</template> |
| 13 | + |
| 14 | +<script setup lang="ts"> |
| 15 | +import { ref, onMounted, watch, Ref } from 'vue'; |
| 16 | +import { callAdminForthApi } from '@/utils'; |
| 17 | +import { AdminForthColumnCommon } from '@/types/Common'; |
| 18 | +import SuggestionInput from 'vue-suggestion-input'; |
| 19 | +import 'vue-suggestion-input/dist/style.css'; |
| 20 | +
|
| 21 | +
|
| 22 | +const props = defineProps<{ |
| 23 | + column: AdminForthColumnCommon, |
| 24 | + record: any, |
| 25 | + meta: any, |
| 26 | +}>(); |
| 27 | +
|
| 28 | +const emit = defineEmits([ |
| 29 | + 'update:value', |
| 30 | +]); |
| 31 | +
|
| 32 | +const currentValue: Ref<string> = ref(''); |
| 33 | +
|
| 34 | +onMounted(() => { |
| 35 | + currentValue.value = props.record[props.column.name] || ''; |
| 36 | +}); |
| 37 | +
|
| 38 | +watch(() => currentValue.value, (value) => { |
| 39 | + emit('update:value', value); |
| 40 | +}); |
| 41 | +
|
| 42 | +watch(() => props.record, (value) => { |
| 43 | + currentValue.value = value[props.column.name] || ''; |
| 44 | +}); |
| 45 | +
|
| 46 | +async function complete(textBeforeCursor: string) { |
| 47 | + const res = await callAdminForthApi({ |
| 48 | + path: `/plugin/${props.meta.pluginInstanceId}/doComplete`, |
| 49 | + method: 'POST', |
| 50 | + body: { |
| 51 | + record: {...props.record, [props.column.name]: textBeforeCursor}, |
| 52 | + }, |
| 53 | + }); |
| 54 | +
|
| 55 | + return res.completion; |
| 56 | +} |
| 57 | +
|
| 58 | +</script> |
| 59 | + |
0 commit comments