This commit is contained in:
吕才卓 2024-04-06 18:08:11 +08:00
commit 448c0b0e1f
8 changed files with 92 additions and 17 deletions

View File

@ -1,6 +1,6 @@
import sdy from './modules/sdy'
import ycy from './modules/ycy'
export default [
...SDY,
...YCY
...sdy,
...ycy
]

View File

@ -1,2 +1,10 @@
import Mock from "mockjs"
const data = Mock.mock({
"items|10": [
{
"id|+1": 1,
"name": "@cname",
}
]
})
export default []

View File

@ -5,14 +5,27 @@ const StockList = Mock.mock({
"id|+1": "0",
billserial: "@integer(10000000000,19999999999)",
billType: "@integer(0,5)",
stockNum: "前端",
unit: "前端",
stockNum: "@integer(1,2)",
unit: "@cword(张本,1)",
stockDate: "@date",
operator: "@cname",
remark: " @integer(10000000000,19999999999)",
},
],
});
export default [
]
export default [
{
url: "/api/stockList",
method: "get",
response: () => {
const obj = {
list: StockList,
};
return {
code: 200,
data: obj,
};
},
},
];

View File

@ -5,4 +5,4 @@ const API = {
};
export const reqUser = () => request.get(API.LOGIN_URL);
// export const reqUser = (data) => request.post(API.LOGIN_URL, data);
export const reqUserone = (data) => request.post(API.LOGIN_URL, data);

7
src/api/stockList.js Normal file
View File

@ -0,0 +1,7 @@
import request from "@/utils/requestMock";
const API = {
STOCK_LIST: "/stockList",
};
export const reqStockList = () => request.get(API.STOCK_LIST);

View File

@ -35,8 +35,9 @@
</template>
<script setup>
import { reactive, ref } from "vue";
import { reactive, ref, onMounted } from "vue";
import { MessagePlugin } from "tdesign-vue-next";
import { reqStockList } from "@/api/stockList";
const tableData = ref();
const columns = ref([
@ -109,6 +110,10 @@ const onSubmit = ({ validateResult, firstError }) => {
MessagePlugin.warning(firstError);
}
};
onMounted(() => {
reqStockList();
});
</script>
<style scoped lang="less">

51
src/utils/requestMock.js Normal file
View File

@ -0,0 +1,51 @@
// 进行axios二次封装使用请求与响应拦截器
import axios from "axios";
import { MessagePlugin } from "tdesign-vue-next";
// 第一步:利用axios对象的create方法去创建axios实例(其他的配置:基础的路径、超时的时间)
const request = axios.create({
baseURL: "/api", // 基础路径上会携带/api
timeout: 5000, // 超时的时间的设置
});
// 第二步axios实例添加请求与响应拦截器
request.interceptors.request.use((config) => {
return config;
});
// 第三步axios响应拦截器
request.interceptors.response.use(
(response) => {
// 成功回调
// 简化数据
return response.data;
},
async (error) => {
// 失败回调处理http网络错误的
// 定义一个变量:存储网络错误信息
let message = "";
const { status } = error.response;
// http状态码
switch (status) {
case 401:
message = "TOKEN过期";
break;
case 403:
message = "无权访问";
break;
case 404:
message = "请求地址错误";
break;
case 500:
message = "服务器出现问题";
break;
default:
message = "网络出现问题";
break;
}
MessagePlugin.error(message);
return Promise.reject(error);
}
);
// 对外暴露
export default request;

View File

@ -8,15 +8,6 @@ import { viteMockServe } from "vite-plugin-mock";
// https://vitejs.dev/config/
export default defineConfig({
server: {
proxy: {
"/api": {
target: "http://192.168.1.10:8000",
changeOrigin: true,
},
},
},
plugins: [
vue(),
vueJsx(),