大屏页面布局
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 登录接口(无需token,不被拦截)
|
||||
* @param {Object} data - 登录参数 {username, password}
|
||||
* @returns {Promise} 登录结果(含token)
|
||||
* 登录接口
|
||||
*/
|
||||
export function login(data) {
|
||||
return request({
|
||||
url: 'userLogin', // 后端登录接口路径
|
||||
url: 'userLogin',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
@@ -15,7 +13,6 @@ export function login(data) {
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function logout() {
|
||||
return request({
|
||||
@@ -26,7 +23,6 @@ export function logout() {
|
||||
|
||||
/**
|
||||
* 获取当前用户信息(需要token验证)
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function getUserInfo() {
|
||||
return request({
|
||||
|
||||
@@ -10,41 +10,40 @@ const service = axios.create({
|
||||
}
|
||||
})
|
||||
|
||||
// 请求拦截器:添加token
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
// 登录接口不添加token
|
||||
if (!config.url.includes('/userLogin')) {
|
||||
const token = localStorage.getItem('token')
|
||||
if (!config.url?.includes('/userLogin')) {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers.Authorization = token
|
||||
config.headers.Authorization = token;
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => Promise.reject(error)
|
||||
)
|
||||
|
||||
// 响应拦截器:处理401未登录
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
const res = response.data
|
||||
if (res.code !== 200) {
|
||||
if (res.code === 401) {
|
||||
ElMessage.error(res.msg)
|
||||
localStorage.removeItem('token')
|
||||
router.push('/login')
|
||||
return Promise.reject(res)
|
||||
}
|
||||
ElMessage.error(res.msg || '请求失败')
|
||||
return Promise.reject(res)
|
||||
}
|
||||
return res.data
|
||||
},
|
||||
(error) => {
|
||||
ElMessage.error(error.message || '网络异常')
|
||||
console.error('【请求拦截器错误】', error);
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
const res = response.data;
|
||||
if (res.code !== 200) {
|
||||
ElMessage.error(res.msg || '接口请求失败');
|
||||
if (res.code === 401) {
|
||||
localStorage.removeItem('token');
|
||||
router.push('/login').catch(err => console.warn('路由跳转失败', err));
|
||||
}
|
||||
return Promise.reject(res);
|
||||
}
|
||||
return res.data;
|
||||
},
|
||||
(error) => {
|
||||
console.error('【响应拦截器错误】', error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
)
|
||||
|
||||
export default service
|
||||
@@ -14,13 +14,15 @@ export default defineConfig({
|
||||
'@': path.resolve(__dirname, './src')
|
||||
}
|
||||
},
|
||||
// 开发环境代理(适配后端接口)
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 5173,
|
||||
open: true,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:31001',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -28,6 +30,7 @@ export default defineConfig({
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
base: '/',
|
||||
assetsDir: 'assets'
|
||||
assetsDir: 'assets',
|
||||
chunkSizeWarningLimit: 1500
|
||||
}
|
||||
})
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.mini.mybigscreen.Model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ItemRequest implements Serializable {
|
||||
|
||||
private String itemCode;
|
||||
private String reqParam;
|
||||
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.mini.mybigscreen.biz.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mini.mybigscreen.Model.ItemRequest;
|
||||
import com.mini.mybigscreen.Model.Result;
|
||||
import com.mini.mybigscreen.biz.domain.ItemInfo;
|
||||
import com.mini.mybigscreen.biz.service.ItemInfoService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -30,11 +29,11 @@ public class ItemInfoController {
|
||||
|
||||
|
||||
@GetMapping("list")
|
||||
public List<ItemInfo> getList(@RequestBody ItemRequest itemRequest) {
|
||||
public Result<List<ItemInfo>> getList(String itemCode,String reqParam) {
|
||||
QueryWrapper<ItemInfo> query = new QueryWrapper<>();
|
||||
query.eq("item_code", itemRequest.getItemCode())
|
||||
.eq("req_param", itemRequest.getReqParam());
|
||||
return infoService.list(query);
|
||||
query.eq("item_code", itemCode)
|
||||
.eq("req_param", reqParam);
|
||||
return Result.success(infoService.list(query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user