Skip to content

Commit

Permalink
feat: 管理后台统一至vite
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Oct 24, 2023
1 parent a62da4f commit cabca43
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 100 deletions.
16 changes: 0 additions & 16 deletions client/src/entries/entry-admin-login.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/admin/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<router-view />
</div>
</template>
2 changes: 1 addition & 1 deletion packages/admin/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Element from 'element-plus'
import 'element-plus/dist/index.css'
import 'font-awesome/scss/font-awesome.scss'
import VueFetch from 'vue-fetch'
import App from './pages/index.vue'
import App from './App.vue'
import router from './router'

export const app = createApp(App)
Expand Down
14 changes: 8 additions & 6 deletions packages/admin/src/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
</div>
</template>

<script>
export default {
<script lang="ts">
import {ElMessageBox} from 'element-plus'
import {defineComponent} from 'vue'
export default defineComponent({
name: 'FreyjaAdminLogin',
data() {
return {
Expand All @@ -54,16 +57,15 @@ export default {
this.loginForm,
)
if (res.status === 200) {
location.href = '/admin/home'
await this.$router.push({name: 'dashboard'})
} else {
this.$message({
message: '用户名或密码错误',
await ElMessageBox.alert('用户名或密码错误', 'Freyja', {
type: 'error',
})
}
},
},
}
})
</script>

<style lang="scss" scoped>
Expand Down
17 changes: 15 additions & 2 deletions packages/admin/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*/

'use strict'
import {createRouter, createWebHistory} from 'vue-router'
import {createRouter, createWebHistory, RouteRecordRaw} from 'vue-router'

const routes = [
const AdminRoutes: RouteRecordRaw[] = [
{
path: '/home',
component: import('./pages/dashboard.vue'),
Expand Down Expand Up @@ -63,6 +63,19 @@ const routes = [
},
]

const routes: RouteRecordRaw[] = [
{
path: '/',
redirect: '/home',
component: import('./pages/index.vue'),
children: AdminRoutes,
},
{
path: '/login',
component: import('./pages/login.vue'),
},
]

export default createRouter({
history: createWebHistory('/admin'),
routes,
Expand Down
1 change: 1 addition & 0 deletions packages/admin/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export default defineConfig({
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
base: '/admin/',
})
3 changes: 1 addition & 2 deletions src/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import ora from 'ora'
import webpack from 'webpack'
import webpackAdminConfig from '../webpack/webpack.admin'
import webpackClientConfig from '../webpack/webpack.conf'
import webpackServerConfig from '../webpack/webpack.server'

Expand All @@ -19,7 +18,7 @@ console.log(' Tip:\n'
const spinner = ora('building for production...')
spinner.start()

webpack([webpackClientConfig, webpackServerConfig, webpackAdminConfig], (err, stats) => {
webpack([webpackClientConfig, webpackServerConfig], (err, stats) => {
spinner.stop()
if (err) {
console.log(err)
Expand Down
5 changes: 2 additions & 3 deletions src/setup-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import {App} from 'vue'
export async function setupDevServer(app: Application): Promise<(args: unknown) => Promise<App>> {
const wdm = require('webpack-dev-middleware')
const webpack: typeof import('webpack') = require('webpack')
const [clientConfig, adminConfig, serverConfig] = await Promise.all([
const [clientConfig, serverConfig] = await Promise.all([
import('./webpack/webpack.conf').then((m) => m.default),
import('./webpack/webpack.admin').then((m) => m.default),
import('./webpack/webpack.server').then((m) => m.default),
])

return new Promise((resolve, reject) => {
const clientCompiler = webpack([clientConfig, adminConfig])
const clientCompiler = webpack([clientConfig])
const devMiddleware = wdm(clientCompiler, {
publicPath: clientConfig.output?.publicPath,
serverSideRender: true,
Expand Down
70 changes: 0 additions & 70 deletions src/webpack/webpack.admin.ts

This file was deleted.

0 comments on commit cabca43

Please sign in to comment.