347617796@qq.com преди 3 години
родител
ревизия
dc770c3622
променени са 1 файла, в които са добавени 34 реда и са изтрити 20 реда
  1. 34 20
      src/home.vue

+ 34 - 20
src/home.vue

@@ -582,7 +582,7 @@ export default {
 		}
 	},
 	mounted() {
-		console.log(this.$supremeAuthority())
+		this.thisweek=this.getTime(7)+'~'+this.getTime(1)
 		if (this.employeeRout) {
 			this.inCommonUse = [];
 			this.inCommonUse.push(
@@ -607,7 +607,6 @@ export default {
 				}, 200);
 			}
 		});
-		this.setDate()
 	},
 	methods: {
 		// 关闭弹框,清除已经生成的二维码
@@ -639,24 +638,39 @@ export default {
 				correctLevel: QRCode.CorrectLevel.H // 容错等级,H是heigh,最高,所以二维码看起来很密
 			})
 		},
-		  setDate() {
-			var thisweek = {};
-			var date = new Date();
-			// 本周一的日期
-			date.setDate(date.getDate() - date.getDay() + 1);
-			let month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
-			let getDate = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
-			thisweek.start_day = month + "-" + getDate;
-			// thisweek.start_day = date.getFullYear() + "-" + month + "-" + getDate;
-		
-			// 本周日的日期
-			date.setDate(date.getDate() + 6);
-			let month2 = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
-			let getDate2 = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
-			thisweek.end_day =month2 + "-" + getDate2;
-			// thisweek.end_day = date.getFullYear() + "-" + month2 + "-" + getDate2;
-			this.thisweek=thisweek.start_day+'~'+thisweek.end_day
-		  },
+		getTime(n) {
+			var now = new Date();
+			var year = now.getFullYear();
+			//因为月份是从0开始的,所以获取这个月的月份数要加1才行
+			var month = now.getMonth() + 1;
+			var date = now.getDate();
+			var day = now.getDay();
+			console.log(date);
+			//判断是否为周日,如果不是的话,就让今天的day-1(例如星期二就是2-1)
+			if (day !== 0) {
+			  n = n + (day - 1);
+			} else {
+			  n = n + day;
+			}
+			if (day) {
+			  //这个判断是为了解决跨年的问题
+			  if (month > 1) {
+				month = month;
+			  }
+			  //这个判断是为了解决跨年的问题,月份是从0开始的
+			  else {
+				year = year - 1;
+				month = 12;
+			  }
+			}
+			now.setDate(now.getDate() - n);
+			year = now.getFullYear();
+			month = now.getMonth() + 1;
+			date = now.getDate();
+			// var s = year + "-" + (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date);
+			var s = (month < 10 ? ('0' + month) : month) + "-" + (date < 10 ? ('0' + date) : date);
+			return s;
+		},
 		GetRequest(urlStr) {
 			if (typeof urlStr == 'undefined') {
 				var url = decodeURI(location.search); //获取url中"?"符后的字符串