Skip to content

Commit

Permalink
feat: 修改项目名称获取方式
Browse files Browse the repository at this point in the history
  • Loading branch information
xinufo committed Sep 21, 2019
1 parent f86cdcb commit 2e17552
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const api = {
GetTags: '/statistic/tags',
// projects
GetProjects: '/projects',
GetProjectNameById: projectId => `/projects/${projectId}/name`,
// apis
GetApisByProjectId: projectId => `/projects/${projectId}/apis`,
// cases
GetCasesByApiId: (projectId, apiId) => `/projects/${projectId}/apis/${apiId}/cases`,
GetCasesByApiId: (projectId, apiId) =>
`/projects/${projectId}/apis/${apiId}/cases`,
// tasks
GetTasks: '/tasks'
}
Expand Down
7 changes: 7 additions & 0 deletions src/api/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ export function getProjects (params) {
params: params
})
}

export function getProjectNameById (projectId) {
return axios({
url: api.GetProjectNameById(projectId),
method: 'get'
})
}
5 changes: 3 additions & 2 deletions src/config/router.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ export const asyncRouterMap = [
component: () => import('@/views/project/ProjectDetail'),
hidden: true,
meta: { title: '项目详情' },
// 在代码中跳转
// redirect: '/project/:projectId/info',
redirect: to => {
return `/project/${to.params.projectId}/info`
},
children: [
{
path: '/project/:projectId/info',
Expand Down
7 changes: 6 additions & 1 deletion src/mock/services/project.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Mock from 'mockjs2'
import { pageBuilder } from '../util'
import { pageBuilder, builder } from '../util'

const getProjects = options => {
return pageBuilder(options, i => {
Expand All @@ -16,4 +16,9 @@ const getProjects = options => {
})
}

const getProjectNameById = options => {
return builder(Mock.mock('@ctitle(3, 6)'))
}

Mock.mock(/\/projects\/\d+\/name/, 'get', getProjectNameById)
Mock.mock(/\/projects/, 'get', getProjects)
25 changes: 13 additions & 12 deletions src/views/project/ProjectDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<script>
import { RouteView } from '@/layouts'
import { getProjectNameById } from '@/api/project'
import { getApisByProjectId } from '@/api/api'
import { getCasesByApiId } from '@/api/case'
Expand All @@ -40,7 +41,6 @@ export default {
return {
spinning: true,
root: null,
name: null,
treeData: [],
expandedKeys: []
}
Expand Down Expand Up @@ -81,30 +81,34 @@ export default {
onTreeSelect (selectedKeys, e) {
const { dataRef } = e.node
if (!e.selected) {
// 禁止取消选择
selectedKeys.push(dataRef.key)
} else {
const { id } = dataRef
switch (dataRef.type) {
case 'p':
this.$router.push({ name: 'ProjectInfo', params: { projectId: id }, query: { name: this.name } })
this.$router.push({ name: 'ProjectInfo', params: { projectId: id } })
break
case 'a':
this.$router.push({ name: 'ApiInfo', params: { projectId: this.root.id, apiId: id }, query: { name: this.name } })
this.$router.push({ name: 'ApiInfo', params: { projectId: this.root.id, apiId: id } })
break
case 'c':
this.$router.push({ name: 'CaseInfo', params: { projectId: this.root.id, apiId: dataRef.apiId, caseId: id }, query: { name: this.name } })
this.$router.push({ name: 'CaseInfo', params: { projectId: this.root.id, apiId: dataRef.apiId, caseId: id } })
break
default:
break
}
}
},
initTreeData (projectId) {
getApisByProjectId(projectId)
.then(resp => {
this.name = this.$route.query.name
this.root = { id: this.$route.params.projectId, title: this.name, key: 'root', type: 'p', scopedSlots: { icon: 'project' } }
this.root.children = resp.data.map(d => {
const p1 = getProjectNameById(projectId)
const p2 = getApisByProjectId(projectId)
Promise.all([p1, p2])
.then(results => {
const name = results[0].data
const apis = results[1].data
this.root = { id: this.$route.params.projectId, title: name, key: 'root', type: 'p', scopedSlots: { icon: 'project' } }
this.root.children = apis.map(d => {
return {
id: d.id,
title: d.name,
Expand All @@ -115,9 +119,6 @@ export default {
})
this.treeData.push(this.root)
this.expandedKeys.push('root')
if (this.$route.name !== 'ProjectInfo') {
this.$router.replace({ name: 'ProjectInfo', params: { projectId: this.root.id }, query: { name: this.name } })
}
})
.catch(e => e)
.finally(() => {
Expand Down
6 changes: 1 addition & 5 deletions src/views/project/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@
showPagination="auto"
:pageSize="15"
>
<router-link
slot="name"
slot-scope="text, record"
:to="{path: `/project/${record.id}`, query: {name: text}}"
>{{text}}</router-link>
<router-link slot="name" slot-scope="text, record" :to="`/project/${record.id}`">{{text}}</router-link>
<span slot="description" slot-scope="text">
<ellipsis :length="30" tooltip>{{ text }}</ellipsis>
</span>
Expand Down

0 comments on commit 2e17552

Please sign in to comment.