panhui há 4 anos atrás
pai
commit
0d4600b905
6 ficheiros alterados com 35 adições e 26 exclusões
  1. 1 1
      .env.development
  2. 1 0
      package.json
  3. 3 7
      src/components/Post.vue
  4. 20 17
      src/mixins/product.js
  5. 5 1
      src/views/Submit.vue
  6. 5 0
      yarn.lock

+ 1 - 1
.env.development

@@ -1,4 +1,4 @@
-VUE_APP_BASE_URL=https://www.raex.vip
+VUE_APP_BASE_URL=https://test.raex.vip
 NODE_ENV=development
 PUBLIC_PATH=/
 ASSETS_PATH=raex

+ 1 - 0
package.json

@@ -16,6 +16,7 @@
         "better-scroll": "^2.4.2",
         "clipboard": "^2.0.8",
         "core-js": "^3.6.5",
+        "date-fns": "^2.27.0",
         "dayjs": "^1.10.7",
         "echarts": "^4.9.0",
         "element-ui": "^2.15.6",

+ 3 - 7
src/components/Post.vue

@@ -64,12 +64,8 @@ import product from '../mixins/product';
 const path = require('path');
 import resolveUrl from 'resolve-url';
 import axios from 'axios';
-import dayjs from 'dayjs';
+import { isBefore, format } from 'date-fns';
 import { abs } from 'mathjs';
-require('dayjs/locale/zh-cn');
-dayjs.locale('zh-cn');
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
-dayjs.extend(isSameOrBefore);
 export default {
     mixins: [product],
     props: {
@@ -125,8 +121,8 @@ export default {
         },
         time() {
             if (this.info.startTime) {
-                if (dayjs().isSameOrBefore(this.info.startTime)) {
-                    return dayjs(this.info.startTime).format('MM月DD日');
+                if (isBefore(new Date(this.info.startTime), new Date())) {
+                    return format(new Date(this.info.startTime), 'mm月dd日');
                 }
             }
 

+ 20 - 17
src/mixins/product.js

@@ -1,15 +1,6 @@
 import dayjs from 'dayjs';
 import { abs } from 'mathjs';
-require('dayjs/locale/zh-cn');
-dayjs.locale('zh-cn');
-var relativeTime = require('dayjs/plugin/relativeTime');
-dayjs.extend(relativeTime);
-var calendar = require('dayjs/plugin/calendar');
-dayjs.extend(calendar);
-var duration = require('dayjs/plugin/duration');
-dayjs.extend(duration);
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
-dayjs.extend(isSameOrBefore);
+import { differenceInSeconds } from 'date-fns';
 export default {
     data() {
         return {
@@ -90,16 +81,22 @@ export default {
             if (!this.isAppointment) {
                 return;
             }
-            var x = dayjs(startTime);
-            var y = dayjs();
-            let d = dayjs.duration(x.diff(y));
-            let day = parseInt(d.asDays());
+
+            let seconds = differenceInSeconds(new Date(startTime), new Date());
+            console.log(seconds);
             let str = '';
-            if (abs(day) > 0) {
-                str += day + '天 ';
+            let d = Math.floor(seconds / 24 / 3600);
+            if (abs(d) > 0) {
+                str += d + '天 ';
             }
 
-            this.startTime = str + dayjs.duration(x.diff(y)).format('HH:mm:ss');
+            this.startTime =
+                str +
+                Math.floor((seconds % 24) / 3600) +
+                ':' +
+                Math.floor((seconds % 3600) / 60) +
+                ':' +
+                Math.floor((seconds % 3600) % 60);
             if (this.timer) {
                 clearTimeout(this.timer);
                 this.timer = null;
@@ -121,5 +118,11 @@ export default {
             }
             return str;
         }
+    },
+    beforeUnmount() {
+        if (this.timer) {
+            clearTimeout(this.timer);
+            this.timer = null;
+        }
     }
 };

+ 5 - 1
src/views/Submit.vue

@@ -197,6 +197,10 @@ export default {
     },
     beforeUnmount() {
         this.emitter.off('iapEvent', this.iapEvent);
+        if (this.timer) {
+            clearTimeout(this.timer);
+            this.timer = null;
+        }
     },
     methods: {
         getOrder(next = false) {
@@ -403,7 +407,7 @@ export default {
                     break;
             }
         }
-    }
+    },
 };
 </script>
 

+ 5 - 0
yarn.lock

@@ -3360,6 +3360,11 @@ dashdash@^1.12.0:
   dependencies:
     assert-plus "^1.0.0"
 
+date-fns@^2.27.0:
+  version "2.27.0"
+  resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.27.0.tgz#e1ff3c3ddbbab8a2eaadbb6106be2929a5a2d92b"
+  integrity sha512-sj+J0Mo2p2X1e306MHq282WS4/A8Pz/95GIFcsPNMPMZVI3EUrAdSv90al1k+p74WGLCruMXk23bfEDZa71X9Q==
+
 dayjs@^1.10.7:
   version "1.10.7"
   resolved "https://registry.nlark.com/dayjs/download/dayjs-1.10.7.tgz#2cf5f91add28116748440866a0a1d26f3a6ce468"