Skip to content

Commit

Permalink
fix: 修复全局触发器get请求参数不显示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luofann committed Dec 12, 2023
1 parent 592cafa commit ec27b68
Show file tree
Hide file tree
Showing 6 changed files with 211 additions and 30 deletions.
8 changes: 3 additions & 5 deletions frontend/pc/src/utils/use-modal-close-confirmation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import i18n from '@/i18n/index.js';

export default function useModalCloseConfirmation(title, subTitle) {
return new Promise(resolve => {
window.app.$bkInfo({
title: title || i18n.$t('m["确定离开当前页?"]'),
subTitle: subTitle || i18n.$t('m["离开将会导致未保存信息丢失"]'),
okText: i18n.$t('m["离开"]'),
title: title || '确定离开当前页?',
subTitle: subTitle || '离开将会导致未保存信息丢失',
okText: '离开',
confirmFn: () => resolve(true),
cancelFn: () => resolve(false),
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/pc/src/views/commonMix/mixins_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default {
checkInfo: false,
key,
type: valueJsonData.type || '',
desc: valueJsonData.description.toString(),
desc: valueJsonData.description || valueJsonData.desc,
default: (valueJsonData.default !== undefined
&& valueJsonData.default.toString()) ? valueJsonData.default : '',
is_necessary: !level
Expand Down Expand Up @@ -109,7 +109,7 @@ export default {
const valueList = {};
valueList[item.key] = {
type: item.type,
description: item.desc.toString(),
description: item.desc || item.description,
required: (item.children && item.children.length)
? item.children.filter(item => item.is_necessary).map(ite => ite.key) : [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,12 @@
key: field.key,
value: {},
};
valueInfo.value = this.treeToJson(field.apiContent.bodyTableData.filter(item => (!item.level)));
console.log(response);
if (!['POST', 'PATCH', 'PUT'].includes(field.apiContent.method)) {
valueInfo.value = field.value;
} else {
valueInfo.value = this.treeToJson(field.apiContent.bodyTableData.filter(item => (!item.level)));
}
// 使用递归来取值
// const checkInfo = (arr, parentKey) => {
// arr.forEach(itemArr => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<!--
- Tencent is pleased to support the open source community by making BK-ITSM 蓝鲸流程服务 available.
- Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
- BK-ITSM 蓝鲸流程服务 is licensed under the MIT License.
-
- License for BK-ITSM 蓝鲸流程服务:
- -------------------------------------------------------------------
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- documentation files (the "Software"), to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all copies or substantial
- portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
- LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
-->

<template>
<div class="bk-get-param">
<bk-table :data="tableData">
<bk-table-column :label="$t(`m.treeinfo['名称']`)" prop="name"></bk-table-column>
<bk-table-column :label="$t(`m.treeinfo['必选']`)">
<template slot-scope="props">
{{ props.row.is_necessary ? $t(`m.treeinfo["是"]`) : $t(`m.treeinfo["否"]`) }}
</template>
</bk-table-column>
<bk-table-column :label="$t(`m.treeinfo['备注']`)" width="150">
<template slot-scope="props">
<span :title="props.row.desc">{{props.row.desc || '--'}}</span>
</template>
</bk-table-column>
<bk-table-column :label="$t(`m.treeinfo['参数值']`)" width="300">
<template slot-scope="props">
<div style="width: 120px; position: absolute; top: 5px; left: 15px;">
<bk-select
v-model="props.row.sourceType"
:clearable="false"
@change="handleSourceTypeChange(props.row)">
<bk-option
v-for="option in sourceTypeList"
:key="option.key"
:id="option.key"
:name="option.name">
</bk-option>
</bk-select>
</div>
<div
v-if="props.row.sourceType === 'CUSTOM'"
style="width: 140px; position: absolute; top: 4px; right: 15px;">
<bk-input
v-model="localVal[props.row.name]"
:clearable="true"
:placeholder="$t(`m.treeinfo['请输入参数值']`)"
@change="change">
</bk-input>
</div>
<div v-else style="width: 140px; position: absolute; top: 4px; right: 15px;">
<bk-select
v-model="localVal[props.row.name]"
:clearable="false"
:searchable="true"
@change="change">
<bk-option
v-for="option in triggerVariables"
:key="option.key"
:id="option.key"
:name="option.name">
</bk-option>
</bk-select>
</div>
</template>
</bk-table-column>
</bk-table>
</div>
</template>

<script>
import { mapState } from 'vuex';

export default {
name: 'getParam',
components: {},
props: {
params: {
type: Array,
default: () => [],
},
value: {
type: Object,
default: () => ({}),
},
},
data() {
return {
tableData: [],
localVal: {},
sourceTypeList: [
{
key: 'CUSTOM',
name: this.$t('m.treeinfo["自定义"]'),
},
{
key: 'FIELDS',
name: this.$t('m.treeinfo["引用变量"]'),
},
],
};
},
computed: {
...mapState('trigger', {
triggerVariables: state => state.triggerVariables.map(item => {
const { key, name } = item;
return {
key: `\$\{params_${key}\}`,
name,
};
}),
}),
},
watch: {
params() {
this.localVal = {};
this.initData();
},
},
created() {
this.initData();
},
methods: {
initData() {
const tableData = [];
this.params.forEach(item => {
const { desc, is_necessary, name, sample, value } = item;
const val = (name in this.value) ? this.value[name] : value;
const sourceType = /\$\{params_\w+\}/.test(val) ? 'FIELDS' : 'CUSTOM';
tableData.push({ desc, is_necessary, name, sample, sourceType });
this.$set(this.localVal, name, val);
});
this.tableData = tableData;
this.change();
},
handleSourceTypeChange(row) {
row.value = '';
this.change();
},
change() {
this.$emit('change', this.localVal);
},
},
};
</script>

<style lang="scss" scoped>
@import '../../../../scss/mixins/clearfix.scss';

.bk-get-param {
color: #424950;
font-size: 14px;
font-weight: normal;
@include clearfix;
.bk-border-error {
border-color: #ff5656;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
import { deepClone } from '../../../../utils/util';
import { mapState } from 'vuex';
export default {
name: 'inputParams',
name: 'postParams',
mixins: [mixins],
props: {
itemInfo: {
Expand Down Expand Up @@ -162,17 +162,17 @@
this.variableList = this.triggerVariables;
},
methods: {
async initData() {
initData() {
this.$set(this.itemInfo.apiContent, 'treeDataList', {});
this.itemInfo.apiContent.treeDataList = await this.jsonschemaToList({
this.itemInfo.apiContent.treeDataList = this.jsonschemaToList({
root: JSON.parse(JSON.stringify(this.itemInfo.apiContent.req_body)),
});
// 如果数据已经存在,则进行表格初始化赋值
if (this.itemInfo.value) {
this.itemInfo.apiContent.treeDataList = this.jsonValueTreeList(this.itemInfo.value, JSON.parse(JSON.stringify(this.itemInfo.apiContent.treeDataList)));
}
// 生成table表格数据
this.itemInfo.apiContent.bodyTableData = await this.treeToTableList(JSON.parse(JSON.stringify(this.itemInfo.apiContent.treeDataList[0].children)));
this.itemInfo.apiContent.bodyTableData = this.treeToTableList(JSON.parse(JSON.stringify(this.itemInfo.apiContent.treeDataList[0].children)));
const bodyTableData = JSON.parse(JSON.stringify(this.itemInfo.apiContent.bodyTableData));
// 加入/引用变量
bodyTableData.forEach((item) => {
Expand All @@ -184,7 +184,7 @@
});
// 多层列表数据 关联 table表格数据
this.recordChildren(bodyTableData);
this.itemInfo.apiContent.bodyTableData = await bodyTableData;
this.itemInfo.apiContent.bodyTableData = bodyTableData;
},
jsonValueTreeList(jsonData, treeDataList) {
const listToJsonStep = function (lastObject, insertObject, key, item, lastType) {
Expand Down Expand Up @@ -324,7 +324,7 @@
return item.children.length === 1;
},
// 计算所有子孙元素
async countChildren(dataOri) {
countChildren(dataOri) {
let count = 0;
const countChildrenStep = function (data) {
if (data.children && data.children.length) {
Expand All @@ -334,11 +334,11 @@
}
}
};
await countChildrenStep(dataOri);
countChildrenStep(dataOri);
return count;
},
// 清除变量值
async cleanValue(item) {
cleanValue(item) {
const copyItem = JSON.parse(JSON.stringify(item));
const countChildrenStep = function (data) {
data.value = '';
Expand All @@ -349,29 +349,29 @@
}
}
};
await countChildrenStep(copyItem);
countChildrenStep(copyItem);
return copyItem;
},
// 添加 array 列表元素
async addChildren(itemChildren) {
addChildren(itemChildren) {
const item = this.itemInfo.apiContent.bodyTableData.filter(ite => (ite.level === itemChildren.level - 1 && ite.primaryKey === itemChildren.parentPrimaryKey && ite.ancestorsList.toString() === itemChildren.ancestorsList.slice(0, -1).toString()))[0];

const index = this.itemInfo.apiContent.bodyTableData.indexOf(item) + 1;
const count = await this.countChildren(item);
const copyItem = await this.cleanValue(item.children[0]);
const insertList = await this.treeToTableList(
const count = this.countChildren(item);
const copyItem = this.cleanValue(item.children[0]);
const insertList = this.treeToTableList(
JSON.parse(JSON.stringify([...item.children, copyItem])), item.level + 1,
item.primaryKey, 'array', item.ancestorsList
);
await insertList.forEach((ite) => {
insertList.forEach((ite) => {
ite.children = [];
});
item.children = insertList.filter(ite => ite.level === item.level + 1);
await this.recordChildren(insertList, item.level + 1);
this.recordChildren(insertList, item.level + 1);
this.itemInfo.apiContent.bodyTableData.splice(index, count, ...insertList);
},
// 删除元素
async deletChildren(item) {
deletChildren(item) {
if (this.countSon(item)) {
return;
}
Expand All @@ -381,7 +381,7 @@
}
currentObj.splice(currentObj.indexOf(item), 1);
const index = this.itemInfo.apiContent.bodyTableData.indexOf(item);
const count = await this.countChildren(item);
const count = this.countChildren(item);
this.itemInfo.apiContent.bodyTableData.splice(index, count + 1);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@
</template>
<template v-if="itemInfo.type === 'API_INFO' && apiId">
<div style="min-height: 100px;" v-bkloading="{ isLoading: isLoading }">
<input-params v-if="!isLoading"
:item-info="itemInfo">
</input-params>
<template v-if="!isLoading">
<get-params
v-if="!['POST', 'PATCH', 'PUT'].includes(itemInfo.apiContent.method)"
:params="itemInfo.apiContent.req_params"
:value="itemInfo.value"
@change="itemInfo.value = $event" />
<post-params v-else :item-info="itemInfo" />
</template>
</div>
</template>
</bk-form-item>
Expand All @@ -68,12 +73,14 @@
</template>
<script>
import { errorHandler } from '../../../../utils/errorHandler';
import inputParams from '../apiContent/inputParams.vue';
import postParams from '../apiContent/postParams.vue';
import getParams from '../apiContent/getParams.vue';

export default {
name: 'apiCall',
components: {
inputParams,
postParams,
getParams,
},
props: {
item: {
Expand All @@ -97,6 +104,7 @@
},
methods: {
initData() {
console.log(this.item);
this.item.wayInfo.field_schema.forEach(schema => {
if (schema.key === 'api_source' && schema.value) {
this.getApiContent(schema.value);
Expand Down

0 comments on commit ec27b68

Please sign in to comment.