|
|
@ -12,6 +12,7 @@ |
|
|
|
:readonly="readonlyIfComputed" |
|
|
|
:disable="disableIfComputed" |
|
|
|
@update:model-value="colorSelected" |
|
|
|
@change="changeValue" |
|
|
|
> |
|
|
|
<template #label> <span v-if="requiredIfComputed" style="color: red">*</span> {{ attrs.label }} </template> |
|
|
|
<template #append> |
|
|
@ -34,7 +35,7 @@ |
|
|
|
:key="`${color}`" |
|
|
|
:class="`bg-${color}`" |
|
|
|
style="min-width: 20px; max-width: 20px; min-height: 20px; max-height: 20px" |
|
|
|
@click="colorSelected(`${color}`)" |
|
|
|
@click="colorClick(`${color}`)" |
|
|
|
> |
|
|
|
<q-tooltip> {{ color }}</q-tooltip> |
|
|
|
</div> |
|
|
@ -68,6 +69,10 @@ const attrs = useAttrs(); |
|
|
|
const rules = attrs.rules; |
|
|
|
const colorRef = ref(); |
|
|
|
const props = defineProps({ |
|
|
|
onChange: { |
|
|
|
type: Function, |
|
|
|
default: () => {}, |
|
|
|
}, |
|
|
|
modelValue: { type: String, default: '' }, |
|
|
|
restore: { type: Boolean, default: false }, |
|
|
|
showIf: { |
|
|
@ -101,7 +106,7 @@ const props = defineProps({ |
|
|
|
default: undefined, |
|
|
|
}, |
|
|
|
}); |
|
|
|
const emit = defineEmits(['update:modelValue']); |
|
|
|
const emit = defineEmits(['update:modelValue', 'change']); |
|
|
|
|
|
|
|
const quasarColors = [ |
|
|
|
['red', 'red-1', 'red-2', 'red-3', 'red-4', 'red-5', 'red-6', 'red-7', 'red-8', 'red-9', 'red-10', 'red-11', 'red-12', 'red-13', 'red-14'], |
|
|
@ -322,7 +327,10 @@ const isShow = ref(false); |
|
|
|
const defaultValue = 'black'; |
|
|
|
const colorValueRef = ref(props.modelValue || defaultValue); |
|
|
|
if (Tools.isEmpty(props.modelValue)) { |
|
|
|
emit('update:modelValue', colorValueRef.value); |
|
|
|
emit('update:modelValue', { |
|
|
|
value: colorValueRef.value, |
|
|
|
form: props.form, |
|
|
|
}); |
|
|
|
} |
|
|
|
const restoreValue = toRaw(props.modelValue || defaultValue); |
|
|
|
|
|
|
@ -367,31 +375,55 @@ const rulesComputed = computed(() => { |
|
|
|
}); |
|
|
|
|
|
|
|
const showIfComputed = computed(() => { |
|
|
|
return props.showIf(props.form); |
|
|
|
return props.showIf({ |
|
|
|
value: colorValueRef.value, |
|
|
|
form: props.form, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const requiredIfComputed = computed(() => { |
|
|
|
if (props.requiredIf) { |
|
|
|
return props.requiredIf(props.form) || false; |
|
|
|
return ( |
|
|
|
props.requiredIf({ |
|
|
|
value: colorValueRef.value, |
|
|
|
form: props.form, |
|
|
|
}) || false |
|
|
|
); |
|
|
|
} else if (props.required) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
}); |
|
|
|
const readonlyIfComputed = computed(() => { |
|
|
|
return props.readonlyIf(props.form); |
|
|
|
return props.readonlyIf({ |
|
|
|
value: colorValueRef.value, |
|
|
|
form: props.form, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const disableIfComputed = computed(() => { |
|
|
|
return props.disableIf(props.form); |
|
|
|
return props.disableIf({ |
|
|
|
value: colorValueRef.value, |
|
|
|
form: props.form, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
const colorSelected = (value) => { |
|
|
|
colorValueRef.value = value; |
|
|
|
emit('update:modelValue', value); |
|
|
|
emit('update:modelValue', value, props.form); |
|
|
|
isShow.value = false; |
|
|
|
}; |
|
|
|
const changeValue = (value) => { |
|
|
|
emit('change', { |
|
|
|
value: value, |
|
|
|
form: props.form, |
|
|
|
}); |
|
|
|
}; |
|
|
|
const colorClick = (value) => { |
|
|
|
colorSelected(value); |
|
|
|
changeValue(value); |
|
|
|
}; |
|
|
|
|
|
|
|
const restoreDefaultValue = () => { |
|
|
|
colorValueRef.value = restoreValue; |
|
|
|
emit('update:modelValue', restoreValue); |
|
|
|
emit('update:modelValue', restoreValue, props.form); |
|
|
|
}; |
|
|
|
</script> |
|
|
|