|
|
@@ -0,0 +1,103 @@
|
|
|
+<!--
|
|
|
+ * @Author: liuJie
|
|
|
+ * @Date: 2026-01-24 16:40:11
|
|
|
+ * @LastEditors: liuJie
|
|
|
+ * @LastEditTime: 2026-01-25 11:56:32
|
|
|
+ * @Describe: 添加物料
|
|
|
+-->
|
|
|
+<script lang="ts" setup>
|
|
|
+import { ref, computed, inject } from 'vue'
|
|
|
+import { Icon } from '@iconify/vue'
|
|
|
+import { ElPopover, ElButton } from 'element-plus'
|
|
|
+import { materialTools, type SourceType } from '@repo/nodes'
|
|
|
+
|
|
|
+defineOptions({
|
|
|
+ name: 'AddMaterialsPop'
|
|
|
+})
|
|
|
+
|
|
|
+const emit = defineEmits<{
|
|
|
+ 'add-node': [value: SourceType]
|
|
|
+}>()
|
|
|
+
|
|
|
+const vueflow = inject('vueflow')
|
|
|
+const hasStart = computed(() => vueflow?.nodes?.some((node) => node.data.type === 'start'))
|
|
|
+const hasEnd = computed(() => vueflow?.nodes?.some((node) => node.data.type === 'end'))
|
|
|
+
|
|
|
+const materials = computed(() => {
|
|
|
+ return materialTools.map((group) => {
|
|
|
+ return {
|
|
|
+ ...group,
|
|
|
+ source: group.source.filter((item) => {
|
|
|
+ return (
|
|
|
+ !(item.type === 'start' && !hasStart.value) && !(item.type === 'end' && !hasEnd.value)
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+const onAddNode = (value: SourceType) => {
|
|
|
+ emit('add-node', value)
|
|
|
+ show.value = false
|
|
|
+}
|
|
|
+const show = ref(false)
|
|
|
+const togglePop = () => {
|
|
|
+ show.value = !show.value
|
|
|
+}
|
|
|
+</script>
|
|
|
+<template>
|
|
|
+ <ElPopover
|
|
|
+ v-bind:visible="show"
|
|
|
+ trigger="click"
|
|
|
+ transition="el-zoom-in-top"
|
|
|
+ :show-after="400"
|
|
|
+ :hide-after="1000"
|
|
|
+ placement="top"
|
|
|
+ >
|
|
|
+ <div v-for="item in materials" :key="item.id">
|
|
|
+ <p class="mb-2 mt-1 text-[#676f83]">{{ item.label }}</p>
|
|
|
+ <ul>
|
|
|
+ <li
|
|
|
+ class="tool mb-3 flex items-center"
|
|
|
+ v-for="value in item.source"
|
|
|
+ :key="value.id"
|
|
|
+ @click="onAddNode(value)"
|
|
|
+ >
|
|
|
+ <Icon
|
|
|
+ :icon="value.icon"
|
|
|
+ height="16"
|
|
|
+ width="16"
|
|
|
+ class="mr-2 bg-[#6172f3] p-1 rounded"
|
|
|
+ color="#fff"
|
|
|
+ />
|
|
|
+ <span>{{ value.name }}</span>
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ <template #reference>
|
|
|
+ <ElButton @click="togglePop" type="primary">
|
|
|
+ <Icon icon="lucide:package-plus" height="16" width="16" class="mr-1" /> 新增节点
|
|
|
+ </ElButton>
|
|
|
+ </template>
|
|
|
+ </ElPopover>
|
|
|
+</template>
|
|
|
+<style lang="less" scoped>
|
|
|
+ul {
|
|
|
+ padding: 0 0 0 10px;
|
|
|
+
|
|
|
+ .tool {
|
|
|
+ list-style: none;
|
|
|
+ cursor: pointer;
|
|
|
+
|
|
|
+ span {
|
|
|
+ color: #354052;
|
|
|
+ }
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ span {
|
|
|
+ color: #6172f3;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|