xiangpei
2025-04-03 121761d95c65b31e27253f72c3f0d07987069015
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<template>
  <div class="panel-tab__content">
    <el-table :data="elementPropertyList" size="mini" max-height="240" border fit>
      <el-table-column label="序号" width="50px" type="index" />
      <el-table-column label="属性名" prop="name" min-width="100px" show-overflow-tooltip />
      <el-table-column label="属性值" prop="value" min-width="100px" show-overflow-tooltip />
      <el-table-column label="操作" width="90px">
        <template slot-scope="{ row, $index }">
          <el-button size="mini" type="text" style="color: #ff4d4f" @click="removeAttributes(row, $index)">移除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="element-drawer__button">
      <el-button size="mini" type="primary" icon="el-icon-setting" @click="openAttributesForm(null, -1)">属性设置</el-button>
    </div>
 
    <el-dialog :visible.sync="propertyFormModelVisible" title="属性配置" width="600px" @close="closeProperty" append-to-body :destroy-on-close="true" :close-on-click-modal="false">
      <div v-for="item in canConfigPropertyList" style="margin-bottom: 20px; display: flex; align-items: center;">
        <!-- Name  -->
        <span style="flex: 0 0 100px; text-align: right; margin-right: 20px;">{{ item.name }}</span>
        <!-- 组件 -->
        <div >
          <!-- Switch -->
          <div v-if="item.vueType === 'switch'">
            <el-switch
              v-model="item.value"
              @change="(val) => item.method(item.name, val === true ? '是' : '否')"
              active-color="#13ce66"
              inactive-color="#ff4949"
            >
            </el-switch>
          </div>
          <!-- Select -->
          <div v-if="item.vueType === 'select'">
            <el-select
              v-model="item.value"
              @change="(val) => item.method(item.name, val)"
              placeholder="请选择"
            >
              <el-option
                v-for="option in item.options"
                :key="option.value"
                :label="option.label"
                :value="option.value"
              >
              </el-option>
            </el-select>
          </div>
        </div>
      </div>
<!--      <el-form :model="propertyForm" label-width="80px" size="mini" ref="attributeFormRef" @submit.native.prevent>-->
<!--        <el-form-item label="属性名:" prop="name">-->
<!--          <el-input v-model="propertyForm.name" clearable />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="属性值:" prop="value">-->
<!--          <el-input v-model="propertyForm.value" clearable />-->
<!--        </el-form-item>-->
<!--      </el-form>-->
      <template slot="footer">
        <el-button size="mini" @click="closeProperty">关 闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>
 
<script>
import {StrUtil} from "@/utils/StrUtil";
 
export default {
  name: "PropertiesPanel",
  props: {
    id: {
      type: String,
      required: true
    },
  },
  data() {
    return {
      canConfigPropertyList: [
        {
          name: '是否审批节点',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        },
        {
          name: '是否允许跳过',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        },
        {
          name: '是否允许容缺',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        },
        {
          name: '是否允许挂起',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        },
        {
          name: '项目阶段',
          value: null,
          vueType: 'select',
          options: [
            {label: '储备规划阶段',value: '储备规划阶段'},
            {label: '项目前期阶段',value: '项目前期阶段'},
            {label: '实施阶段',value: '实施阶段'},
            {label: '竣工投用阶段',value: '竣工投用阶段'}
          ],
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        }
      ], // 可以配置的属性列表
      elementPropertyList: [], // 扩展属性列表
      otherExtensionList: [],
      propertyForm: {},
      editingPropertyIndex: -1,
      propertyFormModelVisible: false
    };
  },
  watch: {
    id: {
      immediate: true,
      handler(val) {
        if (StrUtil.isNotBlank(val)) {
          this.resetAttributesList();
        }
      }
    }
  },
  methods: {
    closeProperty() {
      this.propertyFormModelVisible = false
      // this.resetList()
    },
    resetList() {
      this.canConfigPropertyList = [
        {
          name: '是否审批节点',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        },
        {
          name: '是否允许跳过',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        },
        {
          name: '是否允许容缺',
          value: false,
          vueType: 'switch',
          method: (name, value) => {
            this.propertyForm.name = name
            this.propertyForm.value = value
            this.saveAttribute()
          }
        }
      ]
    },
    resetAttributesList() {
      this.bpmnElement = this.modelerStore.element;
      this.otherExtensionList = []; // 其他扩展配置
      this.bpmnElementProperties =
        this.bpmnElement.businessObject?.extensionElements?.values?.filter(ex => {
          if (ex.$type !== `flowable:Properties`) {
            this.otherExtensionList.push(ex);
          }
          return ex.$type === `flowable:Properties`;
        }) ?? [];
      // 保存所有的 扩展属性字段
      this.bpmnElementPropertyList = this.bpmnElementProperties.reduce((pre, current) => {
        // 检查 current.values 是否是数组,如果不是则使用空数组
        const values = current.values ? current.values : [];
        return pre.concat(values);
      }, []);
      console.log("bpmnElementProperties",this.bpmnElementProperties)
      // 回显
      this.canConfigPropertyList.forEach(item => {
        const find = this.bpmnElementPropertyList.find(el => el.name === item.name);
        if (find) {
          if (item.vueType === 'switch') {
            item.value = find.value === '是' ? true : false
          }else if (item.vueType === 'select') {
            item.value = find.value
          }
        } else {
          item.value = null
        }
      })
      this.elementPropertyList = JSON.parse(JSON.stringify(this.bpmnElementPropertyList ?? []));
    },
    openAttributesForm(attr, index) {
      this.editingPropertyIndex = index;
      this.propertyForm = index === -1 ? {} : JSON.parse(JSON.stringify(attr));
      this.propertyFormModelVisible = true;
      this.$nextTick(() => {
        if (this.$refs["attributeFormRef"]) this.$refs["attributeFormRef"].clearValidate();
      });
    },
    removeAttributes(attr, index) {
      this.$confirm("确认移除该属性吗?", "提示", {
        confirmButtonText: "确 认",
        cancelButtonText: "取 消"
      })
        .then(() => {
          this.elementPropertyList.splice(index, 1);
          this.bpmnElementPropertyList.splice(index, 1);
          // 新建一个属性字段的保存列表
          const propertiesObject = this.modelerStore.moddle.create(`flowable:Properties`, {
            values: this.bpmnElementPropertyList
          });
          this.updateElementExtensions(propertiesObject);
          this.resetAttributesList();
        })
        .catch(() => console.info("操作取消"));
    },
    saveAttribute() {
      const { name, value } = this.propertyForm;
      console.log(this.bpmnElementPropertyList, "属性列表");
      if (this.editingPropertyIndex !== -1) {
        this.modelerStore.modeling.updateModdleProperties(this.bpmnElement, this.bpmnElementPropertyList[this.editingPropertyIndex], {
          name,
          value
        });
      } else {
        // 如果已经存在这个属性,就做修改
        const find = this.bpmnElementPropertyList.find(item => item.name === name);
        if (find) {
          this.modelerStore.modeling.updateModdleProperties(this.bpmnElement, this.bpmnElementPropertyList[this.bpmnElementPropertyList.indexOf(find)], {
            name,
            value
          });
        } else {
          // 新建属性字段
          const newPropertyObject = this.modelerStore.moddle.create(`flowable:Property`, { name, value });
          // 新建一个属性字段的保存列表
          const propertiesObject = this.modelerStore.moddle.create(`flowable:Properties`, {
            values: this.bpmnElementPropertyList.concat([newPropertyObject])
          });
          this.updateElementExtensions(propertiesObject);
        }
      }
      // this.propertyFormModelVisible = false;
      this.$message.success("操作成功")
      this.resetAttributesList();
    },
    updateElementExtensions(properties) {
      const extensions = this.modelerStore.moddle.create("bpmn:ExtensionElements", {
        values: this.otherExtensionList.concat([properties])
      });
 
      this.modelerStore.modeling.updateProperties(this.bpmnElement, {
        extensionElements: extensions
      });
    }
  }
};
</script>