[go: nahoru, domu]

Skip to content

Commit

Permalink
自动分组:只修改对应命名的分组名;优化未命名分组的路径显示;解决登录后未自动加载分组列表
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Jan 13, 2024
1 parent 524eb42 commit f8d8f2a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 57 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@

<a style="color: black; font-weight: bold; margin-right: 0px; padding-right: 0px" class="hint--top save-tool" data-hint="切换显示本地|远程" href="javascript:void(0)" @click="onClickPathRoot()">测试用例:{{ isLocalShow ? '本地历史' : '远程在线' }}</a>
<div v-show="! isLocalShow" v-for="(item, index) in casePaths" style="display: inline-block; padding-left: 0px; margin-left: 0px;" >
<a style="color: gray; padding: 0px; margin: 0px">/</a><a style="color: black; outline: none; border: none; padding: 0px; margin: 0px" href="javascript:void(0)" @click="onClickPath(index, item)">{{ StringUtil.isEmpty(item.name) ? (item.url || '').substring(((casePaths[casePaths.length - 1] || {}).url || '').length + 1) : item.name }}</a>
<a style="color: gray; padding: 0px; margin: 0px">/</a><a style="color: black; outline: none; border: none; padding: 0px; margin: 0px" href="javascript:void(0)" @click="onClickPath(index, item)">{{ StringUtil.isEmpty(item.groupName) ? (StringUtil.isEmpty(item.groupUrl) ? '-' : item.groupUrl.substring(((casePaths[index-1] || {}).groupUrl || '').length + 1)) : item.groupName }}</a>
</div>
<a style="color: black; font-weight: bold; padding-left: 0px" class="hint--top save-tool" data-hint="切换显示分组|用例" href="javascript:void(0)" @click="switchCaseShowType()">{{ '(' + (isCaseGroupShow() && ! isLocalShow ? (caseGroups == null ? 0 : caseGroups.length) : '') + (caseShowType == 0 && isCaseGroupShow() && ! isLocalShow ? '|' : '') + (caseShowType == 2 && isCaseGroupShow() ? '' : (testCases == null ? 0 : testCases.length)) + ')' }}</a>
<div style="display: inline-flex; flex-grow: 1;"></div>
Expand All @@ -186,8 +186,8 @@
<ul class="historys" style="width: 100%; height: 100%;overflow: hidden;overflow-y: scroll;padding-bottom: 50px">
<li v-for="(item, index) in caseGroups" :id="'docGroup' + index" >
<div style="display: inline-table; width: 100%">
<input v-show="isCaseGroupEditable" style="min-width: 60px; width: 40%; margin-right: 6px" v-model="item.name" @keyup="doOnKeyUp(event, 'caseGroup', false, item)" />
<a href="javascript:void(0)" @click="selectCaseGroup(index, item)" :style="{ color: index == currentDocIndex ? 'black' : 'gray' }"> {{(isCaseGroupEditable ? '' : StringUtil.trim(item.name) + ' ') + item.url}}</a><a style="right: 0px; position: absolute; z-index: 101; width: fit-content; background-color: white">{{' (' + item.count + ') '}}</a>
<input v-show="isCaseGroupEditable" style="min-width: 60px; width: 40%; margin-right: 6px" v-model="item.groupName" @keyup="doOnKeyUp(event, 'caseGroup', false, item)" />
<a href="javascript:void(0)" @click="selectCaseGroup(index, item)" :style="{ color: index == currentDocIndex ? 'black' : 'gray' }"> {{(isCaseGroupEditable ? '' : (StringUtil.isEmpty(item.groupName) ? '-' : item.groupName) + ' ') + item.groupUrl}}</a><a style="right: 0px; position: absolute; z-index: 101; width: fit-content; background-color: white">{{' (' + item.count + ') '}}</a>
<!-- <div v-show="isStatisticsEnabled" style="position: absolute; right: 36px; top: 8px; display: inline-flex">-->
<!-- <div v-show="(item.totalCount || 0) > 0" style="background: lightgray; padding: 1px; margin-right: 2px; display: inline-block; position: relative" @click="restoreRemote(index, item, null, true)" >-->
<!-- &lt;!&ndash; 只能写成一行来消除间隙,不能换行、空格 &ndash;&gt;-->
Expand Down Expand Up @@ -221,7 +221,7 @@
<button class="hint--right" :data-hint="item.Document.url" v-show="isShowMethod()" style="width: 60px; margin-right: 0px;padding: 0px;" id="vDocMethod" @click="restoreRemoteAndTest(index, item)">{{ getMethodName(item.Document.method, item.Document.type) }}</button>
<button class="hint--right" :data-hint="item.Document.request" v-show="isShowType()" style="width: 48px;margin-right: 6px;padding: 0px" id="vDocType" @click="restoreRemoteAndTest(index, item)">{{ getTypeName(item.Document.type, item.Document.method) }}</button>
<a class="hint--rounded hint--no-animate" ref="testCaseTexts" @mouseover="setRequestHint(index, item)" href="javascript:void(0)" @click="restoreRemote(index, item)" :style="{ color: index == currentDocIndex ? 'black' : 'gray' }"> {{(item.Document.version > 0 ? 'V' + item.Document.version : 'V*') + ' ' + item.Document.name + ' ' + item.Document.url}}</a>
<div v-show="isStatisticsEnabled" style="position: absolute; right: 36px; top: 8px; display: inline-flex">
<div v-show="isStatisticsEnabled" style="position: absolute; right: 31px; top: 9px; display: inline-flex">
<div v-show="(item.totalCount || 0) > 0" style="background: lightgray; padding: 1px; margin-right: 2px; display: inline-block; position: relative" @click="restoreRemote(index, item, null, true)" >
<!-- 只能写成一行来消除间隙,不能换行、空格 -->
<a style="background: transparent; color: black; position: relative; min-width: 6px; width: auto; height: 100%; margin: 0; padding: 2px">{{ (item.totalCount || 0) + ':' }}</a><a style="background: white; color: black; position: relative; min-width: 6px; width: auto; height: 100%; margin: 0; padding: 2px">{{ item.whiteCount || 0 }}</a><a style="background: green; color: white; position: relative; min-width: 6px; width: auto; height: 100%; margin: 0; padding: 2px">{{ item.greenCount || 0 }}</a><a style="background: blue; color: white; position: relative; min-width: 6px; width: auto; height: 100%; margin: 0; padding: 2px">{{ item.blueCount || 0 }}</a><a style="background: orange; color: white; position: relative; min-width: 6px; width: auto; height: 100%; margin: 0; padding: 2px">{{ item.orangeCount || 0 }}</a><a style="background: red; color: white; position: relative; min-width: 6px; width: auto; height: 100%; margin: 0; padding: 2px">{{ item.redCount || 0 }}</a>
Expand Down
105 changes: 52 additions & 53 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4103,17 +4103,17 @@ https://github.com/Tencent/APIJSON/issues
this.casePaths.push(group)
}

if (group != null && (group.name == '_' || StringUtil.isEmpty(group.url))) {
var groupUrl = group == null ? '' : (group.groupUrl || '')
if (group != null && StringUtil.isEmpty(groupUrl)) {
this.caseGroups = []
this.remotes = App.testCases = []
this.showTestCase(true, false, null)
return
}

var urlPrefix = group == null ? '' : (group.url || '')
var page = this.caseGroupPage = this.caseGroupPages[urlPrefix] || 0
var count = this.caseGroupCount = this.caseGroupCounts[urlPrefix] || 0
var search = this.caseGroupSearch = this.caseGroupSearches[urlPrefix] || ''
var page = this.caseGroupPage = this.caseGroupPages[groupUrl] || 0
var count = this.caseGroupCount = this.caseGroupCounts[groupUrl] || 0
var search = this.caseGroupSearch = this.caseGroupSearches[groupUrl] || ''

search = StringUtil.isEmpty(search, true) ? null : '%' + StringUtil.trim(search).replaceAll('_', '\\_').replaceAll('%', '\\%') + '%'
var req = {
Expand All @@ -4125,22 +4125,26 @@ https://github.com/Tencent/APIJSON/issues
'@from@': {
'Document': {
'@raw': '@column',
'@column': "substr(url,1,length(url)-length(substring_index(url,'/',-1))-1):url;(CASE WHEN length(`group`) > 0 THEN `group` ELSE '_' END):name", // FIXME 新增 Group 表,专门映射 url 和 name 关系
'@column': "substr(url,1,length(url)-length(substring_index(url,'/',-1))-1):groupUrl;group:groupName", // (CASE WHEN length(`group`) > 0 THEN `group` ELSE '-' END):name",
'userId': this.User.id,
'name$': search,
'group$': search,
'url$': search,
// 'url&$': StringUtil.isEmpty(urlPrefix) ? null : [urlPrefix.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%'],
'@combine': search == null ? null : 'name$,url$',
// 'url&$': StringUtil.isEmpty(groupUrl) ? null : [groupUrl.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%'],
'@combine': search == null ? null : 'group$,url$',
'@null': 'sqlauto', //'sqlauto{}': '=null',
'url{}': 'length(url)>0',
// 'group{}': group == null || StringUtil.isNotEmpty(urlPrefix) ? null : 'length(group)<=0' // SQL WHERE 条件不用别名
// '@having': "length(url)>0" // StringUtil.isEmpty(urlPrefix) ? "length(url)>0" : "(url = '" + urlPrefix.replaceAll("'", "\\'") + "')"
'url&$': StringUtil.isEmpty(groupUrl) ? null : [groupUrl.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%']
// 'group{}': group == null || StringUtil.isNotEmpty(groupUrl) ? null : 'length(group)<=0' // SQL WHERE 条件不用别名
// '@having': "length(url)>0" // StringUtil.isEmpty(groupUrl) ? "length(url)>0" : "(url = '" + groupUrl.replaceAll("'", "\\'") + "')"
}
},
'@column': "name,url;length(name):name_len;count(*):count", // FIXME 新增 Group 表,专门映射 url 和 name 关系
'@group': 'name,url',
'@order': 'name_len+,name-,url+',
'url&$': StringUtil.isEmpty(urlPrefix) ? null : [urlPrefix.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%']
'groupUrl&$': StringUtil.isEmpty(groupUrl) ? null : [groupUrl.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%'],
'groupName$': search,
'groupUrl$': search,
'@combine': search == null ? null : 'groupName$,groupUrl$',
'@column': "groupName,groupUrl;any_value(groupName):rawName;length(groupName):groupNameLen;count(*):count",
'@group': 'groupName,groupUrl',
'@order': 'groupNameLen+,groupName-,groupUrl+',
}
},
'@role': IS_NODE ? null : 'LOGIN',
Expand Down Expand Up @@ -4187,7 +4191,7 @@ https://github.com/Tencent/APIJSON/issues
}

this.caseShowType = (this.caseShowType + 1)%3
if (this.caseShowType != 0 && this.casePaths.length <= 0 && this.caseGroups.length <= 0) {
if (this.caseShowType != 1 && this.casePaths.length <= 0 && this.caseGroups.length <= 0) {
this.selectCaseGroup(-1, null)
}
},
Expand Down Expand Up @@ -4237,11 +4241,11 @@ https://github.com/Tencent/APIJSON/issues

var index = this.casePaths.length - 1
var group = this.casePaths[index]
var urlPrefix = group == null ? '' : (group.url || '')
var groupUrl = group == null ? '' : (group.groupUrl || '')

var page = this.testCasePage = this.testCasePages[urlPrefix] || 0
var count = this.testCaseCount = this.testCaseCounts[urlPrefix] || 100
var search = this.testCaseSearch = this.testCaseSearches[urlPrefix] || ''
var page = this.testCasePage = this.testCasePages[groupUrl] || 0
var count = this.testCaseCount = this.testCaseCounts[groupUrl] || 100
var search = this.testCaseSearch = this.testCaseSearches[groupUrl] || ''

search = StringUtil.isEmpty(search, true) ? null : '%' + StringUtil.trim(search).replaceAll('_', '\\_').replaceAll('%', '\\%') + '%'

Expand All @@ -4253,19 +4257,20 @@ https://github.com/Tencent/APIJSON/issues
'page': page || 0,
'join': '@/TestRecord,@/Script:pre,@/Script:post',
'Document': {
'@column': 'id,userId,version,date,group,name,operation,method,type,url,request,standard;substr(url,' + (StringUtil.length(urlPrefix) + 2) + '):substr',
'@column': 'id,userId,version,date,name,operation,method,type,url,request,standard', // ;substr(url,' + (StringUtil.length(groupUrl) + 2) + '):substr',
'@order': 'version-,date-',
'userId': this.User.id,
'name$': search,
'operation$': search,
'url$': search,
'url|$': StringUtil.isEmpty(urlPrefix) ? null : [urlPrefix, urlPrefix.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%'],
'group{}': group == null || StringUtil.isNotEmpty(urlPrefix) ? null : 'length(group)<=0',
'@combine': search == null ? null : 'name$,operation$,url$',
'url|$': StringUtil.isEmpty(groupUrl) ? null : [groupUrl, groupUrl.replaceAll('_', '\\_').replaceAll('%', '\\%') + '/%'],
// 'group{}': group == null || StringUtil.isNotEmpty(groupUrl) ? null : 'length(group)<=0',
// 'group{}': group == null ? null : (group.groupName == null ? "=null" : [group.groupName]),
'@combine': search == null ? null : 'name$,operation$,url$',
'method{}': methods == null || methods.length <= 0 ? null : methods,
'type{}': types == null || types.length <= 0 ? null : types,
'@null': 'sqlauto', //'sqlauto{}': '=null'
// '@having': StringUtil.isEmpty(urlPrefix) ? null : "substring_index(substr,'/',1)<0"
// '@having': StringUtil.isEmpty(groupUrl) ? null : "substring_index(substr,'/',1)<0"
},
'TestRecord': {
'documentId@': '/Document/id',
Expand Down Expand Up @@ -4911,6 +4916,9 @@ https://github.com/Tencent/APIJSON/issues
App.onClickAccount(App.currentAccountIndex, item) //自动登录测试账号

if (user.id > 0) {
if (App.caseShowType != 1 && App.casePaths.length <= 0 && App.caseGroups.length <= 0) {
App.selectCaseGroup(-1, null)
}
App.showTestCase(true, false)
}
}
Expand Down Expand Up @@ -5100,6 +5108,8 @@ https://github.com/Tencent/APIJSON/issues
clearUser: function () {
this.User.id = 0
this.Privacy = {}
this.casePaths = []
this.caseGroups = []
this.remotes = []
// 导致刚登录成功就马上退出 this.delegateId = null
this.saveCache(this.server, 'User', this.User) //应该用lastBaseUrl,baseUrl应随watch输入变化重新获取
Expand Down Expand Up @@ -6347,32 +6357,21 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
}

if (type == 'caseGroup') {
var url = item == null ? null : item.url
if (StringUtil.isEmpty(url)) {
alert('请选择有效的选项!item.url == null !')
return
}
var groupUrl = item == null ? null : item.groupUrl
var rawName = item == null ? null : item.rawName
// if (StringUtil.isEmpty(url)) {
// alert('请选择有效的选项!item.url == null !')
// return
// }

//修改 Document
this.request(true, REQUEST_TYPE_POST, REQUEST_TYPE_JSON, this.server + '/put', {
Document: {
'group': item.name,
'group': item.groupName,
'@raw': '@key',
'@key':"url:substr(url,1,length(url)-length(substring_index(url,'/',-1))-1)",
// 'url{}': "(substr(url,1,length(url)-length(substring_index(url,'/',-1))-1) = '" + url.replaceAll("'", "\\'") + "')",
'url{}': [url], // "='" + url.replaceAll("'", "\\'") + "'",
// 'id{}@': {
// 'Document': {
// '@column': "id",
// '@raw': '@key,@column',
// // '@key':"url:substr(url,1,length(url)-length(substring_index(url,'/',-1))-1)",
// // 'url{}': "(substr(url,1,length(url)-length(substring_index(url,'/',-1))-1) = '" + url.replaceAll("'", "\\'") + "')",
// // 'url{}': [url],
// 'userId': this.User.id,
// '@null': 'sqlauto', // 'sqlauto{}': '=null',
// // 'name{}': 'length(name)<=0'
// }
// }
'url{}': [groupUrl],
'group{}': rawName == null ? "=null" : [rawName]
},
tag: 'Document-group'
}, {}, function (url, res, err) {
Expand All @@ -6383,7 +6382,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
if (err != null) {
msg += '\nerr: ' + err.msg
}
alert('修改' + (isOk ? '成功' : '失败') + '!\nurl: ' + item.url + '\nname: ' + item.name + msg)
alert('修改' + (isOk ? '成功' : '失败') + '!\ngroupUrl: ' + item.groupUrl + '\ngroupName: ' + item.groupName + '\nrawName: ' + item.rawName + msg)

App.isCaseGroupEditable = ! isOk
})
Expand Down Expand Up @@ -6515,12 +6514,12 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
if (type == 'testCase' || type == 'caseGroup') {
var index = this.casePaths.length - 1
var group = this.casePaths[index]
var urlPrefix = group == null ? '' : (group.url || '')
var groupUrl = group == null ? '' : (group.groupUrl || '')

if (type == 'caseGroup') {
this.caseGroupPages[urlPrefix] = this.caseGroupPage
this.caseGroupCounts[urlPrefix] = this.caseGroupCount
this.caseGroupSearches[urlPrefix] = this.caseGroupSearch
this.caseGroupPages[groupUrl] = this.caseGroupPage
this.caseGroupCounts[groupUrl] = this.caseGroupCount
this.caseGroupSearches[groupUrl] = this.caseGroupSearch
if (index < 0) {
this.saveCache(this.server, 'caseGroupPage', this.caseGroupPage)
this.saveCache(this.server, 'caseGroupCount', this.caseGroupCount)
Expand All @@ -6533,9 +6532,9 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
this.selectCaseGroup()
}
else {
this.testCasePages[urlPrefix] = this.testCasePage
this.testCaseCounts[urlPrefix] = this.testCaseCount
this.testCaseSearches[urlPrefix] = this.testCaseSearch
this.testCasePages[groupUrl] = this.testCasePage
this.testCaseCounts[groupUrl] = this.testCaseCount
this.testCaseSearches[groupUrl] = this.testCaseSearch

if (index < 0) {
this.saveCache(this.server, 'testCasePage', this.testCasePage)
Expand Down

0 comments on commit f8d8f2a

Please sign in to comment.