xiongzhu před 4 roky
rodič
revize
f94eba1bed

+ 2 - 10
src/components/Post.vue

@@ -61,15 +61,7 @@
 import vueQrcode from '@chenfengyuan/vue-qrcode';
 import html2canvas from 'html2canvas';
 import product from '../mixins/product';
-const path = require('path');
 import resolveUrl from 'resolve-url';
-import axios from 'axios';
-import dayjs from 'dayjs';
-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 +117,8 @@ export default {
         },
         time() {
             if (this.info.startTime) {
-                if (dayjs().isSameOrBefore(this.info.startTime)) {
-                    return dayjs(this.info.startTime).format('MM月DD日');
+                if (this.dayjs().isSameOrBefore(this.dayjs(this.info.startTime, 'YYYY-MM-DD HH:mm:ss'))) {
+                    return this.dayjs(this.info.startTime, 'YYYY-MM-DD HH:mm:ss').format('MM月DD日');
                 }
             }
 

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

@@ -48,11 +48,6 @@
 
 <script>
 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 {
     mixins: [product],
     props: {
@@ -66,8 +61,8 @@ export default {
     computed: {
         time() {
             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() {
         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());
             if (day <= 0) {
                 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 eruda from 'eruda';
 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();
 
+dayjs.locale('zh-cn');
+dayjs.extend(relativeTime);
+dayjs.extend(calendar);
+dayjs.extend(duration);
+dayjs.extend(isSameOrBefore);
+dayjs.extend(customParseFormat);
+
 let showConsole = localStorage.getItem('showConsole');
 if (showConsole && parseInt(showConsole) > new Date().getTime()) {
     eruda.init();
@@ -47,6 +62,7 @@ const app = createApp(App)
     .use(store)
     .use(router);
 app.config.globalProperties.emitter = emitter;
+app.config.globalProperties.dayjs = dayjs;
 
 let query = queryString.parse(location.search);
 if (query.code) {

+ 6 - 17
src/mixins/product.js

@@ -1,15 +1,4 @@
-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);
 export default {
     data() {
         return {
@@ -60,7 +49,7 @@ export default {
         },
         isAppointment() {
             if (this.info.startTime) {
-                return dayjs().isBefore(dayjs(this.info.startTime));
+                return this.dayjs().isBefore(this.dayjs(this.info.startTime));
             } else {
                 return false;
             }
@@ -90,21 +79,21 @@ export default {
             if (!this.isAppointment) {
                 return;
             }
-            var x = dayjs(startTime);
-            var y = dayjs();
-            let d = dayjs.duration(x.diff(y));
+            var x = this.dayjs(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 str = '';
             if (abs(day) > 0) {
                 str += day + '天 ';
             }
 
-            this.startTime = str + dayjs.duration(x.diff(y)).format('HH:mm:ss');
+            this.startTime = str + this.dayjs.duration(x.diff(y)).format('HH:mm:ss');
             if (this.timer) {
                 clearTimeout(this.timer);
                 this.timer = null;
             }
-            if (!dayjs().isBefore(dayjs(startTime))) {
+            if (!this.dayjs().isBefore(this.dayjs(startTime))) {
                 if (this.getProduct) {
                     this.getProduct();
                 }

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

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