zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<template>
  <app-page-form v-bind="pageFormProps">
    <app-g6-tree v-loading="loading" v-bind="g6TreeProps"/>
  </app-page-form>
</template>
 
<script setup>
 
import {convertFilter} from "@/utils/filter.js";
 
const router = useRouter();
 
import {decode} from '@/utils/tools.js';
 
import {uuid} from '@/utils/tools.js';
import {useEntityStore} from '@/store/modules';
 
import {structure} from '@/hooks';
import {dict} from '@/hooks';
 
const {useStructureData} = structure;
const {useDictMap} = dict;
 
const params = router.currentRoute.value.query;
 
const [_, dictMapCode] = useDictMap(['filter_type']);
 
const props = defineProps({
  pageConfig: {
    type: Array,
    default: []
  }
});
 
const options = props.pageConfig.find(e => e.type === params.type);
 
const loading = ref(false);
 
const g6TreeRef = ref();
 
const g6TreeProps = {
  ref: g6TreeRef,
}
 
const [actionStructure] = useStructureData([
  {
    target: {name: 'sys_data_field_rule', field: 'rule_code'},
    entity: {name: 'sys_library_rule', field: 'code'},
    type: 'object'
  },
  {
    target: {name: 'sys_data_field_rule_filter', field: 'data_field_name'},
    entity: {name: options.property.dataName, field: options.property.value},
    type: 'object'
  },
  {
    target: {name: 'sys_data_field_rule_standrad', field: 'data_field_name'},
    entity: {name: options.property.dataName, field: options.property.value},
    type: 'object'
  }
]);
 
const entityStore = useEntityStore();
 
import {closeTab} from '@/utils/iframe.js';
 
const pageFormProps = {
  subClose() {
    closeTab();
  },
  submitDom: false,
  resetDom: false,
}
 
const initData = async () => {
  loading.value = true;
  const {data} = await entityStore.getEntitySet({
    dataName: 'sys_data_field_rule',
    filter: `${convertFilter({})} ${options.rule.filter}`
  });
 
  const children = [];
 
  data.entityset.forEach(item => {
    children.push({id: uuid(), name: item.rule_name, desc: item.rule_code});
  });
 
  const rulePkg = await Promise.all(data.entityset.map(e => entityStore.getEntity({
    dataName: 'pkg_data_field_rule',
    id: e.id
  })));
 
  for (const index in rulePkg) {
    const structureData = await actionStructure(rulePkg[index].data);
 
    if (structureData.sys_data_field_rule.$rule_code.type_code === 'data_standrad') {
      const {meta} = await entityStore.getEntitySet({
        dataName: structureData.sys_data_field_rule.$rule_code.object_code,
        filter: '1 != 1',
        attachMeta: true,
      });
      const fields = meta[structureData.sys_data_field_rule.$rule_code.object_code].fields;
 
      fields.forEach(e => {
        e.labelchinese = decode(e.labelchinese)
      });
 
      structureData.sys_data_field_rule_standrad.forEach(e => {
        e.$criterion_field_name = fields.find(f => f.field === e.criterion_field_name)
      });
 
      structureData.sys_data_field_rule_filter.forEach(e => {
        e.$criterion_field_name = fields.find(f => f.field === e.criterion_field_name)
      });
    }
    rulePkg[index] = structureData;
  }
 
  children.forEach((item, index) => {
 
    const {sys_data_field_rule_filter, sys_data_field_rule_standrad} = rulePkg[index];
    if (sys_data_field_rule_standrad.length > 0) {
      item.children = [{
        id: uuid(),
        name: '参数',
        desc: '备案参数',
        children: sys_data_field_rule_standrad.map(item => ({
          id: uuid(),
          name: item.$data_field_name && item.$data_field_name[options.property.name],
          desc: item.data_field_name,
          ...(item.criterion_field_name ? {
            children: [{
              id: uuid(),
              name: item.$criterion_field_name?.labelchinese,
              desc: item.criterion_field_name
            }]
          } : {})
        }))
      }];
    }
    if (sys_data_field_rule_filter.length > 0) {
      item.children = [{
        id: uuid(),
        name: '过滤',
        desc: '过滤参数',
        children: sys_data_field_rule_filter.map(item => ({
          id: uuid(),
          name: item.$data_field_name[options.property.value],
          desc: item.data_field_name,
          ...(item.criterion_field_name ? {
            children: [{
              id: uuid(),
              name: dictMapCode?.filter_type[item.relation],
              desc: item.relation,
              children: [{
                id: uuid(),
                name: item.$criterion_field_name?.labelchinese,
                desc: item.criterion_field_name
              }]
            }]
          } : {})
        }))
      }];
    }
  });
  loading.value = false;
  return {id: uuid(), name: options.label, desc: '参数列表', children};
}
 
onMounted(async () => {
  const data = await initData();
  await nextTick();
  g6TreeRef.value.registerNode(data);
})
 
</script>
 
 
<style lang="scss" scoped>
.container {
  width: 100%;
  min-height: 300px;
}
</style>