集成 prettier 插件, 新增 npm run lint:prettier 命令

This commit is contained in:
就眠儀式
2021-12-24 13:42:56 +08:00
parent d814aca171
commit 6717dfead2
80 changed files with 1652 additions and 1450 deletions

View File

@@ -1,5 +1,9 @@
<template>
<div class="layui-tab" :class="[type ? 'layui-tab-' + type : '']" v-if="active">
<div
class="layui-tab"
:class="[type ? 'layui-tab-' + type : '']"
v-if="active"
>
<ul class="layui-tab-title">
<li
v-for="(children, index) in childrens"
@@ -23,12 +27,12 @@
<script lang="ts">
export default {
name: 'LayTab',
}
name: "LayTab",
};
</script>
<script setup lang="ts">
import tabItem from '../tabItem/index.vue'
import tabItem from "../tabItem/index.vue";
import {
defineProps,
Component,
@@ -39,73 +43,74 @@ import {
Ref,
ref,
watch,
} from 'vue'
} from "vue";
const slot = useSlots()
const slots = slot.default && slot.default()
const childrens: Ref<VNode[]> = ref([])
const slot = useSlots();
const slots = slot.default && slot.default();
const childrens: Ref<VNode[]> = ref([]);
const setItemInstanceBySlot = function (nodeList: VNode[]) {
nodeList?.map((item) => {
let component = item.type as Component
let component = item.type as Component;
if (component.name != tabItem.name) {
setItemInstanceBySlot(item.children as VNode[])
setItemInstanceBySlot(item.children as VNode[]);
} else {
childrens.value.push(item)
childrens.value.push(item);
}
})
}
});
};
const props = defineProps<{
type?: string
modelValue: string
allowClose?: boolean
beforeClose?: Function
beforeLeave?: Function
}>()
type?: string;
modelValue: string;
allowClose?: boolean;
beforeClose?: Function;
beforeLeave?: Function;
}>();
const emit = defineEmits(['update:modelValue', 'change', 'close'])
const emit = defineEmits(["update:modelValue", "change", "close"]);
const active = computed({
get() {
return props.modelValue
return props.modelValue;
},
set(val) {
emit('update:modelValue', val)
emit("update:modelValue", val);
},
})
const slotsChange = ref(true)
});
const slotsChange = ref(true);
const change = function (id: any) {
// 回调切换标签之前的回调钩子函数只要不是return false, 则进行切换该tab
if (props.beforeLeave && props.beforeLeave(id) === false) {
return ;
return;
}
emit('update:modelValue', id)
emit('change', id)
}
emit("update:modelValue", id);
emit("change", id);
};
const close = function (index : number, id: any) {
const close = function (index: number, id: any) {
// 回调关闭之前的回调函数只要不是return false, 则进行关闭该tab
if (props.beforeClose && props.beforeClose(id) === false) {
return ;
return;
}
// 删除当前tab
childrens.value.splice(index, 1);
// 点击的是当前激活的tab则需要切换到下一个tab
if (active.value === id) {
const nextChildren = childrens.value[(index === childrens.value.length ? 0 : index)];
change(nextChildren && nextChildren.props ? nextChildren.props.id : "")
const nextChildren =
childrens.value[index === childrens.value.length ? 0 : index];
change(nextChildren && nextChildren.props ? nextChildren.props.id : "");
}
emit('close', id)
}
emit("close", id);
};
watch(slotsChange, function () {
childrens.value = []
setItemInstanceBySlot((slot.default && slot.default()) as VNode[])
})
childrens.value = [];
setItemInstanceBySlot((slot.default && slot.default()) as VNode[]);
});
provide('active', active)
provide('slotsChange', slotsChange)
provide("active", active);
provide("slotsChange", slotsChange);
</script>