submit
This commit is contained in:
parent
f62148c7f5
commit
acd816b2e3
@ -6,7 +6,6 @@
|
||||
<div class="wrap2">{{ title }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup >
|
||||
import { ref } from 'vue'
|
||||
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight + 5)
|
||||
|
@ -1,24 +1,20 @@
|
||||
import {uniFetch} from "@/http/main";
|
||||
const fetch = new uniFetch({
|
||||
baseUrl: 'https://warehouse.szjixun.cn',
|
||||
interceptors: {
|
||||
//请求拦截器
|
||||
request(config) {
|
||||
requestInterceptor:(config)=>{
|
||||
return config
|
||||
},
|
||||
//响应拦截器
|
||||
response(response) {
|
||||
responseInterceptor:(response)=>{
|
||||
if (response.data?.status === 401) {
|
||||
let curPage = getCurrentPages();
|
||||
let route = curPage[curPage.length - 1].route; //获取当前页面的路由
|
||||
if (route !== "pages/login/login") {
|
||||
if (route !== "pages/login/index") {
|
||||
uni.navigateTo({
|
||||
url: "/pages/login/login",
|
||||
url: "/pages/login/index",
|
||||
});
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
})
|
||||
export default fetch
|
||||
|
@ -1,18 +1,19 @@
|
||||
type HttpMethod =
|
||||
| "GET"
|
||||
| 'GET'
|
||||
| 'get'
|
||||
| "POST"
|
||||
| 'POST'
|
||||
| 'post'
|
||||
| "PUT"
|
||||
| 'PUT'
|
||||
| 'put'
|
||||
| "DELETE"
|
||||
| 'DELETE'
|
||||
| 'delete'
|
||||
| "CONNECT"
|
||||
| 'CONNECT'
|
||||
| 'connect'
|
||||
| "OPTIONS"
|
||||
| 'OPTIONS'
|
||||
| 'options'
|
||||
| "TRACE"
|
||||
| 'TRACE'
|
||||
| 'trace';
|
||||
|
||||
interface RequestOptions {
|
||||
baseUrl?: string;
|
||||
url: string;
|
||||
@ -20,24 +21,44 @@ interface RequestOptions {
|
||||
method?: HttpMethod;
|
||||
header?: Record<string, string>;
|
||||
params?: Record<string, any>;
|
||||
timeout?: number,
|
||||
dataType?: string,
|
||||
responseType?: string,
|
||||
sslVerify?: boolean,
|
||||
withCredentials?: boolean
|
||||
firstIpv4?: boolean,
|
||||
enableHttp2?: boolean,
|
||||
enableQuic?: boolean,
|
||||
enableCache?: boolean,
|
||||
enableHttpDNS?: boolean,
|
||||
httpDNSServiceId?: string,
|
||||
enableChunked?: boolean,
|
||||
forceCellularNetwork?: boolean,
|
||||
enableCookie?: boolean,
|
||||
cloudCache?: object | boolean,
|
||||
defer?: boolean,
|
||||
requestInterceptor?: RequestInterceptor,
|
||||
responseInterceptor?: ResponseInterceptor
|
||||
}
|
||||
|
||||
type instantiationParameters = Omit<Omit<RequestOptions, 'baseUrl'>, 'url'> & {
|
||||
baseUrl: string;
|
||||
};
|
||||
type RequestInterceptor = (config: RequestOptions) => RequestOptions;
|
||||
type ResponseInterceptor = (response: any) => 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?: { request: RequestInterceptor | null; response: ResponseInterceptor | null};
|
||||
}) {
|
||||
this.baseUrl = baseUrl;
|
||||
interceptors: { request: RequestInterceptor | undefined; response: ResponseInterceptor | undefined };
|
||||
|
||||
constructor(request: instantiationParameters) {
|
||||
this.baseUrl = request.baseUrl;
|
||||
this.defaultHeader = {
|
||||
"Content-Type": "application/json;charset=UTF-8",
|
||||
...defaultHeader,
|
||||
...request.header,
|
||||
};
|
||||
this.interceptors = interceptors;
|
||||
this.interceptors = {request: request.requestInterceptor, response: request.responseInterceptor};
|
||||
}
|
||||
|
||||
setBaseUrl(baseUrl: string): void {
|
||||
@ -47,14 +68,18 @@ class uniFetch {
|
||||
setDefaultHeader(header: Record<string, string>): void {
|
||||
this.defaultHeader = header;
|
||||
}
|
||||
|
||||
request(options: RequestOptions): Promise<any> {
|
||||
options = this.buildRequestOptions(options)
|
||||
options = options || {};
|
||||
options.baseUrl = options.baseUrl || this.baseUrl;
|
||||
options.url = options.baseUrl + options.url;
|
||||
options.data = options.data || {};
|
||||
options.method = (options.method?.toUpperCase() || "GET") as HttpMethod;
|
||||
options.header = options.header || this.defaultHeader;
|
||||
if (this.interceptors.request) {
|
||||
if (typeof options.requestInterceptor === 'function') {
|
||||
options = options.requestInterceptor(options);
|
||||
} else if (typeof this.interceptors.request === 'function') {
|
||||
options = this.interceptors.request(options);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -77,7 +102,6 @@ class uniFetch {
|
||||
if (this.interceptors.response) {
|
||||
response = this.interceptors.response(response);
|
||||
}
|
||||
|
||||
const statusCode = response.statusCode;
|
||||
if (statusCode === 200) {
|
||||
return response.data;
|
||||
@ -114,20 +138,24 @@ class uniFetch {
|
||||
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}
|
||||
|
||||
export {uniFetch}
|
||||
|
@ -1,5 +1,7 @@
|
||||
<template>
|
||||
<div class="large-container">
|
||||
<title class="title-block" title="智慧门票" :isBack="false">
|
||||
</title>
|
||||
<div class="content1">
|
||||
<div class="wrap1">
|
||||
<div class="wrap1_1">
|
||||
@ -21,7 +23,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="content2">
|
||||
<div class="wrap1 ">
|
||||
<div class="wrap1">
|
||||
<div class="wrap1_1">2</div>
|
||||
<div class="wrap1_2">未使用门票</div>
|
||||
</div>
|
||||
@ -31,9 +33,7 @@
|
||||
<div class="wrap1_2">历史门票</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content3">
|
||||
|
||||
</div>
|
||||
<div class="content3"></div>
|
||||
<div class="content4">·历史预约门票</div>
|
||||
<div class="content5">
|
||||
<div class="wrap1">
|
||||
@ -77,10 +77,11 @@ const goSetUp=()=>{
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.large-container{
|
||||
overflow: hidden;
|
||||
background-image: url('https://cdns.fontree.cn/fonchain-main/prod/image/1833/avatar/16968647-fc99-46fe-b95c-620c55b7646f.png');
|
||||
background-size: 100%;
|
||||
height: 100vh;
|
||||
padding: 38rpx 32rpx 0 32rpx;
|
||||
padding: 0rpx 32rpx 0 32rpx;
|
||||
.content5{
|
||||
margin-top: 14rpx;
|
||||
.wrap1{
|
||||
|
BIN
src/static/zu1105@3x.png
Normal file
BIN
src/static/zu1105@3x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 477 KiB |
Loading…
Reference in New Issue
Block a user