Browse Source

设置页面完成 签到功能完善 基础功能完成

zhengJ_docnet 4 years ago
parent
commit
ea860872dd
8 changed files with 281 additions and 36 deletions
  1. 25 4
      App.vue
  2. 103 5
      common/utils/https.js
  3. 13 1
      pages.json
  4. 71 0
      pages/login/login.vue
  5. 23 7
      pages/mypersonal/personal.vue
  6. 9 14
      pages/setting/setting.vue
  7. 3 3
      pages/syeminfo/syeminfo.vue
  8. 34 2
      store/modules/global.js

+ 25 - 4
App.vue

@@ -1,7 +1,8 @@
 <script>
 	import {
 		mapState,
-		mapMutations
+		mapMutations,
+		mapActions
 	} from "vuex"
 	export default {
 		onLaunch: function() {
@@ -11,12 +12,30 @@
 			}
 		},
 		onShow: function() {
-			console.log('App Show')
+			console.log('App Show', this.signState)
 			uni.getSystemInfo({
 				success: (res) => {
 					this.setSysteminfo(res)
 				}
 			})
+			
+			this.isDay(this.signState.data).then((res) => {
+				console.log(res,"-----9999999999------")
+				if(res) {
+					if(this.signState.status) {
+						this.setState({})
+					}else{
+						this.setState({})
+						this.setSing(0)
+					}
+				}else{
+					if(this.signState.status) {
+						return
+					}else{
+						this.setState({})
+					}
+				}
+			})
 		},
 		onHide: function() {
 			console.log('App Hide')
@@ -31,11 +50,13 @@
 		},
 		computed: {
 			...mapState({
-				setting: state => state.global.setting
+				setting: state => state.global.setting,
+				signState: state => state.global.signState,
 			})
 		},
 		methods:{
-			...mapMutations(["setTing", "setSysteminfo"]),
+			...mapMutations(["setTing", "setSysteminfo", "setState", "setSing"]),
+			...mapActions(["isDay"]),
 			// 更新
 			Upload() {
 				console.log("哈哈")

+ 103 - 5
common/utils/https.js

@@ -2,10 +2,9 @@ const weather = 'https://free-api.heweather.net/s6/weather'
 const future = 'http://v.juhe.cn/weather/index'
 const air = 'https://free-api.heweather.net/s6/air/now'
 const locl = 'http://apis.juhe.cn/geo/'
-// 和风天气Api产品秘钥 自行去官网申请
-const QQ_MAP_KEY1 = '********************************'
-const QQ_MAP_KEY2 = '********************************'
-const QQ_MAP_KEY3 = '********************************'
+const QQ_MAP_KEY1 = '630ac2e3d80941b48c80fe3a8ed1a042'
+const QQ_MAP_KEY2 = 'c649beb3621c84ee57c365f45a9a6ed4'
+const QQ_MAP_KEY3 = 'dd35eaa26348f268f1f02b4a8fbe4aaf'
 
 
 //添加finally事件
@@ -134,4 +133,103 @@ export {
 	getLift,
 	getAir,
 	gelocation
-}
+}
+
+
+// export const getWeather = (location) => {
+//   return new Promise((resolve, reject) => {
+//     wx.request({
+//       url: 'https://free-api.heweather.net/s6/weather/now',
+//       data: {
+//         location:location,
+//         key: QQ_MAP_KEY1
+//       },
+//       success: (res) => {
+//         resolve({result: res.data})
+//       },
+//       fail: (e) => {
+//         reject(e)
+//       },
+// 	  complete: (e) => {
+// 	  	
+// 	  }
+//     })
+//   })
+// }
+// 未来七天天气
+// export const getFuture = (location) => {
+//   return new Promise((resolve, reject) => {
+//     wx.request({
+//       url: 'http://v.juhe.cn/weather/index',
+//       data: {
+//         cityname:location,
+//         key: QQ_MAP_KEY2
+//       },
+//       success: (res) => {
+//         console.log(res)
+//         resolve({result: res.data})
+//       },
+//       fail: (e) => {
+//         console.log("haha  chucuo 2 ")
+//         reject(e)
+//       }
+//     })
+//   })
+// }
+// 生活指数
+// export const getLift = (location) => {
+//     return new Promise((resolve, reject) => {
+//         wx.request({
+//             url: 'https://free-api.heweather.net/s6/weather/lifestyle',
+//             data: {
+//                 location:location,
+//                 key: QQ_MAP_KEY1,
+//             },
+//             success: (res) => {
+//                 resolve({result:res.data})
+//             },
+//             fail: (e) => {
+//                 reject(e)
+//             }
+//         })
+//     })
+// }
+// 获取空气质量
+// export const getAir = (location) => {
+//   return new Promise((resolve, reject) => {
+//       wx.request({
+//           url: 'https://free-api.heweather.net/s6/air/now',
+//           data: {
+//               location:location,
+//               key: QQ_MAP_KEY1,
+//           },
+//           success: (res) => {
+//               resolve({result:res.data})
+//           },
+//           fail: (e) => {
+//               reject(e)
+//           }
+//       })
+//   })
+// }
+// 经纬度逆向解析
+// export const gelocation = (obj) => {
+//   return new Promise((resolve, reject) => {
+//       wx.request({
+//           url: 'http://apis.juhe.cn/geo/',
+//           data: {
+//             key: QQ_MAP_KEY3,
+//             lat:obj.lat,
+//             lng:obj.lng,
+//             type:1
+//           },
+//           success: (res) => {
+//               resolve({result:res.data})
+//           },
+//           fail: (e) => {
+//               reject(e)
+//           }
+//       })
+//   })
+// }
+

+ 13 - 1
pages.json

@@ -43,7 +43,19 @@
         }
         ,{
             "path" : "pages/syeminfo/syeminfo",
-            "style" : {}
+            "style" : {
+				// #ifdef H5 
+				"navigationStyle":"custom"
+				// #endif
+			}
+        }
+        ,{
+            "path" : "pages/login/login",
+            "style" : {
+				// #ifdef H5 
+				"navigationStyle":"custom"
+				// #endif
+			}
         }
     ],
 	"tabBar": {

+ 71 - 0
pages/login/login.vue

@@ -0,0 +1,71 @@
+<template>
+	<view class='page'>
+		<view class='bottom'>
+		<!-- #ifdef MP-WEIXIN -->
+			<button class='wxlogin' open-type='getUserInfo' @getuserinfo = "modalcancel">微信登录</button>
+		<!-- #endif -->
+			<button class='zhlogin' >账号登录</button>
+		</view>
+	</view>
+</template>
+
+<script>import {
+		mapMutations
+	} from "vuex"
+	export default {
+		data () {
+			return {
+				
+			}
+		},
+		methods:{
+			...mapMutations(["setUserinfo"]),
+			// 账号登录 手机号授权
+			modalconfirm: function (e) {
+				console.log("111111111111", e)
+			},
+			// 微信登录
+			modalcancel: function (e) {
+				console.log(e)
+				var that = this;
+				if (e.detail.errMsg != 'getUserInfo:ok') {
+					//用户拒绝
+					console.log("拒绝授权", e);
+				} else {
+					app.getloading("加载中...")
+					console.log("用户允许微信授权", e);
+					// 这里可以发送code到后台换取秘钥
+					this.setUserinfo()
+					// uni.reLaunch({
+					// 	url:"/pages/index/index"
+					// })
+				}		
+			},
+		}
+	}
+</script>
+
+<style scoped>
+	.page{
+		position: fixed;
+		top: 0;
+		left: 0;
+		width: 100%;
+		height: 100%;
+	}
+
+	.bottom{
+		box-sizing: border-box;
+		position: absolute;
+		bottom: 100rpx;
+		width: 100%;
+	}
+	.bottom .wxlogin,
+	.bottom .zhlogin{
+		background: #1296db;
+		font-size: 32rpx;
+		color: #fff;
+		width: 80%;
+		margin: 30rpx auto;
+	}
+</style>

+ 23 - 7
pages/mypersonal/personal.vue

@@ -54,7 +54,7 @@
 		<view class='portrait'>
 			<image class="userinfo-avatar" :src="userInfo.avatarUrl ? userInfo.avatarUrl : '/static/icon.png'" mode="aspectFit"></image>
 			<view>{{userInfo.nickName}}</view>
-			<view class='sign' :class='signState ? "signs" : ""' @tap='signClick'>{{signState?"已签到":"签到"}}</view>
+			<view class='sign' :class='signState.status ? "signs" : ""' @tap='signClick'>{{signState.status?"已签到":"签到"}}</view>
 		</view>
 		
 		<view class='userlist cu-list menu'>  
@@ -77,7 +77,8 @@
 <script >
 	import {
 		mapState,
-		mapMutations
+		mapMutations,
+		mapActions
 	} from "vuex"
 	export default {
 		data() {
@@ -118,6 +119,7 @@
 		},
 		methods: {
 			...mapMutations(["setState", "setSing"]),
+			...mapActions(["Times"]),
 			bind(signClick) {
 				switch (signClick){
 					case "bindSeting":
@@ -162,13 +164,27 @@
 				//#endif
 			},
 			signClick() {
-				if(this.signState) {
-					return
+				var obj = {}
+				//#ifdef MP-WEIXIN
+				if(this.userinfo) {
+				//#endif
+					if(this.signState.status) {
+						return
+					}else{
+						this.Times().then((res) =>{
+							obj.data = res
+							obj.status = true
+							this.setState(obj)
+						})
+						this.setSing(++this.sing)
+					}
+				//#ifdef MP-WEIXIN
 				}else{
-					this.setState(true)
-					console.log(++this.sing)
-					this.setSing(++this.sing)
+					uni.navigateTo({
+						url:"/pages/login/login"
+					})
 				}
+				//#endif
 			},
 		}
 	}

+ 9 - 14
pages/setting/setting.vue

@@ -259,7 +259,7 @@
 			//#endif
 		},
 		onShow() {
-			console.log(this.setting.gesture)
+			console.log(this.setting,"---------")
 		},
 		mounted() {
 			
@@ -305,7 +305,6 @@
 						}, 500);
 					}
 				}
-				console.log(this.setting,"-----------000000000")
 				this.setTing(setting)
 			},
 			screenBrightnessChanging(e) {
@@ -381,6 +380,7 @@
 				}
 			},
 			setClear() {
+				let that = this
 				uni.showModal({
 					title: '提示',
 					content: '确认要初始化设置',
@@ -388,20 +388,15 @@
 					confirmColor: '#40a7e7',
 					success: (res) => {
 						if (res.confirm) {
-							// let setting = that.setting
-							// setting.gesture = false
-							// console.log(setting)
-							// that.setTing(setting)
 							uni.removeStorageSync("word")
-							uni.removeStorage({
-								key: 'setting',
-								success: (res) => {
-									this.setTing({})
-									uni.showToast({
-										title: '初始化成功', icon:"none"
-									})
-								}
+							Object.keys(that.setting).forEach(function(key){
+								that.setting[key] = false
+								console.log(that.setting);
+							});
+							uni.showToast({
+								title: '初始化成功', icon:"none"
 							})
+							
 						}
 					}
 				})

+ 3 - 3
pages/syeminfo/syeminfo.vue

@@ -7,12 +7,13 @@
 			display: flex;
 			height: 80rpx;
 			line-height: 80rpx;
-			flex-direction: column;
 			justify-content: space-between;
-			align-items: flex-start;
 			font-size: 30rpx;
 			color: #000;
 			border-top: 1rpx solid #efefef;
+			.key{
+				align-self:flex-start;
+			}
 			.value {
 				align-self:flex-end;
 				font-size: 24rpx;
@@ -41,7 +42,6 @@
 	export default {
 		data() {
 			return {
-				systeminfoObj: {},
 				systeminfoArr: [
 				  {
 				    key: 'brand',

+ 34 - 2
store/modules/global.js

@@ -1,10 +1,10 @@
 const state = {
-	userInfo:uni.getStorageSync('suserInfo'),
+	userInfo:uni.getStorageSync('userInfo'),
 	city:"北京",
 	//#ifdef H5
 	signState:uni.getStorageSync('signState') || false,
 	//#endif
-	signState:uni.getStorageSync('signState') || false,
+	signState:uni.getStorageSync('signState') || {},
 	sing: uni.getStorageSync("sing") || 0,
 	setting: uni.getStorageSync("setting") || {},
 	// 手势密码
@@ -13,6 +13,10 @@ const state = {
 	systeminfo:""
 }
 const mutations = {
+	setUserinfo(state, value) {
+		uni.setStorageSync("userInfo", value)
+		state.userInfo = value
+	},
 	setCity(state, value){
 		state.city = value
 	},
@@ -40,7 +44,35 @@ const mutations = {
 	}
 }
 const actions = {
+	async Times() {
+		let data = new Date()
+		var oYear = data.getFullYear()
+		var oMonth = data.getMonth()+1 
+		var oDay = data.getDate()
+		var timer = oYear +'-'+ oMonth +'-'+ oDay
+		return timer
+	},
 	
+	async isDay({dispatch}, data) {
+		console.log(data)
+		var falg = ""
+		await dispatch("Times").then((res) => {
+			var oDate1= new Date(res);
+			var oDate2 = new Date(data);
+			if(oDate1.getTime() > oDate2.getTime()){
+				console.log('+1');
+				falg = 1
+			} else {
+				falg = 2
+				console.log('1');
+			}
+		})
+		if(falg === 1) {
+			return true
+		}else if(falg === 2) {
+			return false
+		}
+	},
 }
 
 export default {