2023-07-07 14:35:22 +08:00
|
|
|
import { createRouterManager, Plugin, RouterManager, RouteSchemaComponent } from '@nocobase/client';
|
2023-06-08 19:54:00 +08:00
|
|
|
import React from 'react';
|
2023-11-13 11:01:18 +08:00
|
|
|
import { Navigate, Outlet } from 'react-router-dom';
|
2023-07-07 14:35:22 +08:00
|
|
|
import { MobileClientProvider } from './MobileClientProvider';
|
|
|
|
import MApplication from './router/Application';
|
2024-05-06 18:50:49 +08:00
|
|
|
import {
|
|
|
|
ImageSearchConfigureFields,
|
|
|
|
ImageSearchItemFieldSettings,
|
|
|
|
mBlockInitializers,
|
|
|
|
mBlockInitializers_deprecated,
|
|
|
|
TabSearchFieldSchemaInitializer,
|
|
|
|
} from './core/schema';
|
2023-11-13 11:01:18 +08:00
|
|
|
import { AppConfiguration, InterfaceConfiguration } from './configuration';
|
|
|
|
import { NAMESPACE } from './locale';
|
2023-06-08 19:54:00 +08:00
|
|
|
|
2023-07-07 14:35:22 +08:00
|
|
|
export class MobileClientPlugin extends Plugin {
|
|
|
|
public mobileRouter: RouterManager;
|
|
|
|
async load() {
|
|
|
|
this.setMobileRouter();
|
|
|
|
this.addRoutes();
|
2023-11-13 11:01:18 +08:00
|
|
|
this.addSettings();
|
2023-07-07 14:35:22 +08:00
|
|
|
this.app.use(MobileClientProvider);
|
2024-03-14 14:13:11 +08:00
|
|
|
this.app.schemaInitializerManager.add(mBlockInitializers_deprecated);
|
2023-12-04 14:56:46 +08:00
|
|
|
this.app.schemaInitializerManager.add(mBlockInitializers);
|
2024-05-06 18:50:49 +08:00
|
|
|
this.app.schemaInitializerManager.add(ImageSearchConfigureFields);
|
|
|
|
this.app.schemaSettingsManager.add(ImageSearchItemFieldSettings);
|
|
|
|
this.app.schemaInitializerManager.add(TabSearchFieldSchemaInitializer);
|
2023-07-07 14:35:22 +08:00
|
|
|
}
|
2023-06-08 19:54:00 +08:00
|
|
|
|
2023-11-13 11:01:18 +08:00
|
|
|
addSettings() {
|
|
|
|
this.app.pluginSettingsManager.add(NAMESPACE, {
|
|
|
|
title: `{{t("Mobile Client-side", { ns: "${NAMESPACE}" })}}`,
|
|
|
|
icon: 'MobileOutlined',
|
|
|
|
Component: () => <Outlet />,
|
|
|
|
});
|
|
|
|
this.app.pluginSettingsManager.add(`${NAMESPACE}.interface`, {
|
|
|
|
title: `{{t("Interface Configuration", { ns: "${NAMESPACE}" })}}`,
|
|
|
|
Component: InterfaceConfiguration,
|
|
|
|
sort: 1,
|
|
|
|
});
|
|
|
|
this.app.pluginSettingsManager.add(`${NAMESPACE}.app`, {
|
|
|
|
title: `{{t("App Configuration", { ns: "${NAMESPACE}" })}}`,
|
|
|
|
Component: AppConfiguration,
|
|
|
|
sort: 2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-07 14:35:22 +08:00
|
|
|
setMobileRouter() {
|
2024-03-03 23:06:24 +08:00
|
|
|
const router = createRouterManager({ type: 'hash' }, this.app);
|
2023-07-07 14:35:22 +08:00
|
|
|
router.add('root', {
|
|
|
|
path: '/',
|
|
|
|
element: <Navigate replace to="/mobile" />,
|
|
|
|
});
|
|
|
|
router.add('mobile', {
|
|
|
|
path: '/mobile',
|
|
|
|
element: <MApplication />,
|
|
|
|
});
|
|
|
|
router.add('mobile.page', {
|
|
|
|
path: '/mobile/:name',
|
|
|
|
element: <RouteSchemaComponent />,
|
|
|
|
});
|
|
|
|
this.mobileRouter = router;
|
|
|
|
}
|
|
|
|
|
|
|
|
getMobileRouterComponent() {
|
|
|
|
return this.mobileRouter.getRouterComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
addRoutes() {
|
|
|
|
this.app.router.add('mobile', {
|
|
|
|
path: '/mobile',
|
|
|
|
element: <MApplication />,
|
|
|
|
});
|
|
|
|
this.app.router.add('mobile.page', {
|
|
|
|
path: '/mobile/:name',
|
|
|
|
Component: 'RouteSchemaComponent',
|
|
|
|
});
|
2024-05-06 18:50:49 +08:00
|
|
|
this.app.router.add('mobile.swiper.page', {
|
|
|
|
path: '/mobile/:name/image/:collection/:field/:fieldParams',
|
|
|
|
Component: 'SwiperPage',
|
|
|
|
});
|
2023-07-07 14:35:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MobileClientPlugin;
|