master
xingyy 10 months ago
parent f62148c7f5
commit acd816b2e3

@ -6,7 +6,6 @@
<div class="wrap2">{{ title }}</div> <div class="wrap2">{{ title }}</div>
</div> </div>
</template> </template>
<script setup > <script setup >
import { ref } from 'vue' import { ref } from 'vue'
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight + 5) const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight + 5)

@ -1,24 +1,20 @@
import {uniFetch} from "@/http/main"; import {uniFetch} from "@/http/main";
const fetch = new uniFetch({ const fetch = new uniFetch({
baseUrl: 'https://warehouse.szjixun.cn', baseUrl: 'https://warehouse.szjixun.cn',
interceptors: { requestInterceptor:(config)=>{
//请求拦截器 return config
request(config) { },
return config responseInterceptor:(response)=>{
}, if (response.data?.status === 401) {
//响应拦截器 let curPage = getCurrentPages();
response(response) { let route = curPage[curPage.length - 1].route; //获取当前页面的路由
if (response.data?.status === 401) { if (route !== "pages/login/index") {
let curPage = getCurrentPages(); uni.navigateTo({
let route = curPage[curPage.length - 1].route; //获取当前页面的路由 url: "/pages/login/index",
if (route !== "pages/login/login") { });
uni.navigateTo({
url: "/pages/login/login",
});
}
} }
return response
} }
return response
} }
}) })
export default fetch export default fetch

@ -1,18 +1,19 @@
type HttpMethod = type HttpMethod =
| "GET" | 'GET'
| 'get' | 'get'
| "POST" | 'POST'
| 'post' | 'post'
| "PUT" | 'PUT'
| 'put' | 'put'
| "DELETE" | 'DELETE'
| 'delete' | 'delete'
| "CONNECT" | 'CONNECT'
| 'connect' | 'connect'
| "OPTIONS" | 'OPTIONS'
| 'options' | 'options'
| "TRACE" | 'TRACE'
| 'trace'; | 'trace';
interface RequestOptions { interface RequestOptions {
baseUrl?: string; baseUrl?: string;
url: string; url: string;
@ -20,24 +21,44 @@ interface RequestOptions {
method?: HttpMethod; method?: HttpMethod;
header?: Record<string, string>; header?: Record<string, string>;
params?: Record<string, any>; 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 RequestInterceptor = (config: RequestOptions) => RequestOptions;
type ResponseInterceptor = (response: any) => any; type ResponseInterceptor = (response: any) => any;
class uniFetch { class uniFetch {
baseUrl: string; baseUrl: string;
defaultHeader: Record<string, string>; defaultHeader: Record<string, string>;
interceptors: { request: RequestInterceptor | null; response: ResponseInterceptor | null }; interceptors: { request: RequestInterceptor | undefined; response: ResponseInterceptor | undefined };
constructor({ baseUrl = '', defaultHeader = {}, interceptors = { request: null, response: null } }: {
baseUrl?: string; constructor(request: instantiationParameters) {
defaultHeader?: Record<string, string>; this.baseUrl = request.baseUrl;
interceptors?: { request: RequestInterceptor | null; response: ResponseInterceptor | null};
}) {
this.baseUrl = baseUrl;
this.defaultHeader = { this.defaultHeader = {
"Content-Type": "application/json;charset=UTF-8", "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 { setBaseUrl(baseUrl: string): void {
@ -47,14 +68,18 @@ class uniFetch {
setDefaultHeader(header: Record<string, string>): void { setDefaultHeader(header: Record<string, string>): void {
this.defaultHeader = header; this.defaultHeader = header;
} }
request(options: RequestOptions): Promise<any> { request(options: RequestOptions): Promise<any> {
options = this.buildRequestOptions(options)
options = options || {}; options = options || {};
options.baseUrl = options.baseUrl || this.baseUrl; options.baseUrl = options.baseUrl || this.baseUrl;
options.url = options.baseUrl + options.url; options.url = options.baseUrl + options.url;
options.data = options.data || {}; options.data = options.data || {};
options.method = (options.method?.toUpperCase() || "GET") as HttpMethod; options.method = (options.method?.toUpperCase() || "GET") as HttpMethod;
options.header = options.header || this.defaultHeader; 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); options = this.interceptors.request(options);
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -77,7 +102,6 @@ class uniFetch {
if (this.interceptors.response) { if (this.interceptors.response) {
response = this.interceptors.response(response); response = this.interceptors.response(response);
} }
const statusCode = response.statusCode; const statusCode = response.statusCode;
if (statusCode === 200) { if (statusCode === 200) {
return response.data; return response.data;
@ -114,20 +138,24 @@ class uniFetch {
delete options.params; delete options.params;
return options; return options;
} }
post(options: RequestOptions): Promise<any> { post(options: RequestOptions): Promise<any> {
options = options || {}; options = options || {};
options.method = "POST"; options.method = "POST";
return this.request(this.buildRequestOptions(options)); return this.request(this.buildRequestOptions(options));
} }
put(options: RequestOptions): Promise<any> { put(options: RequestOptions): Promise<any> {
options = options || {}; options = options || {};
options.method = "PUT"; options.method = "PUT";
return this.request(this.buildRequestOptions(options)); return this.request(this.buildRequestOptions(options));
} }
delete(options: RequestOptions): Promise<any> { delete(options: RequestOptions): Promise<any> {
options = options || {}; options = options || {};
options.method = "DELETE"; options.method = "DELETE";
return this.request(this.buildRequestOptions(options)); return this.request(this.buildRequestOptions(options));
} }
} }
export { uniFetch}
export {uniFetch}

@ -1,5 +1,7 @@
<template> <template>
<div class="large-container"> <div class="large-container">
<title class="title-block" title="智慧门票" :isBack="false">
</title>
<div class="content1"> <div class="content1">
<div class="wrap1"> <div class="wrap1">
<div class="wrap1_1"> <div class="wrap1_1">
@ -21,7 +23,7 @@
</div> </div>
</div> </div>
<div class="content2"> <div class="content2">
<div class="wrap1 "> <div class="wrap1">
<div class="wrap1_1">2</div> <div class="wrap1_1">2</div>
<div class="wrap1_2">未使用门票</div> <div class="wrap1_2">未使用门票</div>
</div> </div>
@ -31,9 +33,7 @@
<div class="wrap1_2">历史门票</div> <div class="wrap1_2">历史门票</div>
</div> </div>
</div> </div>
<div class="content3"> <div class="content3"></div>
</div>
<div class="content4">·历史预约门票</div> <div class="content4">·历史预约门票</div>
<div class="content5"> <div class="content5">
<div class="wrap1"> <div class="wrap1">
@ -77,10 +77,11 @@ const goSetUp=()=>{
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.large-container{ .large-container{
overflow: hidden;
background-image: url('https://cdns.fontree.cn/fonchain-main/prod/image/1833/avatar/16968647-fc99-46fe-b95c-620c55b7646f.png'); background-image: url('https://cdns.fontree.cn/fonchain-main/prod/image/1833/avatar/16968647-fc99-46fe-b95c-620c55b7646f.png');
background-size: 100%; background-size: 100%;
height: 100vh; height: 100vh;
padding: 38rpx 32rpx 0 32rpx; padding: 0rpx 32rpx 0 32rpx;
.content5{ .content5{
margin-top: 14rpx; margin-top: 14rpx;
.wrap1{ .wrap1{

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 KiB

Loading…
Cancel
Save