{"id":33401,"date":"2024-11-25T14:43:53","date_gmt":"2024-11-25T06:43:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33401\/"},"modified":"2024-11-25T14:43:53","modified_gmt":"2024-11-25T06:43:53","slug":"%e8%ae%b0%e4%b8%80%e6%ac%a1%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%9c%a8%e5%ae%89%e5%8d%93%e6%89%8b%e6%9c%ba%e4%b8%8a%e7%9a%84%e7%99%bd%e5%b1%8f%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33401\/","title":{"rendered":"\u8bb0\u4e00\u6b21\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5728\u5b89\u5353\u624b\u673a\u4e0a\u7684\u767d\u5c4f\u95ee\u9898"},"content":{"rendered":"<blockquote><p>\n  \u5728\u505a\u5c0f\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u505a\u5230\u4e86\u4e00\u4e2a\u9650\u65f6\u5546\u54c1\u552e\u5356\uff0c\u7528\u5230\u4e86\u5012\u8ba1\u65f6\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u539f\u56e0\u5bfc\u81f4\u4e86\u5b89\u5353\u624b\u673a\u4e0a\u4f7f\u7528\u5c0f\u7a0b\u5e8f\u65f6\uff0c\u5c06\u5c0f\u7a0b\u5e8f\u653e\u5165\u540e\u53f0\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u518d\u6b21\u8fdb\u5165\u5c0f\u7a0b\u5e8f\u540e\u51fa\u73b0\u4e86\u9875\u9762\u767d\u5c4f\u6216\u8005\u70b9\u51fb\u4e8b\u4ef6\u5931\u6548\u7684\u60c5\u51b5\uff0c\u8fd9\u91cc\u8bb0\u5f55\u4e0b\n<\/p><\/blockquote>\n<h1><span style=\"font-size: 14px\">1.\u76f8\u5173\u4ee3\u7801\u6587\u4ef6<\/span><\/h1>\n<blockquote><p>\n  \u6211\u8fd9\u91cc\u662f\u4f7f\u7528\u4e86\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5f62\u5f0f\u6765\u6e32\u67d3\u7684\n<\/p><\/blockquote>\n<ul>\n<li><span style=\"font-size: 14px\">\u5916\u90e8\u7684\u5f15\u7528\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684wxml\u6587\u4ef6<\/span><\/li>\n<\/ul>\n<pre>\/* limitCommodity\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u8fd4\u56de\u7684\u662f\u5546\u54c1\u5bf9\u8c61\uff0c\u5305\u542b\u5546\u54c1\u4ef7\u683c\u3001\u5546\u54c1\u7ed3\u675f\u65f6\u95f4\u3001\u5546\u54c1\u56fe\u7247\u7b49 *\/\n&lt;block wx:for=\"{{limitCommodity}}\" wx:key=\"{{item.id}}\"&gt;\n    &lt;commodityItem class=\"specialContent\" goods=\"{{item}}\" \/&gt;\n&lt;\/block&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><span style=\"font-size: 14px\">\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684js\u6587\u4ef6<\/span><\/li>\n<\/ul>\n<pre>Component({\n  properties: {\n    goods: Object\n  },\n  data: {\n  },\n  timer: null,\n  \/* \u5728\u7ec4\u4ef6\u5b9e\u4f8b\u8fdb\u5165\u9875\u9762\u8282\u70b9\u6811\u65f6\u6267\u884c\uff0c\u5f00\u59cb\u5b9a\u65f6\u5668 *\/\n  attached: function() {\n    if(this.timer) {\n      clearInterval(this.timer);\n    }\n    this.filterTime();\n    let that = this;    \n    this.timer = setInterval(function () {\n      that.filterTime();\n    }, 1000)\n  },\n  \/* \u5728\u7ec4\u4ef6\u5b9e\u4f8b\u88ab\u4ece\u9875\u9762\u8282\u70b9\u6811\u79fb\u9664\u65f6\u6267\u884c\uff0c\u5c06\u5b9a\u65f6\u5668\u6e05\u9664 *\/\n  detached: function() {\n    clearInterval(this.timer);\n    this.timer = null;\n  },\n  methods: {\n    \/* \u7528\u4e8e\u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u6210\u81ea\u5b9a\u4e49\u7684\u65f6\u95f4\u683c\u5f0f *\/\n    filterTime() {\n      let totalTime = new Date(parseInt(this.data.goods.endtime) * 1000) - new Date();\n      let days = parseInt(totalTime \/ 1000 \/ 60 \/ 60 \/ 24, 10);\n      let hours = parseInt(totalTime \/ 1000 \/ 60 \/ 60 % 24, 10);\n      let minutes = parseInt(totalTime \/ 1000 \/ 60 % 60, 10);\n      let seconds = parseInt(totalTime \/ 1000 % 60, 10);\n      let day = days &gt;= 10 ? days : '0' + days;\n      day = day == 0 ? '' : day + '\u5929';\n      let hour = hours &gt;= 10 ? hours : '0' + hours;\n      let minute = minutes &gt;= 10 ? minutes : '0' + minutes;\n      let second = seconds &gt;= 10 ? seconds : '0' + seconds;\n      this.setData({\n        limitTime: day + hour + \":\" + minute + \":\" + second\n      })\n    },\n  }\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h1><span style=\"font-size: 14px\">2.\u5f15\u8d77\u7684\u539f\u56e0<\/span><\/h1>\n<ul>\n<li><span style=\"font-size: 14px\">\u56e0\u4e3a\u5728\u5916\u90e8\u5f15\u5165\u81ea\u5b9a\u4e49\u7684\u7ec4\u4ef6\u65f6\uff0c\u76f4\u63a5\u5c31\u662f\u8c03\u7528\u4e86\u5b9a\u65f6\u5668\u5e76\u4e14\u8fdb\u884c\u4e86setData\u64cd\u4f5c\uff0c\u8fd9\u5c31\u5bfc\u81f4\u4e86\u5f53\u5728\u5916\u90e8\u5f15\u7528\u8fd9\u4e2a\u7ec4\u4ef6\u65f6\uff0c\u5982\u679c\u4f20\u5165\u7684\u5546\u54c1\u6570\u7ec4\u957f\u5ea6\u8f83\u5927\u65f6\uff0c\u5b9a\u65f6\u5668\u589e\u591a\u7684\u540c\u65f6\uff0csetData\u64cd\u4f5c\u4e5f\u4e0d\u65ad\u7684\u589e\u591a<\/span><\/li>\n<li><span style=\"font-size: 14px\">setData\u591a\u4e86\u5c31\u4f1a\u5bfc\u81f4\u5185\u5b58\u5360\u7528\u591a<\/span><\/li>\n<\/ul>\n<h1><span style=\"font-size: 14px\">3.\u6539\u8fdb\u65b9\u6cd5<\/span><\/h1>\n<blockquote><p>\n  \u6539\u8fdb\u65b9\u6cd5\u5c31\u662f\u51cf\u5c11setData\u64cd\u4f5c\n<\/p><\/blockquote>\n<ul>\n<li><span style=\"font-size: 14px\">\u53ef\u4ee5\u518d\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u7528\u4e8e\u5c06\u6574\u4e2a\u6570\u7ec4\u4f20\u5165<\/span><\/li>\n<li><span style=\"font-size: 14px\">\u7136\u540e\u5bf9\u5546\u54c1\u6570\u7ec4\u91cc\u7684\u65f6\u95f4\u5148\u8fdb\u884c\u8ba1\u7b97<\/span><\/li>\n<li><span style=\"font-size: 14px\">\u6539\u8fdb\u540e\u7684js\u6587\u4ef6<\/span><\/li>\n<\/ul>\n<pre>Component({\n  properties: {\n    limitCommodity:Array\n  },\n  data: {\n  },\n  timeOut:null,\n  \/* \u5728\u7ec4\u4ef6\u5b9e\u4f8b\u8fdb\u5165\u9875\u9762\u8282\u70b9\u6811\u65f6\u6267\u884c *\/\n  attached(){\n    this.calculate();\n  },\n  \/* \u5728\u7ec4\u4ef6\u5b9e\u4f8b\u88ab\u4ece\u9875\u9762\u8282\u70b9\u6811\u79fb\u9664\u65f6\u6267\u884c\uff0c\u5c06\u5b9a\u65f6\u5668\u6e05\u9664 *\/\n  detached(){\n    clearTimeout(this.timeOut);\n    this.timeOut = null;\n  },\n  methods: {\n    filterTime(endtime) {\n      let totalTime = new Date(parseInt(endtime) * 1000) - new Date();\n      let days = parseInt(totalTime \/ 1000 \/ 60 \/ 60 \/ 24, 10);\n      let hours = parseInt(totalTime \/ 1000 \/ 60 \/ 60 % 24, 10);\n      let minutes = parseInt(totalTime \/ 1000 \/ 60 % 60, 10);\n      let seconds = parseInt(totalTime \/ 1000 % 60, 10);\n      let day = days &gt;= 10 ? days : '0' + days;\n      day = day == 0 ? '' : day + '\u5929';\n      let hour = hours &gt;= 10 ? hours : '0' + hours;\n      let minute = minutes &gt;= 10 ? minutes : '0' + minutes;\n      let second = seconds &gt;= 10 ? seconds : '0' + seconds;\n      return day + hour + \":\" + minute + \":\" + second\n    },\n    calculate(){\n      let limitCommodity = this.data.limitCommodity;\n      for (let i = 0; i &lt; limitCommodity.length;i++){\n        limitCommodity[i]['endtime_date'] = this.filterTime(limitCommodity[i]['endtime'])\n      }\n      this.setData({\n        limitCommodity\n      })\n      this.timeOut = setTimeout(()=&gt;{\n        this.calculate();\n      },1000);\n    }\n  }\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><span style=\"font-size: 14px\">\u6539\u8fdb\u5c31\u662f\u8ba1\u7b97\u65f6\u95f4\u540e\u518d\u8fd4\u56de\u65f6\u95f4\uff0c\u800csetData\u7684\u662f\u6574\u4e2a\u5546\u54c1\u5217\u8868\u6570\u7ec4\uff0c\u8fd9\u6837\u5c31\u51cf\u5c11\u4e86setData\u6b21\u6570<\/span><\/li>\n<\/ul>\n<blockquote><p>\n  \u6b63\u5728\u52aa\u529b\u5b66\u4e60\u4e2d\uff0c\u82e5\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u5e2e\u52a9\uff0c\u7559\u4e0b\u4f60\u7684\u5370\u8bb0\u5457\uff08\u70b9\u4e2a\u8d5e\u54af^_^\uff09\n<\/p><\/blockquote>\n<p>\u63a8\u8350\u6559\u7a0b\uff1a\u300a\u300b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8bb0\u4e00\u6b21\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5728\u5b89\u5353\u624b\u673a\u4e0a\u7684\u767d\u5c4f\u95ee\u9898\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u505a\u5c0f\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u505a\u5230\u4e86\u4e00\u4e2a\u9650\u65f6\u5546\u54c1\u552e\u5356\uff0c\u7528\u5230\u4e86\u5012\u8ba1\u65f6\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u539f\u56e0\u5bfc\u81f4\u4e86\u5b89\u5353\u624b\u673a\u4e0a\u4f7f\u7528\u5c0f\u7a0b\u5e8f\u65f6\uff0c\u5c06\u5c0f\u7a0b\u5e8f\u653e\u5165\u540e\u53f0\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u540e\uff0c\u518d\u6b21\u8fdb\u5165\u5c0f\u7a0b\u5e8f\u540e\u51fa\u73b0\u4e86\u9875\u9762\u767d\u5c4f\u6216\u8005\u70b9\u51fb\u4e8b\u4ef6\u5931\u6548\u7684\u60c5\u51b5\uff0c\u8fd9\u91cc\u8bb0\u5f55\u4e0b 1.\u76f8\u5173\u4ee3\u7801\u6587\u4ef6 \u6211\u8fd9\u91cc\u662f\u4f7f\u7528\u4e86\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5f62\u5f0f\u6765\u6e32\u67d3\u7684 \u5916\u90e8\u7684\u5f15\u7528\u7684\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684wxml\u6587\u4ef6 \/* limitCommodity\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u8fd4\u56de\u7684\u662f\u5546\u54c1\u5bf9\u8c61\uff0c\u5305\u542b\u5546\u54c1\u4ef7\u683c\u3001\u5546\u54c1\u7ed3\u675f\u65f6\u95f4\u3001\u5546\u54c1\u56fe\u7247\u7b49 *\/ &lt;block wx:for=&#8221;{{limitCommodity}}&#8221; wx:key=&#8221;{{item.id}}&#8221;&gt; &lt;commodityItem class=&#8221;specialContent&#8221; goods=&#8221;{{item}}&#8221; \/&gt; &lt;\/block&gt; \u767b\u5f55\u540e\u590d\u5236 \u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684js\u6587\u4ef6 Component({ properties: { goods: Object }, data: { }, timer: null, \/* \u5728\u7ec4\u4ef6\u5b9e\u4f8b\u8fdb\u5165\u9875\u9762\u8282\u70b9\u6811\u65f6\u6267\u884c\uff0c\u5f00\u59cb\u5b9a\u65f6\u5668 *\/ attached: function() { if(this.timer) { clearInterval(this.timer); } this.filterTime(); let that = this; this.timer = setInterval(function () { that.filterTime(); }, 1000) }, \/* \u5728\u7ec4\u4ef6\u5b9e\u4f8b\u88ab\u4ece\u9875\u9762\u8282\u70b9\u6811\u79fb\u9664\u65f6\u6267\u884c\uff0c\u5c06\u5b9a\u65f6\u5668\u6e05\u9664 *\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-33401","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=33401"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33401\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}