提交 3e9130d0 authored 作者: 王鹏飞's avatar 王鹏飞

chore: add nanoid

上级 2ab95535
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"blueimp-md5": "^2.19.0", "blueimp-md5": "^2.19.0",
"element-plus": "^2.2.32", "element-plus": "^2.2.32",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"nanoid": "^4.0.1",
"pinia": "^2.0.32", "pinia": "^2.0.32",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.1.6" "vue-router": "^4.1.6"
...@@ -4094,14 +4095,14 @@ ...@@ -4094,14 +4095,14 @@
} }
}, },
"node_modules/nanoid": { "node_modules/nanoid": {
"version": "3.3.4", "version": "4.0.1",
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.4.tgz", "resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-4.0.1.tgz",
"integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", "integrity": "sha512-udKGtCCUafD3nQtJg9wBhRP3KMbPglUsgV5JVsXhvyBs/oefqb4sqMEhKBBgqZncYowu58p1prsZQBYvAj/Gww==",
"bin": { "bin": {
"nanoid": "bin/nanoid.cjs" "nanoid": "bin/nanoid.js"
}, },
"engines": { "engines": {
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" "node": "^14 || ^16 || >=18"
} }
}, },
"node_modules/natural-compare": { "node_modules/natural-compare": {
...@@ -4469,6 +4470,17 @@ ...@@ -4469,6 +4470,17 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/postcss/node_modules/nanoid": {
"version": "3.3.4",
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.4.tgz",
"integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==",
"bin": {
"nanoid": "bin/nanoid.cjs"
},
"engines": {
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/prelude-ls": { "node_modules/prelude-ls": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmmirror.com/prelude-ls/-/prelude-ls-1.2.1.tgz", "resolved": "https://registry.npmmirror.com/prelude-ls/-/prelude-ls-1.2.1.tgz",
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
"blueimp-md5": "^2.19.0", "blueimp-md5": "^2.19.0",
"element-plus": "^2.2.32", "element-plus": "^2.2.32",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"nanoid": "^4.0.1",
"pinia": "^2.0.32", "pinia": "^2.0.32",
"vue": "^3.2.47", "vue": "^3.2.47",
"vue-router": "^4.1.6" "vue-router": "^4.1.6"
......
...@@ -5,6 +5,7 @@ export default { ...@@ -5,6 +5,7 @@ export default {
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import { nanoid } from 'nanoid'
import { VueFlow, useVueFlow, PanelPosition } from '@vue-flow/core' import { VueFlow, useVueFlow, PanelPosition } from '@vue-flow/core'
import { Controls } from '@vue-flow/controls' import { Controls } from '@vue-flow/controls'
import Sidebar from './Sidebar.vue' import Sidebar from './Sidebar.vue'
...@@ -20,9 +21,6 @@ const props = withDefaults(defineProps<Props>(), { action: 'edit', role: 'teache ...@@ -20,9 +21,6 @@ const props = withDefaults(defineProps<Props>(), { action: 'edit', role: 'teache
provide('action', props.action) provide('action', props.action)
provide('role', props.role) provide('role', props.role)
let id = 0
const getId = () => `node_${id++}`
const { findNode, onConnect, addEdges, addNodes, project, vueFlowRef } = useVueFlow() const { findNode, onConnect, addEdges, addNodes, project, vueFlowRef } = useVueFlow()
const onDragOver = (event: DragEvent) => { const onDragOver = (event: DragEvent) => {
...@@ -52,7 +50,7 @@ const onDrop = (event: DragEvent) => { ...@@ -52,7 +50,7 @@ const onDrop = (event: DragEvent) => {
const position = project({ x: event.clientX - left, y: event.clientY - top }) const position = project({ x: event.clientX - left, y: event.clientY - top })
const newNode = { const newNode = {
id: getId(), id: nanoid(),
type: 'custom', type: 'custom',
position, position,
label: data.name, label: data.name,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论