diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 677cfdd7..657c5893 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -3,10 +3,29 @@ declare (strict_types = 1); namespace app\admin\controller; -class Index +use app\common\controller\Backend; + +class Index extends Backend { public function index() { - return '您好!这是一个[admin]示例应用'; + return '后台首页'; + } + + public function login() + { + $url = $this->request->get('url', '/admin'); + + // 检查登录态 + + // 检查提交 + if ($this->request->isPost()) { + $username = $this->request->post('username'); + $password = $this->request->post('password'); + $keeplogin = $this->request->post('keeplogin'); + $token = $this->request->post('__token__'); + + print_r($username); + } } } diff --git a/app/admin/library/Auth.php b/app/admin/library/Auth.php new file mode 100644 index 00000000..ed4a07ca --- /dev/null +++ b/app/admin/library/Auth.php @@ -0,0 +1,8 @@ + 'localhost,127.0.0.1', + 'admin_login_captcha' => true, // 允许执行的命令 'allowed_commands' => [ 'ping-baidu' => 'ping baidu.com', diff --git a/web/.env.development b/web/.env.development index 4b564b8f..3a9fa290 100644 --- a/web/.env.development +++ b/web/.env.development @@ -3,3 +3,6 @@ ENV = 'development' # base路径 VITE_BASE_PATH = './' + +# 本地环境接口地址 - 尾部无需带'/' +VITE_AXIOS_BASE_URL = 'http://localhost:8000' diff --git a/web/.env.online b/web/.env.online index eab4b464..72ad5c72 100644 --- a/web/.env.online +++ b/web/.env.online @@ -8,3 +8,6 @@ VITE_BASE_PATH = '/' # 导出路径 VITE_OUT_DIR = '../dist/' + +# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名' +VITE_AXIOS_BASE_URL = 'getCurrentDomain' diff --git a/web/.env.production b/web/.env.production index f995153e..7ef3784f 100644 --- a/web/.env.production +++ b/web/.env.production @@ -6,3 +6,6 @@ VITE_BASE_PATH = '/' # 导出路径 VITE_OUT_DIR = 'dist' + +# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名' +VITE_AXIOS_BASE_URL = 'getCurrentDomain' diff --git a/web/package.json b/web/package.json index 3d3eb691..1803e89b 100644 --- a/web/package.json +++ b/web/package.json @@ -10,6 +10,7 @@ "dependencies": { "@element-plus/icons-vue": "^0.2.4", "@vueuse/core": "^7.5.3", + "axios": "^0.26.0", "countup.js": "^2.0.8", "echarts": "^5.2.2", "element-plus": "^1.3.0-beta.3", diff --git a/web/src/api/backend/index.ts b/web/src/api/backend/index.ts new file mode 100644 index 00000000..979ec6a2 --- /dev/null +++ b/web/src/api/backend/index.ts @@ -0,0 +1,9 @@ +import Axios from '/@/utils/axios' + +export function login(params: object) { + return Axios.request({ + url: '/index.php/admin/index/login', + method: 'post', + data: params + }) +} diff --git a/web/src/utils/axios.ts b/web/src/utils/axios.ts new file mode 100644 index 00000000..22ce9f7a --- /dev/null +++ b/web/src/utils/axios.ts @@ -0,0 +1,24 @@ +import axios from 'axios' +import { computed } from 'vue' +import { ElMessage, ElMessageBox } from 'element-plus' +import { Local } from '/@/utils/storage' +import { store } from '/@/store/index' +import { isProd } from '/@/utils/vite' + +const getUrl = (): string => { + const value: string = import.meta.env.VITE_AXIOS_BASE_URL as string + return value == 'getCurrentDomain' ? window.location.protocol + '//' + window.location.host : value +} + +const lang = computed(() => store.state.config.defaultLang) + +const Axios = axios.create({ + baseURL: getUrl(), + timeout: 50000, + headers: { + 'Content-Type': 'application/json', + 'think-lang': lang.value, + }, +}) + +export default Axios diff --git a/web/src/utils/vite.ts b/web/src/utils/vite.ts index a04fdede..0d9e5b59 100644 --- a/web/src/utils/vite.ts +++ b/web/src/utils/vite.ts @@ -6,6 +6,11 @@ export interface ViteEnv { VITE_OPEN: boolean VITE_BASE_PATH: string VITE_OUT_DIR: string + VITE_AXIOS_BASE_URL: string +} + +export function isOnline(mode: string): boolean { + return mode === 'online' } export function isDev(mode: string): boolean { @@ -13,14 +18,13 @@ export function isDev(mode: string): boolean { } export function isProd(mode: string | undefined): boolean { - return mode === 'production' + return mode === 'production' || mode === 'online' } // Read all environment variable configuration files to process.env -export function loadEnv(): ViteEnv { - const env = process.env.NODE_ENV +export function loadEnv(mode: string): ViteEnv { const ret: any = {} - const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', '.env.online'] + const envList = [`.env.${mode}.local`, `.env.${mode}`, '.env.local', '.env'] envList.forEach((e) => { dotenv.config({ path: e }) }) diff --git a/web/src/views/backend/login.vue b/web/src/views/backend/login.vue index ada1c314..cbe9d852 100644 --- a/web/src/views/backend/login.vue +++ b/web/src/views/backend/login.vue @@ -94,6 +94,7 @@ import type { ElForm } from 'element-plus' import { useI18n } from 'vue-i18n' import { editDefaultLang } from '/@/lang/index' import { useStore } from '/@/store/index' +import { login } from '/@/api/backend' const store = useStore() @@ -177,6 +178,13 @@ const onSubmit = (formEl: InstanceType | undefined) => { formEl.validate((valid) => { if (valid) { form.loading = true + login(form) + .then((res) => { + console.log(res) + }) + .catch((err) => { + console.log(err) + }) console.log(form) } else { console.log('error submit!') diff --git a/web/vite.config.ts b/web/vite.config.ts index 894c8e91..bd0613fe 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -1,54 +1,56 @@ import vue from '@vitejs/plugin-vue' import { resolve } from 'path' -import type { UserConfig } from 'vite' +import type { UserConfig, ConfigEnv } from 'vite' import { isProd, loadEnv } from '/@/utils/vite' import { svgBuilder } from '/@/components/icon/svg/index' -const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR } = loadEnv() - const pathResolve = (dir: string): any => { return resolve(__dirname, '.', dir) } -const alias: Record = { - '/@': pathResolve('./src/'), - assets: pathResolve('./src/assets'), - 'vue-i18n': isProd(process.env.NODE_ENV) ? 'vue-i18n/dist/vue-i18n.cjs.prod.js' : 'vue-i18n/dist/vue-i18n.cjs.js', -} - // https://vitejs.cn/config/ -const viteConfig: UserConfig = { - plugins: [vue(), svgBuilder('./src/assets/icons/')], - root: process.cwd(), - resolve: { alias }, - base: VITE_BASE_PATH, - server: { - host: '0.0.0.0', - port: VITE_PORT, - open: VITE_OPEN, - }, - build: { - sourcemap: false, - outDir: VITE_OUT_DIR, - emptyOutDir: true, - chunkSizeWarningLimit: 1500, - }, - css: { - postcss: { - plugins: [ - { - postcssPlugin: 'internal:charset-removal', - AtRule: { - charset: (atRule) => { - if (atRule.name === 'charset') { - atRule.remove() - } +const viteConfig = ({ mode }: ConfigEnv): UserConfig => { + const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR } = loadEnv(mode) + + const alias: Record = { + '/@': pathResolve('./src/'), + assets: pathResolve('./src/assets'), + 'vue-i18n': isProd(mode) ? 'vue-i18n/dist/vue-i18n.cjs.prod.js' : 'vue-i18n/dist/vue-i18n.cjs.js', + } + + return { + plugins: [vue(), svgBuilder('./src/assets/icons/')], + root: process.cwd(), + resolve: { alias }, + base: VITE_BASE_PATH, + server: { + host: '0.0.0.0', + port: VITE_PORT, + open: VITE_OPEN, + }, + build: { + sourcemap: false, + outDir: VITE_OUT_DIR, + emptyOutDir: true, + chunkSizeWarningLimit: 1500, + }, + css: { + postcss: { + plugins: [ + { + postcssPlugin: 'internal:charset-removal', + AtRule: { + charset: (atRule) => { + if (atRule.name === 'charset') { + atRule.remove() + } + }, }, }, - }, - ], + ], + }, }, - }, + } } export default viteConfig