mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-21 10:53:33 +08:00
feat(startup): redesign the workspace loading screen
This commit is contained in:
parent
15087f503e
commit
bb925eea6c
@ -6,121 +6,154 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title><%= siteInfo.title %></title>
|
||||
<meta name="description" content="<%= siteInfo.description %>" />
|
||||
<meta name="color-scheme" content="light dark" />
|
||||
<script>
|
||||
try {
|
||||
const settings = JSON.parse(
|
||||
localStorage.getItem('<%= storageKeys.appPiniaSettingStore %>') ||
|
||||
'null',
|
||||
)
|
||||
const mode = settings?.appTheme
|
||||
if (mode !== 'auto') {
|
||||
const dark =
|
||||
mode === 'dark' || (mode == null && settings?._appTheme === true)
|
||||
document.documentElement.classList.add(
|
||||
dark ? 'r-template--dark' : 'r-template--light',
|
||||
)
|
||||
}
|
||||
} catch {}
|
||||
try {
|
||||
if (
|
||||
localStorage.getItem('<%= storageKeys.localeLanguage %>') ===
|
||||
'"en-US"'
|
||||
) {
|
||||
document.documentElement.lang = 'en-US'
|
||||
}
|
||||
} catch {}
|
||||
</script>
|
||||
<style>
|
||||
:root {
|
||||
--preloading-tag-color: <%= preloadingConfig.tagColor %>;
|
||||
--preloading-title-color: <%= preloadingConfig.titleColor %>;
|
||||
--r-theme-primary-fade-color: <%= appPrimaryColor.primaryFadeColor %>;
|
||||
--r-theme-primary-color: <%= appPrimaryColor.primaryColor %>;
|
||||
--global-loading-bg-color: #ffffff;
|
||||
html.r-template--dark {
|
||||
color-scheme: dark;
|
||||
}
|
||||
html.r-template--light {
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
#pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
}
|
||||
|
||||
html.dark #pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
|
||||
html.light #pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
|
||||
#pre-loading-animation {
|
||||
.ray-boot {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
color: var(--preloading-title-color);
|
||||
z-index: 1;
|
||||
inset: 0;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 24px;
|
||||
color: CanvasText;
|
||||
color: light-dark(#182436, #e9eef7);
|
||||
background: Canvas;
|
||||
background: light-dark(#f8f9fc, #141b27);
|
||||
font:
|
||||
400 14px / 1.5 system-ui,
|
||||
sans-serif;
|
||||
text-align: center;
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
|
||||
#pre-loading-animation .pre-loading-animation__wrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
.ray-boot__mark {
|
||||
display: block;
|
||||
margin: 0 auto 16px;
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
#pre-loading-animation
|
||||
.pre-loading-animation__wrapper
|
||||
.pre-loading-animation__wrapper-title {
|
||||
font-size: 32px;
|
||||
padding-bottom: 48px;
|
||||
font-weight: 500;
|
||||
.ray-boot__title {
|
||||
display: block;
|
||||
font-size: 24px;
|
||||
font-weight: 650;
|
||||
letter-spacing: -0.025em;
|
||||
}
|
||||
|
||||
.pre-loading-animation__wrapper-loading {
|
||||
.ray-boot__label {
|
||||
margin: 4px 0 0;
|
||||
color: inherit;
|
||||
color: light-dark(#52647c, #b3c0d3);
|
||||
}
|
||||
|
||||
.ray-boot__track {
|
||||
display: block;
|
||||
position: relative;
|
||||
width: 6px;
|
||||
height: 10px;
|
||||
|
||||
animation: rectangle infinite 1s ease-in-out -0.2s;
|
||||
|
||||
background-color: var(--preloading-tag-color);
|
||||
overflow: hidden;
|
||||
inline-size: 112px;
|
||||
block-size: 3px;
|
||||
margin: 20px auto 0;
|
||||
border-radius: 4px;
|
||||
background: currentColor;
|
||||
background: light-dark(#dce4f2, #36435c);
|
||||
}
|
||||
|
||||
.pre-loading-animation__wrapper-loading:before,
|
||||
.pre-loading-animation__wrapper-loading:after {
|
||||
.ray-boot__track::after {
|
||||
position: absolute;
|
||||
width: 6px;
|
||||
height: 10px;
|
||||
inset-block: 0;
|
||||
inset-inline-start: 0;
|
||||
inline-size: 40%;
|
||||
border-radius: inherit;
|
||||
background: Highlight;
|
||||
background: light-dark(#3b63d9, #aabaff);
|
||||
animation: ray-boot-sweep 1.45s ease-in-out infinite alternate;
|
||||
content: '';
|
||||
background-color: var(--preloading-tag-color);
|
||||
}
|
||||
|
||||
.pre-loading-animation__wrapper-loading:before {
|
||||
left: -14px;
|
||||
|
||||
animation: rectangle infinite 1s ease-in-out -0.4s;
|
||||
}
|
||||
|
||||
.pre-loading-animation__wrapper-loading:after {
|
||||
right: -14px;
|
||||
|
||||
animation: rectangle infinite 1s ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes rectangle {
|
||||
0%,
|
||||
80%,
|
||||
100% {
|
||||
height: 20px;
|
||||
box-shadow: 0 0 var(--preloading-tag-color);
|
||||
@keyframes ray-boot-sweep {
|
||||
from {
|
||||
transform: translateX(0);
|
||||
}
|
||||
to {
|
||||
transform: translateX(150%);
|
||||
}
|
||||
}
|
||||
|
||||
40% {
|
||||
height: 30px;
|
||||
box-shadow: 0 -20px var(--preloading-tag-color);
|
||||
.ray-boot progress {
|
||||
position: absolute;
|
||||
inline-size: 1px;
|
||||
block-size: 1px;
|
||||
clip-path: inset(50%);
|
||||
}
|
||||
|
||||
.ray-boot__failure,
|
||||
.ray-boot [lang='en-US'] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
html:lang(en) .ray-boot [lang='zh-CN'] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
html:lang(en) .ray-boot [lang='en-US'] {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.ray-boot[data-state='failed'] .ray-boot__pending {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ray-boot[data-state='failed'] .ray-boot__failure {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ray-boot__retry {
|
||||
margin-block-start: 12px;
|
||||
padding: 5px 12px;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.ray-boot__track::after {
|
||||
animation: none;
|
||||
transform: translateX(75%);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
;(function () {
|
||||
const html = document.documentElement
|
||||
const store = window.localStorage.getItem('piniaSettingStore')
|
||||
const { _appTheme = false } = store ? JSON.parse(store) : {}
|
||||
const loadingBgColor = _appTheme ? '#1c1e23' : '#ffffff'
|
||||
|
||||
html.classList.add(_appTheme ? 'dark' : 'light')
|
||||
html.style.setProperty('--global-loading-bg-color', loadingBgColor)
|
||||
html.style.setProperty('background-color', loadingBgColor)
|
||||
})()
|
||||
</script>
|
||||
<noscript>
|
||||
<style>
|
||||
#pre-loading-animation {
|
||||
@ -145,12 +178,38 @@
|
||||
</p>
|
||||
</main>
|
||||
</noscript>
|
||||
<div id="pre-loading-animation">
|
||||
<div class="pre-loading-animation__wrapper">
|
||||
<div class="pre-loading-animation__wrapper-title">
|
||||
<%= preloadingConfig.title %>
|
||||
<div id="pre-loading-animation" class="ray-boot">
|
||||
<div>
|
||||
<img
|
||||
class="ray-boot__mark"
|
||||
src="/ray.svg"
|
||||
width="56"
|
||||
height="56"
|
||||
alt=""
|
||||
/>
|
||||
<strong class="ray-boot__title"><%= preloadingConfig.title %></strong>
|
||||
<div class="ray-boot__pending">
|
||||
<p class="ray-boot__label" id="ray-boot-label">
|
||||
<span lang="zh-CN">正在载入工作区</span>
|
||||
<span lang="en-US">Loading your workspace</span>
|
||||
</p>
|
||||
<progress aria-labelledby="ray-boot-label"></progress>
|
||||
<span class="ray-boot__track" aria-hidden="true"></span>
|
||||
</div>
|
||||
<div class="ray-boot__failure" role="alert">
|
||||
<p class="ray-boot__label">
|
||||
<span lang="zh-CN">工作区未能启动</span>
|
||||
<span lang="en-US">The workspace could not start</span>
|
||||
</p>
|
||||
<button
|
||||
class="ray-boot__retry"
|
||||
type="button"
|
||||
onclick="location.reload()"
|
||||
>
|
||||
<span lang="zh-CN">重新加载</span>
|
||||
<span lang="en-US">Reload</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="pre-loading-animation__wrapper-loading"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
|
||||
@ -33,12 +33,6 @@ export default defineComponent({
|
||||
html.style.setProperty(htmlWidth, `${width.value}px`)
|
||||
})
|
||||
|
||||
const splash = document.getElementById(
|
||||
GLOBAL_CLASS_NAMES.preLoadingAnimation,
|
||||
)
|
||||
|
||||
if (splash) splash.style.display = 'none'
|
||||
|
||||
return () => null
|
||||
},
|
||||
})
|
||||
|
||||
@ -51,11 +51,9 @@ export const LAYOUT_CONTENT_SPIN_WHEN_ROUTE_CHANGE = false
|
||||
*/
|
||||
export const APP_GLOBAL_LOADING = 'loading'
|
||||
|
||||
/** 首屏加载动画显示的标题和颜色。 */
|
||||
/** 首屏加载界面的品牌标题。 */
|
||||
export const PRE_LOADING_CONFIG: PreloadingConfig = {
|
||||
title: 'Ray Admin',
|
||||
tagColor: '#ff6700',
|
||||
titleColor: '#2d8cf0',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -3,12 +3,21 @@ import './styles/entry'
|
||||
import type { App as AppType } from 'vue'
|
||||
import { setupRayTemplateCore } from './__ray-template'
|
||||
import { installAutocompleteDefaults } from './app-components/provider/AppAutocompleteDefaults'
|
||||
import { GLOBAL_CLASS_NAMES } from './app-config'
|
||||
import { setupDayjs } from './dayjs'
|
||||
import { setupDirectives } from './directives'
|
||||
import { setupI18n } from './locales'
|
||||
import { setupRouter } from './router'
|
||||
import { setupStore } from './store'
|
||||
|
||||
const bootSplash = () =>
|
||||
document.getElementById(GLOBAL_CLASS_NAMES.preLoadingAnimation)
|
||||
|
||||
const showBootError = (error: unknown) => {
|
||||
console.error('[Ray Admin] Startup failed.', error)
|
||||
bootSplash()?.setAttribute('data-state', 'failed')
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inst vue instance
|
||||
@ -37,6 +46,7 @@ const setupTemplate = async () => {
|
||||
|
||||
await setupPlugins(app)
|
||||
app.mount('#app')
|
||||
bootSplash()?.remove()
|
||||
await setupRayTemplateCore()
|
||||
}
|
||||
|
||||
@ -53,9 +63,15 @@ const setupWujieTemplate = async () => {
|
||||
window.__WUJIE_MOUNT = async () => {
|
||||
instance = createApp(App)
|
||||
|
||||
await setupPlugins(instance)
|
||||
instance.mount('#app')
|
||||
await setupRayTemplateCore()
|
||||
try {
|
||||
await setupPlugins(instance)
|
||||
instance.mount('#app')
|
||||
bootSplash()?.remove()
|
||||
await setupRayTemplateCore()
|
||||
} catch (error) {
|
||||
showBootError(error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
window.__WUJIE_UNMOUNT = () => {
|
||||
@ -82,4 +98,6 @@ const setupWujieTemplate = async () => {
|
||||
* setupTemplate()
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
window.__POWERED_BY_WUJIE__ ? setupWujieTemplate() : setupTemplate()
|
||||
void (
|
||||
window.__POWERED_BY_WUJIE__ ? setupWujieTemplate() : setupTemplate()
|
||||
).catch(showBootError)
|
||||
|
||||
@ -25,8 +25,6 @@ export interface RootRoute {
|
||||
|
||||
export interface PreloadingConfig {
|
||||
title?: string
|
||||
tagColor?: string
|
||||
titleColor?: string
|
||||
}
|
||||
|
||||
export interface AppPrimaryColor {
|
||||
|
||||
@ -15,7 +15,7 @@ const config: AppConfigExport = {
|
||||
// 配置首屏加载信息
|
||||
preloadingConfig: PRE_LOADING_CONFIG,
|
||||
|
||||
// 默认主题色(不可省略,必填),也用于 ejs 注入
|
||||
// 默认品牌色(用于构建配置)
|
||||
appPrimaryColor: APP_THEME.appPrimaryColor,
|
||||
|
||||
/**
|
||||
|
||||
@ -16,6 +16,7 @@ import { ViteEjsPlugin as viteEjsPlugin } from 'vite-plugin-ejs'
|
||||
import viteInspect from 'vite-plugin-inspect'
|
||||
import { mockDevServerPlugin } from 'vite-plugin-mock-dev-server'
|
||||
import viteSvgLoader from 'vite-svg-loader'
|
||||
import { APP_CATCH_KEY } from './apps/admin/src/app-config/app-config.ts'
|
||||
import { iconNameFromPath, iconsRoot, scanIcons } from './scripts/icons.mjs'
|
||||
import { iconManifestPlugin } from './vite-helper/icons.ts'
|
||||
import { cdnResolve } from './vite-helper/index.ts'
|
||||
@ -159,7 +160,7 @@ function vueTransformPlugins(): PluginOption[] {
|
||||
|
||||
// 基础插件配置
|
||||
function baseOptions(mode: string): PluginOption[] {
|
||||
const { appPrimaryColor, preloadingConfig } = config
|
||||
const { preloadingConfig } = config
|
||||
const iconPackages = [
|
||||
...new Set(scanIcons().map((name) => name.split('/')[0])),
|
||||
]
|
||||
@ -183,7 +184,7 @@ function baseOptions(mode: string): PluginOption[] {
|
||||
|
||||
viteEjsPlugin({
|
||||
preloadingConfig,
|
||||
appPrimaryColor,
|
||||
storageKeys: APP_CATCH_KEY,
|
||||
siteInfo,
|
||||
}),
|
||||
// 仅适用于开发模式(检查 `Vite` 插件的中间状态)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user