You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.9 KiB
JavaScript
110 lines
3.9 KiB
JavaScript
import React from 'react'
|
|
import ReactDOM from 'react-dom/client'
|
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
|
|
import { ThemeContext } from '@/stores/ThemeContext'
|
|
import AuthApp from '@/views/AuthApp'
|
|
import DesktopApp from '@/views/DesktopApp'
|
|
import MobileApp from '@/views/MobileApp'
|
|
import Standlone from '@/views/Standlone'
|
|
import OrderFollow from '@/views/orders/Follow'
|
|
import ChatHistory from '@/views/ChatHistory'
|
|
import SalesManagement from '@/views/SalesManagement'
|
|
import DingdingCallback from '@/views/dingding/Callback'
|
|
import DingdingLogout from '@/views/dingding/Logout'
|
|
import AccountProfile from '@/views/accounts/Profile'
|
|
import ErrorPage from '@/components/ErrorPage'
|
|
import Conversations from '@/views/Conversations/ChatWindow'
|
|
import MobileConversation from '@/views/mobile/Conversation'
|
|
import MobileChat from '@/views/mobile/Chat'
|
|
import DingdingLogin from '@/views/dingding/Login'
|
|
import useAuthStore from '@/stores/AuthStore'
|
|
import '@/assets/index.css'
|
|
|
|
useAuthStore.getState().loadUserSession()
|
|
|
|
const isMobileApp = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i) !== null;
|
|
|
|
const router = createBrowserRouter([
|
|
{
|
|
path: '/',
|
|
element: <AuthApp />,
|
|
errorElement: <ErrorPage />,
|
|
children: isMobileApp
|
|
? [
|
|
{
|
|
element: <MobileApp />,
|
|
children: [
|
|
{ index: true, element: <MobileConversation /> },
|
|
{ path: 'm/conversation', element: <MobileConversation /> },
|
|
],
|
|
},
|
|
{ path: 'm/chat/:order_sn', element: <MobileChat /> },
|
|
{ path: 'm/chat', element: <MobileChat /> },
|
|
]
|
|
: [
|
|
{
|
|
element: <DesktopApp />,
|
|
children: [
|
|
{ index: true, element: <OrderFollow /> },
|
|
{ path: 'order/follow', element: <OrderFollow /> },
|
|
{ path: 'chat/history', element: <ChatHistory /> },
|
|
{ path: 'sales/management', element: <SalesManagement /> },
|
|
{ path: 'order/chat/:order_sn', element: <Conversations /> },
|
|
{ path: 'order/chat', element: <Conversations /> },
|
|
{ path: 'account/profile', element: <AccountProfile /> },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '/p',
|
|
element: <Standlone />,
|
|
children: [
|
|
{ path: 'dingding/login', element: <DingdingLogin /> },
|
|
{ path: 'dingding/logout', element: <DingdingLogout /> },
|
|
{ path: 'dingding/callback', element: <DingdingCallback /> },
|
|
],
|
|
},
|
|
]);
|
|
|
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
// <React.StrictMode>
|
|
<ThemeContext.Provider value={{ colorPrimary: '#1ba784', borderRadius: 4 }}>
|
|
<RouterProvider router={router} fallbackElement={() => <div>Loading...</div>} />
|
|
</ThemeContext.Provider>
|
|
// </React.StrictMode>
|
|
);
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
const wb = import.meta.env.VITE_SERVICE_WORKER_ENTRY;
|
|
console.log('if service worker', wb);
|
|
window.addEventListener('load', () => {
|
|
console.log('listen load');
|
|
navigator.serviceWorker.register('/service-worker.js').then(
|
|
(registration) => {
|
|
console.log('Service Worker registered:', registration);
|
|
},
|
|
(error) => {
|
|
console.error('Service Worker registration failed:', error);
|
|
}, () => {
|
|
console.log('final');
|
|
}
|
|
);
|
|
|
|
// navigator.serviceWorker.register(wb).then(
|
|
// (registration) => {
|
|
// console.log('vite-plugin-pwa Service Worker registered:', registration);
|
|
// },
|
|
// (error) => {
|
|
// console.error('vite-plugin-pwa Service Worker registration failed:', error);
|
|
// }
|
|
// );
|
|
});
|
|
|
|
|
|
// Listen for messages from the service worker
|
|
navigator.serviceWorker.addEventListener('message', function(event) {
|
|
console.log('Received message from service worker:', event.data);
|
|
});
|
|
}
|