修改导入json

This commit is contained in:
guanj
2025-11-14 14:08:01 +08:00
parent 9bd9403280
commit 9d7d7c0cbd
6 changed files with 23 additions and 13 deletions

View File

@@ -162,6 +162,10 @@ const options = [
{ {
value: '自定义', value: '自定义',
label: '自定义' label: '自定义'
},
{
value: '特殊图元',
label: '特殊图元'
} }
] ]

View File

@@ -55,12 +55,12 @@
</el-button> </el-button>
<el-divider direction="vertical"></el-divider> <el-divider direction="vertical"></el-divider>
<el-button-group> <el-button-group>
<el-button text circle size="small" @click="onImportClick"> <el-button text circle size="small" @click="onImportClick" :disabled="useData.keyName ==''">
<el-icon title="导入数据模型" :size="20"> <el-icon title="导入数据模型" :size="20">
<svg-analysis name="import-json"></svg-analysis> <svg-analysis name="import-json"></svg-analysis>
</el-icon> </el-icon>
</el-button> </el-button>
<el-button text circle size="small" @click="onExportClick"> <el-button text circle size="small" @click="onExportClick" :disabled="useData.keyName ==''">
<el-icon title="导出数据模型" :size="20"> <el-icon title="导出数据模型" :size="20">
<svg-analysis name="export-json"></svg-analysis> <svg-analysis name="export-json"></svg-analysis>
</el-icon> </el-icon>
@@ -229,7 +229,9 @@ import { useDark, useToggle, useFullscreen } from '@vueuse/core'
import { ElIcon, ElDivider, ElPopover, ElButton, ElButtonGroup, ElImage, ElText, ElTag } from 'element-plus' import { ElIcon, ElDivider, ElPopover, ElButton, ElButtonGroup, ElImage, ElText, ElTag } from 'element-plus'
import SvgAnalysis from '@/components/mt-edit/components/svg-analysis/index.vue' import SvgAnalysis from '@/components/mt-edit/components/svg-analysis/index.vue'
import type { IRealTimeData } from '@/components/mt-edit/store/types' import type { IRealTimeData } from '@/components/mt-edit/store/types'
import { useDataStore } from '@/stores/menuList'
import { ref } from 'vue' import { ref } from 'vue'
const useData = useDataStore()
type HeaderPanelProps = { type HeaderPanelProps = {
leftAside: boolean leftAside: boolean
rightAside: boolean rightAside: boolean

View File

@@ -22,7 +22,7 @@
</el-icon> </el-icon>
</el-tooltip> </el-tooltip>
<el-tooltip content="删除" placement="top"> <el-tooltip content="删除" placement="top">
<el-icon @click.stop="del(scope.$index)" style="margin-left: 5px; cursor: pointer"> <el-icon @click.stop="del(scope.$index,scope.row)" style="margin-left: 5px; cursor: pointer">
<Delete /> <Delete />
</el-icon> </el-icon>
</el-tooltip> </el-tooltip>
@@ -205,7 +205,7 @@ const onAddClick = () => {
} }
// 删除功能,传索引行数 // 删除功能,传索引行数
function del(index: number) { function del(index: number,row: any) {
ElMessageBox.confirm('确定删除?', '提示', { ElMessageBox.confirm('确定删除?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
@@ -214,6 +214,7 @@ function del(index: number) {
.then(() => { .then(() => {
// splice方法传两个参数第几行开始删除多少条如果未规定此参数则删除从 index 开始到原数组结尾的所有元素) // splice方法传两个参数第几行开始删除多少条如果未规定此参数则删除从 index 开始到原数组结尾的所有元素)
dataTrees.value.splice(index, 1) dataTrees.value.splice(index, 1)
useData.placeKid(row.kId)
ElMessage({ ElMessage({
type: 'success', type: 'success',
message: '删除成功' message: '删除成功'

View File

@@ -1420,6 +1420,10 @@ watch(
time.value = setTimeout(() => { time.value = setTimeout(() => {
console.log('🚀 ~ globalStore:', globalStore) console.log('🚀 ~ globalStore:', globalStore)
if(useData.keyName==''){
ElMessage.warning('请选择图纸!')
}
const { exportJson } = genExportJson(globalStore.canvasCfg, globalStore.gridCfg, globalStore.done_json) const { exportJson } = genExportJson(globalStore.canvasCfg, globalStore.gridCfg, globalStore.done_json)
// const data_model: any = { // const data_model: any = {

View File

@@ -68,18 +68,16 @@ export const useDataStore = defineStore('data-store', {
modify(kId: number, val: string) { modify(kId: number, val: string) {
this.dataTree.forEach((item: any) => { this.dataTree.forEach((item: any) => {
if (item.kId == kId) { if (item.kId == kId) {
} }
}) })
}, },
// 放置kid // 放置kid
placeKid(id: String) { placeKid(id: String) {
this.identifying = id this.identifying = id
this.keyName = ''
this.dataTree.forEach((item: any) => { this.dataTree.forEach((item: any) => {
if (item.kId == id) { if (item.kId == id) {
this.keyName = item.name this.keyName = item.name
} }
}) })
}, },

View File

@@ -25,14 +25,15 @@ interface SvgConfig {
} }
} }
// 处理单个SVG元素的函数 // 处理单个SVG元素的函数
const processSvgItem = async (item: ElementItem): Promise<SvgConfig> => { const processSvgItem = async (item: ElementItem, type: string): Promise<SvgConfig> => {
try { try {
const svgContent = await download({ filePath: item.path }) const svgContent = await download({ filePath: item.path })
// 替换填充色用于缩略图 // 替换填充色用于缩略图
const filledSvg = svgContent.replace(/(\sfill=(["']))[^"']*(\2)/g, '$1#000000$3') const filledSvg =
type == '特殊图元' ? svgContent : svgContent.replace(/(\sfill=(["']))[^"']*(\2)/g, '$1#000000$3')
// 移除原始填充色 // 移除原始填充色
const cleanSvg = svgContent.replace(/\sfill=(["'])[^"']*\1/g, '') const cleanSvg = type == '特殊图元' ? svgContent : svgContent.replace(/\sfill=(["'])[^"']*\1/g, '')
return { return {
id: item.id, id: item.id,
@@ -142,7 +143,7 @@ const loadSvg = async () => {
// 处理每个类型的元素并注册 // 处理每个类型的元素并注册
for (const [type, items] of Object.entries(groupedElements)) { for (const [type, items] of Object.entries(groupedElements)) {
const svgConfigs = await Promise.all(items.map(item => processSvgItem(item))) const svgConfigs = await Promise.all(items.map(item => processSvgItem(item, type)))
leftAsideStore.registerConfig(type, svgConfigs) leftAsideStore.registerConfig(type, svgConfigs)
} }
} catch (error) { } catch (error) {