Skip to content

Commit

Permalink
refactor: parser and api,case (#183)
Browse files Browse the repository at this point in the history
* refactor: add type hint for Parse and Format, extract statement to function

* refactor(api,case): use mixin replace duplicate methods
  • Loading branch information
lihuacai168 authored Feb 24, 2024
1 parent a333f09 commit 559b6be
Show file tree
Hide file tree
Showing 8 changed files with 761 additions and 800 deletions.
374 changes: 156 additions & 218 deletions fastrunner/utils/parser.py

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions web/src/mixins/apiListMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// apiListMixin.js
export default {
methods: {
getAPIList(params) {
this.$nextTick(() => {
const defaultParams = {
page: this.listCurrentPage || 1, // 提供默认值
node: this.node || this.currentNode, // 支持不同的命名
project: this.project,
search: this.search,
tag: this.visibleTag || this.tag,
rigEnv: this.rigEnv,
onlyMe: this.onlyMe,
showYAPI: this.showYAPI,
creator: this.selectUser
};

// 使用传入的参数覆盖默认参数
const apiParams = { ...defaultParams, ...params };

this.$api.apiList({ params: apiParams }).then(res => {
this.apiData = res;
});
});
}
}
};
28 changes: 28 additions & 0 deletions web/src/mixins/configMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// configMixin.js
export default {
data() {
return {
configOptions: [],
currentConfig: null
};
},
methods: {
getConfig({ addPlaceholder = false, setDefaultConfig = false } = {}) {
this.$api.getAllConfig(this.$route.params.id).then(resp => {
this.configOptions = resp;

// 根据配置决定是否添加占位符,并设置默认选项
if (addPlaceholder) {
const placeHolderOption = { name: '请选择' };
if (setDefaultConfig) {
this.configOptions.unshift(placeHolderOption);
const _config = this.configOptions.find(item => item.is_default === true);
this.currentConfig = _config || placeHolderOption;
} else {
this.configOptions.push(placeHolderOption);
}
}
});
}
}
};
15 changes: 15 additions & 0 deletions web/src/mixins/treeMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// treeMixin.js
export default {
methods: {
getTree(callback) {
this.$api.getTree(this.$route.params.id, { params: { type: 1 } }).then(resp => {
this.dataTree = resp['tree'];

// 如果有提供回调函数,则调用它
if (callback && typeof callback === 'function') {
callback(resp);
}
});
}
}
};
Loading

0 comments on commit 559b6be

Please sign in to comment.