|
|
@ -1,7 +1,6 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
<script lang="ts" setup> |
|
|
|
import type { Select as AntSelect } from 'ant-design-vue' |
|
|
|
import type { Select as AntSelect } from 'ant-design-vue' |
|
|
|
import type { SelectOptionType } from 'nocodb-sdk' |
|
|
|
import { ActiveCellInj, ColumnInj, computed, h, inject, onMounted, ref, useEventListener, useProject, watch } from '#imports' |
|
|
|
import { ActiveCellInj, ColumnInj, computed, inject } from '#imports' |
|
|
|
|
|
|
|
import { EditModeInj } from '~/context' |
|
|
|
import { EditModeInj } from '~/context' |
|
|
|
import MdiCloseCircle from '~icons/mdi/close-circle' |
|
|
|
import MdiCloseCircle from '~icons/mdi/close-circle' |
|
|
|
|
|
|
|
|
|
|
@ -32,9 +31,9 @@ const isOpen = ref(false) |
|
|
|
const options = computed(() => { |
|
|
|
const options = computed(() => { |
|
|
|
if (column?.value.colOptions) { |
|
|
|
if (column?.value.colOptions) { |
|
|
|
const opts = column.value.colOptions |
|
|
|
const opts = column.value.colOptions |
|
|
|
? column.value.colOptions.options.filter((el: SelectOptionType) => el.title !== '') || [] |
|
|
|
? (column.value.colOptions as any).options.filter((el: any) => el.title !== '') || [] |
|
|
|
: [] |
|
|
|
: [] |
|
|
|
for (const op of opts.filter((el: SelectOptionType) => el.order === null)) { |
|
|
|
for (const op of opts.filter((el: any) => el.order === null)) { |
|
|
|
op.title = op.title.replace(/^'/, '').replace(/'$/, '') |
|
|
|
op.title = op.title.replace(/^'/, '').replace(/'$/, '') |
|
|
|
} |
|
|
|
} |
|
|
|
return opts |
|
|
|
return opts |
|
|
@ -43,7 +42,7 @@ const options = computed(() => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const vModel = computed({ |
|
|
|
const vModel = computed({ |
|
|
|
get: () => selectedIds.value.map((el) => options.value.find((op: SelectOptionType) => op.id === el)?.title), |
|
|
|
get: () => selectedIds.value.map((el) => options.value.find((op: any) => op.id === el)?.title), |
|
|
|
set: (val) => emit('update:modelValue', val.length === 0 ? null : val.join(',')), |
|
|
|
set: (val) => emit('update:modelValue', val.length === 0 ? null : val.join(',')), |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -52,8 +51,8 @@ const selectedTitles = computed(() => |
|
|
|
? typeof modelValue === 'string' |
|
|
|
? typeof modelValue === 'string' |
|
|
|
? isMysql |
|
|
|
? isMysql |
|
|
|
? modelValue.split(',').sort((a, b) => { |
|
|
|
? modelValue.split(',').sort((a, b) => { |
|
|
|
const opa = options.value.find((el: SelectOptionType) => el.title === a) |
|
|
|
const opa = options.value.find((el: any) => el.title === a) |
|
|
|
const opb = options.value.find((el: SelectOptionType) => el.title === b) |
|
|
|
const opb = options.value.find((el: any) => el.title === b) |
|
|
|
if (opa && opb) { |
|
|
|
if (opa && opb) { |
|
|
|
return opa.order - opb.order |
|
|
|
return opa.order - opb.order |
|
|
|
} |
|
|
|
} |
|
|
@ -83,25 +82,21 @@ const handleClose = (e: MouseEvent) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
onMounted(() => { |
|
|
|
selectedIds.value = selectedTitles.value.map((el) => { |
|
|
|
selectedIds.value = selectedTitles.value.map((el) => options.value.find((op: any) => op.title === el).id) |
|
|
|
return options.value.find((op: SelectOptionType) => op.title === el).id |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
useEventListener(document, 'click', handleClose) |
|
|
|
useEventListener(document, 'click', handleClose) |
|
|
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
watch( |
|
|
|
() => modelValue, |
|
|
|
() => modelValue, |
|
|
|
(_n, _o) => { |
|
|
|
() => { |
|
|
|
selectedIds.value = selectedTitles.value.map((el) => { |
|
|
|
selectedIds.value = selectedTitles.value.map((el) => options.value.find((op: any) => op.title === el).id) |
|
|
|
return options.value.find((op: SelectOptionType) => op.title === el).id |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
watch(isOpen, (n, _o) => { |
|
|
|
watch(isOpen, (n, _o) => { |
|
|
|
if (n === false) { |
|
|
|
if (!n) { |
|
|
|
aselect.value.blur() |
|
|
|
aselect.value?.blur() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
</script> |
|
|
|
</script> |
|
|
@ -128,10 +123,10 @@ watch(isOpen, (n, _o) => { |
|
|
|
</a-select-option> |
|
|
|
</a-select-option> |
|
|
|
<template #tagRender="{ value: val, onClose }"> |
|
|
|
<template #tagRender="{ value: val, onClose }"> |
|
|
|
<a-tag |
|
|
|
<a-tag |
|
|
|
v-if="options.find((el: SelectOptionType) => el.title === val)" |
|
|
|
v-if="options.find((el) => el.title === val)" |
|
|
|
class="rounded-tag" |
|
|
|
class="rounded-tag" |
|
|
|
:style="{ display: 'flex', alignItems: 'center' }" |
|
|
|
:style="{ display: 'flex', alignItems: 'center' }" |
|
|
|
:color="options.find((el: SelectOptionType) => el.title === val).color" |
|
|
|
:color="options.find((el) => el.title === val).color" |
|
|
|
:closable="active && (vModel.length > 1 || !column?.rqd)" |
|
|
|
:closable="active && (vModel.length > 1 || !column?.rqd)" |
|
|
|
:close-icon="h(MdiCloseCircle, { class: ['ms-close-icon'] })" |
|
|
|
:close-icon="h(MdiCloseCircle, { class: ['ms-close-icon'] })" |
|
|
|
@close="onClose" |
|
|
|
@close="onClose" |
|
|
|