Skip to content

Commit 8e2eca7

Browse files
author
陆小龙
committed
Merge branch 'LBCS-185' into 'develop'
测试前检测是否保存了,添加路径和名称字符校验 See merge request luban/dataspherestudio!238
2 parents 82122be + 7442cae commit 8e2eca7

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
@@ -71,7 +71,7 @@ export default {
7171
});
7272
},
7373
handleTreeModal(project) {
74-
this.$emit("showModal", { type: "api", data: { ...project } });
74+
this.$emit("showModal", { type: "api", data: { ...project }, groupDatas: [...this.originDatas] });
7575
this.treeModalShow = true;
7676
this.currentTreeProject = project;
7777
},

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
@@ -148,6 +148,7 @@ import navMenu from "../common/navMenu.vue";
148148
import tag from "@/components/tag/index.vue";
149149
import apiCongfig from "./apiConfig.vue";
150150
import api from "@/common/service/api";
151+
import _ from 'lodash';
151152
152153
export default {
153154
components: {
@@ -158,23 +159,31 @@ export default {
158159
data() {
159160
const validateGroupName = (rule, value, callback) => {
160161
const result = value && value.trim();
161-
if (!result) {
162-
callback(new Error("业务名称不能为空"));
162+
const reg = /^[\u4e00-\u9fa5a-zA-Z][\w_\u4e00-\u9fa5]{3,19}$/g;
163+
if (!reg.test(result)) {
164+
callback(
165+
new Error(
166+
"支持汉字、英文、数字、下划线(_),以英文或汉字开头,4~20个字符"
167+
)
168+
);
163169
} else {
164170
if (this.groupDatas.some(item => item.name.trim() === result)) {
165171
callback(new Error("该名称已经存在"));
166172
return;
167-
} else if (result.length > 20) {
168-
callback(new Error("名称不能超过20个字符"));
169173
} else {
170174
callback();
171175
}
172176
}
173177
};
174178
const validateAPIName = (rule, value, callback) => {
175179
const result = value && value.trim();
176-
if (!result) {
177-
callback(new Error("名称不能为空"));
180+
const reg = /^[\u4e00-\u9fa5a-zA-Z][\w_\u4e00-\u9fa5]{3,19}$/g;
181+
if (!reg.test(result)) {
182+
callback(
183+
new Error(
184+
"支持汉字、英文、数字、下划线(_),以英文或汉字开头,4~20个字符"
185+
)
186+
);
178187
} else {
179188
const apis = (this.groupData && this.groupData.apis) || [];
180189
const isUpdate = this.modalType === "updateApi";
@@ -199,19 +208,36 @@ export default {
199208
if (isHad) {
200209
callback(new Error("该名称已经存在"));
201210
return;
202-
} else if (result.length > 20) {
203-
callback(new Error("名称不能超过20个字符"));
204211
} else {
205212
callback();
206213
}
207214
}
208215
};
209216
const validateAPIPath = (rule, value, callback) => {
210217
const result = value && value.trim();
211-
if (!result) {
212-
callback(new Error("路径不能为空"));
218+
const reg = /^\/[\w_-]{3,199}$/g;
219+
if (!reg.test(result)) {
220+
callback(
221+
new Error(
222+
"支持英文、数字、下划线(_)、连字符(-),且只能以正斜线(/)开头,不超过200个字符,如/user"
223+
)
224+
);
213225
} else {
214-
callback();
226+
const isUpdate = this.modalType === "updateApi";
227+
const isHad = this.allProjectTree.some(item => {
228+
const { apis } = item;
229+
return apis.some(api => {
230+
return isUpdate
231+
? api.path.trim() === result && api.id !== this.apiForm.id
232+
: api.path.trim() === result;
233+
});
234+
});
235+
if (isHad) {
236+
callback(new Error("该路径已经存在,请更换"));
237+
return;
238+
} else {
239+
callback();
240+
}
215241
}
216242
};
217243
return {
@@ -305,8 +331,10 @@ export default {
305331
this.modalVisible = true;
306332
this.modalType = type;
307333
this.modalTitle = type === "group" ? "新增业务流程" : "生成API";
334+
console.log(pyload);
308335
if (type === "api") {
309336
this.groupData = data;
337+
this.allProjectTree = groupDatas;
310338
} else {
311339
this.groupDatas = groupDatas;
312340
}
@@ -382,7 +410,8 @@ export default {
382410
isActive: true,
383411
name: data.apiName,
384412
id: data.id || data.tempId,
385-
data
413+
data,
414+
originData: _.cloneDeep(data)
386415
});
387416
this.apiTabDatas = newApis;
388417
},
@@ -514,7 +543,7 @@ export default {
514543
const newApis = this.apiTabDatas.map(item => {
515544
let tmp = { ...item };
516545
if (tmp.id === data.id) {
517-
tmp = { ...item, name: data.apiName, data };
546+
tmp = { ...item, name: data.apiName, data, originData: _.cloneDeep(data) };
518547
}
519548
return tmp;
520549
});

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)