mirror of
https://gitee.com/wonderful-code/buildadmin
synced 2024-11-21 22:55:36 +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;
|
namespace app\admin\controller;
|
||||||
|
|
||||||
class Index
|
use app\common\controller\Backend;
|
||||||
|
|
||||||
|
class Index extends Backend
|
||||||
{
|
{
|
||||||
public function index()
|
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 [
|
return [
|
||||||
// 允许跨域访问的域名
|
// 允许跨域访问的域名
|
||||||
'cors_request_domain' => 'localhost,127.0.0.1',
|
'cors_request_domain' => 'localhost,127.0.0.1',
|
||||||
|
'admin_login_captcha' => true,
|
||||||
// 允许执行的命令
|
// 允许执行的命令
|
||||||
'allowed_commands' => [
|
'allowed_commands' => [
|
||||||
'ping-baidu' => 'ping baidu.com',
|
'ping-baidu' => 'ping baidu.com',
|
||||||
|
@ -3,3 +3,6 @@ ENV = 'development'
|
|||||||
|
|
||||||
# base路径
|
# base路径
|
||||||
VITE_BASE_PATH = './'
|
VITE_BASE_PATH = './'
|
||||||
|
|
||||||
|
# 本地环境接口地址 - 尾部无需带'/'
|
||||||
|
VITE_AXIOS_BASE_URL = 'http://localhost:8000'
|
||||||
|
@ -8,3 +8,6 @@ VITE_BASE_PATH = '/'
|
|||||||
|
|
||||||
# 导出路径
|
# 导出路径
|
||||||
VITE_OUT_DIR = '../dist/'
|
VITE_OUT_DIR = '../dist/'
|
||||||
|
|
||||||
|
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
|
||||||
|
VITE_AXIOS_BASE_URL = 'getCurrentDomain'
|
||||||
|
@ -6,3 +6,6 @@ VITE_BASE_PATH = '/'
|
|||||||
|
|
||||||
# 导出路径
|
# 导出路径
|
||||||
VITE_OUT_DIR = 'dist'
|
VITE_OUT_DIR = 'dist'
|
||||||
|
|
||||||
|
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
|
||||||
|
VITE_AXIOS_BASE_URL = 'getCurrentDomain'
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^0.2.4",
|
"@element-plus/icons-vue": "^0.2.4",
|
||||||
"@vueuse/core": "^7.5.3",
|
"@vueuse/core": "^7.5.3",
|
||||||
|
"axios": "^0.26.0",
|
||||||
"countup.js": "^2.0.8",
|
"countup.js": "^2.0.8",
|
||||||
"echarts": "^5.2.2",
|
"echarts": "^5.2.2",
|
||||||
"element-plus": "^1.3.0-beta.3",
|
"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_OPEN: boolean
|
||||||
VITE_BASE_PATH: string
|
VITE_BASE_PATH: string
|
||||||
VITE_OUT_DIR: 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 {
|
export function isDev(mode: string): boolean {
|
||||||
@ -13,14 +18,13 @@ export function isDev(mode: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isProd(mode: string | undefined): 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
|
// Read all environment variable configuration files to process.env
|
||||||
export function loadEnv(): ViteEnv {
|
export function loadEnv(mode: string): ViteEnv {
|
||||||
const env = process.env.NODE_ENV
|
|
||||||
const ret: any = {}
|
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) => {
|
envList.forEach((e) => {
|
||||||
dotenv.config({ path: e })
|
dotenv.config({ path: e })
|
||||||
})
|
})
|
||||||
|
@ -94,6 +94,7 @@ import type { ElForm } from 'element-plus'
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { editDefaultLang } from '/@/lang/index'
|
import { editDefaultLang } from '/@/lang/index'
|
||||||
import { useStore } from '/@/store/index'
|
import { useStore } from '/@/store/index'
|
||||||
|
import { login } from '/@/api/backend'
|
||||||
|
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
@ -177,6 +178,13 @@ const onSubmit = (formEl: InstanceType<typeof ElForm> | undefined) => {
|
|||||||
formEl.validate((valid) => {
|
formEl.validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
form.loading = true
|
form.loading = true
|
||||||
|
login(form)
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err)
|
||||||
|
})
|
||||||
console.log(form)
|
console.log(form)
|
||||||
} else {
|
} else {
|
||||||
console.log('error submit!')
|
console.log('error submit!')
|
||||||
|
@ -1,54 +1,56 @@
|
|||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import type { UserConfig } from 'vite'
|
import type { UserConfig, ConfigEnv } from 'vite'
|
||||||
import { isProd, loadEnv } from '/@/utils/vite'
|
import { isProd, loadEnv } from '/@/utils/vite'
|
||||||
import { svgBuilder } from '/@/components/icon/svg/index'
|
import { svgBuilder } from '/@/components/icon/svg/index'
|
||||||
|
|
||||||
const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR } = loadEnv()
|
|
||||||
|
|
||||||
const pathResolve = (dir: string): any => {
|
const pathResolve = (dir: string): any => {
|
||||||
return resolve(__dirname, '.', dir)
|
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/
|
// https://vitejs.cn/config/
|
||||||
const viteConfig: UserConfig = {
|
const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
|
||||||
plugins: [vue(), svgBuilder('./src/assets/icons/')],
|
const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR } = loadEnv(mode)
|
||||||
root: process.cwd(),
|
|
||||||
resolve: { alias },
|
const alias: Record<string, string> = {
|
||||||
base: VITE_BASE_PATH,
|
'/@': pathResolve('./src/'),
|
||||||
server: {
|
assets: pathResolve('./src/assets'),
|
||||||
host: '0.0.0.0',
|
'vue-i18n': isProd(mode) ? 'vue-i18n/dist/vue-i18n.cjs.prod.js' : 'vue-i18n/dist/vue-i18n.cjs.js',
|
||||||
port: VITE_PORT,
|
}
|
||||||
open: VITE_OPEN,
|
|
||||||
},
|
return {
|
||||||
build: {
|
plugins: [vue(), svgBuilder('./src/assets/icons/')],
|
||||||
sourcemap: false,
|
root: process.cwd(),
|
||||||
outDir: VITE_OUT_DIR,
|
resolve: { alias },
|
||||||
emptyOutDir: true,
|
base: VITE_BASE_PATH,
|
||||||
chunkSizeWarningLimit: 1500,
|
server: {
|
||||||
},
|
host: '0.0.0.0',
|
||||||
css: {
|
port: VITE_PORT,
|
||||||
postcss: {
|
open: VITE_OPEN,
|
||||||
plugins: [
|
},
|
||||||
{
|
build: {
|
||||||
postcssPlugin: 'internal:charset-removal',
|
sourcemap: false,
|
||||||
AtRule: {
|
outDir: VITE_OUT_DIR,
|
||||||
charset: (atRule) => {
|
emptyOutDir: true,
|
||||||
if (atRule.name === 'charset') {
|
chunkSizeWarningLimit: 1500,
|
||||||
atRule.remove()
|
},
|
||||||
}
|
css: {
|
||||||
|
postcss: {
|
||||||
|
plugins: [
|
||||||
|
{
|
||||||
|
postcssPlugin: 'internal:charset-removal',
|
||||||
|
AtRule: {
|
||||||
|
charset: (atRule) => {
|
||||||
|
if (atRule.name === 'charset') {
|
||||||
|
atRule.remove()
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
],
|
||||||
],
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default viteConfig
|
export default viteConfig
|
||||||
|
Loading…
Reference in New Issue
Block a user