mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-06 00:18:51 +08:00
feat: 分段控制器组件添加全局禁用属性disabled
(#1043)
* feat: segmented component global disabled
This commit is contained in:
parent
53e3e601fb
commit
e0f52fc379
@ -34,9 +34,14 @@ const props = {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
/** 控件尺寸 */
|
||||
/** 控件尺寸 */
|
||||
size: {
|
||||
type: String as PropType<"small" | "default" | "large">
|
||||
},
|
||||
/** 是否全局禁用,默认 `false` */
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
};
|
||||
|
||||
@ -57,7 +62,7 @@ export default defineComponent({
|
||||
: ref(0);
|
||||
|
||||
function handleChange({ option, index }, event: Event) {
|
||||
if (option.disabled) return;
|
||||
if (props.disabled || option.disabled) return;
|
||||
event.preventDefault();
|
||||
isNumber(props.modelValue)
|
||||
? emit("update:modelValue", index)
|
||||
@ -67,6 +72,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function handleMouseenter({ option, index }, event: Event) {
|
||||
if (props.disabled) return;
|
||||
event.preventDefault();
|
||||
curMouseActive.value = index;
|
||||
if (option.disabled || curIndex.value === index) {
|
||||
@ -79,6 +85,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function handleMouseleave(_, event: Event) {
|
||||
if (props.disabled) return;
|
||||
event.preventDefault();
|
||||
curMouseActive.value = -1;
|
||||
}
|
||||
@ -124,14 +131,16 @@ export default defineComponent({
|
||||
ref={`labelRef${index}`}
|
||||
class={[
|
||||
"pure-segmented-item",
|
||||
option?.disabled && "pure-segmented-item-disabled"
|
||||
(props.disabled || option?.disabled) &&
|
||||
"pure-segmented-item-disabled"
|
||||
]}
|
||||
style={{
|
||||
background:
|
||||
curMouseActive.value === index ? segmentedItembg.value : "",
|
||||
color:
|
||||
!option.disabled &&
|
||||
(curIndex.value === index || curMouseActive.value === index)
|
||||
color: props.disabled
|
||||
? null
|
||||
: !option.disabled &&
|
||||
(curIndex.value === index || curMouseActive.value === index)
|
||||
? isDark.value
|
||||
? "rgba(255, 255, 255, 0.85)"
|
||||
: "rgba(0,0,0,.88)"
|
||||
|
@ -240,6 +240,9 @@ watch(size, val => (dynamicSize.value = size.value));
|
||||
<p class="mb-2">禁用</p>
|
||||
<Segmented :options="optionsDisabled" :size="dynamicSize" />
|
||||
<el-divider />
|
||||
<p class="mb-2">全局禁用</p>
|
||||
<Segmented :options="optionsBasis" :size="dynamicSize" disabled />
|
||||
<el-divider />
|
||||
<p class="mb-2">block 属性(将宽度调整为父元素宽度)</p>
|
||||
<Segmented :options="optionsBlock" block :size="dynamicSize" />
|
||||
<el-divider />
|
||||
|
Loading…
x
Reference in New Issue
Block a user