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