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

合并发版 #244

Merged
merged 4 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 50 additions & 34 deletions src/flows/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,66 @@ import { StopNode } from 'arkfbp/lib/stopNode'
import { EntranceNode } from './nodes/entrance'
import { TenantNode } from './nodes/tenant'
import { TokenNode } from './nodes/token'
import { UrlNode } from './nodes/url'
import { OpenapiNode } from '@/arkfbp/flows/openapi/nodes/openapi'
import { ConfigNode } from './nodes/config'
import { DeviceNode } from './nodes/device'

export class Main extends Flow {
createNodes() {
return [{
cls: StartNode,
id: 'start',
next: 'entrance'
}, {
cls: EntranceNode,
id: 'entrance',
next: 'tenant'
}, {
cls: TenantNode,
id: 'tenant',
next: 'token'
}, {
cls: TokenNode,
id: 'token',
positiveNext: "openapi",
negativeNext: "stop",
}, {
cls: OpenapiNode,
id: 'openapi',
next: 'config'
}, {
cls: ConfigNode,
id: 'config',
next: 'device'
}, {
cls: DeviceNode,
id: 'device',
next: 'stop'
}, {
cls: StopNode,
id: 'stop'
}]
return [
{
cls: StartNode,
id: 'start',
next: 'entrance',
},
{
cls: EntranceNode,
id: 'entrance',
next: 'tenant',
},
{
cls: TenantNode,
id: 'tenant',
next: 'token',
},
{
cls: TokenNode,
id: 'token',
positiveNext: 'url',
negativeNext: 'stop',
},
{
cls: UrlNode,
id: 'url',
positiveNext: 'openapi',
negativeNext: 'stop',
},
{
cls: OpenapiNode,
id: 'openapi',
next: 'config',
},
{
cls: ConfigNode,
id: 'config',
next: 'device',
},
{
cls: DeviceNode,
id: 'device',
next: 'stop',
},
{
cls: StopNode,
id: 'stop',
},
]
}

createGraph() {
const g = new Graph()
g.nodes = this.createNodes()
return g
}
}
}
9 changes: 9 additions & 0 deletions src/flows/init/nodes/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IFNode } from 'arkfbp/lib/ifNode'
import { ConfigModule } from '@/store/modules/config'

export class UrlNode extends IFNode {
condition() {
const url = ConfigModule.origin
return url !== ''
}
}
32 changes: 32 additions & 0 deletions src/flows/url/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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 { UrlNode } from './nodes/url'

export class Main extends Flow {
createNodes() {
return [
{
cls: StartNode,
id: 'start',
next: 'url',
},
{
cls: UrlNode,
id: 'url',
next: 'stop',
},
{
cls: StopNode,
id: 'stop',
},
]
}

createGraph() {
const g = new Graph()
g.nodes = this.createNodes()
return g
}
}
12 changes: 12 additions & 0 deletions src/flows/url/nodes/url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { APINode } from '@/arkfbp/nodes/apiNode'

export class UrlNode extends APINode {
async run() {
this.url = '/api/v1/set_frontendurl/'
this.method = 'post'
this.params = this.inputs
super.run().then(() => {
window.location.reload()
})
}
}
1 change: 1 addition & 0 deletions src/login/components/LoginComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
center
:modal="false"
:fullscreen="fullscreen"
width="500px"
>
<div
class="content"
Expand Down
122 changes: 72 additions & 50 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,85 +8,107 @@ import { ConfigModule } from '@/store/modules/config'

/* Solve the problem of router repeatedly jumping to the same route */
const originalPush = Router.prototype.push
Router.prototype.push = function push (location: any) {
Router.prototype.push = function push(location: any) {
return (originalPush.call(this, location) as any).catch((err: any) => err)
}

Vue.use(Router)

const ROUTE_PATH = {
login: '/login',
third: '/third_part_callback',
url: '/url',
tenant: '/tenant',
desktop: '/desktop',
mine: '/mine',
home: '/',
}

export const menuRoutes: RouteConfig[] = [
{
path: '/login',
path: ROUTE_PATH.login,
component: () => import('@/login/Login.vue'),
meta: { hidden: true }
meta: { hidden: true },
},
{
path: '/third_part_callback',
path: ROUTE_PATH.third,
component: () => import('@/login/ThirdPartCallback.vue'),
meta: { hidden: true }
meta: { hidden: true },
},
{
path: '/tenant',
path: ROUTE_PATH.url,
component: () => import('@/views/Url.vue'),
meta: { hidden: true },
},
{
path: ROUTE_PATH.tenant,
component: () => import('@/views/Tenant.vue'),
meta: { hidden: true, page: 'tenant' }
meta: { hidden: true, page: 'tenant' },
},
...getDynamicRoutes()
...getDynamicRoutes(),
]

const createRouter = () => new Router({
mode: 'history',
scrollBehavior: (to, from, savedPosition) => {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
},
base: process.env.VUE_APP_BASE_API,
routes: [...menuRoutes]
})
const createRouter = () =>
new Router({
mode: 'history',
scrollBehavior: (to, from, savedPosition) => {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
},
base: process.env.VUE_APP_BASE_API,
routes: [...menuRoutes],
})

const router = createRouter()

router.beforeEach((to, from, next) => {
const isLogin = getToken()
const token = getToken()
const uuid = TenantModule.currentTenant.uuid
const role = UserModule.role
const isVisibleDesktop = ConfigModule.desktop.visible
const tenantSwitch = TenantModule.tenantSwitch
const isPlatformTenant = TenantModule.isPlatformTenant
const visible = ConfigModule.desktop.visible
const url = ConfigModule.origin
const sw = TenantModule.tenantSwitch
const platform = TenantModule.isPlatformTenant
let nextUrl = ''
const { query, path } = to
if (isLogin) {
if (query && query.next) {
nextUrl = ''
} else {
const t = isVisibleDesktop ? ( path === '/desktop' ? '' : '/desktop' ) : '/mine'
switch(path) {
case '/third_part_callback':
case '/desktop':
nextUrl = t
break
case '/tenant':
nextUrl = tenantSwitch === true ? (
role === UserRole.Platform || role !== UserRole.User ? '' : t
) : t
break
case '/login':
case '/':
nextUrl = ((role === UserRole.Platform || isPlatformTenant) && tenantSwitch === true) ? '/tenant' : t
break
default:
nextUrl = ''
}
if (token && url === '') {
nextUrl = path === ROUTE_PATH.url ? nextUrl : ROUTE_PATH.url
} else if (token && !query?.next) {
const target = visible
? path === ROUTE_PATH.desktop
? nextUrl
: ROUTE_PATH.desktop
: ROUTE_PATH.mine
switch (path) {
case ROUTE_PATH.desktop:
case ROUTE_PATH.third:
case ROUTE_PATH.url:
nextUrl = target
break
case ROUTE_PATH.tenant:
nextUrl = sw && role !== UserRole.User ? nextUrl : target
break
case ROUTE_PATH.login:
case ROUTE_PATH.home:
nextUrl =
sw && (role === UserRole.Platform || platform)
? ROUTE_PATH.tenant
: target
break
}
} else {
} else if (!token) {
if (uuid) query.tenant = uuid
if (path !== '/login' && path !== '/third_part_callback') {
nextUrl = '/login'
switch (path) {
case ROUTE_PATH.login:
case ROUTE_PATH.third:
break
default:
nextUrl = ROUTE_PATH.login
}
}

nextUrl === '' ? next() : next(nextUrl)
})

Expand Down
1 change: 1 addition & 0 deletions src/store/modules/tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ITenant {
slug?: string
icon?: string
created?: string
background_url?: string
}

@Module({ dynamic: true, store, name: 'tenant' })
Expand Down
Loading