Kaynağa Gözat

将moment替换为dayjs

jwyu 2 yıl önce
ebeveyn
işleme
ad08b32e72

+ 2 - 0
main.js

@@ -6,6 +6,8 @@ import mixin from './mixin/index'
 // vant 全局组件 
 import './utils/vantRegister';
 
+import './utils/dayjs-zh-cn'
+
 Vue.config.productionTip = false
 
 App.mpType = 'app'

+ 7 - 7
mixin/index.js

@@ -1,5 +1,5 @@
-const moment=require('../utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('../utils/dayjs.min.js')
+dayjs.locale('zh-cn') 
 
 // 引入全局配置的图片资源地址 
 import {globalImgUrls} from "../utils/config"
@@ -29,10 +29,10 @@ module.exports = {
      * @returns 2020-06-04 15:30-16:30 星期一
      */
     formatActivityTime(start,end){
-      const week=moment(start).format('dddd');
-      const day=moment(start).format('YYYY-MM-DD');
-      const startTime=moment(start).format('HH:mm');
-      const endTime=moment(end).format('HH:mm');
+      const week=dayjs(start).format('dddd');
+      const day=dayjs(start).format('YYYY-MM-DD');
+      const startTime=dayjs(start).format('HH:mm');
+      const endTime=dayjs(end).format('HH:mm');
       return `${day} ${startTime}-${endTime} ${week}`
     },
     /**
@@ -50,7 +50,7 @@ module.exports = {
      * 报告时间格式化
      */
     formatReportTime(e){
-      return moment(e).format('YYYY.MM.DD')
+      return dayjs(e).format('YYYY.MM.DD')
     }
 
   },

+ 3 - 3
mixin/questionMixin.js

@@ -4,12 +4,12 @@ import {
 } from '@/api/question'
 import { apiApplyPermission, apiUserInfo } from '@/api/user'
 import {apiCountAudioClick} from '@/api/question'
-const moment = require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs = require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 export default {
     data() {
         return {
-            moment: moment,
+            dayjs: dayjs,
             innerAudio: null, //该页面的音频
             currentAudioMsg: {
                 id: '',

+ 6 - 6
pages-activity/detail.vue

@@ -188,8 +188,8 @@ import {
 import {apiGetSceneToParams} from '@/api/common'
 import {baseApiUrl} from '@/utils/config.js'
 import sharePoster from '../components/sharePoster/sharePoster.vue'
-const moment=require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 export default {
     name: "ActivityDetail",
     components: {
@@ -301,10 +301,10 @@ export default {
             }
         },
         formatActivityTime(start,end){
-            const week=moment(start).format('dddd');
-            const day=moment(start).format('YYYY-MM-DD');
-            const startTime=moment(start).format('HH:mm');
-            const endTime=moment(end).format('HH:mm');
+            const week=dayjs(start).format('dddd');
+            const day=dayjs(start).format('YYYY-MM-DD');
+            const startTime=dayjs(start).format('HH:mm');
+            const endTime=dayjs(end).format('HH:mm');
             return `${day} ${startTime}-${endTime} ${week}`
         },
         // 点击音频项

+ 14 - 14
pages-buy/detail.vue

@@ -21,8 +21,8 @@
 </template>
 
 <script>
-const moment=require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 import {apiBuyDetail} from '@/api/buy'
 export default {
     data () {
@@ -85,11 +85,11 @@ export default {
 
         // 格式化消息时间
         formatMsgTime(e){
-            const hour=moment(e).hour()//获取小时
-            const dayTime=moment(e).format('hh:mm')
+            const hour=dayjs(e).hour()//获取小时
+            const dayTime=dayjs(e).format('hh:mm')
             let dayStr=''
             if(hour>=0&&hour<5){
-                dayStr=`凌晨 ${moment(e).format('HH:mm')}`
+                dayStr=`凌晨 ${dayjs(e).format('HH:mm')}`
             }else if(hour>=5&&hour<7){
                 dayStr=`清晨 ${dayTime}`
             }else if(hour>=7&&hour<9){
@@ -109,27 +109,27 @@ export default {
             }
 
             // 判断是否为今天
-            if(moment(new Date()).isSame(e, 'day')){
+            if(dayjs(new Date()).isSame(e, 'day')){
                 return dayStr
             }
             // 判断昨天
-            if(moment(moment().subtract(1, 'day')).isSame(e,'day')){
+            if(dayjs(dayjs().subtract(1, 'day')).isSame(e,'day')){
                 return `昨天 ${dayStr}`
             }
             // 前天
-            if(moment(moment().subtract(2, 'day')).isSame(e,'day')){
+            if(dayjs(dayjs().subtract(2, 'day')).isSame(e,'day')){
                 return `前天 ${dayStr}`
             }
             // 周内
-            if(moment(new Date()).isSame(e, 'week')){
-                return `${moment(e).format('ddd')} ${dayStr}`
+            if(dayjs(new Date()).isSame(e, 'week')){
+                return `${dayjs(e).format('ddd')} ${dayStr}`
             }
             //年内
-            if(moment(new Date()).isSame(e, 'year')){
-                return `${moment(e).format('MM月DD日')} ${dayStr}`
+            if(dayjs(new Date()).isSame(e, 'year')){
+                return `${dayjs(e).format('MM月DD日')} ${dayStr}`
             }
 
-            return `${moment(e).format('YYYY年MM月DD日')} ${dayStr}`
+            return `${dayjs(e).format('YYYY年MM月DD日')} ${dayStr}`
 
 
         },
@@ -152,7 +152,7 @@ export default {
 
         //格式化标题
         formatTitle(item){
-            let t=moment(item.time).format('MMDD')
+            let t=dayjs(item.time).format('MMDD')
             if(item.activity_id){
                 return `${item.title}`
             }else{

+ 10 - 10
pages-question/answerDetail.vue

@@ -27,7 +27,7 @@
                       questionItem.answer.audioTime -
                         currentAudioMsg.audioCurrentTime >
                       0
-                        ? moment(
+                        ? dayjs(
                             (questionItem.answer.audioTime -
                               currentAudioMsg.audioCurrentTime) *
                               1000
@@ -37,7 +37,7 @@
                   </template>
                   <template v-else>
                     <text>{{
-                      moment(questionItem.answer.audioTime * 1000).format(
+                      dayjs(questionItem.answer.audioTime * 1000).format(
                         "mm:ss"
                       )
                     }}</text>
@@ -50,7 +50,7 @@
                     mode="aspectFill"
                   />
                   <text>{{
-                    moment(questionItem.answer.audioTime).format("mm:ss")
+                    dayjs(questionItem.answer.audioTime).format("mm:ss")
                   }}</text>
                 </template>
               </view>
@@ -161,12 +161,12 @@
                 />
                 <view class="slider-time">
                   <text>{{
-                    moment(currentAudioMsg.audioCurrentTime * 1000).format(
+                    dayjs(currentAudioMsg.audioCurrentTime * 1000).format(
                       "mm:ss.SS"
                     )
                   }}</text>
                   <text>{{
-                    moment(currentAudioMsg.audioTime * 1000).format("mm:ss.SS")
+                    dayjs(currentAudioMsg.audioTime * 1000).format("mm:ss.SS")
                   }}</text>
                 </view>
               </view>
@@ -208,12 +208,12 @@
                 />
                 <view class="slider-time">
                   <text>{{
-                    moment(currentAudioMsg.audioCurrentTime * 1000).format(
+                    dayjs(currentAudioMsg.audioCurrentTime * 1000).format(
                       "mm:ss"
                     )
                   }}</text>
                   <text>{{
-                      moment(questionItem.answer.audioTime * 1000).format(
+                      dayjs(questionItem.answer.audioTime * 1000).format(
                         "mm:ss"
                       )
                     }}</text>
@@ -353,7 +353,7 @@ export default {
       this.audioItem = null;
       this.audioCount = 0;
       this.scrollTop = 0;
-      this.audioTime = this.moment(this.audioCount * 1000).format("mm:ss");
+      this.audioTime = this.dayjs(this.audioCount * 1000).format("mm:ss");
     },
     //onHide触发
     resetAudio(){
@@ -706,7 +706,7 @@ export default {
       this.timer = setInterval(() => {
         if (this.timer) {
           this.audioCount += 30;
-          this.audioTime = this.moment(this.audioCount).format("mm:ss.SS");
+          this.audioTime = this.dayjs(this.audioCount).format("mm:ss.SS");
           this.scrollTop+=1;
         }
       }, 30);
@@ -716,7 +716,7 @@ export default {
       console.log("结束录音计时");
       clearTimeout(this.timer);
       this.playIconKey++; //更新录音暂停播放图标
-      //this.audioTime = this.moment(this.audioCount).format("mm:ss.SS");
+      //this.audioTime = this.dayjs(this.audioCount).format("mm:ss.SS");
     },
     //scroll-view滑动到最右
     handleScrolltolower(){

+ 3 - 3
pages-question/answerList.vue

@@ -42,13 +42,13 @@
                   <template v-if="item.answer.isplay || item.answer.ispause">
                     <text>{{
                       item.answer.audioTime - currentAudioMsg.audioCurrentTime>0?
-                      moment(item.answer.audioTime - currentAudioMsg.audioCurrentTime).format('mm:ss')
+                      dayjs(item.answer.audioTime - currentAudioMsg.audioCurrentTime).format('mm:ss')
                       :'00:00'}}
                     </text>
                   </template>
                   <template v-else>
                     <text>{{
-                      moment(item.answer.audioTime).format("mm:ss")
+                      dayjs(item.answer.audioTime).format("mm:ss")
                     }}</text>
                   </template>
                 </template>
@@ -58,7 +58,7 @@
                     src="../static/loading.png"
                     mode="aspectFill"
                   />
-                  <text>{{ moment(item.answer.audioTime).format("mm:ss") }}</text>
+                  <text>{{ dayjs(item.answer.audioTime).format("mm:ss") }}</text>
                 </template>
               </view>
             </view>

+ 3 - 3
pages-report/reportList.vue

@@ -75,7 +75,7 @@ import audioBox from './components/audioBox.vue'
 import sharePoster from '@/components/sharePoster/sharePoster.vue'
 import {apiReportList,apiSubClassifyList} from '@/api/report'
 import {apiGetSceneToParams} from '@/api/common'
-const moment=require('@/utils/moment-with-locales.min')
+const dayjs=require('@/utils/dayjs.min')
 export default {
   computed: {
     showAudioPop(){//是否显示音频弹窗
@@ -103,13 +103,13 @@ export default {
         obj.img_1=this.list[0].report_img_url
         obj.title_1=this.list[0].title 
         obj.abstract_1=this.list[0].classify_name_second
-        obj.time_1=`${this.list[0].stage}期 | ${moment(this.list[0].publish_time).format('YYYY.MM.DD')}`
+        obj.time_1=`${this.list[0].stage}期 | ${dayjs(this.list[0].publish_time).format('YYYY.MM.DD')}`
       }
       if(this.list[1]){
         obj.img_2=this.list[1].report_img_url
         obj.title_2=this.list[1].title 
         obj.abstract_2=this.list[1].classify_name_second
-        obj.time_2=`${this.list[1].stage}期 | ${moment(this.list[1].publish_time).format('YYYY.MM.DD')}`
+        obj.time_2=`${this.list[1].stage}期 | ${dayjs(this.list[1].publish_time).format('YYYY.MM.DD')}`
       }
       return obj
     },

+ 3 - 3
pages-report/search.vue

@@ -31,8 +31,8 @@
 </template>
 
 <script>
-const moment=require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 import searchBox from './components/searchBox.vue'
 import {apiReportSearch} from '@/api/report'
 export default {
@@ -93,7 +93,7 @@ export default {
         },
 
         getReportListTime(e){
-            return moment(e).format('YYYY年MM月DD日 HH:mm')
+            return dayjs(e).format('YYYY年MM月DD日 HH:mm')
         }
     }
 }

+ 2 - 2
pages-report/specialColumn/detail.vue

@@ -61,7 +61,7 @@ import {apiSpecialColumnDetail,apiSpecialColumnReportList} from '@/api/report'
 import {apiGetSceneToParams} from '@/api/common'
 import audioBox from '../components/audioBox.vue'
 import sharePoster from '@/components/sharePoster/sharePoster.vue'
-const moment=require('@/utils/moment-with-locales.min')
+const dayjs=require('@/utils/dayjs.min')
 export default {
     computed: {
         showAudioPop(){//是否显示音频弹窗
@@ -214,7 +214,7 @@ export default {
         },
 
         formatTitle(item){
-            let t=moment(item.publish_time).format('MMDD')
+            let t=dayjs(item.publish_time).format('MMDD')
             return `【第${item.stage}期】${item.classify_name_second}(${t})`
         }
     }

+ 8 - 8
pages-user/messageList.vue

@@ -55,8 +55,8 @@
 
 <script>
 	import * as $message from '@/api/message.js'
-	const moment = require('../utils/moment-with-locales.min.js');
-	moment.locale('zh-cn'); 
+	const dayjs = require('../utils/dayjs.min.js');
+	dayjs.locale('zh-cn') 
 	export default {
 		filters: {
 			formatTime(val) {
@@ -67,17 +67,17 @@
 	
 				//当天
 				if(infer_time === 0) {
-					return moment(time).format('HH:mm:ss')
+					return dayjs(time).format('HH:mm:ss')
 				} else if(infer_time === 1) {
-					return `昨天 ${moment(time).format('HH:mm:ss')}`
+					return `昨天 ${dayjs(time).format('HH:mm:ss')}`
 				} else if(infer_time === 2) {
-					return `前天 ${moment(time).format('HH:mm:ss')}`
+					return `前天 ${dayjs(time).format('HH:mm:ss')}`
 				} else if( infer_time >=3 && infer_time <=7 ) { //周内
-					return moment(time).format('ddd HH:mm:ss')
+					return dayjs(time).format('ddd HH:mm:ss')
 				} else if(infer_year === 0) {
-					return moment(time).format('MM-DD HH:mm:ss')
+					return dayjs(time).format('MM-DD HH:mm:ss')
 				} else {
-					return moment(time).format('YYYY-MM-DD HH:mm:ss')
+					return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
 				}
 			}
 		},

+ 6 - 6
pages/activity/activity.vue

@@ -209,8 +209,8 @@ import {
 } from '@/api/activity'
 import {apiApplyPermission,apiUserInfo} from '@/api/user'
 import sharePoster from '../../components/sharePoster/sharePoster.vue'
-const moment=require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 export default {
     components: {
         sharePoster
@@ -371,10 +371,10 @@ export default {
 
     methods: {
         formatActivityTime(start,end){
-            const week=moment(start).format('dddd');
-            const day=moment(start).format('YYYY-MM-DD');
-            const startTime=moment(start).format('HH:mm');
-            const endTime=moment(end).format('HH:mm');
+            const week=dayjs(start).format('dddd');
+            const day=dayjs(start).format('YYYY-MM-DD');
+            const startTime=dayjs(start).format('HH:mm');
+            const endTime=dayjs(end).format('HH:mm');
             return `${day} ${startTime}-${endTime} ${week}`
         },
         // 初始化音频状态

+ 8 - 8
pages/buy/buy.vue

@@ -17,23 +17,23 @@
 </template>
 
 <script>
-const moment=require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 import {apiBuyList} from '@/api/buy.js'
 export default {
   filters: {
     showTime(e){
       // 判断是否为今年
-      const isYear=moment(e).isBefore(new Date(), 'year');
+      const isYear=dayjs(e).isBefore(new Date(), 'year');
       if(isYear){
-        return moment(e).format("YYYY年MM月DD日");
+        return dayjs(e).format("YYYY年MM月DD日");
       }else{
-        const isDay=moment(e).isBefore(new Date(), 'day');
+        const isDay=dayjs(e).isBefore(new Date(), 'day');
         if(isDay){
-          return moment(e).format("MM月DD日");
+          return dayjs(e).format("MM月DD日");
         }else{
-          const hour=moment(e).hour()
-          return hour<12?`上午 ${moment(e).format('hh:mm')}`:`下午 ${moment(e).format('hh:mm')}`
+          const hour=dayjs(e).hour()
+          return hour<12?`上午 ${dayjs(e).format('hh:mm')}`:`下午 ${dayjs(e).format('hh:mm')}`
         }
       }
     }

+ 3 - 3
pages/question/question.vue

@@ -51,17 +51,17 @@
 									<template v-if="item.answer.isplay || item.answer.ispause">
 										<text>{{
 											item.answer.audioTime - currentAudioMsg.audioCurrentTime>0?
-											moment(item.answer.audioTime - currentAudioMsg.audioCurrentTime).format('mm:ss')
+											dayjs(item.answer.audioTime - currentAudioMsg.audioCurrentTime).format('mm:ss')
 											:'00:00'}}
 										</text>
 									</template>
 									<template v-else>
-										<text>{{ moment(item.answer.audioTime).format('mm:ss') }}</text>
+										<text>{{ dayjs(item.answer.audioTime).format('mm:ss') }}</text>
 									</template>
 								</template>
 								<template v-else>
 									<image class="load-img" src="../../static/loading.png" mode="aspectFill" />
-									<text>{{ moment(item.answer.audioTime).format('mm:ss') }}</text>
+									<text>{{ dayjs(item.answer.audioTime).format('mm:ss') }}</text>
 								</template>
 							</view>
 						</view>

+ 6 - 6
pages/report/report.vue

@@ -84,14 +84,14 @@
 </template>
 
 <script>
-const moment=require('@/utils/moment-with-locales.min')
-moment.locale('zh-cn');
+const dayjs=require('@/utils/dayjs.min')
+dayjs.locale('zh-cn') 
 import {apiReportIndexPageAuthList,apiReportIndexPageList} from '@/api/report'
 import { apiHomeTab } from '@/api/user.js';
 export default {
   filters: {
     getListTime(e){
-      return moment(e).format('HH:mm:ss')
+      return dayjs(e).format('HH:mm:ss')
     }
   },
   data () {
@@ -317,11 +317,11 @@ export default {
 
     //设置列表日期显示
     getReportListDate(e){
-      const isSameYear=moment(e).isSame(new Date(), 'year');
+      const isSameYear=dayjs(e).isSame(new Date(), 'year');
       if(isSameYear){//今年
-        return moment(e).format('MM.DD')+' '+ moment(e).format('ddd')
+        return dayjs(e).format('MM.DD')+' '+ dayjs(e).format('ddd')
       }else{
-        return moment(e).format('YY.MM.DD')+' '+moment(e).format('ddd')
+        return dayjs(e).format('YY.MM.DD')+' '+dayjs(e).format('ddd')
       }
     }
   }

+ 2 - 2
pages/user/user.vue

@@ -96,7 +96,7 @@
 </template>
 
 <script>
-	const moment=require('@/utils/moment-with-locales.min')
+	const dayjs=require('@/utils/dayjs.min')
 	import {apiLastApplyRecord,apiApplyPermission} from '@/api/user'
 	import {apiGetUnread} from '@/api/question'
 	export default {
@@ -114,7 +114,7 @@
 				if(timeArr.length===0){
 					return ''
 				}else{
-					return moment(maxTime).format('YYYY.MM.DD')
+					return dayjs(maxTime).format('YYYY.MM.DD')
 				}
 				
 			}	

+ 2 - 2
pages/voice/voice.vue

@@ -82,7 +82,7 @@ import {apiVoiceList,apiVoiceSectionList,apiVoicePlayRecord,apiVoiceDel} from '@
 import {apiGetSceneToParams} from '@/api/common'
 import noAuth from './components/noAuth.vue'
 import voiceBox from '@/components/voiceBox/voiceBox.vue'
-const moment=require('@/utils/moment-with-locales.min')
+const dayjs=require('@/utils/dayjs.min')
 export default {
     components:{
         noAuth,
@@ -90,7 +90,7 @@ export default {
     },
     filters:{
         formatTime(e){
-            return moment(e).format('YYYY-MM-DD HH:mm:ss')
+            return dayjs(e).format('YYYY-MM-DD HH:mm:ss')
         },
         formatVoiceTime(e){
             let m=parseInt(e/60)

+ 68 - 0
utils/dayjs-zh-cn.js

@@ -0,0 +1,68 @@
+// Chinese (China) [zh-cn]
+const dayjs=require('./dayjs.min.js')
+
+const locale = {
+  name: 'zh-cn',
+  weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'),
+  weekdaysShort: '周日_周一_周二_周三_周四_周五_周六'.split('_'),
+  weekdaysMin: '日_一_二_三_四_五_六'.split('_'),
+  months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'),
+  monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
+  ordinal: (number, period) => {
+    switch (period) {
+      case 'W':
+        return `${number}周`
+      default:
+        return `${number}日`
+    }
+  },
+  weekStart: 1,
+  yearStart: 4,
+  formats: {
+    LT: 'HH:mm',
+    LTS: 'HH:mm:ss',
+    L: 'YYYY/MM/DD',
+    LL: 'YYYY年M月D日',
+    LLL: 'YYYY年M月D日Ah点mm分',
+    LLLL: 'YYYY年M月D日ddddAh点mm分',
+    l: 'YYYY/M/D',
+    ll: 'YYYY年M月D日',
+    lll: 'YYYY年M月D日 HH:mm',
+    llll: 'YYYY年M月D日dddd HH:mm'
+  },
+  relativeTime: {
+    future: '%s内',
+    past: '%s前',
+    s: '几秒',
+    m: '1 分钟',
+    mm: '%d 分钟',
+    h: '1 小时',
+    hh: '%d 小时',
+    d: '1 天',
+    dd: '%d 天',
+    M: '1 个月',
+    MM: '%d 个月',
+    y: '1 年',
+    yy: '%d 年'
+  },
+  meridiem: (hour, minute) => {
+    const hm = (hour * 100) + minute
+    if (hm < 600) {
+      return '凌晨'
+    } else if (hm < 900) {
+      return '早上'
+    } else if (hm < 1100) {
+      return '上午'
+    } else if (hm < 1300) {
+      return '中午'
+    } else if (hm < 1800) {
+      return '下午'
+    }
+    return '晚上'
+  }
+}
+
+dayjs.locale(locale, null, true)
+
+export default locale
+

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
utils/dayjs.min.js


Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
utils/moment-with-locales.min.js


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor