diff --git a/.env.example b/.env.example index 2d4a58a..eeecc31 100644 --- a/.env.example +++ b/.env.example @@ -4,13 +4,6 @@ APP_KEY=base64:q3NPkuRVhdHFRkVskaqQatUEs+fXcFVgJNiDtE9nSAA= APP_DEBUG=true APP_URL=http://127.0.0.1:8000 -GATEWAY_PORT=4000 -GATEWAY_REGISTER=4001 -GATEWAY_START=4002 -GATEWAY_PING='{"action":"ping"}' -GATEWAY_PANG='{"action":"pang"}' -GATEWAY_CLOSE=/api/Gateway/close - REQUEST_LOG=true TIMEZONE=Asia/Shanghai diff --git a/admin/src/pages/login.vue b/admin/src/pages/login.vue index 81a856f..2941643 100644 --- a/admin/src/pages/login.vue +++ b/admin/src/pages/login.vue @@ -44,7 +44,7 @@ const routerChange = (query) => { f: query.f || default_page_options.f, m: Number(query.m) || default_page_options.m, } - if (page_options.value.m === 1) apiManaShow() + if (page_options.value.m === 1) proxyManaShow() } const getCaptchaCreate = (reload = true) => { if (login_type_active.value === 'password') { @@ -128,65 +128,65 @@ const AdminQuit = async () => { } }) } -const api_list = ref([]) -const api_mana_show = ref(false) -const apiManaShow = () => { - api_list.value = JSON.parse(JSON.stringify($config.value.api.url)) - api_mana_show.value = true +const proxy_list = ref([]) +const proxy_mana_show = ref(false) +const proxyManaShow = () => { + proxy_list.value = JSON.parse(JSON.stringify($config.value.api.url)) + proxy_mana_show.value = true } -const add_api_data = ref({ +const add_proxy_data = ref({ name: '', url: '', active: false }) const addApiClick = () => { - if (!add_api_data.value.name) return window.$message().error('请输入名称') - if (!add_api_data.value.url) return window.$message().error('请输入接口地址') - if (add_api_data.value.url.indexOf('http') !== 0) return window.$message().error('请输入正确的接口地址') - if (add_api_data.value.active) { - api_list.value.forEach((item) => { + if (!add_proxy_data.value.name) return window.$message().error('请输入名称') + if (!add_proxy_data.value.url) return window.$message().error('请输入接口地址') + if (add_proxy_data.value.url.indexOf('http') !== 0) return window.$message().error('请输入正确的接口地址') + if (add_proxy_data.value.active) { + proxy_list.value.forEach((item) => { item.active = false }) } - api_list.value.unshift(JSON.parse(JSON.stringify(add_api_data.value))) - add_api_data.value = { + proxy_list.value.unshift(JSON.parse(JSON.stringify(add_proxy_data.value))) + add_proxy_data.value = { name: '', url: '', active: false } } -const apiDelClick = (k) => { - if (api_list.length === 1) return - let active = api_list.value[k] - api_list.value.splice(k, 1) +const proxyDelClick = (k) => { + if (proxy_list.length === 1) return + let active = proxy_list.value[k] + proxy_list.value.splice(k, 1) if (!!active) { - api_list.value[0].active = true + proxy_list.value[0].active = true } } -const apiActiveChange = (e, k) => { +const proxyActiveChange = (e, k) => { if (!!e) { - api_list.value.forEach((item) => { + proxy_list.value.forEach((item) => { item.active = false }) - api_list.value[k].active = true + proxy_list.value[k].active = true } else { - api_list.value[k].active = false - api_list.value[0].active = true + proxy_list.value[k].active = false + proxy_list.value[0].active = true } } -const apiSaveClick = () => { +const proxySaveClick = () => { const active_item = $config.value.api.url.filter((item) => { return item.active }) - const change_item = api_list.value.filter((item) => { + const change_item = proxy_list.value.filter((item) => { return item.active }) - $config.value.api.url = JSON.parse(JSON.stringify(api_list.value)) - api_mana_show.value = false + $config.value.api.url = JSON.parse(JSON.stringify(proxy_list.value)) + proxy_mana_show.value = false if (change_item[0].url !== active_item[0].url) { if (page_options.value.m === 1) { window.location.href = '/#/login' @@ -197,7 +197,7 @@ const apiSaveClick = () => { } } -const apiResetClick = () => { +const proxyResetClick = () => { window.$box.confirm( '确定要重置代理配置吗?', '提示', @@ -239,12 +239,6 @@ const apiResetClick = () => { size="small">密码登录 -
-
扫码登录
- 扫码登录 - -
@@ -295,31 +289,12 @@ const apiResetClick = () => {
-
-
- - -
-
- - - - - 刷新二维码 - -
- 扫码登录功能暂未开启 -
-
-
-
@@ -334,15 +309,15 @@ const apiResetClick = () => { @@ -354,20 +329,20 @@ const apiResetClick = () => { - +
- + - -
- + - + - + - + @@ -379,17 +354,17 @@ const apiResetClick = () => { -
- +
+
@@ -397,20 +372,20 @@ const apiResetClick = () => {
diff --git a/zero/src/api/index.js b/zero/src/api/index.js deleted file mode 100644 index cdb4e6a..0000000 --- a/zero/src/api/index.js +++ /dev/null @@ -1,55 +0,0 @@ -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() - } -} diff --git a/zero/src/components/Icon.vue b/zero/src/components/Icon.vue deleted file mode 100644 index 9ca278a..0000000 --- a/zero/src/components/Icon.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - diff --git a/zero/src/components/Mounting.vue b/zero/src/components/Mounting.vue deleted file mode 100644 index 5068811..0000000 --- a/zero/src/components/Mounting.vue +++ /dev/null @@ -1,24 +0,0 @@ - - diff --git a/zero/src/layouts/404.vue b/zero/src/layouts/404.vue deleted file mode 100644 index c74af7f..0000000 --- a/zero/src/layouts/404.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/zero/src/layouts/default.vue b/zero/src/layouts/default.vue deleted file mode 100644 index 3c47e25..0000000 --- a/zero/src/layouts/default.vue +++ /dev/null @@ -1,12 +0,0 @@ - - - diff --git a/zero/src/layouts/none.vue b/zero/src/layouts/none.vue deleted file mode 100644 index f4edaf1..0000000 --- a/zero/src/layouts/none.vue +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/zero/src/main.js b/zero/src/main.js deleted file mode 100644 index a8cad17..0000000 --- a/zero/src/main.js +++ /dev/null @@ -1,14 +0,0 @@ -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') diff --git a/zero/src/pages/[...all].vue b/zero/src/pages/[...all].vue deleted file mode 100755 index b6c110e..0000000 --- a/zero/src/pages/[...all].vue +++ /dev/null @@ -1,27 +0,0 @@ - - - - -{"name":"404","meta":{"layout":"404"}} - diff --git a/zero/src/pages/index.vue b/zero/src/pages/index.vue deleted file mode 100644 index bc67215..0000000 --- a/zero/src/pages/index.vue +++ /dev/null @@ -1,27 +0,0 @@ - - - - -{"meta":{"title":"首页"}} - - diff --git a/zero/src/router/index.js b/zero/src/router/index.js deleted file mode 100644 index 0046c5f..0000000 --- a/zero/src/router/index.js +++ /dev/null @@ -1,61 +0,0 @@ -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 diff --git a/zero/src/store/index.js b/zero/src/store/index.js deleted file mode 100644 index 928c9ce..0000000 --- a/zero/src/store/index.js +++ /dev/null @@ -1,17 +0,0 @@ -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', [])) diff --git a/zero/src/styles/main.css b/zero/src/styles/main.css deleted file mode 100755 index 05928c3..0000000 --- a/zero/src/styles/main.css +++ /dev/null @@ -1,7 +0,0 @@ -html, -body, -#app { - height: 100%; - margin: 0; - padding: 0; -} diff --git a/zero/src/tool/axios.js b/zero/src/tool/axios.js deleted file mode 100644 index e4eef7a..0000000 --- a/zero/src/tool/axios.js +++ /dev/null @@ -1,37 +0,0 @@ -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 -} diff --git a/zero/src/tool/favicon.js b/zero/src/tool/favicon.js deleted file mode 100644 index e2d8198..0000000 --- a/zero/src/tool/favicon.js +++ /dev/null @@ -1,10 +0,0 @@ -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) -} diff --git a/zero/vite.config.js b/zero/vite.config.js deleted file mode 100644 index 154fe4d..0000000 --- a/zero/vite.config.js +++ /dev/null @@ -1,52 +0,0 @@ -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, - })], - })] -})