Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1fb6d05

Browse files
优化代码,避免可能的异常
1 parent d8f045c commit 1fb6d05

File tree

3 files changed

+56
-31
lines changed

3 files changed

+56
-31
lines changed

‎apijson/CodeUtil.js‎

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,34 @@ var CodeUtil = {
4646
line = lines[i].trim();
4747

4848
//每一种都要提取:左边的key
49-
index = line.indexOf(': '); //可能是 ' 或 ",所以不好用 ': , ": 判断
49+
index = line==null ? -1 : line.indexOf(': '); //可能是 ' 或 ",所以不好用 ': , ": 判断
5050
if (index < 0) {
5151
continue;
5252
}
53-
54-
key = line.substring(1, index - 1);
55-
56-
if (line.endsWith('{')) { //对象,判断是不是Table,再加对应的注释
57-
depth ++;
58-
names[depth] = key;
59-
comment = CodeUtil.getComment4Request(tableList, names[depth], key, null);
60-
}
61-
else if (line.endsWith('[')) { //数组,判断是不是 key{}
62-
depth ++;
63-
names[depth] = key;
64-
comment = CodeUtil.getComment4Request(tableList, names[depth], key, null);
53+
if (index == 0) { // ":user": value 不合法
54+
// throw new Error('不允许将 : 作为key的第一个字符!');
55+
comment = ' ! 不允许将 : 作为key的第一个字符!';
6556
}
66-
else if (line.endsWith('}') || line.endsWith(']')) {
67-
depth --;
68-
}
69-
else { //其它,直接在后面加上注释
70-
value = line.substring(index + 2);
71-
comment = CodeUtil.getComment4Request(tableList, names[depth], key, value);
57+
else {
58+
key = line.substring(1, index - 1);
59+
60+
if (line.endsWith('{')) { //对象,判断是不是Table,再加对应的注释
61+
depth ++;
62+
names[depth] = key;
63+
comment = CodeUtil.getComment4Request(tableList, names[depth], key, null);
64+
}
65+
else if (line.endsWith('[')) { //数组,判断是不是 key{}
66+
depth ++;
67+
names[depth] = key;
68+
comment = CodeUtil.getComment4Request(tableList, names[depth], key, null);
69+
}
70+
else if (line.endsWith('}') || line.endsWith(']')) {
71+
depth --;
72+
}
73+
else { //其它,直接在后面加上注释
74+
value = line.substring(index + 2);
75+
comment = CodeUtil.getComment4Request(tableList, names[depth], key, value);
76+
}
7277
}
7378

7479
//maxLength = maxLineLength - lines[i].length;
@@ -734,7 +739,22 @@ var CodeUtil = {
734739
return id.toLowerCase() == 'id';
735740
},
736741

742+
743+
737744
QUERY_TYPES: ['数据', '数量', '全部'],
745+
REQUEST_ROLES: {
746+
UNKNOWN: '未登录',
747+
748+
LOGIN: '已登录',
749+
750+
CONTACT: '联系人',
751+
752+
CIRCLE: '圈子成员',
753+
754+
OWNER: '拥有者',
755+
756+
ADMIN: '管理员'
757+
},
738758

739759
/**获取请求JSON的注释
740760
* @param tableList
@@ -792,13 +812,24 @@ var CodeUtil = {
792812
case '@correct':
793813
return CodeUtil.getComment('字段校正', false, ' ');
794814
case '@role':
795-
return CodeUtil.getComment('登录角色', false, ' ');
815+
return CodeUtil.getComment('登录角色:'+CodeUtil.REQUEST_ROLES[value.toLowerCase()], false, ' ');
796816
}
797817
return '';
798818
}
799819
return CodeUtil.getComment(CodeUtil.getCommentFromDoc(tableList, name, key), false, ' ');
800820
}
801821

822+
if (StringUtil.isEmpty(name)) {
823+
switch (key) {
824+
case 'tag':
825+
return '请求密钥';
826+
case 'version':
827+
return '版本号';
828+
case '@role':
829+
return '默认角色:' + CodeUtil.REQUEST_ROLES[value.toLowerCase()];
830+
}
831+
}
832+
802833
return '';
803834
},
804835

‎index.html‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@
9292
</ul>
9393
<div v-show="! isRemoteShow" style="width: 100%;height: 100%;" >
9494
<textarea id="vComment" style="width: 100%; height: 100%; position: absolute; z-index: 0; color: darkseagreen" wrap="off" disabled>
95-
{
96-
"[]": { //数组
97-
"User": { //用户开放信息表
98-
"sex": 1 //性别
99-
}
100-
}
101-
}
10295
</textarea>
10396
<textarea id="vInput" @keyup="onChange(true)"style="width: 100%;height: 100%; position: absolute; z-index: 100; background: #0000;" wrap="off" >
10497
{

‎js/main.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,11 @@
707707

708708
App.showDoc()
709709

710-
// alert('vComment.with = ' + vComment.cols);
711-
// alert('vInput.with = ' + vInput.cols);
712-
vComment.value = CodeUtil.parseComment(before, docObj == null ? null : docObj['[]'])
713-
710+
try {
711+
vComment.value = CodeUtil.parseComment(before, docObj == null ? null : docObj['[]'])
712+
} catch (e) {
713+
log('onHandle try { vComment.value = CodeUtil.parseComment >> } catch (e) {\n' + e.message);
714+
}
714715
} catch(e) {
715716
log(e)
716717
vSend.disabled = true

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /