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 #136 from longguikeji/dev/plpl
Browse files Browse the repository at this point in the history
Dev/plpl
  • Loading branch information
longgui-penglei authored May 20, 2021
2 parents 6ecb714 + 5be3262 commit 99f07d9
Showing 13 changed files with 94 additions and 76 deletions.
21 changes: 13 additions & 8 deletions src/flows/init/index.ts
Original file line number Diff line number Diff line change
@@ -2,28 +2,33 @@ import { Flow } from 'arkfbp/lib/flow'
import { Graph } from 'arkfbp/lib/graph'
import { StartNode } from 'arkfbp/lib/startNode'
import { StopNode } from 'arkfbp/lib/stopNode'
import { InterceptToken } from './nodes/interceptToken'
import { VerifyToken } from './nodes/verifyToken'
import { GetOriginHost } from './nodes/getOriginHost'
import { Tenant } from './nodes/tenant'
import { GetOriginUrl } from './nodes/getOriginUrl'
import { Slug } from './nodes/slug'
import { AfterLogin } from './nodes/afterLogin'

export class Main extends Flow {
createNodes() {
return [{
cls: StartNode,
id: 'start',
next: 'interceptToken'
}, {
cls: InterceptToken,
id: 'interceptToken',
next: 'verifyToken'
}, {
cls: VerifyToken,
id: 'verifyToken',
next: 'getOriginHost'
next: 'getOriginUrl'
}, {
cls: GetOriginHost,
id: 'getOriginHost',
next: 'tenant'
cls: GetOriginUrl,
id: 'getOriginUrl',
next: 'slug'
}, {
cls: Tenant,
id: 'tenant',
cls: Slug,
id: 'slug',
next: 'afterLogin'
}, {
cls: AfterLogin,
19 changes: 18 additions & 1 deletion src/flows/init/nodes/afterLogin.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@ import { AuthApiNode } from '@/nodes/authApiNode'
import OpenAPI from '@/config/openapi'
import { UserModule } from '@/store/modules/user'
import { getToken } from '@/utils/auth'
import { TenantModule } from '@/store/modules/tenant'
import processUUId from '@/utils/process-uuid'
import { getUrlParamByName } from '@/utils/url'

export class AfterLogin extends AuthApiNode {
async run() {
@@ -11,9 +14,23 @@ export class AfterLogin extends AuthApiNode {
// 获取OpenAPI内容
await OpenAPI.instance.init('/api/schema?format=json')

// 此时进行tenant的获取
if (TenantModule.currentTenant.uuid === undefined) {
let tenantUUId = TenantModule?.currentTenant?.uuid || getUrlParamByName('tenant') || getUrlParamByName('tenant_uuid')
tenantUUId = processUUId(tenantUUId)
this.url = '/api/v1/tenant/'
this.method = 'GET'
const outputs = await super.run()
outputs.results.forEach(output => {
if (output.uuid === tenantUUId || outputs.results.length === 1) {
TenantModule.changeCurrentTenant(output)
}
})
}

// 进行用户信息的获取,包括用户的头像、名称、用户的uuid以及用户的权限
this.url = '/api/v1/user/info/'
this.method = 'get'
this.method = 'GET'
const userInfo = await super.run()
UserModule.setUser(userInfo)
}
12 changes: 0 additions & 12 deletions src/flows/init/nodes/getOriginHost.ts

This file was deleted.

15 changes: 15 additions & 0 deletions src/flows/init/nodes/getOriginUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { APINode } from "arkfbp/lib/apiNode"
import { getOriginUrl, setOriginUrl } from '@/utils/cookies'

export class GetOriginUrl extends APINode {
async run() {
const originUrl = getOriginUrl()
if (!originUrl) {
this.url = '/api/v1/get_frontendurl/'
this.method = 'GET'
const outputs = await super.run()
const url = outputs.url as string
setOriginUrl(url)
}
}
}
14 changes: 14 additions & 0 deletions src/flows/init/nodes/interceptToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FunctionNode } from 'arkfbp/lib/functionNode'
import { getUrlParamByName } from '@/utils/url'
import { setToken } from '@/utils/auth'

export class InterceptToken extends FunctionNode {
async run() {
if (window.location.pathname === '/' && window.location.search.includes('token')) {
const token = getUrlParamByName('token') as string
setToken(token)
const url = window.location.origin + '/' + process.env.VUE_APP_BASE_API
window.location.replace(url)
}
}
}
19 changes: 19 additions & 0 deletions src/flows/init/nodes/slug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { APINode } from "arkfbp/lib/apiNode"
import { TenantModule } from '@/store/modules/tenant'
import { getSlug } from '@/utils/url'

export class Slug extends APINode {
async run() {
// 通过 slug 查找
const slug = getSlug()
if (slug) {
this.url = '/api/v1/tenant/' + slug + '/slug/'
this.method = 'GET'
const outputs = await super.run()
if (outputs.uuid) {
TenantModule.setHasSlug(true)
TenantModule.changeCurrentTenant(outputs)
}
}
}
}
38 changes: 0 additions & 38 deletions src/flows/init/nodes/tenant.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/flows/tenant/switchTenant/nodes/switchTenant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { StateNode } from '@/nodes/stateNode'
import { TenantModule } from '@/store/modules/tenant'
import TablePageState from '@/admin/TablePage/TablePageState'
import { getOriginUrl } from '@/utils/cookies'
import { getToken } from '@/utils/auth'

export class SwitchTenant extends StateNode {
async run() {
@@ -14,9 +16,10 @@ export class SwitchTenant extends StateNode {
const slug = data.slug
if (slug) {
TenantModule.setHasSlug(true)
const host = TenantModule.originHost
const host = getOriginUrl()
const newHost = host?.replace(window.location.protocol + '//', window.location.protocol + '//' + slug + '.')
window.location.replace(newHost + '/' + process.env.VUE_APP_BASE_API)
const url = newHost + '/' + process.env.VUE_APP_BASE_API + '?token=' + getToken()
window.location.replace(url)
} else {
router.push({
path: '/',
2 changes: 1 addition & 1 deletion src/nodes/getDialogValues.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ export class GetDialogValues extends AuthApiNode {
throw Error('dialogs is not data')
}
this.url = getUrl(this.inputs.params.url, data)
this.method = this.inputs.params.method || 'get'
this.method = this.inputs.params.method || 'GET'
const outputs = await super.run()
return {
outputs: outputs,
7 changes: 0 additions & 7 deletions src/store/modules/tenant.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import TablePageState from '@/admin/TablePage/TablePageState'
export interface ITenantState {
tenantState: TablePageState
currentTenant: any
originHost: string
hasSlug: boolean
}

@@ -15,7 +14,6 @@ class Tenant extends VuexModule implements ITenantState {
type: 'TablePage'
}
currentTenant: any = {}
originHost: string = ''
hasSlug: boolean = false

@Mutation
@@ -28,11 +26,6 @@ class Tenant extends VuexModule implements ITenantState {
this.currentTenant = payload
}

@Mutation
public setOriginHost(originHost: string) {
this.originHost = originHost
}

@Mutation
public setHasSlug(hasSlug: boolean) {
this.hasSlug = hasSlug
9 changes: 4 additions & 5 deletions src/utils/cookies.ts
Original file line number Diff line number Diff line change
@@ -13,8 +13,7 @@ const sizeKey = 'size'
export const getSize = () => Cookies.get(sizeKey)
export const setSize = (size: string) => Cookies.set(sizeKey, size)

// User
const tokenKey = 'vue_typescript_admin_access_token'
export const getToken = () => Cookies.get(tokenKey)
export const setToken = (token: string) => Cookies.set(tokenKey, token)
export const removeToken = () => Cookies.remove(tokenKey)
// OriginUrl
const originUrlKey = 'origin_url'
export const getOriginUrl = () => Cookies.get(originUrlKey)
export const setOriginUrl = (originUrl: string) => Cookies.set(originUrlKey, originUrl)
3 changes: 2 additions & 1 deletion src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
// id参数则需要在调用该函数时传入data,通过data.id或data.uuid的方式进行读取
import { TenantModule } from '@/store/modules/tenant'
import { UserModule } from '@/store/modules/user'
import { getOriginUrl } from '@/utils/cookies'

export default function getUrl(currentUrl: string, data: any = {}) {
let url = currentUrl
@@ -38,7 +39,7 @@ export function getUrlParamByName(name: string) {
}

export function getSlug() {
const host = TenantModule.originHost
const host = getOriginUrl()
const hostname = host?.replace(window.location.protocol + '//', '') || ''
let slug = window.location.host.replace(hostname, '')
if (slug.length > 0) {
4 changes: 3 additions & 1 deletion src/views/tenant/TenantManager.vue
Original file line number Diff line number Diff line change
@@ -45,7 +45,9 @@ export default class extends Vue {
this.isShow = true
// 执行查看 TenantModule.currentTenant 当前的内容,如果不存在uuid,则设置isShowClose为false
const currentTenant = TenantModule.currentTenant
if (currentTenant?.uuid?.length) this.isShowClose = true
if (currentTenant.uuid?.length) {
this.isShowClose = true
}
const currentPage = this.$route.meta.page
const initContent: ITagPage | undefined = getInitContent(currentPage)
if (!initContent) {

0 comments on commit 99f07d9

Please sign in to comment.