Skip to content

Commit 7442cae

Browse files
author
sihy
committed
测试前检测是否保存了
1 parent 8588106 commit 7442cae

File tree

4 files changed

+70
-22
lines changed

4 files changed

+70
-22
lines changed

web/src/apps/dataService/module/common/treeMenu.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default {
6767
});
6868
},
6969
handleTreeModal(project) {
70-
this.$emit("showModal", { type: "api", data: { ...project } });
70+
this.$emit("showModal", { type: "api", data: { ...project }, groupDatas: [...this.originDatas] });
7171
this.treeModalShow = true;
7272
this.currentTreeProject = project;
7373
},

web/src/apps/dataService/module/dataService/emptyGuide.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
return {
2323
steps: [
2424
"点击左侧菜单-服务开发课表-加号按钮-创建业务流程",
25-
"点击业务流程-加号按钮-常见API",
25+
"点击业务流程-加号按钮-创建API",
2626
"配置API-添加数据源及设置参数,并保存",
2727
"测试",
2828
"发布-左侧菜单-服务管理,管理已发布API"

web/src/apps/dataService/module/dataService/index.vue

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ import navMenu from "../common/navMenu.vue";
147147
import tag from "@/components/tag/index.vue";
148148
import apiCongfig from "./apiConfig.vue";
149149
import api from "@/common/service/api";
150+
import _ from 'lodash';
150151
151152
export default {
152153
components: {
@@ -157,23 +158,31 @@ export default {
157158
data() {
158159
const validateGroupName = (rule, value, callback) => {
159160
const result = value && value.trim();
160-
if (!result) {
161-
callback(new Error("业务名称不能为空"));
161+
const reg = /^[\u4e00-\u9fa5a-zA-Z][\w_\u4e00-\u9fa5]{3,19}$/g;
162+
if (!reg.test(result)) {
163+
callback(
164+
new Error(
165+
"支持汉字、英文、数字、下划线(_),以英文或汉字开头,4~20个字符"
166+
)
167+
);
162168
} else {
163169
if (this.groupDatas.some(item => item.name.trim() === result)) {
164170
callback(new Error("该名称已经存在"));
165171
return;
166-
} else if (result.length > 20) {
167-
callback(new Error("名称不能超过20个字符"));
168172
} else {
169173
callback();
170174
}
171175
}
172176
};
173177
const validateAPIName = (rule, value, callback) => {
174178
const result = value && value.trim();
175-
if (!result) {
176-
callback(new Error("名称不能为空"));
179+
const reg = /^[\u4e00-\u9fa5a-zA-Z][\w_\u4e00-\u9fa5]{3,19}$/g;
180+
if (!reg.test(result)) {
181+
callback(
182+
new Error(
183+
"支持汉字、英文、数字、下划线(_),以英文或汉字开头,4~20个字符"
184+
)
185+
);
177186
} else {
178187
const apis = (this.groupData && this.groupData.apis) || [];
179188
const isUpdate = this.modalType === "updateApi";
@@ -198,19 +207,36 @@ export default {
198207
if (isHad) {
199208
callback(new Error("该名称已经存在"));
200209
return;
201-
} else if (result.length > 20) {
202-
callback(new Error("名称不能超过20个字符"));
203210
} else {
204211
callback();
205212
}
206213
}
207214
};
208215
const validateAPIPath = (rule, value, callback) => {
209216
const result = value && value.trim();
210-
if (!result) {
211-
callback(new Error("路径不能为空"));
217+
const reg = /^\/[\w_-]{3,199}$/g;
218+
if (!reg.test(result)) {
219+
callback(
220+
new Error(
221+
"支持英文、数字、下划线(_)、连字符(-),且只能以正斜线(/)开头,不超过200个字符,如/user"
222+
)
223+
);
212224
} else {
213-
callback();
225+
const isUpdate = this.modalType === "updateApi";
226+
const isHad = this.allProjectTree.some(item => {
227+
const { apis } = item;
228+
return apis.some(api => {
229+
return isUpdate
230+
? api.path.trim() === result && api.id !== this.apiForm.id
231+
: api.path.trim() === result;
232+
});
233+
});
234+
if (isHad) {
235+
callback(new Error("该路径已经存在,请更换"));
236+
return;
237+
} else {
238+
callback();
239+
}
214240
}
215241
};
216242
return {
@@ -304,8 +330,10 @@ export default {
304330
this.modalVisible = true;
305331
this.modalType = type;
306332
this.modalTitle = type === "group" ? "新增业务流程" : "生成API";
333+
console.log(pyload);
307334
if (type === "api") {
308335
this.groupData = data;
336+
this.allProjectTree = groupDatas;
309337
} else {
310338
this.groupDatas = groupDatas;
311339
}
@@ -381,7 +409,8 @@ export default {
381409
isActive: true,
382410
name: data.apiName,
383411
id: data.id || data.tempId,
384-
data
412+
data,
413+
originData: _.cloneDeep(data)
385414
});
386415
this.apiTabDatas = newApis;
387416
},
@@ -513,7 +542,7 @@ export default {
513542
const newApis = this.apiTabDatas.map(item => {
514543
let tmp = { ...item };
515544
if (tmp.id === data.id) {
516-
tmp = { ...item, name: data.apiName, data };
545+
tmp = { ...item, name: data.apiName, data, originData: _.cloneDeep(data) };
517546
}
518547
return tmp;
519548
});

web/src/apps/dataService/module/dataService/paramsConfig.vue

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@
295295
<script>
296296
import api from "@/common/service/api";
297297
import Test from "../common/test.vue";
298+
import _ from "lodash";
298299
299300
const compareItems = [
300301
{
@@ -630,20 +631,24 @@ export default {
630631
this.getTableCols(tblName, true);
631632
}
632633
},
633-
mounted() {},
634634
methods: {
635635
handleToolShow(item) {
636+
const { data, originData } = this.apiData;
636637
const { type } = item;
637638
if (type === "property") {
638639
this.$emit("showApiForm", this.apiData);
639640
} else if (type === "save") {
640-
this.saveApi();
641+
this.validateApi(type);
641642
} else if (type === "test") {
642-
if (!this.apiData.data.id) {
643+
if (!data.id) {
643644
this.$Message.info("请先保存API");
644645
return;
645646
}
646-
this.showTestPanel = true;
647+
if (!_.isEqual(data, originData)) {
648+
this.$Message.info("api内容有更改,请先保存API");
649+
return;
650+
}
651+
this.validateApi(type);
647652
} else if (type === "release") {
648653
if (!this.hadTestSuccess) {
649654
this.$Message.info("请先测试API");
@@ -658,9 +663,10 @@ export default {
658663
setTestSuccess() {
659664
this.hadTestSuccess = true;
660665
},
661-
saveApi() {
666+
validateApi(action) {
662667
const { data } = this.apiData;
663668
const { apiType } = data;
669+
const isSave = action === "save";
664670
const {
665671
name,
666672
type,
@@ -763,15 +769,28 @@ export default {
763769
this.$refs["pageForm"].validate(valid2 => {
764770
if (valid2) {
765771
reqParams.pageSize = parseInt(this.pageForm.pageSize);
766-
this.executeSaveApi(reqParams);
772+
isSave
773+
? this.executeSaveApi(reqParams)
774+
: this.showTest(reqParams);
767775
}
768776
});
769777
return;
770778
}
771-
this.executeSaveApi(reqParams);
779+
isSave ? this.executeSaveApi(reqParams) : this.showTest(reqParams);
772780
}
773781
});
774782
},
783+
showTest(reqParams) {
784+
const { originData } = this.apiData;
785+
const isSame = Object.keys(reqParams).every(
786+
key => originData[key] + "" === reqParams[key] + ""
787+
);
788+
if (!isSame) {
789+
this.$Message.info("api内容有更改,请先保存API");
790+
return;
791+
}
792+
this.showTestPanel = true;
793+
},
775794
executeSaveApi(reqParams) {
776795
const { data } = this.apiData;
777796
this.confirmLoading = true;

0 commit comments

Comments
 (0)