修改导入json
This commit is contained in:
@@ -162,6 +162,10 @@ const options = [
|
||||
{
|
||||
value: '自定义',
|
||||
label: '自定义'
|
||||
},
|
||||
{
|
||||
value: '特殊图元',
|
||||
label: '特殊图元'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@@ -55,12 +55,12 @@
|
||||
</el-button>
|
||||
<el-divider direction="vertical"></el-divider>
|
||||
<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">
|
||||
<svg-analysis name="import-json"></svg-analysis>
|
||||
</el-icon>
|
||||
</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">
|
||||
<svg-analysis name="export-json"></svg-analysis>
|
||||
</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 SvgAnalysis from '@/components/mt-edit/components/svg-analysis/index.vue'
|
||||
import type { IRealTimeData } from '@/components/mt-edit/store/types'
|
||||
import { useDataStore } from '@/stores/menuList'
|
||||
import { ref } from 'vue'
|
||||
const useData = useDataStore()
|
||||
type HeaderPanelProps = {
|
||||
leftAside: boolean
|
||||
rightAside: boolean
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
<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 />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
@@ -205,7 +205,7 @@ const onAddClick = () => {
|
||||
}
|
||||
|
||||
// 删除功能,传索引行数
|
||||
function del(index: number) {
|
||||
function del(index: number,row: any) {
|
||||
ElMessageBox.confirm('确定删除?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
@@ -214,6 +214,7 @@ function del(index: number) {
|
||||
.then(() => {
|
||||
// splice方法,传两个参数:第几行开始,删除多少条(如果未规定此参数,则删除从 index 开始到原数组结尾的所有元素)
|
||||
dataTrees.value.splice(index, 1)
|
||||
useData.placeKid(row.kId)
|
||||
ElMessage({
|
||||
type: 'success',
|
||||
message: '删除成功'
|
||||
|
||||
@@ -1420,6 +1420,10 @@ watch(
|
||||
|
||||
time.value = setTimeout(() => {
|
||||
console.log('🚀 ~ globalStore:', globalStore)
|
||||
if(useData.keyName==''){
|
||||
ElMessage.warning('请选择图纸!')
|
||||
}
|
||||
|
||||
|
||||
const { exportJson } = genExportJson(globalStore.canvasCfg, globalStore.gridCfg, globalStore.done_json)
|
||||
// const data_model: any = {
|
||||
|
||||
@@ -68,18 +68,16 @@ export const useDataStore = defineStore('data-store', {
|
||||
modify(kId: number, val: string) {
|
||||
this.dataTree.forEach((item: any) => {
|
||||
if (item.kId == kId) {
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
},
|
||||
// 放置kid
|
||||
placeKid(id: String) {
|
||||
this.identifying = id
|
||||
this.keyName = ''
|
||||
this.dataTree.forEach((item: any) => {
|
||||
if (item.kId == id) {
|
||||
this.keyName = item.name
|
||||
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@@ -25,14 +25,15 @@ interface SvgConfig {
|
||||
}
|
||||
}
|
||||
// 处理单个SVG元素的函数
|
||||
const processSvgItem = async (item: ElementItem): Promise<SvgConfig> => {
|
||||
const processSvgItem = async (item: ElementItem, type: string): Promise<SvgConfig> => {
|
||||
try {
|
||||
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 {
|
||||
id: item.id,
|
||||
@@ -142,7 +143,7 @@ const loadSvg = async () => {
|
||||
|
||||
// 处理每个类型的元素并注册
|
||||
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)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user