封装请求拦截器
							parent
							
								
									6defa160cd
								
							
						
					
					
						commit
						786066cbfb
					
				@ -1,9 +1,9 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "compilerOptions": {
 | 
					  "compilerOptions": {
 | 
				
			||||||
    "types": [
 | 
					    "types": ["@dcloudio/types", "miniprogram-api-typings", "mini-types"],
 | 
				
			||||||
      "@dcloudio/types",
 | 
					    "baseUrl": ".",
 | 
				
			||||||
      "miniprogram-api-typings",
 | 
					    "paths": {
 | 
				
			||||||
      "mini-types"
 | 
					      "@/*": ["src/*"]
 | 
				
			||||||
    ]
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,87 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <!-- 导航条 -->
 | 
				
			||||||
 | 
					  <view class="navbar" :style="{ paddingTop: paddingTop + 'px' }">
 | 
				
			||||||
 | 
					    <!-- 文字logo -->
 | 
				
			||||||
 | 
					    <view class="logo">
 | 
				
			||||||
 | 
					      <text>{{ title }}</text>
 | 
				
			||||||
 | 
					    </view>
 | 
				
			||||||
 | 
					    <!-- 搜索条 -->
 | 
				
			||||||
 | 
					    <view class="search">
 | 
				
			||||||
 | 
					      <text class="icon-search">UDI码信息查询</text>
 | 
				
			||||||
 | 
					      <uni-icons type="search" size="30"></uni-icons>
 | 
				
			||||||
 | 
					      <uni-icons type="scan" size="30"></uni-icons>
 | 
				
			||||||
 | 
					    </view>
 | 
				
			||||||
 | 
					  </view>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script>
 | 
				
			||||||
 | 
					// 引入vuex
 | 
				
			||||||
 | 
					import { mapState } from 'vuex';
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
					  computed: {
 | 
				
			||||||
 | 
					    ...mapState(['safeArea']),
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  data() {
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					      paddingTop: 0,
 | 
				
			||||||
 | 
					      title: 'UDI码信息查询',
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  created() {
 | 
				
			||||||
 | 
					    this.paddingTop = uni.getSystemInfoSync().safeArea.top;
 | 
				
			||||||
 | 
					    console.log(
 | 
				
			||||||
 | 
					      'this.paddingTop',
 | 
				
			||||||
 | 
					      this.paddingTop,
 | 
				
			||||||
 | 
					      uni.getSystemInfoSync().safeArea.top
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<style lang="scss">
 | 
				
			||||||
 | 
					.navbar {
 | 
				
			||||||
 | 
					  background-color: #00c09d;
 | 
				
			||||||
 | 
					  background-size: cover;
 | 
				
			||||||
 | 
					  position: relative;
 | 
				
			||||||
 | 
					  overflow: hidden;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  .logo {
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    align-items: center;
 | 
				
			||||||
 | 
					    height: 64rpx;
 | 
				
			||||||
 | 
					    padding-left: 30rpx;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    text {
 | 
				
			||||||
 | 
					      flex: 1;
 | 
				
			||||||
 | 
					      line-height: 28rpx;
 | 
				
			||||||
 | 
					      color: #fff;
 | 
				
			||||||
 | 
					      margin: 10rpx 0 0 0;
 | 
				
			||||||
 | 
					      font-size: 40rpx;
 | 
				
			||||||
 | 
					      text-align: center;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  .search {
 | 
				
			||||||
 | 
					    display: flex;
 | 
				
			||||||
 | 
					    align-items: center;
 | 
				
			||||||
 | 
					    justify-content: space-between;
 | 
				
			||||||
 | 
					    padding: 0 10rpx 0 26rpx;
 | 
				
			||||||
 | 
					    height: 64rpx;
 | 
				
			||||||
 | 
					    margin: 16rpx 20rpx;
 | 
				
			||||||
 | 
					    color: #fff;
 | 
				
			||||||
 | 
					    font-size: 28rpx;
 | 
				
			||||||
 | 
					    border-radius: 32rpx;
 | 
				
			||||||
 | 
					    background-color: rgba(255, 255, 255, 0.5);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  .icon-search {
 | 
				
			||||||
 | 
					    &::before {
 | 
				
			||||||
 | 
					      margin-right: 10rpx;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  .icon-scan {
 | 
				
			||||||
 | 
					    font-size: 30rpx;
 | 
				
			||||||
 | 
					    padding: 15rpx;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					const baseURL = ''; //基地址
 | 
				
			||||||
 | 
					const request = {
 | 
				
			||||||
 | 
					  invoke(args) {
 | 
				
			||||||
 | 
					    uni.showLoading({ title: '加载中' });
 | 
				
			||||||
 | 
					    if (!args.url.startsWith('http')) {
 | 
				
			||||||
 | 
					      args.url = baseURL + args.url;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    args.header = {
 | 
				
			||||||
 | 
					      ...args.header, // 保留原本的 header
 | 
				
			||||||
 | 
					      'source-client': 'miniapp', // 添加小程序端调用标识
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  complete(res) {
 | 
				
			||||||
 | 
					    uni.hideLoading();
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					uni.addInterceptor('request', request);
 | 
				
			||||||
 | 
					uni.addInterceptor('uploadFile', request);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default (options) => {
 | 
				
			||||||
 | 
					  return new Promise((resolve, reject) => {
 | 
				
			||||||
 | 
					    uni.request({
 | 
				
			||||||
 | 
					      ...options,
 | 
				
			||||||
 | 
					      success(res) {
 | 
				
			||||||
 | 
					        if (res.statusCode >= 200 && res.statusCode < 300) {
 | 
				
			||||||
 | 
					          resolve(res.data);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          reject(res);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      fail(err) {
 | 
				
			||||||
 | 
					        reject(res);
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
					Loading…
					
					
				
		Reference in New Issue