瀏覽代碼

time&settimeout清理

panhui 4 年之前
父節點
當前提交
8afd6a4ba5

+ 0 - 1
src/components/Post.vue

@@ -61,7 +61,6 @@
 import vueQrcode from '@chenfengyuan/vue-qrcode';
 import vueQrcode from '@chenfengyuan/vue-qrcode';
 import html2canvas from 'html2canvas';
 import html2canvas from 'html2canvas';
 import product from '../mixins/product';
 import product from '../mixins/product';
-const path = require('path');
 import resolveUrl from 'resolve-url';
 import resolveUrl from 'resolve-url';
 import axios from 'axios';
 import axios from 'axios';
 import { isBefore, format } from 'date-fns';
 import { isBefore, format } from 'date-fns';

+ 5 - 10
src/components/product/productInfo.vue

@@ -48,11 +48,6 @@
 
 
 <script>
 <script>
 import product from '../../mixins/product';
 import product from '../../mixins/product';
-import dayjs from 'dayjs';
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
-dayjs.extend(isSameOrBefore);
-var duration = require('dayjs/plugin/duration');
-dayjs.extend(duration);
 export default {
 export default {
     mixins: [product],
     mixins: [product],
     props: {
     props: {
@@ -66,8 +61,8 @@ export default {
     computed: {
     computed: {
         time() {
         time() {
             if (this.info.startTime) {
             if (this.info.startTime) {
-                if (dayjs().isSameOrBefore(this.info.startTime)) {
-                    return dayjs(this.info.startTime).format('MM月DD日');
+                if (this.dayjs().isSameOrBefore(this.info.startTime, 'YYYY-MM-DD HH:mm:ss')) {
+                    return this.dayjs(this.info.startTime, 'YYYY-MM-DD HH:mm:ss').format('MM月DD日');
                 }
                 }
             }
             }
 
 
@@ -76,9 +71,9 @@ export default {
     },
     },
     mounted() {
     mounted() {
         if (this.info.startTime) {
         if (this.info.startTime) {
-            var x = dayjs(this.info.startTime);
-            var y = dayjs();
-            let d = dayjs.duration(x.diff(y));
+            var x = this.dayjs(this.info.startTime);
+            var y = this.dayjs();
+            let d = this.dayjs.duration(x.diff(y));
             let day = parseInt(d.asDays());
             let day = parseInt(d.asDays());
             if (day <= 0) {
             if (day <= 0) {
                 this.getTime(this.info.startTime);
                 this.getTime(this.info.startTime);

+ 5 - 10
src/components/product/productLarge.vue

@@ -56,11 +56,6 @@
 
 
 <script>
 <script>
 import product from '../../mixins/product';
 import product from '../../mixins/product';
-import dayjs from 'dayjs';
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
-dayjs.extend(isSameOrBefore);
-var duration = require('dayjs/plugin/duration');
-dayjs.extend(duration);
 export default {
 export default {
     mixins: [product],
     mixins: [product],
     props: {
     props: {
@@ -74,8 +69,8 @@ export default {
     computed: {
     computed: {
         time() {
         time() {
             if (this.info.startTime) {
             if (this.info.startTime) {
-                if (dayjs().isSameOrBefore(this.info.startTime)) {
-                    return dayjs(this.info.startTime).format('MM月DD日');
+                if (this.dayjs().isSameOrBefore(this.info.startTime, 'YYYY-MM-DD HH:mm:ss')) {
+                    return this.dayjs(this.info.startTime).format('MM月DD日');
                 }
                 }
             }
             }
 
 
@@ -84,9 +79,9 @@ export default {
     },
     },
     mounted() {
     mounted() {
         if (this.info.startTime) {
         if (this.info.startTime) {
-            var x = dayjs(this.info.startTime);
-            var y = dayjs();
-            let d = dayjs.duration(x.diff(y));
+            var x = this.dayjs(this.info.startTime, 'YYYY-MM-DD HH:mm:ss');
+            var y = this.dayjs();
+            let d = this.dayjs.duration(x.diff(y));
             let day = parseInt(d.asDays());
             let day = parseInt(d.asDays());
             if (day <= 0) {
             if (day <= 0) {
                 this.getTime(this.info.startTime);
                 this.getTime(this.info.startTime);

+ 16 - 0
src/main.js

@@ -21,8 +21,23 @@ import queryString from 'query-string';
 import PageBar from './components/PageBar';
 import PageBar from './components/PageBar';
 import eruda from 'eruda';
 import eruda from 'eruda';
 import mitt from 'mitt';
 import mitt from 'mitt';
+import dayjs from 'dayjs';
+import relativeTime from 'dayjs/plugin/relativeTime';
+import calendar from 'dayjs/plugin/calendar';
+import duration from 'dayjs/plugin/duration';
+import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
+import customParseFormat from 'dayjs/plugin/customParseFormat';
+require('dayjs/locale/zh-cn');
+
 const emitter = mitt();
 const emitter = mitt();
 
 
+dayjs.locale('zh-cn');
+dayjs.extend(relativeTime);
+dayjs.extend(calendar);
+dayjs.extend(duration);
+dayjs.extend(isSameOrBefore);
+dayjs.extend(customParseFormat);
+
 let showConsole = localStorage.getItem('showConsole');
 let showConsole = localStorage.getItem('showConsole');
 if (showConsole && parseInt(showConsole) > new Date().getTime()) {
 if (showConsole && parseInt(showConsole) > new Date().getTime()) {
     eruda.init();
     eruda.init();
@@ -47,6 +62,7 @@ const app = createApp(App)
     .use(store)
     .use(store)
     .use(router);
     .use(router);
 app.config.globalProperties.emitter = emitter;
 app.config.globalProperties.emitter = emitter;
+app.config.globalProperties.dayjs = dayjs;
 
 
 let query = queryString.parse(location.search);
 let query = queryString.parse(location.search);
 if (query.code) {
 if (query.code) {

+ 1 - 4
src/mixins/coupon.js

@@ -1,10 +1,7 @@
-import dayjs from 'dayjs';
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
-dayjs.extend(isSameOrBefore);
 export default {
 export default {
     methods: {
     methods: {
         checkTime(info) {
         checkTime(info) {
-            return dayjs().isSameOrBefore(info.expiration);
+            return this.dayjs().isSameOrBefore(this.dayjs(info.expiration, 'YYYY-MM-DD HH:mm:ss'));
         },
         },
         checkUse(info, collectionId = 0) {
         checkUse(info, collectionId = 0) {
             if (collectionId && info.limited) {
             if (collectionId && info.limited) {

+ 13 - 6
src/mixins/product.js

@@ -1,4 +1,3 @@
-import dayjs from 'dayjs';
 import { abs } from 'mathjs';
 import { abs } from 'mathjs';
 import { differenceInSeconds } from 'date-fns';
 import { differenceInSeconds } from 'date-fns';
 export default {
 export default {
@@ -51,7 +50,7 @@ export default {
         },
         },
         isAppointment() {
         isAppointment() {
             if (this.info.startTime) {
             if (this.info.startTime) {
-                return dayjs().isBefore(dayjs(this.info.startTime));
+                return this.dayjs().isBefore(this.dayjs(this.info.startTime));
             } else {
             } else {
                 return false;
                 return false;
             }
             }
@@ -92,16 +91,16 @@ export default {
 
 
             this.startTime =
             this.startTime =
                 str +
                 str +
-                Math.floor((seconds % 24) / 3600) +
+                this.getCutNum((seconds % 24) / 3600) +
                 ':' +
                 ':' +
-                Math.floor((seconds % 3600) / 60) +
+                this.getCutNum((seconds % 3600) / 60) +
                 ':' +
                 ':' +
-                Math.floor((seconds % 3600) % 60);
+                this.getCutNum((seconds % 3600) % 60);
             if (this.timer) {
             if (this.timer) {
                 clearTimeout(this.timer);
                 clearTimeout(this.timer);
                 this.timer = null;
                 this.timer = null;
             }
             }
-            if (!dayjs().isBefore(dayjs(startTime))) {
+            if (!this.dayjs().isBefore(this.dayjs(startTime, 'YYYY-MM-DD HH:mm:ss'))) {
                 if (this.getProduct) {
                 if (this.getProduct) {
                     this.getProduct();
                     this.getProduct();
                 }
                 }
@@ -112,6 +111,14 @@ export default {
                 }, 1000);
                 }, 1000);
             }
             }
         },
         },
+        getCutNum(num = 0) {
+            num = Math.floor(num);
+            if (num < 10) {
+                return '0' + num;
+            } else {
+                return num;
+            }
+        },
         getShort(str = '') {
         getShort(str = '') {
             if (str) {
             if (str) {
                 str = '...' + str.substr(-8, 8);
                 str = '...' + str.substr(-8, 8);

+ 8 - 1
src/views/Givesubmit.vue

@@ -103,7 +103,8 @@ export default {
             showKeyboard: false,
             showKeyboard: false,
             hrefUrl: '',
             hrefUrl: '',
             inWeixin,
             inWeixin,
-            inApp
+            inApp,
+            timer: null
         };
         };
     },
     },
     computed: {
     computed: {
@@ -288,6 +289,12 @@ export default {
                     }
                     }
                 });
                 });
         }
         }
+    },
+    beforeUnmount() {
+        if (this.timer) {
+            clearTimeout(this.timer);
+            this.timer = null;
+        }
     }
     }
 };
 };
 </script>
 </script>

+ 2 - 5
src/views/asset/Detail.vue

@@ -316,9 +316,6 @@ import { Dialog } from 'vant';
 import HashCode from '../../components/product/HashCode.vue';
 import HashCode from '../../components/product/HashCode.vue';
 import ProductTitle from '../../components/product/ProductTitle.vue';
 import ProductTitle from '../../components/product/ProductTitle.vue';
 import ProductBanner from '../../components/product/ProductBanner.vue';
 import ProductBanner from '../../components/product/ProductBanner.vue';
-import dayjs from 'dayjs';
-var isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
-dayjs.extend(isSameOrBefore);
 export default {
 export default {
     components: {
     components: {
         HashCode,
         HashCode,
@@ -465,7 +462,7 @@ export default {
                     return this.checkBank();
                     return this.checkBank();
                 })
                 })
                 .then(() => {
                 .then(() => {
-                    if (dayjs().isSameOrBefore(dayjs(this.orderInfo.payTime).add(this.holdDays, 'days'))) {
+                    if (this.dayjs().diff(this.dayjs(this.info.createdAt), 'day') < this.holdDays) {
                         this.$toast('持有满' + this.holdDays + '天才能寄售');
                         this.$toast('持有满' + this.holdDays + '天才能寄售');
                     } else if (!this.info.consignment) {
                     } else if (!this.info.consignment) {
                         Dialog.confirm({
                         Dialog.confirm({
@@ -506,7 +503,7 @@ export default {
                 }).then(() => {
                 }).then(() => {
                     this.$router.push('/Authentication');
                     this.$router.push('/Authentication');
                 });
                 });
-            } else if (dayjs().isSameOrBefore(dayjs(this.orderInfo.payTime).add(this.holdDays, 'days'))) {
+            } else if (this.dayjs().diff(this.dayjs(this.info.createdAt), 'day') < this.holdDays) {
                 this.$toast('持有满' + this.holdDays + '天才能转赠');
                 this.$toast('持有满' + this.holdDays + '天才能转赠');
             } else if (this.userInfo.authStatus === 'SUCCESS') {
             } else if (this.userInfo.authStatus === 'SUCCESS') {
                 this.$router.push('/giveSearch?id=' + this.info.id);
                 this.$router.push('/giveSearch?id=' + this.info.id);

+ 0 - 1
src/views/order/Detail.vue

@@ -83,7 +83,6 @@
 import OrderOpen from '../../components/order/OrderOpen.vue';
 import OrderOpen from '../../components/order/OrderOpen.vue';
 import order from '../../mixins/order';
 import order from '../../mixins/order';
 import product from '../../mixins/product';
 import product from '../../mixins/product';
-import dayjs from 'dayjs';
 export default {
 export default {
     components: { OrderOpen },
     components: { OrderOpen },
     name: 'detail',
     name: 'detail',