Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #116 from longguikeji/dev/plpl
Browse files Browse the repository at this point in the history
Dev/plpl
  • Loading branch information
welylongguikeji authored Apr 22, 2021
2 parents 306ac08 + a9b1bf0 commit d7fc036
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 138 deletions.
103 changes: 19 additions & 84 deletions src/components/HeaderSearch/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,54 +21,35 @@
@change="change"
>
<el-option
v-for="item in options"
:key="item.path"
:value="item"
:label="item.meta.title.join(' > ')"
v-for="(item, index) in options"
:key="index"
:value="item.url"
:label="item.name"
/>
</el-select>
</div>
</template>

<script lang="ts">
import path from 'path'
import Fuse from 'fuse.js' // A lightweight fuzzy-search module
import { Component, Vue, Watch } from 'vue-property-decorator'
import { RouteConfig } from 'vue-router'
import { AppModule } from '@/store/modules/app'
import { menuRoutes } from '@/router/index'
import i18n from '@/lang' // Internationalization
import { UserModule, IUserApp } from '@/store/modules/user'
@Component({
name: 'HeaderSearch'
})
export default class extends Vue {
private search = ''
private show = false
private options: RouteConfig[] = []
private searchPool: RouteConfig[] = []
private fuse?: Fuse<RouteConfig>
private options: Array<IUserApp> = []
private fuse?: Fuse<IUserApp>
get routes() {
return menuRoutes
get apps() {
return UserModule.userApps
}
get lang() {
return AppModule.language
}
@Watch('lang')
private onLangChange() {
this.searchPool = this.generateRoutes(this.routes)
}
@Watch('routes')
private onRoutesChange() {
this.searchPool = this.generateRoutes(this.routes)
}
@Watch('searchPool')
private onSearchPoolChange(value: RouteConfig[]) {
@Watch('apps')
private onAppListChange(value: Array<IUserApp>) {
this.initFuse(value)
}
Expand All @@ -81,10 +62,6 @@ export default class extends Vue {
}
}
mounted() {
this.searchPool = this.generateRoutes(this.routes)
}
private click() {
this.show = !this.show
if (this.show) {
Expand All @@ -98,72 +75,29 @@ export default class extends Vue {
this.show = false
}
private change(route: RouteConfig) {
this.$router.push(route.path)
this.search = ''
this.options = []
this.$nextTick(() => {
this.show = false
})
private change(val: string) {
if (val) {
window.open(val, '_blank')
}
}
private initFuse(list: RouteConfig[]) {
private initFuse(list: Array<IUserApp>) {
this.fuse = new Fuse(list, {
shouldSort: true,
threshold: 0.4,
location: 0,
distance: 100,
minMatchCharLength: 1,
keys: [{
name: 'title',
name: 'name',
weight: 0.7
}, {
name: 'path',
name: 'description',
weight: 0.3
}]
})
}
// Filter out the routes that can be displayed in the sidebar
// And generate the internationalized title
private generateRoutes(routes: RouteConfig[], basePath = '/', prefixTitle: string[] = []) {
let res: RouteConfig[] = []
for (const router of routes) {
// skip hidden router
if (router.meta && router.meta.hidden) {
continue
}
const data: RouteConfig = {
path: path.resolve(basePath, router.path),
meta: {
title: [...prefixTitle]
}
}
if (router.meta && router.meta.title) {
// generate internationalized title
const i18ntitle = i18n.t(`route.${router.meta.title}`).toString()
data.meta.title = [...data.meta.title, i18ntitle]
if (router.redirect !== 'noRedirect') {
// only push the routes with title
// special case: need to exclude parent router without redirect
res.push(data)
}
}
// recursive child routes
if (router.children) {
const tempRoutes = this.generateRoutes(router.children, data.path, data.meta.title)
if (tempRoutes.length >= 1) {
res = [...res, ...tempRoutes]
}
}
}
return res
}
private querySearch(query: string) {
if (query !== '') {
if (this.fuse) {
Expand Down Expand Up @@ -205,6 +139,7 @@ export default class extends Vue {
border-bottom: 1px solid #d9d9d9;
vertical-align: middle;
}
}
&.show {
Expand Down
4 changes: 2 additions & 2 deletions src/flows/desktop/nodes/getUserApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import getUrl from '@/utils/url'

export class GetUserApp extends AuthApiNode {
async run() {
// get user app list
this.url = this.inputs.url
// get user app list
this.url = getUrl(this.inputs.url)
this.method = this.inputs.method
const outputs = await super.run()
return outputs
Expand Down
8 changes: 6 additions & 2 deletions src/flows/init/nodes/afterLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ export class AfterLogin extends AuthApiNode {
if (token) {
// 获取OpenAPI内容
await OpenAPI.instance.init('/api/schema?format=json')
// 此外,这里之后也可以进行当前用户信息的获取
// 包括用户的头像、名称、用户的uuid以及用户的权限

// 进行用户信息的获取,包括用户的头像、名称、用户的uuid以及用户的权限
this.url = '/api/v1/user/info/'
this.method = 'get'
const userInfo = await super.run()
UserModule.setUser(userInfo)
}
}
}
23 changes: 20 additions & 3 deletions src/layout/components/Navbar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@
>
<div class="avatar-wrapper">
<img
v-if="avatar"
:src="avatar"
class="user-avatar"
>
<div
v-else
class="user-avatar-placeholder"
>
{{ username[0].toUpperCase() }}
</div>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>
Expand Down Expand Up @@ -89,11 +96,11 @@ export default class extends Vue {
}
get avatar() {
return localStorage.getItem('avatar') || require('@/assets/HAAIFF-01.png')
return UserModule.userAvatar
}
get username() {
return localStorage.getItem('username')
return UserModule.userNickname || UserModule.username
}
private toggleSideBar() {
Expand Down Expand Up @@ -171,14 +178,24 @@ export default class extends Vue {
.avatar-wrapper {
margin-top: 5px;
position: relative;
cursor: pointer;
.user-avatar {
cursor: pointer;
width: 40px;
height: 40px;
border-radius: 10px;
}
.user-avatar-placeholder {
width: 40px;
height: 40px;
border-radius: 20px;
background-color: #006064;
color: #fff;
text-align: center;
line-height: 40px;
}
.el-icon-caret-bottom {
cursor: pointer;
position: absolute;
Expand Down
39 changes: 27 additions & 12 deletions src/store/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,33 @@ import { VuexModule, Module, Action, Mutation, getModule } from 'vuex-module-dec
import store from '@/store'

export interface IUserState {
userid: string // 用户id
userUUId: string
username: string
userType: string
userAvatar: string
userMobile: string
userAddress: string
userDes: string
userOcc: string
userWeChatId: string // 微信Id
userGithubId: string // Git Id
userWeChatId: string
userGithubId: string
userPermissions: Array<string>
userNickname: string
userApps: Array<IUserApp>
}

export interface IUserApp {
name?: string
logo?: string
description?: string
url?: string
uuid?: string
[key: string]: any
}

@Module({ dynamic: true, store, name: 'user' })
class User extends VuexModule implements IUserState {
public userid = '' // 用户id
public userUUId = '' // 用户id
public username = ''
public userType = ''
public userAvatar = ''
Expand All @@ -26,6 +38,9 @@ class User extends VuexModule implements IUserState {
public userOcc = ''
public userWeChatId = '' // 微信Id
public userGithubId = '' // Git Id
public userPermissions: Array<string> = []
public userNickname = ''
public userApps: Array<IUserApp> = []

@Mutation
setUserMobile(mobile: string) {
Expand All @@ -44,12 +59,12 @@ class User extends VuexModule implements IUserState {

@Mutation
setUser(data: any) {
this.userUUId = data.uuid
this.username = data.username
localStorage.setItem('username', data.username)
localStorage.setItem('avatar', data.avatar)
this.userType = data.is_extern_user
this.userAvatar = data.avatar || require('@/assets/HAAIFF-01.png')
this.userAvatar = data.avatar
this.userMobile = data.mobile
this.userType = data.is_extern_user
this.userNickname = data.nickname
}

@Mutation
Expand All @@ -60,13 +75,13 @@ class User extends VuexModule implements IUserState {
}

@Mutation
setUserId(data: any) {
this.userid = data
setUserAvatar(data: any) {
this.userAvatar = data
}

@Mutation
setUserAvatar(data: any) {
this.userAvatar = data
setUserApps(apps: Array<IUserApp>) {
this.userApps = apps
}

@Action
Expand Down
19 changes: 19 additions & 0 deletions src/utils/arr-trans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IUserApp } from '@/store/modules/user'

export default function arrTrans(arr: Array<IUserApp>, num: number): Array<Array<IUserApp>> {
if (arr.length === 0) return []
const arrTrans = new Array()
if (num === 0 || num === 1) {
arrTrans[0] = arr
} else {
const dimensionCapacity = Math.ceil(arr.length / num)
arr.forEach((item, index) => {
const arrTransIndex = Math.floor(index / dimensionCapacity)
if (!arrTrans[arrTransIndex]) {
arrTrans[arrTransIndex] = []
}
arrTrans[arrTransIndex].push(item)
})
}
return arrTrans
}
4 changes: 2 additions & 2 deletions src/utils/generate-dialog-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ function createItemByPropSchema(prop:string, schema: ISchema, showReadOnly:boole
prop: prop,
state: itemState
}
} else if (schema.allOf && schema.allOf[0]) {
const ref = schema.allOf[0].$ref
} else if (schema.allOf?.length || schema.oneOf?.length) {
const ref = schema.allOf?.length ? schema.allOf[0].$ref : schema.oneOf![0].$ref
const objectSchema = OpenAPI.instance.getSchemaByRef(ref!)
objectSchema.title = schema.title
objectSchema.default = schema.default
Expand Down
19 changes: 13 additions & 6 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@
// 除id参数之外,其余内容,当使用到的时候进行引入 store 中的相关存储值进行读取
// id参数则需要在调用该函数时传入data,通过data.id或data.uuid的方式进行读取
import { TenantModule } from '@/store/modules/tenant'
import { UserModule } from '@/store/modules/user'

export default function getUrl(currentUrl: string, data: any = {}) {
let url = currentUrl
if (url.indexOf('{') !== -1) {
const property = url.slice(url.indexOf('{') + 1, url.indexOf('}'))
// 之后如果某个url中有其他的参数需要,可以继续在这里进行添加
if (property === 'parent_lookup_tenant') {
url = url.slice(0, url.indexOf('{')) + TenantModule.currentTenant.uuid + url.slice(url.indexOf('}') + 1)
}
// 后端路径中的id统一修改成uuid之后,这里可以将property==='id'的判断去掉
if (property === 'id' || property === 'uuid') {
url = url.slice(0, url.indexOf('{')) + data.uuid + url.slice(url.indexOf('}') + 1)
let param
switch (property) {
case 'parent_lookup_tenant':
param = TenantModule.currentTenant.uuid
break
case 'parent_lookup_user':
param = UserModule.userUUId
break
case 'id':
case 'uuid':
param = data.uuid
}
url = url.slice(0, url.indexOf('{')) + param + url.slice(url.indexOf('}') + 1)
}
if (url.indexOf('{') !== -1) return getUrl(url, data)
return url
Expand Down
Loading

0 comments on commit d7fc036

Please sign in to comment.