|
@ -1,5 +1,18 @@ |
|
|
<template> |
|
|
<template> |
|
|
<q-input v-model="valueRef" @update:model-value="valueChanged"> |
|
|
<div v-show="showIfComputed"> |
|
|
|
|
|
<q-input |
|
|
|
|
|
ref="iconRef" |
|
|
|
|
|
v-model="valueRef" |
|
|
|
|
|
:hide-bottom-space="true" |
|
|
|
|
|
:hide-hint="true" |
|
|
|
|
|
:outlined="true" |
|
|
|
|
|
:dense="true" |
|
|
|
|
|
v-bind="attrs" |
|
|
|
|
|
:rules="rulesComputed" |
|
|
|
|
|
:readonly="readonlyIfComputed" |
|
|
|
|
|
:disable="disableIfComputed" |
|
|
|
|
|
@update:model-value="valueChanged" |
|
|
|
|
|
> |
|
|
<template #prepend> |
|
|
<template #prepend> |
|
|
<q-icon v-if="valueRef" :name="valueRef"> </q-icon> |
|
|
<q-icon v-if="valueRef" :name="valueRef"> </q-icon> |
|
|
<w-icon-empty v-else></w-icon-empty> |
|
|
<w-icon-empty v-else></w-icon-empty> |
|
@ -75,10 +88,12 @@ |
|
|
></q-btn> |
|
|
></q-btn> |
|
|
</template> |
|
|
</template> |
|
|
</q-input> |
|
|
</q-input> |
|
|
|
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
|
<script setup lang="ts"> |
|
|
<script setup lang="ts"> |
|
|
import { ref, toRaw, onMounted } from 'vue'; |
|
|
import { ref, toRaw, onMounted, computed, useAttrs, watch } from 'vue'; |
|
|
import { Tools } from '@/platform'; |
|
|
import { Tools } from '@/platform'; |
|
|
|
|
|
import { FormValidators } from '@/platform/components'; |
|
|
import bootstrap from './icons/bootstrap.json'; |
|
|
import bootstrap from './icons/bootstrap.json'; |
|
|
import materialIcons from './icons/material-icons.json'; |
|
|
import materialIcons from './icons/material-icons.json'; |
|
|
import materialSymbolsOutlined from './icons/material-symbols-outlined.json'; |
|
|
import materialSymbolsOutlined from './icons/material-symbols-outlined.json'; |
|
@ -87,9 +102,42 @@ import fontawesomeBrands from './icons/fontawesome-v6-icons-brands.json'; |
|
|
import fontawesomeRegular from './icons/fontawesome-v6-icons-regular.json'; |
|
|
import fontawesomeRegular from './icons/fontawesome-v6-icons-regular.json'; |
|
|
import fontawesomeSolid from './icons/fontawesome-v6-icons-solid.json'; |
|
|
import fontawesomeSolid from './icons/fontawesome-v6-icons-solid.json'; |
|
|
|
|
|
|
|
|
|
|
|
const attrs = useAttrs(); |
|
|
|
|
|
const rules = attrs.rules; |
|
|
|
|
|
const iconRef = ref(); |
|
|
const props = defineProps({ |
|
|
const props = defineProps({ |
|
|
modelValue: { type: String, default: '' }, |
|
|
modelValue: { type: String, default: '' }, |
|
|
restore: { type: Boolean, default: false }, |
|
|
restore: { type: Boolean, default: false }, |
|
|
|
|
|
showIf: { |
|
|
|
|
|
type: Function, |
|
|
|
|
|
default: () => { |
|
|
|
|
|
return true; |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
required: { |
|
|
|
|
|
type: Boolean, |
|
|
|
|
|
default: false, |
|
|
|
|
|
}, |
|
|
|
|
|
requiredIf: { |
|
|
|
|
|
type: Function, |
|
|
|
|
|
default: undefined, |
|
|
|
|
|
}, |
|
|
|
|
|
readonlyIf: { |
|
|
|
|
|
type: Function, |
|
|
|
|
|
default: () => { |
|
|
|
|
|
return false; |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
disableIf: { |
|
|
|
|
|
type: Function, |
|
|
|
|
|
default: () => { |
|
|
|
|
|
return false; |
|
|
|
|
|
}, |
|
|
|
|
|
}, |
|
|
|
|
|
form: { |
|
|
|
|
|
type: Object, |
|
|
|
|
|
default: undefined, |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
const emit = defineEmits(['update:modelValue']); |
|
|
const emit = defineEmits(['update:modelValue']); |
|
|
|
|
|
|
|
@ -108,8 +156,45 @@ const selectedTab = ref('bootstrap'); |
|
|
const isShow = ref(false); |
|
|
const isShow = ref(false); |
|
|
const searchRef = ref(''); |
|
|
const searchRef = ref(''); |
|
|
const valueRef = ref(props.modelValue || 'bi-arrow-up-left-square'); |
|
|
const valueRef = ref(props.modelValue || 'bi-arrow-up-left-square'); |
|
|
|
|
|
watch( |
|
|
|
|
|
() => props.modelValue, |
|
|
|
|
|
(newVal, oldVal) => { |
|
|
|
|
|
valueRef.value = newVal; |
|
|
|
|
|
}, |
|
|
|
|
|
); |
|
|
const restoreValue = toRaw(props.modelValue || ''); |
|
|
const restoreValue = toRaw(props.modelValue || ''); |
|
|
|
|
|
|
|
|
|
|
|
const rulesComputed = computed(() => { |
|
|
|
|
|
let result = rules || <any>[]; |
|
|
|
|
|
if (showIfComputed.value && requiredIfComputed.value) { |
|
|
|
|
|
result.push(FormValidators.required()); |
|
|
|
|
|
} else if (!showIfComputed.value) { |
|
|
|
|
|
result = []; |
|
|
|
|
|
} |
|
|
|
|
|
if (iconRef?.value) { |
|
|
|
|
|
iconRef.value.resetValidation(); |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const showIfComputed = computed(() => { |
|
|
|
|
|
return props.showIf(props.form); |
|
|
|
|
|
}); |
|
|
|
|
|
const requiredIfComputed = computed(() => { |
|
|
|
|
|
if (props.requiredIf) { |
|
|
|
|
|
return props.requiredIf(props.form) || false; |
|
|
|
|
|
} else if (props.required) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
}); |
|
|
|
|
|
const readonlyIfComputed = computed(() => { |
|
|
|
|
|
return props.readonlyIf(props.form); |
|
|
|
|
|
}); |
|
|
|
|
|
const disableIfComputed = computed(() => { |
|
|
|
|
|
return props.disableIf(props.form); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
if (Tools.isEmpty(valueRef.value)) { |
|
|
if (Tools.isEmpty(valueRef.value)) { |
|
|
selectedTab.value = 'bootstrap'; |
|
|
selectedTab.value = 'bootstrap'; |
|
|
} else if (valueRef.value.startsWith('bi')) { |
|
|
} else if (valueRef.value.startsWith('bi')) { |
|
|