submit
This commit is contained in:
parent
4a73f5f51d
commit
99dc5eac39
8
package-lock.json
generated
8
package-lock.json
generated
@ -23,9 +23,12 @@
|
|||||||
"@dcloudio/uni-mp-weixin": "3.0.0-3090820231124001",
|
"@dcloudio/uni-mp-weixin": "3.0.0-3090820231124001",
|
||||||
"@dcloudio/uni-mp-xhs": "3.0.0-3090820231124001",
|
"@dcloudio/uni-mp-xhs": "3.0.0-3090820231124001",
|
||||||
"@dcloudio/uni-quickapp-webview": "3.0.0-3090820231124001",
|
"@dcloudio/uni-quickapp-webview": "3.0.0-3090820231124001",
|
||||||
|
"@xingyy/uni-fetch": "^1.0.2",
|
||||||
"echarts": "5.4.2",
|
"echarts": "5.4.2",
|
||||||
"node-sass": "^9.0.0",
|
"node-sass": "^9.0.0",
|
||||||
"pinia": " 2.0.33",
|
"pinia": " 2.0.33",
|
||||||
|
"sass": "^1.69.5",
|
||||||
|
"sass-loader": "^13.3.2",
|
||||||
"vue": "3.2.47",
|
"vue": "3.2.47",
|
||||||
"vue-i18n": "9.8.0"
|
"vue-i18n": "9.8.0"
|
||||||
},
|
},
|
||||||
@ -4562,6 +4565,11 @@
|
|||||||
"@xtuc/long": "4.2.2"
|
"@xtuc/long": "4.2.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@xingyy/uni-fetch": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@xingyy/uni-fetch/-/uni-fetch-1.0.2.tgz",
|
||||||
|
"integrity": "sha512-NCJq9IeyxpNl1G3VsWq6jgwkZSyBNeCQn5S8R5pmqn4+Gg+gy4y05RoowW0QtnW/DCvRYE7cMKwPh9JevCQu1g=="
|
||||||
|
},
|
||||||
"node_modules/@xtuc/ieee754": {
|
"node_modules/@xtuc/ieee754": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz",
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
"@dcloudio/uni-mp-weixin": "3.0.0-3090820231124001",
|
"@dcloudio/uni-mp-weixin": "3.0.0-3090820231124001",
|
||||||
"@dcloudio/uni-mp-xhs": "3.0.0-3090820231124001",
|
"@dcloudio/uni-mp-xhs": "3.0.0-3090820231124001",
|
||||||
"@dcloudio/uni-quickapp-webview": "3.0.0-3090820231124001",
|
"@dcloudio/uni-quickapp-webview": "3.0.0-3090820231124001",
|
||||||
|
"@xingyy/uni-fetch": "^1.0.2",
|
||||||
"echarts": "5.4.2",
|
"echarts": "5.4.2",
|
||||||
"node-sass": "^9.0.0",
|
"node-sass": "^9.0.0",
|
||||||
"pinia": " 2.0.33",
|
"pinia": " 2.0.33",
|
||||||
|
23
src/http/init.ts
Normal file
23
src/http/init.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import {uniFetch} from "@/http/main";
|
||||||
|
const fetch=new uniFetch({
|
||||||
|
baseUrl:'https://warehouse.szjixun.cn',
|
||||||
|
interceptors:{
|
||||||
|
//请求拦截器
|
||||||
|
request(config ){
|
||||||
|
|
||||||
|
},
|
||||||
|
//响应拦截器
|
||||||
|
response(response){
|
||||||
|
if (response.data?.status === 401) {
|
||||||
|
let curPage = getCurrentPages();
|
||||||
|
let route = curPage[curPage.length - 1].route; //获取当前页面的路由
|
||||||
|
if (route !== "pages/login/login") {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: "/pages/login/login",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
export default fetch
|
@ -1,8 +1,8 @@
|
|||||||
import http from "./interface";
|
|
||||||
|
|
||||||
|
import fetch from "@/http/init";
|
||||||
// openId
|
// openId
|
||||||
export const login = (data) => {
|
export const login = (data) => {
|
||||||
return http.request({
|
return fetch.request({
|
||||||
url: "/api/wxuser/openid",
|
url: "/api/wxuser/openid",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data,
|
data,
|
||||||
@ -10,7 +10,7 @@ export const login = (data) => {
|
|||||||
};
|
};
|
||||||
// 获取手机号
|
// 获取手机号
|
||||||
export const getTel = (data) => {
|
export const getTel = (data) => {
|
||||||
return http.request({
|
return fetch.request({
|
||||||
url: "/api/wxuser/get/telnum",
|
url: "/api/wxuser/get/telnum",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data,
|
data,
|
||||||
@ -18,7 +18,7 @@ export const getTel = (data) => {
|
|||||||
};
|
};
|
||||||
// 注册
|
// 注册
|
||||||
export const register = (data) => {
|
export const register = (data) => {
|
||||||
return http.request({
|
return fetch.request({
|
||||||
url: "/api/wxuser/register",
|
url: "/api/wxuser/register",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data,
|
data,
|
||||||
@ -26,7 +26,7 @@ export const register = (data) => {
|
|||||||
};
|
};
|
||||||
// 身份验证
|
// 身份验证
|
||||||
export const chenckId = (data) => {
|
export const chenckId = (data) => {
|
||||||
return http.request({
|
return fetch.request({
|
||||||
url: "/api/wxuser/ocr",
|
url: "/api/wxuser/ocr",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data,
|
data,
|
||||||
@ -34,7 +34,7 @@ export const chenckId = (data) => {
|
|||||||
};
|
};
|
||||||
// 法大大
|
// 法大大
|
||||||
export const fddRealName = (data) => {
|
export const fddRealName = (data) => {
|
||||||
return http.request({
|
return fetch.request({
|
||||||
url: "/api/wxuser/bind/fdd",
|
url: "/api/wxuser/bind/fdd",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
data,
|
data,
|
||||||
@ -42,7 +42,7 @@ export const fddRealName = (data) => {
|
|||||||
};
|
};
|
||||||
//法大大是否验证
|
//法大大是否验证
|
||||||
export const checkFdd = () => {
|
export const checkFdd = () => {
|
||||||
return http.request({
|
return fetch.request({
|
||||||
url: "/api/wxuser/fdd/check",
|
url: "/api/wxuser/fdd/check",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
});
|
});
|
||||||
|
147
src/http/main.ts
Normal file
147
src/http/main.ts
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
type HttpMethod =
|
||||||
|
| "GET"
|
||||||
|
| 'get'
|
||||||
|
| "POST"
|
||||||
|
| 'post'
|
||||||
|
| "PUT"
|
||||||
|
| 'put'
|
||||||
|
| "DELETE"
|
||||||
|
| 'delete'
|
||||||
|
| "PATCH"
|
||||||
|
| 'patch'
|
||||||
|
| "OPTIONS"
|
||||||
|
| 'options'
|
||||||
|
| "HEAD"
|
||||||
|
| 'head'
|
||||||
|
| "TRACE"
|
||||||
|
| 'trace'
|
||||||
|
| "CONNECT"
|
||||||
|
| 'connect';
|
||||||
|
interface RequestOptions {
|
||||||
|
baseUrl?: string;
|
||||||
|
dataType?: string;
|
||||||
|
url: string;
|
||||||
|
data?: Record<string, any>;
|
||||||
|
method?: HttpMethod;
|
||||||
|
header?: Record<string, string>;
|
||||||
|
params?: Record<string, any>; // 新增的参数字段
|
||||||
|
}
|
||||||
|
type RequestInterceptor = (config: RequestOptions) => RequestOptions;
|
||||||
|
type ResponseInterceptor = (response: any) => any;
|
||||||
|
interface Interceptors{
|
||||||
|
request:(config: RequestOptions)=>{},
|
||||||
|
response:(response:any)=>{}
|
||||||
|
}
|
||||||
|
class uniFetch {
|
||||||
|
baseUrl: string;
|
||||||
|
defaultHeader: Record<string, string>;
|
||||||
|
interceptors: { request: RequestInterceptor | null; response: ResponseInterceptor | null };
|
||||||
|
constructor({ baseUrl = '', defaultHeader = {}, interceptors = { request: null, response: null } }: {
|
||||||
|
baseUrl?: string;
|
||||||
|
defaultHeader?: Record<string, string>;
|
||||||
|
interceptors?: Interceptors;
|
||||||
|
}) {
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
this.defaultHeader = {
|
||||||
|
"Content-Type": "application/json;charset=UTF-8",
|
||||||
|
...defaultHeader,
|
||||||
|
};
|
||||||
|
this.interceptors = interceptors;
|
||||||
|
}
|
||||||
|
|
||||||
|
setBaseUrl(baseUrl: string): void {
|
||||||
|
this.baseUrl = baseUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDefaultHeader(header: Record<string, string>): void {
|
||||||
|
this.defaultHeader = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
request(options: RequestOptions): Promise<any> {
|
||||||
|
options = options || {};
|
||||||
|
options.baseUrl = options.baseUrl || this.baseUrl;
|
||||||
|
options.dataType = options.dataType || "json";
|
||||||
|
options.url = options.baseUrl + options.url;
|
||||||
|
options.data = options.data || {};
|
||||||
|
options.method = options.method || "GET";
|
||||||
|
options.header = options.header || this.defaultHeader;
|
||||||
|
if (this.interceptors.request) {
|
||||||
|
options = this.interceptors.request(options);
|
||||||
|
}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.request({
|
||||||
|
...options,
|
||||||
|
success: (res) => {
|
||||||
|
const response = this.handleResponse(res);
|
||||||
|
resolve(response);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
const error = this.handleError(err);
|
||||||
|
reject(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleResponse(response: any): any {
|
||||||
|
// 执行响应拦截器(如果有)
|
||||||
|
if (this.interceptors.response) {
|
||||||
|
response = this.interceptors.response(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusCode = response.statusCode;
|
||||||
|
if (statusCode === 200) {
|
||||||
|
return response.data;
|
||||||
|
} else {
|
||||||
|
throw response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleError(error: any): any {
|
||||||
|
// 在这里处理错误
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRequestInterceptor(interceptor: RequestInterceptor): void {
|
||||||
|
this.interceptors.request = interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
setResponseInterceptor(interceptor: ResponseInterceptor): void {
|
||||||
|
this.interceptors.response = interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
get(options: RequestOptions): Promise<any> {
|
||||||
|
options = options || {};
|
||||||
|
options.method = "GET";
|
||||||
|
return this.request(this.buildRequestOptions(options));
|
||||||
|
}
|
||||||
|
|
||||||
|
private buildRequestOptions(options: RequestOptions): RequestOptions {
|
||||||
|
if (options.params) {
|
||||||
|
const queryString = Object.keys(options.params)
|
||||||
|
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(options.params[key])}`)
|
||||||
|
.join('&');
|
||||||
|
options.url += `?${queryString}`;
|
||||||
|
}
|
||||||
|
delete options.params;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
post(options: RequestOptions): Promise<any> {
|
||||||
|
options = options || {};
|
||||||
|
options.method = "POST";
|
||||||
|
return this.request(this.buildRequestOptions(options));
|
||||||
|
}
|
||||||
|
put(options: RequestOptions): Promise<any> {
|
||||||
|
options = options || {};
|
||||||
|
options.method = "PUT";
|
||||||
|
return this.request(this.buildRequestOptions(options));
|
||||||
|
}
|
||||||
|
delete(options: RequestOptions): Promise<any> {
|
||||||
|
options = options || {};
|
||||||
|
options.method = "DELETE";
|
||||||
|
return this.request(this.buildRequestOptions(options));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export { uniFetch}
|
@ -15,6 +15,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/login/index",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "",
|
||||||
|
"enablePullDownRefresh": false,
|
||||||
|
"app-plus": {
|
||||||
|
"titleNView": false // 禁用原生导航
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/setup/index",
|
"path": "pages/setup/index",
|
||||||
"style": {
|
"style": {
|
||||||
|
@ -288,7 +288,6 @@ background-image: url('https://cdns.fontree.cn/fonchain-main/prod/image/1833/ava
|
|||||||
height: 100rpx;
|
height: 100rpx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user