mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:06:06 +00:00
fix: mobile auth (#5015)
* fix(T-5026): mobile auth * fix: bug * fix: plugin settings only have link type * fix: bug
This commit is contained in:
parent
7f2703ede2
commit
aa76b78da4
@ -54,7 +54,6 @@ export const SettingsCenterConfigure = () => {
|
|||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const settings = app.pluginSettingsManager.getList(false);
|
const settings = app.pluginSettingsManager.getList(false);
|
||||||
console.log(settings);
|
|
||||||
const allAclSnippets = app.pluginSettingsManager.getAclSnippets();
|
const allAclSnippets = app.pluginSettingsManager.getAclSnippets();
|
||||||
const [snippets, setSnippets] = useState<string[]>([]);
|
const [snippets, setSnippets] = useState<string[]>([]);
|
||||||
const allChecked = useMemo(
|
const allChecked = useMemo(
|
||||||
|
@ -33,6 +33,7 @@ export interface PluginSettingOptions {
|
|||||||
sort?: number;
|
sort?: number;
|
||||||
aclSnippet?: string;
|
aclSnippet?: string;
|
||||||
link?: string;
|
link?: string;
|
||||||
|
isTopLevel?: boolean;
|
||||||
[index: string]: any;
|
[index: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,6 +148,7 @@ export class PluginSettingsManager {
|
|||||||
.sort((a, b) => (a.sort || 0) - (b.sort || 0));
|
.sort((a, b) => (a.sort || 0) - (b.sort || 0));
|
||||||
const { title, icon, aclSnippet, ...others } = pluginSetting;
|
const { title, icon, aclSnippet, ...others } = pluginSetting;
|
||||||
return {
|
return {
|
||||||
|
isTopLevel: name === pluginSetting.topLevelName,
|
||||||
...others,
|
...others,
|
||||||
aclSnippet: this.getAclSnippet(name),
|
aclSnippet: this.getAclSnippet(name),
|
||||||
title,
|
title,
|
||||||
|
@ -81,11 +81,24 @@ export const AdminSettingsLayout = () => {
|
|||||||
if (!settings || !settings.length) {
|
if (!settings || !settings.length) {
|
||||||
return '/admin';
|
return '/admin';
|
||||||
}
|
}
|
||||||
const first = settings[0];
|
|
||||||
if (first.children?.length) {
|
if (settings.filter((item) => item.isTopLevel).length === 1) {
|
||||||
return getFirstDeepChildPath(first.children);
|
// 如果是外链类型的,需要跳转外链,如果是内页则返回内页 path
|
||||||
|
const pluginSetting = settings.find((item) => item.isTopLevel);
|
||||||
|
// 如果仅有 1 个,且是外链类型的,跳转到 /admin
|
||||||
|
// @see https://nocobase.height.app/inbox/T-5038
|
||||||
|
return pluginSetting.link ? '/admin' : pluginSetting.path;
|
||||||
}
|
}
|
||||||
return first.path;
|
|
||||||
|
function find(settings: PluginSettingsPageType[]) {
|
||||||
|
const first = settings.find((item) => !item.link); // 找到第一个非外链类型的
|
||||||
|
if (first.children?.length) {
|
||||||
|
return getFirstDeepChildPath(first.children);
|
||||||
|
}
|
||||||
|
return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return find(settings).path;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const settingsMapByPath = useMemo<Record<string, PluginSettingsPageType>>(() => {
|
const settingsMapByPath = useMemo<Record<string, PluginSettingsPageType>>(() => {
|
||||||
@ -120,6 +133,12 @@ export const AdminSettingsLayout = () => {
|
|||||||
if (location.pathname === currentTopLevelSetting.path && currentTopLevelSetting.children?.length > 0) {
|
if (location.pathname === currentTopLevelSetting.path && currentTopLevelSetting.children?.length > 0) {
|
||||||
return <Navigate replace to={getFirstDeepChildPath(currentTopLevelSetting.children)} />;
|
return <Navigate replace to={getFirstDeepChildPath(currentTopLevelSetting.children)} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果是外链类型的,需要跳转并返回到上一个页面
|
||||||
|
if (currentSetting.link) {
|
||||||
|
return <Navigate replace to={currentSetting.link} />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Layout>
|
<Layout>
|
||||||
|
@ -10,13 +10,14 @@
|
|||||||
import React, { FC, useCallback } from 'react';
|
import React, { FC, useCallback } from 'react';
|
||||||
import { SafeArea } from 'antd-mobile';
|
import { SafeArea } from 'antd-mobile';
|
||||||
import 'antd-mobile/es/components/tab-bar/tab-bar.css';
|
import 'antd-mobile/es/components/tab-bar/tab-bar.css';
|
||||||
|
import { Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { useStyles } from './styles';
|
import { useStyles } from './styles';
|
||||||
import { useMobileRoutes } from '../../mobile-providers';
|
import { useMobileRoutes } from '../../mobile-providers';
|
||||||
|
|
||||||
import { getMobileTabBarItemSchema, MobileTabBarItem } from './MobileTabBar.Item';
|
import { getMobileTabBarItemSchema, MobileTabBarItem } from './MobileTabBar.Item';
|
||||||
import { MobileTabBarPage, MobileTabBarLink } from './types';
|
import { MobileTabBarPage, MobileTabBarLink } from './types';
|
||||||
import { cx, DndContext, DndContextProps, SchemaComponent, useDesignable, css } from '@nocobase/client';
|
import { cx, DndContext, DndContextProps, SchemaComponent, useDesignable, css, useApp } from '@nocobase/client';
|
||||||
import { MobileTabBarInitializer } from './initializer';
|
import { MobileTabBarInitializer } from './initializer';
|
||||||
import { isInnerLink } from '../../utils';
|
import { isInnerLink } from '../../utils';
|
||||||
|
|
||||||
@ -32,6 +33,8 @@ export const MobileTabBar: FC<MobileTabBarProps> & {
|
|||||||
Page: typeof MobileTabBarPage;
|
Page: typeof MobileTabBarPage;
|
||||||
Link: typeof MobileTabBarLink;
|
Link: typeof MobileTabBarLink;
|
||||||
} = ({ enableTabBar = true }) => {
|
} = ({ enableTabBar = true }) => {
|
||||||
|
const app = useApp();
|
||||||
|
const hasAuth = app.pluginSettingsManager.hasAuth('mobile');
|
||||||
const { styles } = useStyles();
|
const { styles } = useStyles();
|
||||||
const { designable } = useDesignable();
|
const { designable } = useDesignable();
|
||||||
const { routeList, activeTabBarItem, resource, refresh } = useMobileRoutes();
|
const { routeList, activeTabBarItem, resource, refresh } = useMobileRoutes();
|
||||||
@ -53,6 +56,10 @@ export const MobileTabBar: FC<MobileTabBarProps> & {
|
|||||||
[resource, refresh],
|
[resource, refresh],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!hasAuth) {
|
||||||
|
return <Navigate to="/admin" />;
|
||||||
|
}
|
||||||
|
|
||||||
if (!enableTabBar) {
|
if (!enableTabBar) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
import { defineCollection } from '@nocobase/database';
|
import { defineCollection } from '@nocobase/database';
|
||||||
|
|
||||||
export default defineCollection({
|
export default defineCollection({
|
||||||
key: 'd1za29o7irk',
|
|
||||||
name: 'mobileRoutes',
|
name: 'mobileRoutes',
|
||||||
|
dumpRules: 'required',
|
||||||
title: 'mobileRoutes',
|
title: 'mobileRoutes',
|
||||||
inherit: false,
|
inherit: false,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
|
@ -10,19 +10,12 @@
|
|||||||
import { Plugin } from '@nocobase/server';
|
import { Plugin } from '@nocobase/server';
|
||||||
|
|
||||||
export class PluginMobileServer extends Plugin {
|
export class PluginMobileServer extends Plugin {
|
||||||
async afterAdd() {}
|
async load() {
|
||||||
|
this.app.acl.registerSnippet({
|
||||||
async beforeLoad() {}
|
name: `pm.${this.name}`,
|
||||||
|
actions: ['mobileRoutes:*'],
|
||||||
async load() {}
|
});
|
||||||
|
}
|
||||||
async install() {}
|
|
||||||
|
|
||||||
async afterEnable() {}
|
|
||||||
|
|
||||||
async afterDisable() {}
|
|
||||||
|
|
||||||
async remove() {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PluginMobileServer;
|
export default PluginMobileServer;
|
||||||
|
Loading…
Reference in New Issue
Block a user