Commit 614cc922 authored by cwuyiqing's avatar cwuyiqing
Browse files

feat: support redirect by project customId

Showing with 57 additions and 15 deletions
+57 -15
......@@ -110,6 +110,8 @@ CloudBase CMS 是云开发推出的,基于 Node.js 的 Headless 内容管理
| 功能 | 状态 | 发布版本 |
| ------------------------------------------------ | --------- | -------- |
| 字段禁止编辑 | 👷 进行中 | |
| 地图组件 | 👷 进行中 | |
| 支持以微前端的模式嵌入系统 | 🏹 设计中 | |
| 提供项目模板,支持从模板创建项目 | 🏹 设计中 | |
| 支持操作记录 | 🏹 设计中 | |
......
......@@ -33,6 +33,11 @@ const routesConfig: IConfig = {
exact: true,
redirect: '/home',
},
{
path: '/redirect',
exact: true,
component: './redirect',
},
{
component: '../layout/index',
layout: false,
......
......@@ -72,7 +72,6 @@ export async function getInitialState(): Promise<{
if (currentUser?._id && window.parent !== window.self) {
window.parent.postMessage(
JSON.stringify({
ack: 2,
from: 'cms',
status: 'success',
}),
......
......@@ -4,22 +4,34 @@ import { history, useRequest } from 'umi'
import { getCollectionInfo } from '@/services/common'
export default () => {
const { collectionName, from } = history.location.query || {}
const { collectionName, from, customId } = history.location.query || {}
// 不存在 projectCustomId
if (!collectionName || !from) {
return history.push('/home')
if (!customId || !from) {
history.push('/home')
return ''
}
// 获取项目信息
const { data: schema } = useRequest<{ data: Schema }>(() => getCollectionInfo(collectionName))
// 获取项目、模型信息
const { data } = useRequest<{
data: {
schema: Schema
project: Project
}
}>(() => getCollectionInfo(customId, collectionName))
useEffect(() => {
if (!data) return
const { schema, project } = data
// 跳转到对应的集合管理页面
if (schema?._id) {
history.push(`/${schema.projectId}/content/${schema._id}`)
history.push(`/${project._id}/content/${schema._id}`)
} else if (project) {
history.push(`/${project._id}/home`)
} else {
history.push('/home')
}
}, [schema])
}, [data])
return (
<div className="flex items-center justify-center h-full">
......
import { tcbRequest } from '@/utils'
export const getCollectionInfo = async (collectionName: string) => {
export const getCollectionInfo = async (customId: string, collectionName: string) => {
return tcbRequest('/collectionInfo', {
method: 'POST',
data: {
customId,
collectionName,
},
})
......
import { Body, Controller, Get, Post } from '@nestjs/common'
import { AppService } from './app.service'
import { RecordNotExistException } from './common'
import { Collection } from './constants'
import { CloudBaseService } from './services'
import { getCollectionSchema } from './utils'
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
constructor(
private readonly appService: AppService,
private readonly cloudbaseService: CloudBaseService
) {}
@Get()
async getHello(): Promise<string> {
......@@ -15,15 +20,33 @@ export class AppController {
// 根据 collectionName 查询 collection 信息
@Post('collectionInfo')
async getCollectionInfo(@Body() body) {
const { collectionName } = body
const schema = await getCollectionSchema(collectionName)
const { collectionName, customId } = body
if (!schema) {
throw new RecordNotExistException('数据集合不存在')
// 查询项目信息
const {
data: [project],
} = await this.cloudbaseService
.collection(Collection.Projects)
.where({
customId,
})
.get()
let schema
// 如果有 collectionName,也查询集合信息
if (collectionName) {
schema = await getCollectionSchema(collectionName)
if (!schema) {
throw new RecordNotExistException('数据集合不存在')
}
}
return {
data: schema,
data: {
project,
schema,
},
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment