chenrong 1 rok temu
rodzic
commit
ea2cff1358

+ 1 - 10
App.vue

@@ -2,16 +2,7 @@
 	export default {
 		onLaunch: function() {
 			console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
-			console.log('App Launch')
-			// 定义 request 拦截器
-			console.log(wx.interceptors, 'wx.interceptors')
-			wx.interceptors.request.use(config => {
-			  // 在请求前做一些处理,例如添加 token 等
-			  let token = wx.getStorageSync('token')
-			  config.header['X-Bkmmall-Token'] = token;
-			  return config;
-			});
-			
+			console.log('App Launch')		
 		},
 		onShow: function() {
 			console.log('App Show')

+ 35 - 0
api/address.js

@@ -0,0 +1,35 @@
+import { request } from "@/api/config.js"
+
+// 地址列表
+export function addressListApi(data) {
+  return request({
+    url: '/wx/address/list',
+    method: 'get',
+    data: data
+  })
+}
+// 保存地址
+export function addressSaveApi(data) {
+  return request({
+    url: '/wx/address/save',
+    method: 'post',
+    data: data
+  })
+}
+
+// 获取地址详情
+export function addressDetailApi(data) {
+  return request({
+    url: '/wx/address/detail',
+    method: 'get',
+    data: data
+  })
+}
+// 删除地址
+export function addressDeleteApi(data) {
+  return request({
+    url: '/wx/address/delete',
+    method: 'post',
+    data: data
+  })
+}

+ 17 - 7
api/config.js

@@ -4,16 +4,26 @@ let basUrl = "https://mall.rongtongh.cn"
  */
 export function request(params) {
 	params.url = basUrl + params.url
+	
+	let token = wx.getStorageSync('token')
+	console.log('token请求拦截', token)
+
 	return new Promise(function(resolve, reject) {
 		wx.request({
 			...params,
+			header: {
+				'X-Bkmmall-Token': token
+			},
 			success: function(res) {
-				resolve(res.data);
-				return
+				console.log(res, 'res')
 				if (res.statusCode == 200) {
-
-					if (res.data.errno == 501) {
+					if (res.data.errno == 401) {
+						// 未登录
 						// 清除登录相关内容
+						// wx.showToast({
+						// 	title: '',
+						// 	icon: 'none',
+						// })
 						try {
 							wx.removeStorageSync('userInfo');
 							wx.removeStorageSync('token');
@@ -21,9 +31,9 @@ export function request(params) {
 							// Do something when catch error
 						}
 						// 切换到登录页面
-						// wx.navigateTo({
-						//   url: '/pages/auth/login/login'
-						// });
+						wx.navigateTo({
+						  url: '/pages/login/login'
+						});
 					} else {
 						resolve(res.data);
 					}

+ 19 - 0
api/invite.js

@@ -0,0 +1,19 @@
+import { request } from "@/api/config.js"
+
+
+// 推广码
+export function inviteQrcodeApi(data) {
+  return request({
+    url: '/wx/invite/qrcode',
+    method: 'get',
+    data: data
+  })
+}
+// 已邀请列表
+export function inviteInfoApi(data) {
+  return request({
+    url: '/wx/invite/info',
+    method: 'get',
+    data: data
+  })
+}

+ 0 - 1
api/user.js

@@ -1,6 +1,5 @@
 import { request } from "@/api/config.js"
 
-console.log(request, 'requestsss')
 
 // 登录方法
 export function loginByWeixinApi(data) {

+ 1 - 2
manifest.json

@@ -1,6 +1,6 @@
 {
     "name" : "宝可梦小程序",
-    "appid" : "",
+    "appid" : "__UNI__642FD30",
     "description" : "",
     "versionName" : "1.0.0",
     "versionCode" : "100",
@@ -49,7 +49,6 @@
     "quickapp" : {},
     /* 快应用特有相关 */
     "mp-weixin" : {
-        /* 小程序特有相关 */
         "appid" : "wx834984c9e6fb827d",
         "setting" : {
             "urlCheck" : false

+ 40 - 4
pages.json

@@ -2,13 +2,13 @@
 	"pages": [{
 		"path": "pages/index/index",
 		"style": {
-			"navigationBarTitleText": "uni-app"
+			"navigationBarTitleText": "宝可梦"
 		}
 	}    ,{
             "path" : "pages/mine/mine",
             "style" :                                                                                    
             {
-                "navigationBarTitleText": "",
+                "navigationBarTitleText": "我的",
                 "enablePullDownRefresh": false
             }
             
@@ -17,7 +17,7 @@
             "path" : "pages/shoppingMall/shoppingMall",
             "style" :                                                                                    
             {
-                "navigationBarTitleText": "",
+                "navigationBarTitleText": "商城",
                 "enablePullDownRefresh": false
             }
             
@@ -26,7 +26,43 @@
             "path" : "pages/knapsack/knapsack",
             "style" :                                                                                    
             {
-                "navigationBarTitleText": "",
+                "navigationBarTitleText": "背包",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+        ,{
+            "path" : "pages/addressManage/addressManage",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "我的收货地址",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+        ,{
+            "path" : "pages/login/login",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "授权登录",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+        ,{
+            "path" : "pages/addressEdit/addressEdit",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "新增收货地址",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+        ,{
+            "path" : "pages/invite/invite",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "邀请好友",
                 "enablePullDownRefresh": false
             }
             

+ 172 - 0
pages/addressEdit/addressEdit.vue

@@ -0,0 +1,172 @@
+<template>
+	<view class="container">
+		<uni-forms class="form" :rules="rules" ref="form" :modelValue="form" label-width="80px" label-align="right">
+			<uni-forms-item label="姓名" required name="name">
+				<uni-easyinput v-model="form.name" placeholder="请输入姓名" />
+			</uni-forms-item>
+			<uni-forms-item label="手机号" required name="tel">
+				<uni-easyinput v-model="form.tel" placeholder="请输手机号" />
+			</uni-forms-item>
+			<uni-forms-item label="选择地址" required name="areaCode">
+				<picker mode="region" @change="onchange">
+					<!-- <uni-easyinput v-model="form.name" placeholder="请输入姓名" /> -->
+					<view class="inputBox" v-if="form.areaCode">{{form.province}}/{{form.city}}/{{form.county}}</view>
+					<view class="inputBox" v-else>
+						点击选择地址
+					</view>
+				</picker>
+			</uni-forms-item>
+			<uni-forms-item label="详细地址" required name="addressDetail">
+				<uni-easyinput type="textarea" v-model="form.addressDetail" placeholder="请输详细地址" />
+			</uni-forms-item>
+			<uni-forms-item label="设为默认地址" required name="isDefault">
+				<switch :checked="form.isDefault == 1" @change="switchChange" style="transform:scale(0.7)" />
+			</uni-forms-item>
+		</uni-forms>
+		<view class="bottom">
+			<button class="m_button" type="default" @click="save">保存</button>
+		</view>
+	</view>
+</template>
+
+<script>
+	import {
+		addressSaveApi,
+		addressDetailApi
+	} from "@/api/address.js"
+	export default {
+		data() {
+			return {
+				address: [],
+				form: {
+					"id": null,
+					"areaCode": null,
+					"name": null, //姓名
+					"province": null, //省
+					"city": null, //市
+					"county": null, //县区
+					"addressDetail": null, //详细地址
+					"tel": null, //电话
+					"isDefault": 0,
+				},
+				rules: {
+					name: {
+						rules: [{
+							required: true,
+							errorMessage: '姓名不能为空'
+						}]
+					},
+					tel: {
+						rules: [{
+							required: true,
+							errorMessage: '手机号不能为空'
+						}]
+					},
+					areaCode: {
+						rules: [{
+							required: true,
+							errorMessage: '请选择地址'
+						}]
+					},
+					addressDetail: {
+						rules: [{
+							required: true,
+							errorMessage: '详细地址不能为空'
+						}]
+					},
+				},
+			}
+		},
+		onLoad(option) {
+			console.log(option, 'option')
+			if (option.id) {
+				let params = {
+					id: option.id
+				}
+				addressDetailApi(params).then(res => {
+					console.log(res, 'res')
+					this.form = {
+						...res.data
+					}
+				})
+			}
+		},
+		onShow() {},
+		methods: {
+			onchange(value) {
+				console.log(value, 'value')
+				this.form.areaCode = value.detail.code[2]
+				this.form.province = value.detail.value[0]
+				
+				if (value.detail.value[0] == value.detail.value[1]) {
+					this.form.city = "市辖区"
+				} else {
+					this.form.city = value.detail.value[1]
+				}
+				this.form.county = value.detail.value[2]
+			},
+			switchChange(value) {
+				console.log(value, 'value')
+				if (value.detail.value) {
+					this.form.isDefault = 1
+				} else {
+					this.form.isDefault = 0
+				}
+			},
+			save() {
+				let _this = this
+				console.log(this.form, 'this.form')
+				this.$refs.form.validate().then(val => {
+					addressSaveApi(this.form).then(res => {
+						console.log(res, '提交新增地址')
+						wx.navigateTo({
+							url: "/pages/addressManage/addressManage"
+						})
+						wx.showToast({
+							title: '保存成功'
+						})
+					})
+				}).catch(err => {
+					console.log('err', err);
+				})
+				
+			}
+		}
+	}
+</script>
+
+<style scoped lang="scss">
+	.container {
+		background: #fff;
+		padding: 20px;
+
+		.form {
+			margin-top: 20px;
+		}
+
+		.inputBox {
+			border: 1px solid #F0F0F0;
+			border-radius: 4px;
+			height: 35px;
+			line-height: 35px;
+			padding-left: 10px;
+			color: #333;
+		}
+	}
+
+	.bottom {
+		position: fixed;
+		bottom: 0;
+		padding: 20px 0;
+		text-align: center;
+		width: calc(100% - 40px);
+
+		.m_button {
+			height: 36px;
+			width: 40vw;
+			line-height: 36px;
+			border-radius: 18px;
+			font-size: 13px;
+		}
+	}
+</style>

+ 115 - 0
pages/addressManage/addressManage.vue

@@ -0,0 +1,115 @@
+<template>
+	<view class="container">
+		<view class="list">
+			<view class="card" v-for="(item, index) in list" :key="index">
+				<view class="row">
+					<view>
+						{{item.name}}
+					</view>
+					<view>
+						{{item.tel}}
+					</view>
+					<uni-icons color="#ff5a5a" type="trash" size="25" @click="clickDelete(item)"></uni-icons>
+				</view>
+				<view class="row" style="margin-top: 5px;">
+					<view style="font-size: 12px;">
+						{{item.province}}{{item.city}}{{item.county}}{{item.addressDetail}}
+					</view>
+					<uni-icons color="#00ce65" type="compose" size="25" @click="clickEdit(item)"></uni-icons>
+				</view>
+			</view>
+		</view>
+		<view class="bottom">
+			<button class="m_button" type="default" @click="toAdd">新建地址</button>
+		</view>
+	</view>
+</template>
+
+<script>
+	import {
+		addressListApi,
+		addressDeleteApi
+	} from "@/api/address.js"
+	export default {
+		data() {
+			return {
+				list: [],
+			}
+		},
+		onShow() {
+			this.getList()
+		},
+		methods: {
+			getList() {
+				addressListApi().then(res => {
+					console.log(res, 'addressListApi-res')
+					this.list = res.data.list
+				})
+			},
+			toAdd() {
+				wx.navigateTo({url: '/pages/addressEdit/addressEdit'})
+			},
+			clickEdit(data) {
+				wx.navigateTo({
+					url: `/pages/addressEdit/addressEdit?id=${data.id}`
+				})
+			},
+			clickDelete(data) {
+				let _this = this
+				wx.showModal({
+					title: '提示',
+					content	: '删除该收货地址?',
+					success: () => {
+						let params = {
+							id: data.id
+						}
+						addressDeleteApi(params).then(res => {
+							wx.showToast({
+								title: '操作成功'
+							})
+							_this.getList()
+						})
+					}
+				})	
+			}
+		}
+	}
+</script>
+
+<style scoped lang="scss">
+	.container {
+		background: #eaeaea;
+		overflow: scroll;
+	}
+	.list {
+		margin-bottom: 60px;
+	}
+	.card {
+		margin-top: 10px;
+		margin-left: 10px;
+		margin-right: 10px;
+		padding: 10px;
+		background: white;
+		border-radius: 5px;
+		font-size: 14px;
+		.row {
+			display: flex;
+			justify-content: space-between;
+			align-items: center;
+		}
+	}
+	.bottom {
+		position: fixed;
+		bottom: 0;
+		padding: 20px;
+		text-align: center;
+		width: calc(100% - 40px);
+		.m_button {
+			height: 36px;
+			width: 40vw;
+			line-height: 36px;
+			border-radius: 18px;
+			font-size: 13px;
+		}
+	}
+</style>

+ 1 - 1
pages/index/index.vue

@@ -1,6 +1,6 @@
 <template>
 	<view class="container">
-		<image class="headImg" mode="aspectFill" src="/static/img/homeHead.png"></image>
+		<image class="headImg" mode="aspectFill" src="/static/img/homeHead.jpeg"></image>
 		<view class="tabs">
 			<view class="tab">
 				<image src="/static/img/Frame3.png" alt="">

+ 124 - 0
pages/invite/invite.vue

@@ -0,0 +1,124 @@
+<template>
+	<view class="container">
+		<view class="m_button illustrate">
+			规则说明
+		</view>
+		<view class="">
+			邀请好友
+		</view>
+		<view class="">
+			领现金
+		</view>
+		<view class="">
+			笔笔有提成
+		</view>
+		<view class="box">
+			<view class="item">
+				<view class="label">
+					已邀请
+				</view>
+				<view class="value">
+					0人
+				</view>
+			</view>
+			<view class="item">
+				<view class="label">
+					奖励总览
+				</view>
+				<view class="value">
+					0元
+				</view>
+			</view>
+		</view>
+		<view class="buttons">
+			<view class="m_button">
+				邀请好友
+			</view>
+			<view class="m_button" @click="promotionCode">
+				我的推广码
+			</view>
+		</view>
+		<uni-popup ref="popup" background-color="#fff">
+			<view class="popup-content" >
+				<image class="qrcode" :src="imgUrl" mode=""></image>
+			</view>
+		</uni-popup>
+	</view>
+</template>
+
+<script>
+	import {
+		inviteQrcodeApi, 
+		inviteInfoApi
+	} from "@/api/invite.js"
+	export default {
+		data() {
+			return {
+				imgUrl: ''
+			}
+		},
+		methods: {
+			promotionCode() {
+				let _this = this
+				inviteQrcodeApi().then(res => {
+					console.log(res, '推广码')
+					_this.imgUrl = res.data
+					_this.$refs.popup.open('center')
+				})
+			}
+		}
+	}
+</script>
+
+<style scoped lang="scss">
+	.container {
+		background: #e7ffec;
+		text-align: center;
+		illustrate {
+			position: absolute;
+			right: 20px;
+			top: 40px;
+			font-size: 12px;
+			padding: 5px 10px;
+			border-radius: 4px;
+		}
+		.box {
+			background: #fff;
+			margin: 20px 20px;
+			padding: 20px;
+			border-radius: 15px;
+			display: flex;
+			justify-content: space-around;
+			
+			.item {
+				display: flex;
+				flex-direction: column;
+				justify-content: center;
+				align-items: center;
+				.label {
+					font-size: 24px;
+					font-weight: 600;
+				}
+				.value {
+					font-size: 24px;
+					font-weight: 600;
+					margin-top: 20px;
+				}
+			}
+		}
+		.buttons {
+			display: flex;
+			justify-content: space-around;
+			
+			.m_button {
+				width: 40vw;
+				height: 30px;
+				line-height: 30px;
+			}
+		}
+		.qrcode {
+			width: 70vw;
+			height: 70vw;
+		}
+	}
+</style>

+ 127 - 0
pages/login/login.vue

@@ -0,0 +1,127 @@
+<template>
+	<view class="loginPage">
+		<image class="bk" src="/static/img/ka.jpeg" mode=""></image>
+		<view class="box">
+			<view class="tip">
+				<radio :checked="checkbox1" @click="checkbox1 = !checkbox1" />
+				<view class="text">我已阅读并同意<span class="textColor1">《用户协议》</span>及 <span class="textColor1">《隐私政策》</span></view>
+			</view>
+			<button @click="wxLogin" class="m_button" type="default">微信授权登录</button>
+		</view>
+		
+	</view>
+</template>
+
+<script>
+	import {
+		loginByWeixinApi
+	} from "@/api/user.js"
+	export default {
+		data() {
+			return {
+				checkbox1: false, 
+			}
+		},
+		methods: {
+			wxLogin: function(e) {
+				if (!this.checkbox1) {
+					wx.showToast({
+						title: '请先阅读并同意《用户协议》',
+						icon: 'none',
+					})
+				}
+				let _this = this
+				wx.getUserProfile({
+					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+					success: (res) => {
+						console.log(res, 'res111')
+						_this.getWXCode(res.userInfo)
+				
+					},
+					fail: () => {
+						console.log('微信登录失败')
+						// util.showErrorToast('微信登录失败');
+					}
+				})
+			},
+			getWXCode(userInfo) {
+				let _this = this
+				wx.login({
+					success: function(res) {
+						console.log(res, 'res222')
+						if (res.code) {
+							let params = {
+								code: res.code,
+								userInfo: userInfo
+							}
+							_this.executeLoginApi(params)
+						}
+					},
+					fail: function(err) {
+						reject(err);
+					}
+				});
+			},
+			executeLoginApi(params) {
+				let _this = this
+				console.log(222)
+				loginByWeixinApi(params).then(res => {
+					console.log('调用登录api', res)
+					//存储用户信息
+					wx.setStorageSync('userInfo', res.data.userInfo);
+					wx.setStorageSync('token', res.data.token);
+					wx.setStorageSync('userId', res.data.userId);
+					getApp().globalData.hasLogin = true;
+					wx.navigateBack({
+						delta: 1
+					})
+				})
+			}
+		}
+	}
+</script>
+
+<style scoped lang="scss">
+	.loginPage {
+		height: 100vh;
+		overflow: hidden;
+		// background: url(@/static/img/ka.jpeg) no-repeat;
+		// background-size: 100% 100%;
+		.bk {
+			height: 100%;
+			width: 100%;
+		}
+		.box {
+			position: absolute;
+			bottom: 0;
+			display: flex;
+			align-items: center;
+			justify-content: center;
+			flex-direction: column;
+			width: 100%;;
+			background-color: rgba(255, 255, 255, 0.7);
+			padding: 30px 10px;
+			.tip {
+				display: flex;
+				justify-content: center;
+				align-items: center;
+				margin-bottom: 10px;
+				color: #000;
+				font-size: 12px;
+				
+				.checkBox {
+					// font-size: 12px;
+					height: 12px;
+					width: 12px;
+				}
+			}
+			.m_button {
+				height: 40px;
+				width: 50vw;
+				border-radius: 20px;
+				line-height: 40px;
+				font-size: 16px;
+			}
+		}
+	}
+</style>

+ 12 - 53
pages/mine/mine.vue

@@ -2,12 +2,12 @@
 	<view class="container">
 		<view class="user">
 			<view class="userInfo">
-				<image class="userPhoto" src=""></image>
+				<image class="userPhoto" :src="userInfo.avatarUrl"></image>
 				<view class="info">
 					<view class="name" v-if="hasLogin">
 						{{userInfo.nickName}}
 					</view>
-					<view class="loginText" @click="wxLogin" v-else>
+					<view class="loginText" @click="toLogin" v-else>
 						点击登录
 					</view>
 					<view class="id">
@@ -39,7 +39,7 @@
 				<image src="/static/img/mine/title.png" mode=""></image>
 			</view>
 			<view class="menuList">
-				<view class="menu">
+				<view class="menu" @click="pageTo('/pages/addressManage/addressManage')">
 					<image src="/static/img/mine/menu1.png"></image>
 					<span>地址管理</span>
 				</view>
@@ -69,9 +69,6 @@
 </template>
 
 <script>
-	import {
-		loginByWeixinApi
-	} from "@/api/user.js"
 	export default {
 		data() {
 			return {
@@ -83,58 +80,20 @@
 		},
 		onShow() {
 			//获取用户的登录信息
-			if (getApp().globalData.hasLogin) {
-				let userInfo = wx.getStorageSync('userInfo');
-				this.userInfo = userInfo
+			if (wx.getStorageSync('token')) {
+				this.userInfo = wx.getStorageSync('userInfo');
+				this.userId = wx.getStorageSync('userId');
 				this.hasLogin = true
 			}
 		},
 		methods: {
-			wxLogin: function(e) {
-				console.log('111')
-				let _this = this
-				wx.getUserProfile({
-					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
-					success: (res1) => {
-						console.log(res1, 'res111')
-						wx.login({
-							success: function(res2) {
-								console.log(res2, 'res222')
-								if (res2.code) {
-									let params = {
-										code: res2.code,
-										userInfo: res1.userInfo
-									}
-									_this.executeLoginApi(params)
-								}
-							},
-							fail: function(err) {
-								reject(err);
-							}
-						});
-					},
-					fail: () => {
-						console.log('微信登录失败')
-						// util.showErrorToast('微信登录失败');
-					}
-				})
+			toLogin() {
+				wx.navigateTo({url: '/pages/login/login'})
 			},
-			executeLoginApi(params) {
-				let _this = this
-				console.log(222)
-				loginByWeixinApi(params).then(res => {
-					console.log('调用登录api', res)
-					//存储用户信息
-					wx.setStorageSync('userInfo', res.data.userInfo);
-					wx.setStorageSync('token', res.data.token);
-					wx.setStorageSync('userId', res.data.userId);
-					getApp().globalData.hasLogin = true;
-					
-					_this.userInfo = wx.getStorageSync('userInfo');
-					_this.userId = wx.getStorageSync('userId');
-					_this.hasLogin = true
-				})
-			}
+			pageTo(url) {
+				wx.navigateTo({url: url})
+			},
+			
 		}
 	}
 </script>

BIN
static/img/homeHead.jpeg


BIN
static/img/homeHead.png


+ 8 - 0
static/style.scss

@@ -4,3 +4,11 @@ image {
 .container {
 	min-height: 100vh;
 }
+.m_button {
+	background: linear-gradient(180deg,  #FFAD3D 0%, #FF740A 100%);
+	color: #fff !important;
+	font-weight: 600;
+}
+.textColor1 {
+	color: #FFAD3D;
+}