修复 src 结构
This commit is contained in:
0
src/component/switch/index.less
Normal file
0
src/component/switch/index.less
Normal file
9
src/component/switch/index.ts
Normal file
9
src/component/switch/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { App } from "vue";
|
||||
import Component from "./index.vue";
|
||||
import type { IDefineComponent } from "../type/index";
|
||||
|
||||
Component.install = (app: App) => {
|
||||
app.component(Component.name || "LaySwitch", Component);
|
||||
};
|
||||
|
||||
export default Component as IDefineComponent;
|
||||
57
src/component/switch/index.vue
Normal file
57
src/component/switch/index.vue
Normal file
@@ -0,0 +1,57 @@
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: "LaySwitch",
|
||||
};
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineProps, defineEmits, computed } from "vue";
|
||||
import "./index.less";
|
||||
|
||||
export interface LaySwitchProps {
|
||||
disabled?: boolean;
|
||||
activeText?: string;
|
||||
modelValue?: boolean;
|
||||
inactiveText?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<LaySwitchProps>(), {
|
||||
disabled: false,
|
||||
activeText: "启用",
|
||||
inactiveText: "禁用",
|
||||
});
|
||||
|
||||
const emit = defineEmits(["update:modelValue", "change"]);
|
||||
|
||||
const isActive = computed({
|
||||
get() {
|
||||
return props.modelValue;
|
||||
},
|
||||
set(val) {
|
||||
emit("change", val);
|
||||
emit("update:modelValue", val);
|
||||
},
|
||||
});
|
||||
|
||||
const handleClick = function () {
|
||||
if (!props.disabled) {
|
||||
isActive.value = !isActive.value;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span @click.stop="handleClick">
|
||||
<div
|
||||
class="layui-unselect layui-form-switch"
|
||||
:class="{
|
||||
'layui-disabled': disabled,
|
||||
'layui-form-onswitch': isActive,
|
||||
'layui-checkbox-disbaled': disabled,
|
||||
}"
|
||||
>
|
||||
<em>{{ isActive == true ? activeText : inactiveText }}</em>
|
||||
<i></i>
|
||||
</div>
|
||||
</span>
|
||||
</template>
|
||||
Reference in New Issue
Block a user