no message
parent
3578ef735d
commit
2d330ce829
@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
# Vue 3 + Vite
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm i
|
||||||
|
# If you don't have pnpm installed, run: npm install -g pnpm
|
||||||
|
pnpm dev
|
||||||
|
pnpm build
|
||||||
|
```
|
||||||
|
|
||||||
|
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||||
|
|
||||||
|
## Recommended IDE Setup
|
||||||
|
|
||||||
|
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>鹿和后台</title>
|
||||||
|
<link rel="shortcut icon" href="favicon.png"/>
|
||||||
|
<script>
|
||||||
|
// PUBLIC CONFIG
|
||||||
|
(function () {
|
||||||
|
const config_data = {
|
||||||
|
token_key: 'TOKEN',
|
||||||
|
api: {
|
||||||
|
url: 'http://mix.sa0.online',
|
||||||
|
error_message: '网络请求发生错误',
|
||||||
|
login: [100001, 100003],
|
||||||
|
success: 200
|
||||||
|
},
|
||||||
|
layout: {
|
||||||
|
logo: 40,
|
||||||
|
background: '#f5f7f9',
|
||||||
|
header: 64,
|
||||||
|
footer: 30,
|
||||||
|
sider: {
|
||||||
|
inverted: false,
|
||||||
|
open: 240,
|
||||||
|
close: 64,
|
||||||
|
background: '#ffffff',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
title: document.title,
|
||||||
|
app_theme: '#1c8eee',
|
||||||
|
version: {
|
||||||
|
version: '13.0.1 [Mix]',
|
||||||
|
date: '2022年12月25日 14:58:11',
|
||||||
|
desc: '鹿和后台管理系统 北有神鹿 其名鹿和'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
localStorage.setItem('APP_CONFIG', JSON.stringify(config_data))
|
||||||
|
})()
|
||||||
|
// PUBLIC CONFIG END
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"></div>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
|
const setting = localStorage.getItem('color-schema') || 'auto'
|
||||||
|
if (setting === 'dark' || (prefersDark && setting !== 'light'))
|
||||||
|
document.documentElement.classList.toggle('dark', true)
|
||||||
|
})()
|
||||||
|
</script>
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "lu-code-vue-user",
|
||||||
|
"packageManager": "pnpm@7.0.0",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite --port 3333 --open",
|
||||||
|
"build": "vite build"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@icon-park/vue-next": "^1.4.2",
|
||||||
|
"@vueuse/core": "^8.4.2",
|
||||||
|
"animate.css": "^4.1.1",
|
||||||
|
"axios": "^0.26.1",
|
||||||
|
"naive-ui": "^2.34.3",
|
||||||
|
"normalize.css": "^8.0.1",
|
||||||
|
"pinia": "^2.0.14",
|
||||||
|
"vue": "^3.2.33",
|
||||||
|
"vue-router": "^4.0.15"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitejs/plugin-vue": "^2.3.3",
|
||||||
|
"pnpm": "^7.0.1",
|
||||||
|
"unocss": "^0.33.2",
|
||||||
|
"unplugin-auto-import": "^0.7.1",
|
||||||
|
"unplugin-vue-components": "^0.19.5",
|
||||||
|
"vite": "^2.9.9",
|
||||||
|
"vite-plugin-pages": "^0.23.0",
|
||||||
|
"vite-plugin-vue-layouts": "^0.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
@ -0,0 +1,53 @@
|
|||||||
|
<script setup>
|
||||||
|
import {zhCN, dateZhCN, darkTheme} from 'naive-ui'
|
||||||
|
import color from '~/tool/color'
|
||||||
|
import {isDark} from '~/composables'
|
||||||
|
import {useStore, useConfig} from '~/store'
|
||||||
|
|
||||||
|
const $store = useStore()
|
||||||
|
const $config = useConfig()
|
||||||
|
const get_theme_overrides = $computed(() => {
|
||||||
|
const app_theme = $config.value.app_theme;
|
||||||
|
const lighten_str = color.lighten($config.value.app_theme, 6);
|
||||||
|
return {
|
||||||
|
common: {
|
||||||
|
primaryColor: app_theme,
|
||||||
|
primaryColorHover: lighten_str,
|
||||||
|
primaryColorSuppl: lighten_str,
|
||||||
|
primaryColorPressed: lighten_str,
|
||||||
|
},
|
||||||
|
LoadingBar: {
|
||||||
|
colorLoading: app_theme,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<n-config-provider :theme-overrides="get_theme_overrides" :theme="isDark?darkTheme:{}" :locale="zhCN"
|
||||||
|
:date-locale="dateZhCN">
|
||||||
|
<n-spin class="spin_wrapper" :show="$store.api_loading > 0">
|
||||||
|
<n-notification-provider>
|
||||||
|
<n-loading-bar-provider>
|
||||||
|
<n-message-provider>
|
||||||
|
<n-dialog-provider>
|
||||||
|
<Mounting/>
|
||||||
|
<main font-sans>
|
||||||
|
<router-view/>
|
||||||
|
</main>
|
||||||
|
</n-dialog-provider>
|
||||||
|
</n-message-provider>
|
||||||
|
</n-loading-bar-provider>
|
||||||
|
</n-notification-provider>
|
||||||
|
</n-spin>
|
||||||
|
</n-config-provider>
|
||||||
|
</template>
|
||||||
|
<style>
|
||||||
|
.form_tag_wrapper {
|
||||||
|
width: 80px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form_input_wrapper {
|
||||||
|
width: 200px !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
import {$post} from '~/tool/axios'
|
||||||
|
import {useConfig, useSessionToken, useSaveTokenType, useToken} from "~/store";
|
||||||
|
import $router from "~/router";
|
||||||
|
|
||||||
|
const $save_token_type = useSaveTokenType()
|
||||||
|
const $session_token = useSessionToken()
|
||||||
|
const $token = useToken()
|
||||||
|
const $config = useConfig()
|
||||||
|
const admin_api = 'Admin'
|
||||||
|
export const yo = async (data) => await $post({url: `${$config.value.api.url}/api/yo`, data}, true)
|
||||||
|
export const ConfigGetAction = async (label_arr) => await $post({
|
||||||
|
url: `${$config.value.api.url}/api/${admin_api}/Config/get`, data: {label_arr}
|
||||||
|
}, true)
|
||||||
|
export const $headers = () => {
|
||||||
|
let $token
|
||||||
|
if ($save_token_type.value === 'local') {
|
||||||
|
$token = useToken()
|
||||||
|
} else {
|
||||||
|
$token = useSessionToken()
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'Authorization': 'Bearer ' + $token.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const $image = (path) => {
|
||||||
|
const path_ret = ['http://', 'https://', ';base64,']
|
||||||
|
for (let i = 0; i < path_ret.length; i++) {
|
||||||
|
if (path.indexOf(path_ret[i]) !== -1) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return `${$config.value.api.url}${path}`
|
||||||
|
}
|
||||||
|
export const $base64 = (file) => {
|
||||||
|
let reader = new FileReader()
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
return new Promise(resolve => (reader.onloadend = () => resolve(reader.result)))
|
||||||
|
}
|
||||||
|
export const $response = (res, then, next = false) => {
|
||||||
|
if (res) {
|
||||||
|
if ($config.value.api.login.indexOf(res.code) !== -1) {
|
||||||
|
$session_token.value = null
|
||||||
|
$token.value = null
|
||||||
|
if (!!next) {
|
||||||
|
next('/login')
|
||||||
|
} else {
|
||||||
|
$router.push('/login')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (res.code !== $config.value.api.success) return window.$message().error(res.message)
|
||||||
|
then()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<template></template>
|
||||||
|
<script setup>
|
||||||
|
import {useMessage, useLoadingBar, useDialog, useNotification} from 'naive-ui'
|
||||||
|
|
||||||
|
const $message = useMessage()
|
||||||
|
window.$message = () => {
|
||||||
|
$message.destroyAll()
|
||||||
|
return $message
|
||||||
|
}
|
||||||
|
window.$dialog = useDialog();
|
||||||
|
window.$loading = useLoadingBar();
|
||||||
|
window.$notification = useNotification();
|
||||||
|
</script>
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
export const isDark = useDark()
|
||||||
|
export const toggleDark = useToggle(isDark)
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
const {isFullscreen, toggle} = useFullscreen()
|
||||||
|
export const isFull = isFullscreen
|
||||||
|
export const toggleFull = toggle
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
export * from './dark'
|
||||||
|
export * from './fullscreen'
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<script setup>
|
||||||
|
const $router = useRouter()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<main p="x4 y10" text="center blue-500 dark:gray-200">
|
||||||
|
<RouterView/>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
<script setup>
|
||||||
|
import {useConfig, useCollapsed} from "~/store"
|
||||||
|
import {isDark} from '~/composables'
|
||||||
|
|
||||||
|
const $config = useConfig()
|
||||||
|
|
||||||
|
const layout_content_wrapper_background = ref($config.value.layout.background)
|
||||||
|
const layout_sider_wrapper_background = ref($config.value.layout.sider.background)
|
||||||
|
|
||||||
|
const layout_header_wrapper_height = ref(`${$config.value.layout.header}px`)
|
||||||
|
const layout_footer_wrapper_height = ref(`${$config.value.layout.footer}px`)
|
||||||
|
|
||||||
|
const layout_router_view_margin_bottom = ref('10px');
|
||||||
|
const layout_router_view_wrapper_min_height = ref(`calc(100vh - ${$config.value.layout.header}px - ${$config.value.layout.footer}px - 1px - ${layout_router_view_margin_bottom.value})`)
|
||||||
|
const layout_content_wrapper_height = ref(`calc(100vh - ${$config.value.layout.header}px)`)
|
||||||
|
const layout_content_container_wrapper_height = ref(`calc(100vh - ${$config.value.layout.header}px)`)
|
||||||
|
|
||||||
|
const $collapsed = useCollapsed()
|
||||||
|
const collapsedOnUpdate = (e) => {
|
||||||
|
$collapsed.value = e
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="layout_wrapper">
|
||||||
|
<n-layout has-sider class="layout_header_container_wrapper">
|
||||||
|
<n-layout-sider :collapsed="$collapsed" :class="[isDark?'':'layout_sider_background']"
|
||||||
|
collapse-mode="width" :collapsed-width="$config.layout.sider.close"
|
||||||
|
:width="$config.layout.sider.open" :inverted="$config.layout.sider.inverted || isDark"
|
||||||
|
:native-scrollbar="false" bordered>
|
||||||
|
<Logo></Logo>
|
||||||
|
</n-layout-sider>
|
||||||
|
<n-layout>
|
||||||
|
<n-layout-header class="layout_header_wrapper" bordered>
|
||||||
|
<n-button ml-5 text @click="collapsedOnUpdate(!$collapsed)">
|
||||||
|
<Icon v-if="$collapsed" type="menu-unfold-one"></Icon>
|
||||||
|
<Icon v-else type="menu-fold-one"></Icon>
|
||||||
|
</n-button>
|
||||||
|
<Breadcrumb></Breadcrumb>
|
||||||
|
<User></User>
|
||||||
|
</n-layout-header>
|
||||||
|
</n-layout>
|
||||||
|
</n-layout>
|
||||||
|
<n-layout has-sider class="layout_content_container_wrapper">
|
||||||
|
<n-layout-sider :collapsed="$collapsed" :class="[isDark?'':'layout_sider_background']"
|
||||||
|
collapse-mode="width" :collapsed-width="$config.layout.sider.close"
|
||||||
|
:width="$config.layout.sider.open" :inverted="$config.layout.sider.inverted || isDark"
|
||||||
|
:native-scrollbar="false" bordered>
|
||||||
|
<Menu></Menu>
|
||||||
|
</n-layout-sider>
|
||||||
|
<n-layout :class="[isDark?'':'layout_content_background']">
|
||||||
|
<n-layout position="absolute" :native-scrollbar="false" class="layout_content_wrapper">
|
||||||
|
<div class="layout_router_view_wrapper" px-2>
|
||||||
|
<router-view v-slot="{ Component }">
|
||||||
|
<component :is="Component"/>
|
||||||
|
</router-view>
|
||||||
|
</div>
|
||||||
|
<n-layout-footer class="layout_footer_wrapper" text="xs center gray-500" bordered>
|
||||||
|
<span>{{ $config.version.desc }}</span>
|
||||||
|
<span mx-3>{{ $config.version.version }}</span>
|
||||||
|
<span>{{ $config.version.date }}</span>
|
||||||
|
</n-layout-footer>
|
||||||
|
</n-layout>
|
||||||
|
</n-layout>
|
||||||
|
</n-layout>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<style scoped>
|
||||||
|
.layout_wrapper {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_content_container_wrapper {
|
||||||
|
height: v-bind(layout_content_container_wrapper_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_header_container_wrapper {
|
||||||
|
height: v-bind(layout_header_wrapper_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_header_wrapper {
|
||||||
|
position: relative;
|
||||||
|
height: v-bind(layout_header_wrapper_height);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_sider_background {
|
||||||
|
background: v-bind(layout_sider_wrapper_background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_content_background {
|
||||||
|
background: v-bind(layout_content_wrapper_background);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_footer_wrapper {
|
||||||
|
line-height: v-bind(layout_footer_wrapper_height);
|
||||||
|
height: v-bind(layout_footer_wrapper_height);
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_content_wrapper {
|
||||||
|
top: 0.5rem;
|
||||||
|
background: #00000000;
|
||||||
|
height: v-bind(layout_content_wrapper_height);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layout_router_view_wrapper {
|
||||||
|
min-height: v-bind(layout_router_view_wrapper_min_height);
|
||||||
|
overflow: hidden;
|
||||||
|
margin-bottom: v-bind(layout_router_view_margin_bottom);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
<script setup>
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<main class="px-4 py-10 text-gray-700 dark:text-gray-200">
|
||||||
|
<RouterView/>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
import {createApp} from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
import router from '~/router'
|
||||||
|
import {createPinia} from 'pinia'
|
||||||
|
import './styles/main.css'
|
||||||
|
import 'uno.css'
|
||||||
|
import 'normalize.css'
|
||||||
|
import 'animate.css';
|
||||||
|
import '@icon-park/vue-next/styles/index.css';
|
||||||
|
|
||||||
|
const app = createApp(App)
|
||||||
|
app.use(router)
|
||||||
|
app.use(createPinia())
|
||||||
|
app.mount('#app')
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
<script setup>
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="i404_wrapper">
|
||||||
|
<img src="https://iph.href.lu/300x300/?text=404" alt="">
|
||||||
|
</div>
|
||||||
|
未找到页面
|
||||||
|
<div mt-10>
|
||||||
|
<n-button type="primary" @click="$router.back()">返回</n-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<style scoped>
|
||||||
|
.i404_wrapper {
|
||||||
|
width: 300px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.i404_wrapper img {
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<route>
|
||||||
|
{"name":"404","meta":{"layout":"404"}}
|
||||||
|
</route>
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
<script setup>
|
||||||
|
import ApiComponent from '~/components/dev/Api.vue'
|
||||||
|
import StoreComponent from '~/components/dev/Store.vue'
|
||||||
|
import RouterQueryComponent from '~/components/dev/RouterQuery.vue'
|
||||||
|
import RouterPushComponent from '~/components/dev/RouterPush.vue'
|
||||||
|
import RouterParamsComponent from '~/components/dev/RouterParams.vue'
|
||||||
|
import IconParkComponent from '~/components/dev/IconPark.vue'
|
||||||
|
import StyleVBindComponent from '~/components/dev/StyleVBind.vue'
|
||||||
|
import UnoCSSComponent from '~/components/dev/UnoCSS.vue'
|
||||||
|
import UseMessageComponent from '~/components/dev/UseMessage.vue'
|
||||||
|
import SonFatherComponent from '~/components/dev/SonFather/Father.vue'
|
||||||
|
|
||||||
|
const $props = defineProps({
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
default: '鹿和'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const $router = useRouter()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<n-table striped size="small">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>功能</th>
|
||||||
|
<th>内容</th>
|
||||||
|
<th>操作</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<ApiComponent></ApiComponent>
|
||||||
|
<StoreComponent></StoreComponent>
|
||||||
|
<RouterQueryComponent></RouterQueryComponent>
|
||||||
|
<RouterParamsComponent :name="$props.name"></RouterParamsComponent>
|
||||||
|
<RouterPushComponent></RouterPushComponent>
|
||||||
|
<IconParkComponent></IconParkComponent>
|
||||||
|
<StyleVBindComponent></StyleVBindComponent>
|
||||||
|
<UnoCSSComponent></UnoCSSComponent>
|
||||||
|
<UseMessageComponent></UseMessageComponent>
|
||||||
|
<SonFatherComponent></SonFatherComponent>
|
||||||
|
</tbody>
|
||||||
|
</n-table>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<route>
|
||||||
|
{"meta":{"title":"基础功能示例","icon":"i-ic-round-code"}}
|
||||||
|
</route>
|
||||||
@ -0,0 +1,68 @@
|
|||||||
|
import {createRouter, createWebHashHistory} from 'vue-router'
|
||||||
|
import {setupLayouts} from 'virtual:generated-layouts'
|
||||||
|
import generatedRoutes from 'virtual:generated-pages'
|
||||||
|
import {ConfigGetAction, $response} from "~/api"
|
||||||
|
import {$favicon} from "~/tool/favicon"
|
||||||
|
import {
|
||||||
|
useStore, useSaveTokenType, useSessionToken, useToken, useRouterActive
|
||||||
|
} from '~/store'
|
||||||
|
|
||||||
|
const no_login_list = ['login', '404'];
|
||||||
|
const $router_active = useRouterActive()
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHashHistory(import.meta.env.BASE_URL), routes: setupLayouts(generatedRoutes)
|
||||||
|
})
|
||||||
|
|
||||||
|
const updateRouterActive = (matched) => {
|
||||||
|
matched.shift()
|
||||||
|
const last = matched[matched.length - 1]
|
||||||
|
if (no_login_list.indexOf(last.name) !== -1) return
|
||||||
|
setTimeout(() => {
|
||||||
|
$router_active.value = matched.map((item) => {
|
||||||
|
return {
|
||||||
|
title: 'title' in item.meta ? item.meta.title : item.name,
|
||||||
|
key: item.name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
router.beforeEach(async (to, from, next) => {
|
||||||
|
window.$loading.start()
|
||||||
|
const $store = useStore()
|
||||||
|
if (!$store.config) {
|
||||||
|
const response = await ConfigGetAction(['Logo', 'Favicon', 'Login欢迎图片', '网站名称'])
|
||||||
|
$response(response, () => {
|
||||||
|
$store.config = response.data
|
||||||
|
})
|
||||||
|
$favicon($store.config['Favicon'])
|
||||||
|
}
|
||||||
|
document.title = ('title' in to.meta && to.meta.title !== '首页') ? `${to.meta.title} ${$store.config['网站名称']}` : $store.config['网站名称']
|
||||||
|
if (no_login_list.indexOf(to.name) === -1) {
|
||||||
|
const $save_token_type = useSaveTokenType()
|
||||||
|
let $token;
|
||||||
|
if ($save_token_type.value === 'local') {
|
||||||
|
$token = useToken()
|
||||||
|
} else {
|
||||||
|
$token = useSessionToken()
|
||||||
|
}
|
||||||
|
if ($token.value === '') {
|
||||||
|
next('/login?f=' + encodeURIComponent(to.fullPath))
|
||||||
|
setTimeout(() => {
|
||||||
|
window.$loading.finish()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
updateRouterActive(to.matched.map(item => item))
|
||||||
|
next()
|
||||||
|
setTimeout(() => {
|
||||||
|
window.$loading.finish()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
setTimeout(() => {
|
||||||
|
window.$loading.finish()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export default router
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
import {defineStore} from 'pinia'
|
||||||
|
|
||||||
|
export const useStore = defineStore('main', {
|
||||||
|
state: () => {
|
||||||
|
return {
|
||||||
|
config: false,
|
||||||
|
admin_info: false, api_loading: 0, count: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const TOKEN_KEY = JSON.parse(localStorage.getItem('APP_CONFIG') ?? '{}').token_key
|
||||||
|
export const useConfig = createGlobalState(() => useStorage('APP_CONFIG', JSON.parse(localStorage.getItem('APP_CONFIG') ?? '{}')))
|
||||||
|
export const useToken = createGlobalState(() => useStorage(TOKEN_KEY, ''))
|
||||||
|
export const useSessionToken = createGlobalState(() => useStorage(TOKEN_KEY, '', sessionStorage))
|
||||||
|
export const useSaveTokenType = createGlobalState(() => useStorage('SAVE_TOKEN_TYPE', 'session'))
|
||||||
|
export const useRouterActive = createGlobalState(() => useStorage('ROUTER_ACTIVE', []))
|
||||||
|
export const useCollapsed = createGlobalState(() => useStorage('COLLAPSED', false))
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark {
|
||||||
|
background: #333;
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
import {useToken, useStore, useConfig, useSaveTokenType, useSessionToken} from '~/store'
|
||||||
|
const $save_token_type = useSaveTokenType()
|
||||||
|
let $token;
|
||||||
|
const post = axios.create({
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
post.interceptors.request.use(config => {
|
||||||
|
if ($save_token_type.value === 'local') {
|
||||||
|
$token = useToken()
|
||||||
|
} else {
|
||||||
|
$token = useSessionToken()
|
||||||
|
}
|
||||||
|
config.headers['Authorization'] = 'Bearer ' + $token.value
|
||||||
|
return config
|
||||||
|
}, error => Promise.reject(error))
|
||||||
|
post.interceptors.response.use(response => {
|
||||||
|
return (response.status === 200) ? response : Promise.reject('[ERROR] response.status: ' + response.status)
|
||||||
|
}, error => Promise.reject(error))
|
||||||
|
|
||||||
|
const $config = useConfig()
|
||||||
|
export const $post = async (request, loading = false) => {
|
||||||
|
const $store = useStore()
|
||||||
|
if (loading) $store.api_loading++
|
||||||
|
const response = await post(request).catch((e) => {
|
||||||
|
window.$message().error($config.value.api.error_message)
|
||||||
|
})
|
||||||
|
if (loading) $store.api_loading--
|
||||||
|
return !!response ? response.data : false
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
function addLight(color, amount) {
|
||||||
|
const cc = parseInt(color, 16) + amount;
|
||||||
|
const c = cc > 255 ? 255 : cc;
|
||||||
|
return c.toString(16).length > 1 ? c.toString(16) : `0${c.toString(16)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lighten(color, amount) {
|
||||||
|
color = color.indexOf('#') >= 0 ? color.substring(1, color.length) : color;
|
||||||
|
amount = Math.trunc((255 * amount) / 100);
|
||||||
|
return `#${addLight(color.substring(0, 2), amount)}${addLight(color.substring(2, 4), amount)}${addLight(color.substring(4, 6), amount)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {lighten}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
import {$image} from "~/api";
|
||||||
|
|
||||||
|
export const $favicon = (path, t = false) => {
|
||||||
|
const link = document.querySelector("link[rel*='icon']") || document.createElement('link')
|
||||||
|
link.type = 'image/x-icon'
|
||||||
|
link.rel = 'shortcut icon'
|
||||||
|
let href = $image(path)
|
||||||
|
link.href = t ? [href, 't=' + String(new Date() / 1)].join(href.indexOf('?') === -1 ? '?' : '&') : href
|
||||||
|
document.getElementsByTagName('head')[0].appendChild(link)
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
import {defineConfig} from 'vite'
|
||||||
|
import Vue from '@vitejs/plugin-vue'
|
||||||
|
import path from 'path'
|
||||||
|
import Pages from 'vite-plugin-pages'
|
||||||
|
import Layouts from 'vite-plugin-vue-layouts'
|
||||||
|
import Components from 'unplugin-vue-components/vite'
|
||||||
|
import AutoImport from 'unplugin-auto-import/vite'
|
||||||
|
import {NaiveUiResolver} from 'unplugin-vue-components/resolvers'
|
||||||
|
import Unocss from 'unocss/vite'
|
||||||
|
import {presetAttributify, presetUno, presetIcons} from 'unocss'
|
||||||
|
|
||||||
|
const admin_path = 'normal'
|
||||||
|
export default defineConfig({
|
||||||
|
base: `/${admin_path}/`,
|
||||||
|
build: {
|
||||||
|
outDir: `../public/${admin_path}`, assetsDir: 'lib'
|
||||||
|
},
|
||||||
|
resolve: {alias: {'~/': `${path.resolve(__dirname, 'src')}/`}},
|
||||||
|
plugins: [Vue({reactivityTransform: true}), Pages(), Layouts(), AutoImport({
|
||||||
|
imports: ['vue', 'vue/macros', 'vue-router', '@vueuse/core',],
|
||||||
|
}), Components({resolvers: [NaiveUiResolver()]}), Unocss({
|
||||||
|
presets: [presetAttributify({}), presetUno(), presetIcons({
|
||||||
|
warn: true,
|
||||||
|
})],
|
||||||
|
})]
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue