feat:增加纯净模板
parent
82de0e24c2
commit
befc8e3e62
@ -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,38 @@
|
||||
<!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_str = localStorage.getItem('APP_CONFIG')
|
||||
let config_data = {
|
||||
token: '559C7B84-8C8F-49E8-9AB2-37CB49C5F7D3',
|
||||
api: {
|
||||
url: [{
|
||||
name: '开发环境',
|
||||
url: 'http://127.0.0.1:8000',
|
||||
active: true
|
||||
}],
|
||||
error_message: '网络请求发生错误',
|
||||
success_code: 200
|
||||
},
|
||||
title: document.title,
|
||||
app_theme: '#1c8eee',
|
||||
version: `${document.title} 14.0.1 [入魔入佛]`
|
||||
}
|
||||
window.CONFIG_RESET_DATA = JSON.parse(JSON.stringify(config_data))
|
||||
if (!!config_data_str) config_data.api = JSON.parse(config_data_str).api
|
||||
localStorage.setItem('APP_CONFIG', JSON.stringify(config_data))
|
||||
})()
|
||||
// PUBLIC CONFIG END
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<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 --host",
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@icon-park/vue-next": "^1.4.2",
|
||||
"@vueuse/core": "^8.4.2",
|
||||
"axios": "^0.26.1",
|
||||
"element-plus": "^2.3.8",
|
||||
"normalize.css": "^8.0.1",
|
||||
"pinia": "^2.0.14",
|
||||
"vue": "^3.2.33",
|
||||
"vue-router": "^4.0.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
||||
"@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,18 @@
|
||||
<script setup>
|
||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
|
||||
|
||||
const button_config = {
|
||||
autoInsertSpace: true,
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<Mounting/>
|
||||
<el-config-provider :button="button_config" :locale="zhCn">
|
||||
<router-view/>
|
||||
</el-config-provider>
|
||||
</template>
|
||||
<style>
|
||||
body {
|
||||
background: #ffffff;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,55 @@
|
||||
import {$post} from '~/tool/axios'
|
||||
import {useConfig, useSessionToken, useSaveTokenType, useToken} from "~/store";
|
||||
|
||||
const $save_token_type = useSaveTokenType()
|
||||
const $config = useConfig()
|
||||
const app_name = 'Zero'
|
||||
let url = ''
|
||||
const urlPick = () => {
|
||||
if ($config.value.api.url.length > 0) {
|
||||
url = $config.value.api.url[0].url
|
||||
for (let i in $config.value.api.url) {
|
||||
if (!!$config.value.api.url[i].active) {
|
||||
url = $config.value.api.url[i].url
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
urlPick()
|
||||
export const ConfigGetAction = async (data) => await $post({
|
||||
url: `${url}/api/${app_name}/Config/get?client=user`,
|
||||
data
|
||||
}, true)
|
||||
export const yo = async (data) => await $post({url: `${url}/api/yo`, data}, 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 `${url}${path}`
|
||||
}
|
||||
export const $base64 = async (file) => {
|
||||
let reader = new FileReader()
|
||||
reader.readAsDataURL(file)
|
||||
return await new Promise(resolve => (reader.onloadend = () => resolve(reader.result)))
|
||||
}
|
||||
export const $response = (res, then, next = false) => {
|
||||
if (res) {
|
||||
if (res.code !== $config.value.api.success_code) return window.$message().error(res.message)
|
||||
then()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
<template></template>
|
||||
<script setup>
|
||||
import {ElLoading, ElMessage, ElMessageBox} from 'element-plus'
|
||||
|
||||
window.$message = () => {
|
||||
ElMessage.closeAll()
|
||||
return ElMessage
|
||||
}
|
||||
window.$box = ElMessageBox
|
||||
let loading = null
|
||||
window.$loading = () => {
|
||||
return {
|
||||
open: () => {
|
||||
loading = ElLoading.service({
|
||||
lock: true,
|
||||
text: '加载中...',
|
||||
})
|
||||
},
|
||||
close: () => {
|
||||
loading.close()
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,5 @@
|
||||
<template>
|
||||
<main>
|
||||
<RouterView/>
|
||||
</main>
|
||||
</template>
|
||||
@ -0,0 +1,12 @@
|
||||
<script setup>
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<router-view v-slot="{ Component }">
|
||||
<component :is="Component"/>
|
||||
</router-view>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@ -0,0 +1,7 @@
|
||||
<script setup>
|
||||
</script>
|
||||
<template>
|
||||
<main>
|
||||
<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 '@icon-park/vue-next/styles/index.css'
|
||||
import 'element-plus/dist/index.css'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
app.use(createPinia())
|
||||
app.mount('#app')
|
||||
@ -0,0 +1,27 @@
|
||||
<script setup>
|
||||
</script>
|
||||
<template>
|
||||
<div p="x4 y10" text="center blue-500 dark:gray-200">
|
||||
<div class="i404_wrapper">
|
||||
<div>404</div>
|
||||
</div>
|
||||
<div mt-2>未找到页面</div>
|
||||
<div mt-10>
|
||||
<el-button type="primary" @click="$router.back()">返回</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped>
|
||||
.i404_wrapper {
|
||||
width: 300px;
|
||||
margin: 0 auto;
|
||||
font-size: 100px;
|
||||
}
|
||||
|
||||
.i404_wrapper img {
|
||||
width: 300px;
|
||||
}
|
||||
</style>
|
||||
<route>
|
||||
{"name":"404","meta":{"layout":"404"}}
|
||||
</route>
|
||||
@ -0,0 +1,61 @@
|
||||
import {createRouter, createWebHashHistory} from 'vue-router'
|
||||
import {setupLayouts} from 'virtual:generated-layouts'
|
||||
import generatedRoutes from 'virtual:generated-pages'
|
||||
import {$favicon} from "~/tool/favicon"
|
||||
import {
|
||||
useStore, useRouterActive
|
||||
} from '~/store'
|
||||
import {$image, $response, ConfigGetAction} from "~/api";
|
||||
|
||||
const allow_unlogged_in_page = ['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 (allow_unlogged_in_page.indexOf(last.name) !== -1) return
|
||||
setTimeout(() => {
|
||||
$router_active.value = matched.map((item) => {
|
||||
return {
|
||||
title: 'title' in item.meta ? item.meta.title : item.name,
|
||||
key: 'active' in item.meta ? item.meta.active : item.name,
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
let token_check = ''
|
||||
let error_status = false
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const $store = useStore()
|
||||
if (!$store.config) {
|
||||
const response = await ConfigGetAction({
|
||||
config_arr: [
|
||||
"Favicon",
|
||||
"网站名称",
|
||||
]
|
||||
})
|
||||
$response(response, () => {
|
||||
$store.config = response.data
|
||||
$favicon($image(response.data['Favicon']))
|
||||
})
|
||||
if (!response) error_status = true
|
||||
}
|
||||
if (!!error_status) {
|
||||
$store.config = {
|
||||
"Favicon": "https://www.sa0.online/storage/assets/default/favicon.png",
|
||||
"网站名称": "网络错误",
|
||||
}
|
||||
$favicon($image($store.config['Favicon']))
|
||||
}
|
||||
document.title = ('title' in to.meta && to.meta.title !== '首页') ? `${to.meta.title} ${$store.config['网站名称']}` : $store.config['网站名称']
|
||||
if (allow_unlogged_in_page.indexOf(to.name) === -1) {
|
||||
updateRouterActive(to.matched.map(item => item))
|
||||
next()
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
export default router
|
||||
@ -0,0 +1,17 @@
|
||||
import {defineStore} from 'pinia'
|
||||
|
||||
export const useStore = defineStore('main', {
|
||||
state: () => {
|
||||
return {
|
||||
config: false,
|
||||
info: false,
|
||||
loading: 0
|
||||
}
|
||||
}
|
||||
})
|
||||
const TOKEN_KEY = JSON.parse(localStorage.getItem('APP_CONFIG') ?? '{}').token
|
||||
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', []))
|
||||
@ -0,0 +1,7 @@
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
import axios from 'axios'
|
||||
import {useToken, useStore, useConfig, useSaveTokenType, useSessionToken} from '~/store'
|
||||
const $save_token_type = useSaveTokenType()
|
||||
let $token
|
||||
let loading_active
|
||||
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.loading++
|
||||
if ($store.loading === 1) window.$loading().open()
|
||||
}
|
||||
const response = await post(request).catch((e) => {
|
||||
window.$message().error($config.value.api.error_message)
|
||||
})
|
||||
if (loading) {
|
||||
$store.loading--
|
||||
if ($store.loading === 0) window.$loading().close()
|
||||
}
|
||||
return !!response ? response.data : false
|
||||
}
|
||||
@ -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,52 @@
|
||||
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 {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
|
||||
import {viteCommonjs} from '@originjs/vite-plugin-commonjs'
|
||||
import Unocss from 'unocss/vite'
|
||||
import {presetAttributify, presetUno, presetIcons} from 'unocss'
|
||||
|
||||
const package_path = 'zero'
|
||||
export default defineConfig({
|
||||
base: `/${package_path}/`,
|
||||
build: {
|
||||
outDir: `../public/${package_path}`,
|
||||
assetsDir: 'lib'
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'~/': `${path.resolve(__dirname, 'src')}/`
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
Vue({
|
||||
reactivityTransform: true
|
||||
}),
|
||||
viteCommonjs(),
|
||||
Pages(),
|
||||
Layouts(),
|
||||
AutoImport({
|
||||
resolvers: [ElementPlusResolver()],
|
||||
imports: [
|
||||
'vue',
|
||||
'vue/macros',
|
||||
'vue-router',
|
||||
'@vueuse/core'
|
||||
],
|
||||
}),
|
||||
Components({
|
||||
resolvers: [ElementPlusResolver()]
|
||||
}),
|
||||
Unocss({
|
||||
presets: [
|
||||
presetAttributify({}),
|
||||
presetUno(),
|
||||
presetIcons({
|
||||
warn: true,
|
||||
})],
|
||||
})]
|
||||
})
|
||||
Loading…
Reference in New Issue