集成 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,48 +1,48 @@
<script lang="ts">
export default {
name: 'TreeNode',
}
name: "TreeNode",
};
</script>
<script setup lang="ts">
import { StringOrNumber } from './tree.type'
import { Nullable } from '../type'
import { StringOrNumber } from "./tree.type";
import { Nullable } from "../type";
import LayIcon from '../icon'
import LayCheckbox from '../checkbox'
import { Ref } from 'vue'
import { Tree } from './tree'
import LayIcon from "../icon";
import LayCheckbox from "../checkbox";
import { Ref } from "vue";
import { Tree } from "./tree";
type CustomKey = string | number
type CustomString = (() => string) | string
type CustomKey = string | number;
type CustomString = (() => string) | string;
interface TreeData {
id: CustomKey
title: CustomString
children: TreeData[]
parentKey: Nullable<StringOrNumber>
isRoot: boolean
isChecked: Ref<boolean>
isDisabled: Ref<boolean>
isLeaf: Ref<boolean>
hasNextSibling: boolean
parentNode: Nullable<TreeData>
id: CustomKey;
title: CustomString;
children: TreeData[];
parentKey: Nullable<StringOrNumber>;
isRoot: boolean;
isChecked: Ref<boolean>;
isDisabled: Ref<boolean>;
isLeaf: Ref<boolean>;
hasNextSibling: boolean;
parentNode: Nullable<TreeData>;
}
interface TreeNodeProps {
tree: Tree
nodeList: TreeData[]
showCheckbox: boolean
showLine: boolean
onlyIconControl: boolean
tree: Tree;
nodeList: TreeData[];
showCheckbox: boolean;
showLine: boolean;
onlyIconControl: boolean;
}
interface TreeNodeEmits {
(e: 'node-click', node: TreeData): void
(e: "node-click", node: TreeData): void;
}
const props = defineProps<TreeNodeProps>()
const emit = defineEmits<TreeNodeEmits>()
const props = defineProps<TreeNodeProps>();
const emit = defineEmits<TreeNodeEmits>();
function renderLineShort(node: TreeData) {
return (
@@ -52,7 +52,7 @@ function renderLineShort(node: TreeData) {
(!node.parentNode.hasNextSibling ||
//上一层父级有延伸线
(node.parentNode.hasNextSibling && !node.parentNode.children))
)
);
}
/**
* 展开收起 icon样式
@@ -61,33 +61,35 @@ function renderLineShort(node: TreeData) {
const nodeIconType = (node: TreeData): string => {
if (!props.showLine) {
if (node.children.length > 0) {
return 'layui-tree-iconArrow '
return "layui-tree-iconArrow ";
}
return ''
return "";
}
if (node.children.length !== 0) {
return !node.isLeaf.value ? 'layui-icon-addition' : 'layui-icon-subtraction'
return !node.isLeaf.value
? "layui-icon-addition"
: "layui-icon-subtraction";
}
return 'layui-icon-file'
}
return "layui-icon-file";
};
function recursiveNodeClick(node: TreeData) {
emit('node-click', node)
emit("node-click", node);
}
function handleChange(checked: boolean, node: TreeData) {
props.tree.setCheckedKeys(checked, node)
props.tree.setCheckedKeys(checked, node);
}
function handleIconClick(node: TreeData) {
node.isLeaf.value = !node.isLeaf.value
node.isLeaf.value = !node.isLeaf.value;
}
function handleTitleClick(node: TreeData) {
if (!props.onlyIconControl) {
handleIconClick(node)
handleIconClick(node);
}
emit('node-click', node)
emit("node-click", node);
}
</script>
@@ -119,7 +121,7 @@ function handleTitleClick(node: TreeData) {
label=""
@change="
(checked) => {
handleChange(checked, node)
handleChange(checked, node);
}
"
>

View File

@@ -6,50 +6,50 @@
-->
<script lang="ts">
export default {
name: 'LayTree',
}
name: "LayTree",
};
// import { TreeEmits, TreeProps as Tp } from './tree.type'
</script>
<script lang="ts" setup>
import TreeNode from './TreeNode.vue'
import { computed } from 'vue'
import { useTree } from './useTree'
import { TreeData } from './tree'
import TreeNode from "./TreeNode.vue";
import { computed } from "vue";
import { useTree } from "./useTree";
import { TreeData } from "./tree";
type StringFn = () => string
type StringOrNumber = string | number
type KeysType = (number | string)[]
type EditType = boolean | ('add' | 'update' | 'delete')
type StringFn = () => string;
type StringOrNumber = string | number;
type KeysType = (number | string)[];
type EditType = boolean | ("add" | "update" | "delete");
interface OriginalTreeData {
title: StringFn | string
id: StringOrNumber
field: StringFn | string
children?: OriginalTreeData[]
disabled?: boolean
title: StringFn | string;
id: StringOrNumber;
field: StringFn | string;
children?: OriginalTreeData[];
disabled?: boolean;
}
interface TreeProps {
checkedKeys?: KeysType
data: OriginalTreeData
showCheckbox?: boolean
edit?: EditType
accordion?: boolean
onlyIconControl?: boolean
showLine?: boolean
disabled?: boolean
checkedKeys?: KeysType;
data: OriginalTreeData;
showCheckbox?: boolean;
edit?: EditType;
accordion?: boolean;
onlyIconControl?: boolean;
showLine?: boolean;
disabled?: boolean;
replaceFields?: {
id?: string
children?: string
title?: string
}
id?: string;
children?: string;
title?: string;
};
}
interface TreeEmits {
(e: 'update:checkedKeys', keys: KeysType): void
(e: 'update:expandKeys', keys: KeysType): void
(e: 'node-click', node: OriginalTreeData): void
(e: "update:checkedKeys", keys: KeysType): void;
(e: "update:expandKeys", keys: KeysType): void;
(e: "node-click", node: OriginalTreeData): void;
}
const props = withDefaults(defineProps<TreeProps>(), {
@@ -61,28 +61,28 @@ const props = withDefaults(defineProps<TreeProps>(), {
showLine: true,
replaceFields: () => {
return {
id: 'id',
children: 'children',
title: 'title',
}
id: "id",
children: "children",
title: "title",
};
},
})
});
const emit = defineEmits<TreeEmits>()
const emit = defineEmits<TreeEmits>();
const className = computed(() => {
return {
'layui-tree': true,
'layui-form': props.showCheckbox,
'layui-tree-line': props.showLine,
}
})
"layui-tree": true,
"layui-form": props.showCheckbox,
"layui-tree-line": props.showLine,
};
});
const { tree, nodeList } = useTree(props, emit)
const { tree, nodeList } = useTree(props, emit);
function handleClick(node: TreeData) {
const originNode = tree.getOriginData(node.id)
emit('node-click', originNode)
const originNode = tree.getOriginData(node.id);
emit("node-click", originNode);
}
</script>
<template>