diff --git a/.cloudbase/container/debug.json b/.cloudbase/container/debug.json deleted file mode 100644 index 0d44458..0000000 --- a/.cloudbase/container/debug.json +++ /dev/null @@ -1 +0,0 @@ -{"containers":[],"config":{}} \ No newline at end of file diff --git a/pages/appointment/appointment.js b/pages/appointment/appointment.js index 556a23e..8bd380b 100644 --- a/pages/appointment/appointment.js +++ b/pages/appointment/appointment.js @@ -1,6 +1,5 @@ // appointment.js -const { formatDate } = require('../../utils/util') -const { appointmentDB } = require('../../utils/api') +const { formatDate, appointmentDB } = require('../../utils/api') const app = getApp() // 订阅消息模板ID diff --git a/utils/api.js b/utils/api.js index b43b758..2e37d1b 100644 --- a/utils/api.js +++ b/utils/api.js @@ -32,21 +32,61 @@ function request(options) { } /** - * 格式化记录中的 createTime 字段 - * @param {object} record - 含 createTime 的记录 + * 格式化时间戳为本地日期时间字符串 + * @param {string|number} timestamp - 时间戳 + * @returns {string} 格式化后的日期时间,如:2024/04/27 18:30:45 + */ +function formatDateTime(timestamp) { + if (!timestamp) return '' + const date = new Date(timestamp) + const year = date.getFullYear() + const month = String(date.getMonth() + 1).padStart(2, '0') + const day = String(date.getDate()).padStart(2, '0') + const hour = String(date.getHours()).padStart(2, '0') + const minute = String(date.getMinutes()).padStart(2, '0') + const second = String(date.getSeconds()).padStart(2, '0') + return `${year}/${month}/${day} ${hour}:${minute}:${second}` +} + +/** + * 格式化记录中的时间字段 + * @param {object} record - 含时间字段的记录 * @returns {object} 格式化后的记录 */ function formatRecord(record) { - if (!record || !record.createTime) return record - return { - ...record, - createTime: new Date(record.createTime).toLocaleString('zh-CN') + if (!record) return record + const formatted = { ...record } + if (record.createTime) { + formatted.createTime = formatDateTime(record.createTime) } + if (record.visitDate) { + formatted.visitDate = formatDate(record.visitDate) + } + if (record.updateTime) { + formatted.updateTime = formatDateTime(record.updateTime) + } + return formatted +} + +/** + * 格式化日期为 YYYY-MM-DD 格式 + * @param {string|number|Date} date - 日期 + * @returns {string} 格式化后的日期,如:2024-04-27 + */ +function formatDate(date) { + if (!date) return '' + const d = new Date(date) + const year = d.getFullYear() + const month = String(d.getMonth() + 1).padStart(2, '0') + const day = String(d.getDate()).padStart(2, '0') + return `${year}-${month}-${day}` } /** * 将后端 API 返回的预约记录映射为前端模板字段 * 后端: id, visitDate, visitTime → 前端: _id, date, time + * @param {object} record - 后端返回的记录 + * @returns {object} 映射后的记录 */ function mapApiRecord(record) { if (!record) return null @@ -54,7 +94,9 @@ function mapApiRecord(record) { ...record, _id: record.id, date: record.visitDate, - time: record.visitTime + time: record.visitTime, + createTime: record.createTime, + updateTime: record.updateTime } } @@ -171,6 +213,9 @@ async function getWxacode(scene, page = 'pages/scan/result/index') { module.exports = { request, formatRecord, + mapApiRecord, + formatDateTime, + formatDate, appointmentDB, getWxacode } diff --git a/utils/util.js b/utils/util.js deleted file mode 100644 index 624788c..0000000 --- a/utils/util.js +++ /dev/null @@ -1,27 +0,0 @@ -const formatTime = date => { - const year = date.getFullYear() - const month = date.getMonth() + 1 - const day = date.getDate() - const hour = date.getHours() - const minute = date.getMinutes() - const second = date.getSeconds() - - return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` -} - -const formatDate = date => { - const year = date.getFullYear() - const month = date.getMonth() + 1 - const day = date.getDate() - return `${year}-${formatNumber(month)}-${formatNumber(day)}` -} - -const formatNumber = n => { - n = n.toString() - return n[1] ? n : `0${n}` -} - -module.exports = { - formatTime, - formatDate -} diff --git a/utils/weapp.qrcode.esm.js b/utils/weapp.qrcode.esm.js deleted file mode 100644 index 5613f25..0000000 --- a/utils/weapp.qrcode.esm.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * weapp.qrcode.js v1.0.0 (https://github.com/yingye/weapp-qrcode#readme) - */ - -var hasOwn=Object.prototype.hasOwnProperty,toStr=Object.prototype.toString,defineProperty=Object.defineProperty,gOPD=Object.getOwnPropertyDescriptor,isArray=function(t){return"function"==typeof Array.isArray?Array.isArray(t):"[object Array]"===toStr.call(t)},isPlainObject=function(t){if(!t||"[object Object]"!==toStr.call(t))return!1;var e,r=hasOwn.call(t,"constructor"),o=t.constructor&&t.constructor.prototype&&hasOwn.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!r&&!o)return!1;for(e in t);return void 0===e||hasOwn.call(t,e)},setProperty=function(t,e){defineProperty&&"__proto__"===e.name?defineProperty(t,e.name,{enumerable:!0,configurable:!0,value:e.newValue,writable:!0}):t[e.name]=e.newValue},getProperty=function(t,e){if("__proto__"===e){if(!hasOwn.call(t,e))return;if(gOPD)return gOPD(t,e).value}return t[e]},extend=function t(){var e,r,o,n,i,a,s=arguments[0],u=1,l=arguments.length,h=!1;for("boolean"==typeof s&&(h=s,s=arguments[1]||{},u=2),(null==s||"object"!=typeof s&&"function"!=typeof s)&&(s={});u=7&&this.setupTypeNumber(t),null==this.dataCache&&(this.dataCache=QRCode.createData(this.typeNumber,this.errorCorrectLevel,this.dataList)),this.mapData(this.dataCache,e)},setupPositionProbePattern:function(t,e){for(var r=-1;r<=7;r++)if(!(t+r<=-1||this.moduleCount<=t+r))for(var o=-1;o<=7;o++)e+o<=-1||this.moduleCount<=e+o||(this.modules[t+r][e+o]=0<=r&&r<=6&&(0==o||6==o)||0<=o&&o<=6&&(0==r||6==r)||2<=r&&r<=4&&2<=o&&o<=4)},getBestMaskPattern:function(){for(var t=0,e=0,r=0;r<8;r++){this.makeImpl(!0,r);var o=QRUtil.getLostPoint(this);(0==r||t>o)&&(t=o,e=r)}return e},createMovieClip:function(t,e,r){var o=t.createEmptyMovieClip(e,r);this.make();for(var n=0;n>r&1);this.modules[Math.floor(r/3)][r%3+this.moduleCount-8-3]=o}for(r=0;r<18;r++){o=!t&&1==(e>>r&1);this.modules[r%3+this.moduleCount-8-3][Math.floor(r/3)]=o}},setupTypeInfo:function(t,e){for(var r=this.errorCorrectLevel<<3|e,o=QRUtil.getBCHTypeInfo(r),n=0;n<15;n++){var i=!t&&1==(o>>n&1);n<6?this.modules[n][8]=i:n<8?this.modules[n+1][8]=i:this.modules[this.moduleCount-15+n][8]=i}for(n=0;n<15;n++){i=!t&&1==(o>>n&1);n<8?this.modules[8][this.moduleCount-n-1]=i:n<9?this.modules[8][15-n-1+1]=i:this.modules[8][15-n-1]=i}this.modules[this.moduleCount-8][8]=!t},mapData:function(t,e){for(var r=-1,o=this.moduleCount-1,n=7,i=0,a=this.moduleCount-1;a>0;a-=2)for(6==a&&a--;;){for(var s=0;s<2;s++)if(null==this.modules[o][a-s]){var u=!1;i>>n&1)),QRUtil.getMask(e,o,a-s)&&(u=!u),this.modules[o][a-s]=u,-1==--n&&(i++,n=7)}if((o+=r)<0||this.moduleCount<=o){o-=r,r=-r;break}}}},QRCode.PAD0=236,QRCode.PAD1=17,QRCode.createData=function(t,e,r){for(var o=QRRSBlock.getRSBlocks(t,e),n=new QRBitBuffer,i=0;i8*s)throw new Error("code length overflow. ("+n.getLengthInBits()+">"+8*s+")");for(n.getLengthInBits()+4<=8*s&&n.put(0,4);n.getLengthInBits()%8!=0;)n.putBit(!1);for(;!(n.getLengthInBits()>=8*s||(n.put(QRCode.PAD0,8),n.getLengthInBits()>=8*s));)n.put(QRCode.PAD1,8);return QRCode.createBytes(n,o)},QRCode.createBytes=function(t,e){for(var r=0,o=0,n=0,i=new Array(e.length),a=new Array(e.length),s=0;s=0?g.get(c):0}}var d=0;for(h=0;h=0;)e^=QRUtil.G15<=0;)e^=QRUtil.G18<>>=1;return e},getPatternPosition:function(t){return QRUtil.PATTERN_POSITION_TABLE[t-1]},getMask:function(t,e,r){switch(t){case QRMaskPattern.PATTERN000:return(e+r)%2==0;case QRMaskPattern.PATTERN001:return e%2==0;case QRMaskPattern.PATTERN010:return r%3==0;case QRMaskPattern.PATTERN011:return(e+r)%3==0;case QRMaskPattern.PATTERN100:return(Math.floor(e/2)+Math.floor(r/3))%2==0;case QRMaskPattern.PATTERN101:return e*r%2+e*r%3==0;case QRMaskPattern.PATTERN110:return(e*r%2+e*r%3)%2==0;case QRMaskPattern.PATTERN111:return(e*r%3+(e+r)%2)%2==0;default:throw new Error("bad maskPattern:"+t)}},getErrorCorrectPolynomial:function(t){for(var e=new QRPolynomial([1],0),r=0;r5&&(r+=3+i-5)}for(o=0;o=256;)t-=255;return QRMath.EXP_TABLE[t]},EXP_TABLE:new Array(256),LOG_TABLE:new Array(256)},i=0;i<8;i++)QRMath.EXP_TABLE[i]=1<=1&&n<=127?e+=t.charAt(r):n>2047?(e+=String.fromCharCode(224|n>>12&15),e+=String.fromCharCode(128|n>>6&63),e+=String.fromCharCode(128|n>>0&63)):(e+=String.fromCharCode(192|n>>6&31),e+=String.fromCharCode(128|n>>0&63));return e}function drawQrcode(t){t=t||{},(t=extend(!0,{width:256,height:256,x:0,y:0,typeNumber:-1,correctLevel:QRErrorCorrectLevel.H,background:"#ffffff",foreground:"#000000",image:{imageResource:"",dx:0,dy:0,dWidth:100,dHeight:100}},t)).canvasId||t.ctx?function(){var e,r=new QRCode(t.typeNumber,t.correctLevel);r.addData(utf16to8(t.text)),r.make(),e=t.ctx?t.ctx:t._this?wx.createCanvasContext&&wx.createCanvasContext(t.canvasId,t._this):wx.createCanvasContext&&wx.createCanvasContext(t.canvasId);for(var o=t.width/r.getModuleCount(),n=t.height/r.getModuleCount(),i=0;i>>7-t%8&1)},put:function(t,e){for(var r=0;r>>e-r-1&1))},getLengthInBits:function(){return this.length},putBit:function(t){var e=Math.floor(this.length/8);this.buffer.length<=e&&this.buffer.push(0),t&&(this.buffer[e]|=128>>>this.length%8),this.length++}};export default drawQrcode;