mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 06:29:50 +00:00
feat:web端接口初步整合
This commit is contained in:
parent
933f7101e4
commit
c2c4326d7b
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
app/admin/library/Auth.php
Normal file
8
app/admin/library/Auth.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\library;
|
||||
|
||||
class Auth
|
||||
{
|
||||
|
||||
}
|
5
app/admin/middleware.php
Normal file
5
app/admin/middleware.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
\app\common\library\AllowCrossDomain::class,
|
||||
\think\middleware\LoadLangPack::class,
|
||||
];
|
16
app/common/controller/Backend.php
Normal file
16
app/common/controller/Backend.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use app\admin\library\Auth;
|
||||
|
||||
class Backend extends Api
|
||||
{
|
||||
protected $noNeedLogin = [];
|
||||
protected $noNeedPermission = [];
|
||||
|
||||
protected $auth = null;
|
||||
|
||||
protected $model = null;
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
return [
|
||||
// 允许跨域访问的域名
|
||||
'cors_request_domain' => 'localhost,127.0.0.1',
|
||||
'admin_login_captcha' => true,
|
||||
// 允许执行的命令
|
||||
'allowed_commands' => [
|
||||
'ping-baidu' => 'ping baidu.com',
|
||||
|
@ -3,3 +3,6 @@ ENV = 'development'
|
||||
|
||||
# base路径
|
||||
VITE_BASE_PATH = './'
|
||||
|
||||
# 本地环境接口地址 - 尾部无需带'/'
|
||||
VITE_AXIOS_BASE_URL = 'http://localhost:8000'
|
||||
|
@ -8,3 +8,6 @@ VITE_BASE_PATH = '/'
|
||||
|
||||
# 导出路径
|
||||
VITE_OUT_DIR = '../dist/'
|
||||
|
||||
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
|
||||
VITE_AXIOS_BASE_URL = 'getCurrentDomain'
|
||||
|
@ -6,3 +6,6 @@ VITE_BASE_PATH = '/'
|
||||
|
||||
# 导出路径
|
||||
VITE_OUT_DIR = 'dist'
|
||||
|
||||
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
|
||||
VITE_AXIOS_BASE_URL = 'getCurrentDomain'
|
||||
|
@ -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",
|
||||
|
9
web/src/api/backend/index.ts
Normal file
9
web/src/api/backend/index.ts
Normal file
@ -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
|
||||
})
|
||||
}
|
24
web/src/utils/axios.ts
Normal file
24
web/src/utils/axios.ts
Normal file
@ -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
|
@ -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 })
|
||||
})
|
||||
|
@ -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<typeof ElForm> | 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!')
|
||||
|
@ -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<string, string> = {
|
||||
'/@': 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<string, string> = {
|
||||
'/@': 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
|
||||
|
Loading…
Reference in New Issue
Block a user