Commit 74df59a8e075caa671a40140f098896622aa7d44
1 parent
c9d45ef5
商户券 有效期
Showing
2 changed files
with
29 additions
and
3 deletions
common/date.js
0 → 100644
| 1 | +export function formatDate (date, fmt) { | ||
| 2 | + if (/(y+)/.test(fmt)) { | ||
| 3 | + fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)); | ||
| 4 | + } | ||
| 5 | + let o = { | ||
| 6 | + 'M+': date.getMonth() + 1, | ||
| 7 | + 'd+': date.getDate(), | ||
| 8 | + 'h+': date.getHours(), | ||
| 9 | + 'm+': date.getMinutes(), | ||
| 10 | + 's+': date.getSeconds() | ||
| 11 | + }; | ||
| 12 | + for (let k in o) { | ||
| 13 | + if (new RegExp(`(${k})`).test(fmt)) { | ||
| 14 | + let str = o[k] + ''; | ||
| 15 | + fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str)); | ||
| 16 | + } | ||
| 17 | + } | ||
| 18 | + return fmt; | ||
| 19 | +}; | ||
| 20 | +function padLeftZero (str) { | ||
| 21 | + return ('00' + str).substr(str.length); | ||
| 22 | +}; | ||
| 0 | \ No newline at end of file | 23 | \ No newline at end of file |
pages/businessCard/printCard.vue
| @@ -34,6 +34,7 @@ | @@ -34,6 +34,7 @@ | ||
| 34 | 34 | ||
| 35 | <script> | 35 | <script> |
| 36 | import uQRCode from '../../common/uqrcode.js' //引入uqrcode.js | 36 | import uQRCode from '../../common/uqrcode.js' //引入uqrcode.js |
| 37 | +import {formatDate} from '../../common/date.js'; | ||
| 37 | export default { | 38 | export default { |
| 38 | data() { | 39 | data() { |
| 39 | return { | 40 | return { |
| @@ -47,7 +48,8 @@ export default { | @@ -47,7 +48,8 @@ export default { | ||
| 47 | deadline: '2099-10-01 00:00:00', | 48 | deadline: '2099-10-01 00:00:00', |
| 48 | qrUrl: '', // 图片地址 | 49 | qrUrl: '', // 图片地址 |
| 49 | single: '', | 50 | single: '', |
| 50 | - startTime:'' | 51 | + startTime:'', |
| 52 | + deadlineInit:"" | ||
| 51 | } | 53 | } |
| 52 | }, | 54 | }, |
| 53 | onLoad(params) { | 55 | onLoad(params) { |
| @@ -70,8 +72,9 @@ export default { | @@ -70,8 +72,9 @@ export default { | ||
| 70 | mounted() { | 72 | mounted() { |
| 71 | setTimeout(() => { | 73 | setTimeout(() => { |
| 72 | this.startTime = Date.now() | 74 | this.startTime = Date.now() |
| 73 | - this.single = Date.now() | ||
| 74 | - | 75 | + this.single = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss') |
| 76 | + this.deadlineInit = formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss'); | ||
| 77 | + console.log(this.single) | ||
| 75 | },500) | 78 | },500) |
| 76 | }, | 79 | }, |
| 77 | computed: {}, | 80 | computed: {}, |
| @@ -115,6 +118,7 @@ export default { | @@ -115,6 +118,7 @@ export default { | ||
| 115 | }) | 118 | }) |
| 116 | }, | 119 | }, |
| 117 | changeTime: function () { | 120 | changeTime: function () { |
| 121 | + console.log(this.single) | ||
| 118 | this.deadline = this.single | 122 | this.deadline = this.single |
| 119 | this.getCouponStaticQR() | 123 | this.getCouponStaticQR() |
| 120 | }, | 124 | }, |