Browse Source

前端时间

wangjiawen 4 years ago
parent
commit
c6480f8d1d
2 changed files with 34 additions and 3 deletions
  1. 21 0
      main.js
  2. 13 3
      pages/index/Index.vue

+ 21 - 0
main.js

@@ -11,6 +11,27 @@ import Dataprocessing from './common/dataprocessing.js';
 Vue.prototype.dataprocessing=Dataprocessing;
 import Common from './common/common.js';
 Vue.prototype.common = Common;
+
+Vue.prototype.getTimeFormat = function(){
+         Date.prototype.Format = function(fmt) {
+				var o = {
+					'y+': this.getYear() + 1, //年
+					'M+': this.getMonth() + 1, //月份
+					'd+': this.getDate(), //日
+					'h+': this.getHours(), //小时
+					'm+': this.getMinutes(), //分
+					's+': this.getSeconds(), //秒
+					'q+': Math.floor((this.getMonth() + 3) / 3), //季度
+					S: this.getMilliseconds() //毫秒
+				};
+				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
+				for (var k in o)
+					if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[
+						k]).substr(('' + o[k]).length));
+				return fmt;
+			};
+}
+
 const app = new Vue({
 	 store,
     ...App

+ 13 - 3
pages/index/Index.vue

@@ -33,7 +33,7 @@
 				<view class="timeimageshizhong" @tap="common.navTo('/components/weatherProphet/WeatherProphet')">
 					<image src="../../static/picture/dafeng.png" style="width: 20px;height: 20px;margin-left: 10px;"></image>
 				</view>
-				<view class="timeText">推荐时间:2020年4月15日 19:31</view>
+				<view class="timeText">推荐时间:{{dateNow}}</view>
 				<view class="timeIcon">
 					<image src="../../static/picture/qingwhite.png" style="width: 25px;height: 25px;"></image>
 				</view>
@@ -953,10 +953,14 @@
 				},
 
 				module: true,
-				cardmodule: true
+				cardmodule: true,
+				dateNow:""
 			};
 		},
 		created: function() {
+
+			this.timeNow();
+			
 			this.viewUserid();
 			this.monitoringAuthority();
 			
@@ -1009,7 +1013,13 @@
 			this.windPowerStationId =this.dataprocessing.getWindPowerStationId();
 		},
 		methods: {
-			viewUserid: function() {
+			timeNow(){
+				this.getTimeFormat();
+				this.dateNow =  new Date().Format('yyyy年MM月dd hh:mm');
+				setTimeout(function() {
+					this.dateNow =  new Date().Format('yyyy年MM月dd hh:mm');
+				}, 60000);
+			},viewUserid: function() {
 				let _this = this;
 				_this.userid = uni.getStorageSync('userid')
 				//_this.userid = sessionStorage.getItem('userid');