浏览代码

拉取代码

mabaoyi 9 月之前
父节点
当前提交
06b3778400
共有 28 个文件被更改,包括 79 次插入78 次删除
  1. 44 71
      commont/http.interceptor.js
  2. 1 0
      manifest.json
  3. 20 7
      pages/index/index.vue
  4. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/common/main.js.map
  5. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map
  6. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/components/kj-tabbar/kj-tabbar.js.map
  7. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/cart/cart.js.map
  8. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/express/express.js.map
  9. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/index/index.js.map
  10. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/login/login.js.map
  11. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/mine/mine.js.map
  12. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/pages/shopping/shopping.js.map
  13. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-badge/u-badge.js.map
  14. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-checkbox-group/u-checkbox-group.js.map
  15. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-checkbox/u-checkbox.js.map
  16. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-icon/u-icon.js.map
  17. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-loading-icon/u-loading-icon.js.map
  18. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-navbar/u-navbar.js.map
  19. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-safe-bottom/u-safe-bottom.js.map
  20. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-status-bar/u-status-bar.js.map
  21. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-subsection/u-subsection.js.map
  22. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-swiper-indicator/u-swiper-indicator.js.map
  23. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-swiper/u-swiper.js.map
  24. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-tabbar-item/u-tabbar-item.js.map
  25. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-tabbar/u-tabbar.js.map
  26. 0 0
      unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-tabs/u-tabs.js.map
  27. 14 0
      unpackage/dist/dev/mp-weixin/pages/index/index.js
  28. 0 0
      unpackage/dist/dev/mp-weixin/pages/index/index.wxml

+ 44 - 71
commont/http.interceptor.js

@@ -1,76 +1,49 @@
-import url from "./url.js"
-const install = (Vue, vm) => {
-	Vue.prototype.$u.http.setConfig({
-		baseUrl: url, // 请求的本域名
-		loadingText: '加载中...',
-		loadingTime: 800,
-		showLoading: true, // 是否显示请求中的loading
-		loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
-		originalData: true, // 是否在拦截器中返回服务端的原始数据
-		// 配置请求头信息
-		header: {
-			'content-type': 'application/json;charset=UTF-8',
-			'version': 'v1'
-		},
-	});
-	// 请求拦截部分,如配置,每次请求前都会执行
-	Vue.prototype.$u.http.interceptor.request = (config) => {
-		// 引用token
-		// 方式一,存放在vuex的token,假设使用了uView封装的vuex方式
-		// 见:https://uviewui.com/components/globalVariable.html
-		// config.header.token = vm.token;
-
-		// 方式二,如果没有使用uView封装的vuex方法,那么需要使用$store.state获取
-		// config.header.token = vm.$store.state.token;
-
-		// 方式三,如果token放在了globalData,通过getApp().globalData获取
-		// config.header.token = getApp().globalData.username;
-
-		// 方式四,如果token放在了Storage本地存储中,拦截是每次请求都执行的
-		// 所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
-		const token = uni.getStorageSync('token');
-		config.header.Authorization = token;
-
-		// 可以对某个url进行特别处理,此url参数为this.$u.get(url)中的url值
-		// if(config.url == '/user/login') config.header.noToken = true;
-		// 最后需要将config进行return
-		return config;
-		// 如果return一个false值,则会取消本次请求
-		// if(config.url == '/user/rest') return false; // 取消某次请求
-	}
-	// 响应拦截,如配置,每次请求结束都会执行本方法
-	Vue.prototype.$u.http.interceptor.response = (res) => {
-		if (res.statusCode == 200) {
-			// res为服务端返回值,可能有code,result等字段
-			// 这里对res.result进行返回,将会在this.$u.post(url).then(res => {})的then回调中的res的到
-			// 如果配置了originalData为true,请留意这里的返回值
-			return res.data;
-		} else {
-			// 假设201为token失效,这里跳转登录
-			if (res.statusCode == 500) {
-				// var html = res.data
-				// var start = html.indexOf('<h1>')
-				// var end = html.indexOf('</h1>')
-				// var title = html.substring(start + 4, end)
+// 此vm参数为页面的实例,可以通过它引用vuex中的变量
+module.exports = (vm) => {
+    // 初始化请求配置
+    uni.$u.http.setConfig((config) => {
+        /* config 为默认全局配置*/
+        config.baseURL = ''; /* 根域名 */
+        return config
+    })
+	
+	// 请求拦截
+	uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作
+	    // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
+	    config.data = config.data || {}
+		// 根据custom参数中配置的是否需要token,添加对应的请求头
+		if(config?.custom?.auth) {
+			// 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
+			config.header.token = vm.$store.state.userInfo.token
+		}
+	    return config 
+	}, config => { // 可使用async await 做异步操作
+	    return Promise.reject(config)
+	})
+	
+	// 响应拦截
+	uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
+		const data = response.data
 
-				// var start1 = html.indexOf('</abbr> in <a class="toggle" title=')
-				// var end1 = html.indexOf('</a></h2>')
-				// var title1 = html.substring(start1 + 35, end1)
+		// 自定义参数
+		const custom = response.config?.custom
+		if (data.code !== 200) { 
+			// 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
+			if (custom.toast !== false) {
+				uni.$u.toast(data.message)
+			}
 
-				// uni.showModal({
-				// 	title: `网络错误:${res.statusCode}`,
-				// 	content: `位置:${title1}\r\n 标题:${title}`
-				// })
+			// 如果需要catch返回,则进行reject
+			if (custom?.catch) {
+				return Promise.reject(data)
 			} else {
-				uni.showModal({
-					content: `未知错误:${res.statusCode}`
-				})
+				// 否则返回一个pending中的promise,请求不会进入catch中
+				return new Promise(() => { })
 			}
-			return false;
 		}
-	}
-}
-
-export default {
-	install
-}
+		return data.data === undefined ? {} : data.data
+	}, (response) => { 
+		// 对响应错误做点什么 (statusCode !== 200)
+		return Promise.reject(response)
+	})
+}

+ 1 - 0
manifest.json

@@ -90,3 +90,4 @@
 		}
 	}
 }
+

+ 20 - 7
pages/index/index.vue

@@ -58,7 +58,7 @@
 						</image>
 						<view class="biaoqian" style="background: #F35D22;">{{i18n.expensive}}</view>
 					</view>
-					<view class="u-flex" style="flex-wrap: wrap;justify-content: space-between;" >
+					<view class="u-flex" style="flex-wrap: wrap;justify-content: space-between;">
 						<view v-for="(item,idx) in 4" class="ssbox  " style="margin-top: 16rpx;">
 							<view class="" style="position: relative">
 								<image src=""
@@ -139,7 +139,7 @@
 				</view>
 			</view>
 			<view class="u-flex u-row-between" style="flex-wrap: wrap;">
-				<view class="bigbox" v-for="(item,index) in 6" style="position: relative;" @click="todetail">
+				<view class="bigbox" v-for="(item,index) in recomlist" style="position: relative;" @click="todetail">
 					<image src="../../static/images/index/discount.png"
 						style="width: 60rpx;height: 36rpx;position: absolute;left: 12rpx;top: 12rpx;z-index: 10;"
 						mode="">
@@ -189,6 +189,7 @@
 	export default {
 		data() {
 			return {
+				recomlist: [], //推荐列表
 				//顶部分段器
 				list: [],
 				current: 1,
@@ -222,16 +223,27 @@
 			}
 		},
 		onLoad(options) {
-			this.list = [this.i18n.border,this.i18n.shop]
+			this.list = [this.i18n.border, this.i18n.shop]
 			// this.seater()
 			if (options.current) {
 				this.current = options.current
 			}
 		},
+		onShow() {
+			//商品推荐
+			this.recommend()
+		},
 		methods: {
-			subsidy(item){
+			//商品推荐
+			recommend() {
+				console.log(1111);
+				uni.$u.http.post('/api/goods/recommend', {}).then(res => {
+					this.recomlist = res.data
+				})
+			},
+			subsidy(item) {
 				uni.navigateTo({
-					url:'/pageA/subsidy?show=' + item
+					url: '/pageA/subsidy?show=' + item
 				})
 			},
 			//物流计算器
@@ -274,9 +286,10 @@
 </script>
 
 <style lang="scss" scoped>
-	page{
-		background-color: rgba(0,0,0,0)
+	page {
+		background-color: rgba(0, 0, 0, 0)
 	}
+
 	.index-navbar {
 		position: sticky;
 		top: 0;

文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/common/main.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/common/vendor.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/components/kj-tabbar/kj-tabbar.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/cart/cart.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/express/express.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/index/index.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/login/login.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/mine/mine.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/pages/shopping/shopping.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-badge/u-badge.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-checkbox-group/u-checkbox-group.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-checkbox/u-checkbox.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-icon/u-icon.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-loading-icon/u-loading-icon.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-navbar/u-navbar.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-safe-bottom/u-safe-bottom.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-status-bar/u-status-bar.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-subsection/u-subsection.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-swiper-indicator/u-swiper-indicator.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-swiper/u-swiper.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-tabbar-item/u-tabbar-item.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-tabbar/u-tabbar.js.map


文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/.sourcemap/mp-weixin/uview-ui/components/u-tabs/u-tabs.js.map


+ 14 - 0
unpackage/dist/dev/mp-weixin/pages/index/index.js

@@ -377,6 +377,8 @@ exports.default = void 0;
 var _default = {
   data: function data() {
     return {
+      recomlist: [],
+      //推荐列表
       //顶部分段器
       list: [],
       current: 1,
@@ -412,7 +414,19 @@ var _default = {
       this.current = options.current;
     }
   },
+  onShow: function onShow() {
+    //商品推荐
+    this.recommend();
+  },
   methods: {
+    //商品推荐
+    recommend: function recommend() {
+      var _this = this;
+      console.log(1111);
+      uni.$u.http.post('/api/goods/recommend', {}).then(function (res) {
+        _this.recomlist = res.data;
+      });
+    },
     subsidy: function subsidy(item) {
       uni.navigateTo({
         url: '/pageA/subsidy?show=' + item

文件差异内容过多而无法显示
+ 0 - 0
unpackage/dist/dev/mp-weixin/pages/index/index.wxml


部分文件因为文件数量过多而无法显示