ddf10R23">23
            highlight-current
17 24
            draggable
18 25
            :default-expanded-keys="currentNodes"
26
            :default-expand-all="defaultExpandAll"
19 27
            node-key="uuid"
20 28
            @node-click="getCurrentNode"
21 29
            @node-contextmenu="cancelCurrent"
@ -39,6 +47,7 @@
39 47
                  v-model="data.alias"
40 48
                  class="tree-int"
41 49
                  size="small"
50
                  @click.stop
42 51
                ></el-input>
43 52
                <common-icon
44 53
                  name="common-shanchu"
@ -51,6 +60,16 @@
51 60
      </div>
52 61
53 62
      <div class="__down">
63
        <h5>后台jsonpath</h5>
64
        <div class="attr-content">
65
          <JsonEditor
66
            v-model="jsonpathData"
67
            class="editor"
68
            current-mode="code"
69
            :mode-list="['code']"
70
            @blur="validate"
71
          ></JsonEditor>
72
        </div>
54 73
        <h5 class="title">属性内容</h5>
55 74
        <div class="attr-content">
56 75
          <JsonEditor
@ -65,7 +84,12 @@
65 84
    </div>
66 85
    <!--右列表-->
67 86
    <div class="__right">
68
      <h5 class="title">属性</h5>
87
      <h5 class="title">
88
        <span>数据总线</span>
89
        <el-button size="small" type="primary" @click.stop="quickCreate">
90
          快速创建
91
        </el-button>
92
      </h5>
69 93
      <ul class="tag-list">
70 94
        <li v-for="(item, index) in tagList" :key="index">
71 95
          <h5 class="tag-title">
@ -82,12 +106,21 @@
82 106
                {{ tag.name }}
83 107
              </span>
84 108
            </template>
85
            <!-- <el-button size="small" @click.stop="">快速创建</el-button> -->
86 109
          </div>
87 110
        </li>
88 111
      </ul>
89 112
    </div>
90 113
  </div>
114
115
  <common-dialog
116
    v-if="showAttrDialog"
117
    title="新增自定义属性"
118
    @close-dialog="closeDialog"
119
    @confirm-dialog="confirmDialog"
120
  >
121
    <!-- 自定义属性 -->
122
    <CustomDetail ref="customDetail" :attr-info="attrInfo"></CustomDetail>
123
  </common-dialog>
91 124
</template>
92 125
93 126
<script setup lang="ts">
@ -103,21 +136,24 @@ import JsonEditor from 'json-editor-vue3';
103 136
import { v4 as uuidv4 } from 'uuid';
104 137
import { useRoute } from 'vue-router';
105 138
139
import CustomDetail from '../../panel/global/CustomDetail.vue';
140
106 141
const { proxy } = getCurrentInstance();
107 142
const route = useRoute();
108 143
109 144
const systemId = route.query.id;
110
111
const dataBus = JSON.parse(localStorage.getItem('panelGlobal'))?.[
112
  `${systemId}`
113
];
114
const customAttrs = dataBus?.customAttrs?.data || [];
115
console.log(customAttrs);
145
const panelGlobal = JSON.parse(localStorage.getItem('panelGlobal'));
146
const dataBus = panelGlobal?.[`${systemId}`];
147
const customAttrs = ref<any>(dataBus?.customAttrs?.data || []);
116 148
117 149
const props = defineProps({
118 150
  dataSource: {
119 151
    type: Array,
120 152
    default: () => []
153
  },
154
  isJsonPath: {
155
    type: Boolean,
156
    default: () => false
121 157
  }
122 158
});
123 159
// 源数据
@ -134,6 +170,7 @@ const tagList = ref<any>([
134 170
]);
135 171
const treeData = ref<any>([...props.dataSource] || []);
136 172
const jsonData = ref<any>({});
173
const jsonpathData = ref<any>({});
137 174
138 175
const currentNode = ref<any>({});
139 176
const myTree = ref<any>(null);
@ -144,14 +181,16 @@ function formateSourceData(data: any) {
144 181
    data.forEach((tag: any) => {
145 182
      if (tag.type === item.type) {
146 183
        tag.alias = '';
147
        item.tags.push(tag);
184
        if (!item.tags.some((el: any) => el.id === tag.id)) {
185
          item.tags.push(tag);
186
        }
148 187
      }
149 188
    });
150 189
    return item;
151 190
  });
152 191
}
153 192
154
formateSourceData(customAttrs);
193
formateSourceData(customAttrs.value);
155 194
/**
156 195
 * el-tree拖拽start
157 196
 */
@ -175,7 +214,7 @@ const allowDrag = (draggingNode: any) => {
175 214
  console.log(draggingNode);
176 215
  return true;
177 216
};
178
217
const defaultExpandAll = ref(false);
179 218
function handleDragStart() {}
180 219
function handleDragEnter() {}
181 220
function handleDragLeave() {}
@ -183,6 +222,15 @@ function handleDragOver() {}
183 222
function handleDragEnd() {}
184 223
function handleDrop() {}
185 224
225
// 展开全部
226
function expandAll() {
227
  defaultExpandAll.value = true;
228
}
229
// 清除树组件数据
230
function clearAll() {
231
  treeData.value = [];
232
}
233
186 234
// 获取当前节点
187 235
function getCurrentNode(node: any) {
188 236
  if (currentNode.value === node) {
@ -207,10 +255,25 @@ function handleClickTag(tag: any) {
207 255
    type: tag.type,
208 256
    children: []
209 257
  };
258
  if (tag.type === 'array') {
259
    proxy
260
      .$confirm('需要创建有迭代器的数组吗?', '提示', {
261
        confirmButtonText: '是的',
262
        cancelButtonText: '不是',
263
        type: 'warning'
264
      })
265
      .then(() => {
266
        newChild.type = 'array-interator';
267
      })
268
      .catch(() => {
269
        newChild.type = 'array-null';
270
      });
271
  }
272
210 273
  if (currentNode.value?.type) {
211 274
    if (
212 275
      currentNode.value?.type === 'object' ||
213
      currentNode.value?.type === 'array'
276
      currentNode.value?.type.indexOf('array') > -1
214 277
    ) {
215 278
      if (
216 279
        !currentNode.value.children.some((el: any) => el.name === newChild.name)
@ -228,11 +291,12 @@ function handleClickTag(tag: any) {
228 291
  } else {
229 292
    treeData.value.push(newChild);
230 293
  }
294
295
  console.log(JSON.stringify(treeData.value));
296
231 297
  nextTick(() => {
232 298
    myTree.value.setCurrentKey(currentNode.value.uuid);
233 299
  });
234
  // myTree.value.updateKeyChildren(treeData.value[0]);
235
  // console.log(myTree.value.getCurrentKey());
236 300
}
237 301
238 302
function cancelCurrent() {
@ -266,6 +330,8 @@ const defaultvalueMap = <any>{
266 330
  int: 0,
267 331
  boolean: false,
268 332
  array: [],
333
  'array-interator': [],
334
  'array-null': [],
269 335
  long: 0,
270 336
  date: '',
271 337
  datetime: '',
@ -273,19 +339,103 @@ const defaultvalueMap = <any>{
273 339
};
274 340
275 341
// 数据处理
276
function tree2json(data: any[], type: 'array' | 'object'): any {
342
function tree2json(
343
  data: any[],
344
  type: 'array-interator' | 'array-null' | 'object'
345
): any {
277 346
  const obj: any = {};
278
  data.forEach((item) => {
279
    const { children } = item;
280
    if (children && children.length) {
281
      const childType = item.type;
282
      obj[item.id] = tree2json(children, childType as 'array' | 'object');
283
    } else {
284
      // obj[item.name] = assignment(item.type);
285
      obj[item.id] = defaultvalueMap[item.type];
347
  data.map(({ children = [], type, alias, id }) => {
348
    const key = alias || id;
349
    obj[key] = children.length
350
      ? tree2json(children, type)
351
      : defaultvalueMap[type];
352
    return null;
353
  });
354
  return type.indexOf('array') > -1 ? [obj] : obj;
355
}
356
357
/**
358
 *
359
 * @param data 数据源
360
 * @param type 数据类型
361
 * 方法说明:
362
 * 1. 正常取值转换,通过对databus中的基础数据进行直接赋值的操作;
363
 * 2. 对象型数据转换,从模型中取数进行数据的赋值;
364
 * 3. 数组数据转换;1)需要迭代器的数据格式;2)不需要迭代器的数据格式;
365
 */
366
367
// tree to jsonpath
368
function arrayNullFunc(item: any) {
369
  const { children, id } = item;
370
  let values;
371
  if (children.length) {
372
    values = children.map((child: any) => {
373
      if (child.type === 'array-null' && child.children.length) {
374
        const childKey = child.alias || child.id;
375
        return {
376
          [childKey]: {
377
            _$$_isInterator: false,
378
            _$$_interator: '',
379
            values: arrayNullFunc(child)
380
          }
381
        };
382
      }
383
      if (
384
        (child.type === 'object' || child.type === 'array-interator') &&
385
        child.children.length
386
      ) {
387
        // eslint-disable-next-line no-use-before-define
388
        return tree2Jsonpath(child.children);
389
      }
390
      return `$.${child.id}`;
391
    });
392
  } else {
393
    values = `$.${id}`;
394
  }
395
  return values;
396
}
397
function tree2Jsonpath(data: any) {
398
  const result = {};
399
  const typeMap = {
400
    'array-null': (item: any) => {
401
      const { id, alias } = item;
402
      const key = alias || id;
403
404
      const values = arrayNullFunc(item);
405
      result[key] = {
406
        _$$_isInterator: false,
407
        _$$_interator: '',
408
        values
409
      };
410
    },
411
    'array-interator': (item: any) => {
412
      const { children, id, alias } = item;
413
      const key = alias || id;
414
      result[key] = {
415
        _$$_isInterator: true,
416
        _$$_interator: `$.${id}`,
417
        values: [tree2Jsonpath(children)]
418
      };
419
    },
420
    object: (item: any) => {
421
      const { children, id, alias } = item;
422
      const key = alias || id;
423
      result[key] = tree2Jsonpath(children);
424
    },
425
    default: (item: any) => {
426
      const { id, alias } = item;
427
      const key = alias || id;
428
      result[key] = `$.${id}`;
286 429
    }
430
  };
431
432
  data.forEach((item: any) => {
433
    const { type } = item;
434
    const fn = typeMap[type] || typeMap.default;
435
    fn(item);
287 436
  });
288
  return type === 'array' ? [obj] : obj;
437
438
  return result;
289 439
}
290 440
291 441
function validate() {}
@ -294,14 +444,48 @@ watch(
294 444
  () => {
295 445
    if (treeData.value?.length) {
296 446
      jsonData.value = tree2json(treeData.value, 'object');
297
      // myTree.value.setCurrentKey(currentNode.value.uuid);
447
      jsonpathData.value = tree2Jsonpath(treeData.value);
298 448
    } else {
299 449
      currentNode.value = {};
450
      jsonData.value = {};
451
      jsonpathData.value = {};
300 452
    }
301 453
  },
302 454
  { deep: true }
303 455
);
304 456
457
// 快速创建databus数据
458
const attrInfo = ref<any>([]);
459
const showAttrDialog = ref<any>(false);
460
const customDetail = ref<any>(null);
461
function quickCreate() {
462
  showAttrDialog.value = true;
463
}
464
// 关闭弹窗
465
function closeDialog() {
466
  showAttrDialog.value = false;
467
}
468
function confirmEvent() {}
469
const btns = [
470
  // { label: '编辑', name: 'edit', onClick: editFn },
471
  { label: '删除', name: 'delete', onClick: confirmEvent }
472
];
473
// 确认弹窗
474
function confirmDialog() {
475
  const data = customDetail.value.attrList;
476
  data.forEach((item: any) => {
477
    if (!customAttrs.value.some((el: any) => el.id === item.id)) {
478
      item.actions = btns;
479
      customAttrs.value.push(item);
480
    }
481
  });
482
483
  formateSourceData(customAttrs.value);
484
  dataBus.customAttrs.data = customAttrs.value;
485
  panelGlobal[`${systemId}`] = dataBus;
486
  localStorage.setItem('panelGlobal', JSON.stringify(panelGlobal));
487
  closeDialog();
488
}
305 489
const currentNodes = ref<any>([]);
306 490
307 491
watch(
@ -314,12 +498,14 @@ watch(
314 498
315 499
defineExpose({
316 500
  treeData,
317
  jsonData
501
  jsonData,
502
  jsonpathData
318 503
});
319 504
320 505
onMounted(() => {
321 506
  if (treeData.value?.length) {
322 507
    jsonData.value = tree2json(treeData.value, 'object');
508
    jsonpathData.value = tree2Jsonpath(treeData.value);
323 509
  } else {
324 510
    currentNode.value = {};
325 511
  }
@ -337,7 +523,11 @@ onMounted(() => {
337 523
    width: calc(60% - 7px);
338 524
    .__up {
339 525
      height: calc(50% - 20px);
340
526
      .title {
527
        display: flex;
528
        justify-content: space-between;
529
        margin-bottom: 5px;
530
      }
341 531
      .tree-content {
342 532
        background: #ffffff;
343 533
        border: 1px solid rgba(0, 0, 0, 0.15);
@ -371,7 +561,12 @@ onMounted(() => {
371 561
  .__right {
372 562
    width: calc(40% - 8px);
373 563
    height: 100%;
374
564
    .title {
565
      display: flex;
566
      justify-content: space-between;
567
      align-items: center;
568
      margin-bottom: 5px;
569
    }
375 570
    .tag-list {
376 571
      background-color: #ffffff;
377 572
      border: 1px solid rgba(0, 0, 0, 0.15);

+ 7 - 1
src/views/_components/right-panel/_components/PanelNodeIO.vue

@ -25,12 +25,13 @@
25 25
    <panel-data-assembly
26 26
      ref="dataAssembly"
27 27
      :data-source="inputData.data"
28
      :is-json-path="isJsonPath"
28 29
    ></panel-data-assembly>
29 30
  </common-dialog>
30 31
</template>
31 32
32 33
<script setup lang="ts">
33
import { ref, watch } from 'vue';
34
import { ref, watch, computed } from 'vue';
34 35
import PanelDataAssembly from './PanelDataAssembly.vue';
35 36
36 37
const showDataAssembly = ref<any>(false);
@ -69,6 +70,11 @@ const props = defineProps({
69 70
    default: () => 'input'
70 71
  }
71 72
});
73
const isJsonPath = computed(
74
  () =>
75
    ['polymerization'].includes(props.targetNode.cell.getData().id) &&
76
    props.inputType === 'function'
77
);
72 78
73 79
const nodePanelData = ref<any>(
74 80
  props.targetNode.cell.getData()?.attrsData || null

update: 修改属性组件使用问题 · c453de15bf - Nuosi Git Service
ソースを参照

update: 修改属性组件使用问题

liuyang 2 年 前
コミット
c453de15bf
共有1 個のファイルを変更した25 個の追加10 個の削除を含む
  1. 25 10
      src/views/_components/drag/DragComments.vue

+ 25 - 10
src/views/_components/drag/DragComments.vue

@ -131,6 +131,15 @@ const tagList = ref<any>([
131 131
      { label: '学生', name: 'student', type: 'object', id: 14 },
132 132
      { label: '员工', name: 'staff', type: 'object', id: 15 }
133 133
    ]
134
  },
135
  {
136
    label: '数组',
137
    type: 'array',
138
    id: 16,
139
    tags: [
140
      { label: '兴趣', name: 'likes', type: 'array', id: 17 },
141
      { label: '作品', name: 'works', type: 'array', id: 18 }
142
    ]
134 143
  }
135 144
]);
136 145
const treeData = ref<any>([]);
@ -186,7 +195,6 @@ function getCurrentNode(node: any) {
186 195
187 196
// 标签点击,添加至左边树
188 197
function handleClickTag(tag: any) {
189
  console.log(tag);
190 198
  const newChild = {
191 199
    label: tag.label,
192 200
    name: tag.name,
@ -200,8 +208,12 @@ function handleClickTag(tag: any) {
200 208
      currentNode.value?.type === 'object' ||
201 209
      currentNode.value?.type === 'array'
202 210
    ) {
203
      currentNode.value.children.push(newChild);
204
      treeData.value = [...treeData.value];
211
      if (!currentNode.value.children.some((el) => el.name === newChild.name)) {
212
        currentNode.value.children.push(newChild);
213
        treeData.value = [...treeData.value];
214
      } else {
215
        proxy.$message.error(`${currentNode.value?.label}中已存在改属性!`);
216
      }
205 217
    } else {
206 218
      proxy.$message.error(`${currentNode.value?.type}类型不能有子类!`);
207 219
    }
@ -269,23 +281,26 @@ function assignment(type: any) {
269 281
}
270 282
271 283
// 数据处理
272
function tree2json(data: any) {
273
  const obj = {};
274
  data.forEach((item: any) => {
275
    if (item.children?.length) {
276
      obj[item.name] = tree2json(item.children);
284
function tree2json(data: any[], type: 'array' | 'object'): any {
285
  const obj: any = {};
286
  data.forEach((item) => {
287
    const { children } = item;
288
    if (children && children.length) {
289
      const childType = item.type;
290
      obj[item.name] = tree2json(children, childType as 'array' | 'object');
277 291
    } else {
278 292
      obj[item.name] = assignment(item.type);
279 293
    }
280 294
  });
281
  return obj;
295
  return type === 'array' ? [obj] : obj;
282 296
}
297
283 298
function validate() {}
284 299
watch(
285 300
  treeData.value,
286 301
  () => {
287 302
    if (treeData.value?.length) {
288
      jsonData.value = tree2json(treeData.value);
303
      jsonData.value = tree2json(treeData.value, 'object');
289 304
    } else {
290 305
      currentNode.value = {};
291 306
    }