缩小小程序体积
|
|
@ -1,15 +0,0 @@
|
||||||
@font-face {
|
|
||||||
font-family: "SourceHanSansCN-Regular";
|
|
||||||
font-style: normal;
|
|
||||||
src: url("./PingFang_Medium.ttf") format("opentype");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: "SourceHanSansCN-Medium";
|
|
||||||
font-style: normal;
|
|
||||||
src: url("./SourceHanSansCN-Medium.otf") format("opentype");
|
|
||||||
}
|
|
||||||
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
font-family: "SourceHanSansCN-Regular";
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 480 B |
|
Before Width: | Height: | Size: 989 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 233 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 994 B |
|
Before Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 258 B |
|
Before Width: | Height: | Size: 646 B |
|
Before Width: | Height: | Size: 851 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 106 KiB |
|
Before Width: | Height: | Size: 701 B |
|
Before Width: | Height: | Size: 234 B |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 470 B |
|
Before Width: | Height: | Size: 707 B |
|
Before Width: | Height: | Size: 536 B |
|
Before Width: | Height: | Size: 860 B |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 800 B |
|
Before Width: | Height: | Size: 237 KiB |
|
Before Width: | Height: | Size: 639 B |
|
Before Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 416 B |
|
Before Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 839 B |
|
Before Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 388 B |
|
Before Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 735 B |
|
Before Width: | Height: | Size: 142 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 892 B |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 466 B |
|
Before Width: | Height: | Size: 502 B |
|
Before Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 231 B |
|
Before Width: | Height: | Size: 269 B |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 1.7 KiB |
|
|
@ -1,4 +1,4 @@
|
||||||
// const baseURL = "http://192.168.31.25:8060/api";
|
// const baseURL = "http://192.168.31.25:8060/api";
|
||||||
const baseURL = "http://localhost:8060/api";
|
export const baseUrl = "https://cankao.cs.com.cn/apih5";
|
||||||
|
export const baseUrlDataV = "https://cankao.cs.com.cn/zzck_datav";
|
||||||
|
|
||||||
export default baseURL;
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ import { createSSRApp } from "vue";
|
||||||
import pinia from "@/stores/index";
|
import pinia from "@/stores/index";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
import uviewPlus from "@/uni_modules/uview-plus";
|
import uviewPlus from "@/uni_modules/uview-plus";
|
||||||
import "@/assets/fonts/font.css";
|
// import "@/assets/fonts/font.css";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function createApp() {
|
export function createApp() {
|
||||||
const app = createSSRApp(App);
|
const app = createSSRApp(App);
|
||||||
|
|
|
||||||
|
|
@ -123,12 +123,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, onUnmounted, reactive } from "vue";
|
import { ref, onMounted, onUnmounted, reactive } from "vue";
|
||||||
import Line from "@/components/charts/Line.vue";
|
import Line from "@/components/charts/Line.vue";
|
||||||
// import bannerImg from "https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/banner_pic.png";
|
|
||||||
// import bannerTitle from "https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/banner_title.png";
|
|
||||||
// import tagicon_1_bg from "https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/tagicon_1_bg.png";
|
|
||||||
// import tagicon_2_bg from "https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/tagicon_2_bg.png";
|
|
||||||
// import tagicon_1 from "https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/tagicon_1.png";
|
|
||||||
// import tagicon_2 from "https://cankao.obs.cn-east-3.myhuaweicloud.com/mini/zixun/tagicon_2.png";
|
|
||||||
|
|
||||||
import LoginPopup from "@/components/loginPopup/index.vue";
|
import LoginPopup from "@/components/loginPopup/index.vue";
|
||||||
import { Session } from "@/utils/storage";
|
import { Session } from "@/utils/storage";
|
||||||
|
|
@ -148,6 +142,7 @@ import InfoSummary from "@/components/InfoSummary.vue"; // 路径根据实际调
|
||||||
import indexMenuTitle from "@/components/indexMenuTitle.vue"; // 路径根据实际调整
|
import indexMenuTitle from "@/components/indexMenuTitle.vue"; // 路径根据实际调整
|
||||||
import dayjs from "dayjs/esm/index";
|
import dayjs from "dayjs/esm/index";
|
||||||
import HotIndustryList from "@/components/HotIndustryList.vue"; // 路径根据实际调整
|
import HotIndustryList from "@/components/HotIndustryList.vue"; // 路径根据实际调整
|
||||||
|
import { onLoad } from "@dcloudio/uni-app";
|
||||||
|
|
||||||
const newsList = ref([]);
|
const newsList = ref([]);
|
||||||
|
|
||||||
|
|
@ -265,12 +260,19 @@ onUnmounted(() => {
|
||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
// onMounted(async () => {
|
||||||
|
// initData();
|
||||||
|
// if (!Session.get("token")) {
|
||||||
|
// LoginShow.value = true;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
onLoad(() => {
|
||||||
initData();
|
initData();
|
||||||
if (!Session.get("token")) {
|
if (!Session.get("token")) {
|
||||||
LoginShow.value = true;
|
LoginShow.value = true;
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
import axios from "axios";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
// import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
|
||||||
|
import { Session } from "@/utils/storage";
|
||||||
|
import qs from "qs";
|
||||||
|
|
||||||
|
// 配置新建一个 axios 实例
|
||||||
|
const service = axios.create({
|
||||||
|
baseURL: import.meta.env.VITE_API_URL,
|
||||||
|
timeout: 50000,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
paramsSerializer: {
|
||||||
|
serialize(params) {
|
||||||
|
return qs.stringify(params, { allowDots: true });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加请求拦截器
|
||||||
|
service.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
// 在发送请求之前做些什么 token
|
||||||
|
if (Session.get("token")) {
|
||||||
|
config.headers!["auth-token"] = `${Session.get("token")}`;
|
||||||
|
config.headers!["phone"] = `${Session.get("userPhone")}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
// 对请求错误做些什么
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 添加响应拦截器
|
||||||
|
service.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
// 对响应数据做点什么
|
||||||
|
const res: AxiosResponse = response.data;
|
||||||
|
if (res.code && res.code !== 200) {
|
||||||
|
console.log("提示");
|
||||||
|
uni.showToast({
|
||||||
|
title: res.msg,
|
||||||
|
icon: "error",
|
||||||
|
duration: 2000,
|
||||||
|
});
|
||||||
|
// ElNotification({
|
||||||
|
// title: '提示',
|
||||||
|
// message: 'res.msg',
|
||||||
|
// type: 'error',
|
||||||
|
// });
|
||||||
|
|
||||||
|
// `token` 过期或者账号已在别处登录
|
||||||
|
if (res.code === 401 || res.code === 4001) {
|
||||||
|
Session.clear(); // 清除浏览器全部临时缓存
|
||||||
|
window.location.href = "/"; // 去登录页
|
||||||
|
console.log("你已被登出,请重新登录");
|
||||||
|
// ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
||||||
|
// .then(() => {})
|
||||||
|
// .catch(() => {});
|
||||||
|
}
|
||||||
|
// return Promise.reject(service.interceptors.response);
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
// 对响应错误做点什么
|
||||||
|
if (error.message.indexOf("timeout") != -1) {
|
||||||
|
// ElMessage.error('网络超时');
|
||||||
|
console.log("网络超时");
|
||||||
|
} else if (error.message == "Network Error") {
|
||||||
|
// ElMessage.error('网络连接错误');
|
||||||
|
console.log("网络连接错误");
|
||||||
|
} else {
|
||||||
|
if (error.response.data) {
|
||||||
|
// ElMessage.error(error.response.statusText)
|
||||||
|
console.log("error.response.statusText ===>", error.response.statusText);
|
||||||
|
} else {
|
||||||
|
// ElMessage.error('接口路径找不到')
|
||||||
|
console.log("接口路径找不到");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 导出 axios 实例
|
||||||
|
export default service;
|
||||||
|
|
@ -1,42 +1,26 @@
|
||||||
import axios from "axios";
|
import requestClass from "./requestClass";
|
||||||
import type { AxiosResponse } from "axios";
|
import { baseUrl } from "@/config/index";
|
||||||
// import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
|
|
||||||
import { Session } from "@/utils/storage";
|
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
|
|
||||||
// 配置新建一个 axios 实例
|
const Request = new requestClass();
|
||||||
const service = axios.create({
|
|
||||||
baseURL: import.meta.env.VITE_API_URL,
|
// 请求拦截器
|
||||||
timeout: 50000,
|
Request.interceptors.request((request: any) => {
|
||||||
headers: { "Content-Type": "application/json" },
|
if (request.header.contentType) {
|
||||||
paramsSerializer: {
|
request.header["content-type"] = request.header.contentType;
|
||||||
serialize(params) {
|
delete request.header.contentType;
|
||||||
return qs.stringify(params, { allowDots: true });
|
}
|
||||||
},
|
if (request.method === "GET") {
|
||||||
},
|
request.data = qs.stringify(request.data);
|
||||||
|
request.url = request.url + "?" + request.data;
|
||||||
|
}
|
||||||
|
return request;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 添加请求拦截器
|
// 响应拦截器
|
||||||
service.interceptors.request.use(
|
Request.interceptors.response((response: any) => {
|
||||||
(config) => {
|
|
||||||
// 在发送请求之前做些什么 token
|
|
||||||
if (Session.get("token")) {
|
|
||||||
config.headers!["auth-token"] = `${Session.get("token")}`;
|
|
||||||
config.headers!["phone"] = `${Session.get("userPhone")}`;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
// 对请求错误做些什么
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 添加响应拦截器
|
|
||||||
service.interceptors.response.use(
|
|
||||||
(response) => {
|
|
||||||
// 对响应数据做点什么
|
// 对响应数据做点什么
|
||||||
const res: AxiosResponse = response.data;
|
const res = response.data;
|
||||||
if (res.code && res.code !== 200) {
|
if (res.code && res.code !== 200) {
|
||||||
console.log("提示");
|
console.log("提示");
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
|
|
@ -44,47 +28,30 @@ service.interceptors.response.use(
|
||||||
icon: "error",
|
icon: "error",
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
// ElNotification({
|
|
||||||
// title: '提示',
|
|
||||||
// message: 'res.msg',
|
|
||||||
// type: 'error',
|
|
||||||
// });
|
|
||||||
|
|
||||||
// `token` 过期或者账号已在别处登录
|
// `token` 过期或者账号已在别处登录
|
||||||
if (res.code === 401 || res.code === 4001) {
|
// if (res.code === 401 || res.code === 4001) {
|
||||||
Session.clear(); // 清除浏览器全部临时缓存
|
// Session.clear(); // 清除浏览器全部临时缓存
|
||||||
window.location.href = "/"; // 去登录页
|
// window.location.href = "/"; // 去登录页
|
||||||
console.log("你已被登出,请重新登录");
|
// console.log("你已被登出,请重新登录");
|
||||||
// ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
// }
|
||||||
// .then(() => {})
|
|
||||||
// .catch(() => {});
|
|
||||||
}
|
|
||||||
// return Promise.reject(service.interceptors.response);
|
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
(error) => {
|
|
||||||
// 对响应错误做点什么
|
|
||||||
if (error.message.indexOf("timeout") != -1) {
|
|
||||||
// ElMessage.error('网络超时');
|
|
||||||
console.log("网络超时");
|
|
||||||
} else if (error.message == "Network Error") {
|
|
||||||
// ElMessage.error('网络连接错误');
|
|
||||||
console.log("网络连接错误");
|
|
||||||
} else {
|
|
||||||
if (error.response.data) {
|
|
||||||
// ElMessage.error(error.response.statusText)
|
|
||||||
console.log("error.response.statusText ===>", error.response.statusText);
|
|
||||||
} else {
|
|
||||||
// ElMessage.error('接口路径找不到')
|
|
||||||
console.log("接口路径找不到");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 导出 axios 实例
|
// 设置默认配置
|
||||||
export default service;
|
Request.setConfig((config: any) => {
|
||||||
|
config.baseURL = baseUrl;
|
||||||
|
// config.baseURL = "http://127.0.0.1:8082";
|
||||||
|
if (uni.getStorageSync("token")) {
|
||||||
|
// config.header["Authorization"] = "Bearer " + uni.getStorageSync("token");
|
||||||
|
config.headers!["auth-token"] = uni.getStorageSync("token");
|
||||||
|
config.headers!["phone"] = uni.getStorageSync("token");
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Request;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
import axios from "axios";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
// import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
|
||||||
|
import { Session } from "@/utils/storage";
|
||||||
|
import qs from "qs";
|
||||||
|
|
||||||
|
// 配置新建一个 axios 实例
|
||||||
|
const service = axios.create({
|
||||||
|
baseURL: import.meta.env.VITE_API_DATAV_URL,
|
||||||
|
timeout: 50000,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
paramsSerializer: {
|
||||||
|
serialize(params) {
|
||||||
|
return qs.stringify(params, { allowDots: true });
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 添加请求拦截器
|
||||||
|
service.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
// 在发送请求之前做些什么 token
|
||||||
|
if (Session.get("token")) {
|
||||||
|
config.headers!["auth-token"] = `${Session.get("token")}`;
|
||||||
|
config.headers!["phone"] = `${Session.get("userPhone")}`;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
// 对请求错误做些什么
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 添加响应拦截器
|
||||||
|
service.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
// 对响应数据做点什么
|
||||||
|
const res: AxiosResponse = response.data;
|
||||||
|
if (res.status && res.status !== 200) {
|
||||||
|
console.log("提示");
|
||||||
|
uni.showToast({
|
||||||
|
title: res.msg,
|
||||||
|
icon: "error",
|
||||||
|
duration: 2000,
|
||||||
|
});
|
||||||
|
// ElNotification({
|
||||||
|
// title: '提示',
|
||||||
|
// message: 'res.msg',
|
||||||
|
// type: 'error',
|
||||||
|
// });
|
||||||
|
|
||||||
|
// `token` 过期或者账号已在别处登录
|
||||||
|
if (res.status === 401 || res.status === 4001) {
|
||||||
|
Session.clear(); // 清除浏览器全部临时缓存
|
||||||
|
window.location.href = "/"; // 去登录页
|
||||||
|
console.log("你已被登出,请重新登录");
|
||||||
|
// ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
||||||
|
// .then(() => {})
|
||||||
|
// .catch(() => {});
|
||||||
|
}
|
||||||
|
// return Promise.reject(service.interceptors.response);
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
// 对响应错误做点什么
|
||||||
|
if (error.message.indexOf("timeout") != -1) {
|
||||||
|
// ElMessage.error('网络超时');
|
||||||
|
console.log("网络超时");
|
||||||
|
} else if (error.message == "Network Error") {
|
||||||
|
// ElMessage.error('网络连接错误');
|
||||||
|
console.log("网络连接错误");
|
||||||
|
} else {
|
||||||
|
if (error.response.data) {
|
||||||
|
// ElMessage.error(error.response.statusText)
|
||||||
|
console.log("error.response.statusText ===>", error.response.statusText);
|
||||||
|
} else {
|
||||||
|
// ElMessage.error('接口路径找不到')
|
||||||
|
console.log("接口路径找不到");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// 导出 axios 实例
|
||||||
|
export default service;
|
||||||
|
|
@ -1,90 +1,57 @@
|
||||||
import axios from "axios";
|
import requestClass from "./requestClass";
|
||||||
import type { AxiosResponse } from "axios";
|
import { baseUrlDataV } from "@/config/index";
|
||||||
// import { ElMessage, ElMessageBox, ElNotification } from 'element-plus';
|
|
||||||
import { Session } from "@/utils/storage";
|
|
||||||
import qs from "qs";
|
import qs from "qs";
|
||||||
|
|
||||||
// 配置新建一个 axios 实例
|
const Request = new requestClass();
|
||||||
const service = axios.create({
|
|
||||||
baseURL: import.meta.env.VITE_API_DATAV_URL,
|
// 请求拦截器
|
||||||
timeout: 50000,
|
Request.interceptors.request((request: any) => {
|
||||||
headers: { "Content-Type": "application/json" },
|
if (request.header.contentType) {
|
||||||
paramsSerializer: {
|
request.header["content-type"] = request.header.contentType;
|
||||||
serialize(params) {
|
delete request.header.contentType;
|
||||||
return qs.stringify(params, { allowDots: true });
|
}
|
||||||
},
|
if (request.method === "GET") {
|
||||||
},
|
request.data = qs.stringify(request.data);
|
||||||
|
request.url = request.url + "?" + request.data;
|
||||||
|
}
|
||||||
|
return request;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 添加请求拦截器
|
// 响应拦截器
|
||||||
service.interceptors.request.use(
|
Request.interceptors.response((response: any) => {
|
||||||
(config) => {
|
|
||||||
// 在发送请求之前做些什么 token
|
|
||||||
if (Session.get("token")) {
|
|
||||||
config.headers!["auth-token"] = `${Session.get("token")}`;
|
|
||||||
config.headers!["phone"] = `${Session.get("userPhone")}`;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
// 对请求错误做些什么
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 添加响应拦截器
|
|
||||||
service.interceptors.response.use(
|
|
||||||
(response) => {
|
|
||||||
// 对响应数据做点什么
|
// 对响应数据做点什么
|
||||||
const res: AxiosResponse = response.data;
|
const res = response.data;
|
||||||
if (res.status && res.status !== 200) {
|
if (res.code && res.code !== 200) {
|
||||||
console.log("提示");
|
console.log("提示");
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: res.msg,
|
title: res.msg,
|
||||||
icon: "error",
|
icon: "error",
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
});
|
});
|
||||||
// ElNotification({
|
|
||||||
// title: '提示',
|
|
||||||
// message: 'res.msg',
|
|
||||||
// type: 'error',
|
|
||||||
// });
|
|
||||||
|
|
||||||
// `token` 过期或者账号已在别处登录
|
// `token` 过期或者账号已在别处登录
|
||||||
if (res.status === 401 || res.status === 4001) {
|
// if (res.code === 401 || res.code === 4001) {
|
||||||
Session.clear(); // 清除浏览器全部临时缓存
|
// Session.clear(); // 清除浏览器全部临时缓存
|
||||||
window.location.href = "/"; // 去登录页
|
// window.location.href = "/"; // 去登录页
|
||||||
console.log("你已被登出,请重新登录");
|
// console.log("你已被登出,请重新登录");
|
||||||
// ElMessageBox.alert('你已被登出,请重新登录', '提示', {})
|
// }
|
||||||
// .then(() => {})
|
|
||||||
// .catch(() => {});
|
|
||||||
}
|
|
||||||
// return Promise.reject(service.interceptors.response);
|
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
(error) => {
|
|
||||||
// 对响应错误做点什么
|
|
||||||
if (error.message.indexOf("timeout") != -1) {
|
|
||||||
// ElMessage.error('网络超时');
|
|
||||||
console.log("网络超时");
|
|
||||||
} else if (error.message == "Network Error") {
|
|
||||||
// ElMessage.error('网络连接错误');
|
|
||||||
console.log("网络连接错误");
|
|
||||||
} else {
|
|
||||||
if (error.response.data) {
|
|
||||||
// ElMessage.error(error.response.statusText)
|
|
||||||
console.log("error.response.statusText ===>", error.response.statusText);
|
|
||||||
} else {
|
|
||||||
// ElMessage.error('接口路径找不到')
|
|
||||||
console.log("接口路径找不到");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// 导出 axios 实例
|
// 设置默认配置
|
||||||
export default service;
|
Request.setConfig((config: any) => {
|
||||||
|
config.baseURL = baseUrlDataV;
|
||||||
|
// config.baseURL = "http://127.0.0.1:8082";
|
||||||
|
if (uni.getStorageSync("token")) {
|
||||||
|
// config.header["Authorization"] = "Bearer " + uni.getStorageSync("token");
|
||||||
|
config.headers!["auth-token"] = uni.getStorageSync("token");
|
||||||
|
config.headers!["phone"] = uni.getStorageSync("token");
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Request;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
const config = Symbol("config");
|
||||||
|
const isCompleteURL = Symbol("isCompleteURL");
|
||||||
|
const requestBefore = Symbol("requestBefore");
|
||||||
|
const requestAfter = Symbol("requestAfter");
|
||||||
|
|
||||||
|
class requestClass {
|
||||||
|
// 默认配置
|
||||||
|
[config]: { baseURL?: string } & UniApp.RequestOptions = {
|
||||||
|
baseURL: "",
|
||||||
|
url: "",
|
||||||
|
header: {
|
||||||
|
// "content-type": "application/x-www-form-urlencoded",
|
||||||
|
"content-type": "application/json",
|
||||||
|
},
|
||||||
|
method: "GET",
|
||||||
|
timeout: 3000,
|
||||||
|
dataType: "json",
|
||||||
|
responseType: "text",
|
||||||
|
};
|
||||||
|
|
||||||
|
// 拦截器
|
||||||
|
interceptors = {
|
||||||
|
request: (func: Fn) => {
|
||||||
|
if (func) {
|
||||||
|
requestClass[requestBefore] = func;
|
||||||
|
} else {
|
||||||
|
requestClass[requestBefore] = (request) => request;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
response: (func: Fn) => {
|
||||||
|
if (func) {
|
||||||
|
requestClass[requestAfter] = func;
|
||||||
|
} else {
|
||||||
|
requestClass[requestAfter] = (response) => response;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 请求之前,是默认配置
|
||||||
|
static [requestBefore](config: UniApp.RequestOptions) {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
// 请求之后,默认配置发生改变的话
|
||||||
|
static [requestAfter](response: any) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
// 判断url是否完整
|
||||||
|
static [isCompleteURL](url: string) {
|
||||||
|
return /(http|https):\/\/([\w.]+\/?)\S*/.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
request(options: UniApp.RequestOptions & { baseURL?: string }) {
|
||||||
|
options.baseURL = options.baseURL || this[config].baseURL;
|
||||||
|
options.dataType = options.dataType || this[config].dataType;
|
||||||
|
options.url = requestClass[isCompleteURL](options.url)
|
||||||
|
? options.url
|
||||||
|
: options.baseURL + options.url;
|
||||||
|
options.data = options.data;
|
||||||
|
options.header = { ...options.header, ...this[config].header };
|
||||||
|
options.method = options.method || this[config].method;
|
||||||
|
|
||||||
|
options = { ...options, ...requestClass[requestBefore](options) };
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
options.success = function (res) {
|
||||||
|
resolve(requestClass[requestAfter](res));
|
||||||
|
};
|
||||||
|
options.fail = function (err) {
|
||||||
|
reject(requestClass[requestAfter](err));
|
||||||
|
};
|
||||||
|
uni.request(options);
|
||||||
|
// 中断请求实现方法
|
||||||
|
// let obj: any = {}
|
||||||
|
// obj[request.url] = uni.request(options)
|
||||||
|
// abortRequest() {
|
||||||
|
// for (const key in obj) {
|
||||||
|
// if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
|
// const element = obj[key];
|
||||||
|
// element.abort()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get(url: string, data: any = {}, options: Recordable = {}) {
|
||||||
|
return this.request({ ...options, url, data, method: "GET" });
|
||||||
|
}
|
||||||
|
|
||||||
|
post(url: string, data: any = {}, options: Recordable = {}) {
|
||||||
|
return this.request({ ...options, url, data, method: "POST" });
|
||||||
|
}
|
||||||
|
|
||||||
|
put(url: string, data: any = {}, options: Recordable = {}) {
|
||||||
|
return this.request({ ...options, url, data, method: "PUT" });
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(url: string, data: any = {}, options: Recordable = {}) {
|
||||||
|
return this.request({ ...options, url, data, method: "DELETE" });
|
||||||
|
}
|
||||||
|
|
||||||
|
getConfig() {
|
||||||
|
return this[config];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改默认配置的一个方法,可以修改请求地址,请求方式等等..
|
||||||
|
setConfig(func: Fn) {
|
||||||
|
this[config] = func(this[config]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default requestClass;
|
||||||