From 917252ef3ea2b63c74d162cc67a6fbe103cb9b4d Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期五, 25 十月 2024 14:06:09 +0800 Subject: [PATCH] 1.开关阀记录界面。2.虚拟卡充值相关。3.问题反馈相关 --- pages/home/home.js | 332 ++++++-- app.wxss | 6 package-lock.json | 6 pages/rechargeCard/rechargeCard.js | 157 ++- pages/rechargeMoney/rechargMoney.js | 158 +++ pages/wxlogin/wxlogin.js | 50 + pages/rechargeCard/rechargeCard.wxml | 24 pages/rechargeCard/rechargeCard.wxss | 3 app.js | 9 pages/rechargeMoney/rechargMoney.wxml | 10 pages/home/home.wxml | 10 pages/home/home.wxss | 3 pages/rechargeMoney/rechargMoney.wxss | 5 miniprogram_npm/js-md5/index.js | 889 +++++++++++++++++++++++ pages/feedback/feedback.js | 160 ++- pages/valveList/valveList.wxss | 43 + pages/valveList/valveList.wxml | 65 + pages/rechargeCard/rechargeCard.json | 8 miniprogram_npm/dayjs/index.js | 4 app.json | 1 api/config.js | 4 pages/valveList/valveList.js | 166 +++ pages/wxbind/wxbind.js | 99 ++ api/request.js | 20 package.json | 1 miniprogram_npm/js-md5/index.js.map | 1 26 files changed, 1,925 insertions(+), 309 deletions(-) diff --git a/api/config.js b/api/config.js index ed78f00..a21494d 100644 --- a/api/config.js +++ b/api/config.js @@ -8,8 +8,8 @@ case 'test': // BASEURL = 'https://irrigate.dayuyanjiuyuan.top/' // BASEURL = 'https://d4x9787456.vicp.fun/' - // BASEURL = 'http://127.0.0.1:8087/' - BASEURL = 'http://192.168.40.166:8087/' + BASEURL = 'http://127.0.0.1:8087/' + // BASEURL = 'http://192.168.40.166:8087/' break default: BASEURL = '' diff --git a/api/request.js b/api/request.js index 0833bc0..985fe4c 100644 --- a/api/request.js +++ b/api/request.js @@ -33,7 +33,8 @@ form, isShowLoding, timeout, - header + header, + useParams } = _options const app = getApp() // 璁剧疆璇锋眰澶� @@ -56,6 +57,8 @@ header.Authorization = `Bearer ${token}` } header.tag = app.globalData.tag; + header.appId = app.globalData.AppID; + return new Promise((resolve, reject) => { console.log("url:" + BASEURL + url); if (isShowLoding) { @@ -70,6 +73,12 @@ } else { myUrl = BASEURL + url; } + // 濡傛灉 useParams 涓� true锛屾嫾鎺ユ煡璇㈠弬鏁� + if (useParams && data) { + const queryString = objToQueryString(data); // 浣跨敤涓婇潰瀹氫箟鐨勫嚱鏁� + myUrl += `?${queryString}`; // 鎷兼帴鏌ヨ瀛楃涓� + data = {}; // 璇锋眰浣撴暟鎹涓虹┖ + } wx.request({ url: myUrl, data, @@ -114,7 +123,14 @@ }) }) } - +function objToQueryString(obj) { + return Object.keys(obj) + .map(key => { + // 瀵归敭鍜屽�艰繘琛� URL 缂栫爜 + return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`; + }) + .join('&'); // 灏嗘墍鏈夐敭鍊煎鐢� '&' 杩炴帴璧锋潵 +} // 灏佽toast鍑芥暟 function showToast(title, icon = 'none', duration = 2500, mask = false) { wx.showToast({ diff --git a/app.js b/app.js index 575689c..7cdd3e2 100644 --- a/app.js +++ b/app.js @@ -14,12 +14,13 @@ }) }, globalData: { - sessionId:'2024052821300200006', - clientId:'2024091215314000006', - tag:'ym', + sessionId:2024102118013700009, + clientId:"", + tag:'test', userInfo: null, userId:"", userCode:"", - token:"" + token:"", + AppID:"wxc5e09d2676d31e15" } }) diff --git a/app.json b/app.json index b8a7a94..fd923d6 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,5 @@ { "pages": [ - "pages/home/home", "pages/valveList/valveList", "pages/feedback/feedback", diff --git a/app.wxss b/app.wxss index d5d4919..8fd9af2 100644 --- a/app.wxss +++ b/app.wxss @@ -37,4 +37,10 @@ overflow-y: auto; z-index: 0; margin-top: 10rpx; +} + + +.loading { + text-align: center; + padding: 20px; } \ No newline at end of file diff --git a/miniprogram_npm/dayjs/index.js b/miniprogram_npm/dayjs/index.js index 4874036..7e99e4a 100644 --- a/miniprogram_npm/dayjs/index.js +++ b/miniprogram_npm/dayjs/index.js @@ -4,10 +4,10 @@ var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; }; var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } }; var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; }; -__DEFINE__(1724049949958, function(require, module, exports) { +__DEFINE__(1729495434246, function(require, module, exports) { !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).dayjs=e()}(this,(function(){var t=1e3,e=6e4,n=36e5,r="millisecond",i="second",s="minute",u="hour",a="day",o="week",c="month",f="quarter",h="year",d="date",l="Invalid Date",$=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,M={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(t){var e=["th","st","nd","rd"],n=t%100;return"["+t+(e[(n-20)%10]||e[n]||e[0])+"]"}},m=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},v={s:m,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+m(r,2,"0")+":"+m(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,c),s=n-i<0,u=e.clone().add(r+(s?-1:1),c);return+(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:c,y:h,w:o,d:a,D:d,h:u,m:s,s:i,ms:r,Q:f}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},g="en",D={};D[g]=M;var p="$isDayjsObject",S=function(t){return t instanceof _||!(!t||!t[p])},w=function t(e,n,r){var i;if(!e)return g;if("string"==typeof e){var s=e.toLowerCase();D[s]&&(i=s),n&&(D[s]=n,i=s);var u=e.split("-");if(!i&&u.length>1)return t(u[0])}else{var a=e.name;D[a]=e,i=a}return!r&&i&&(g=i),i||!r&&g},O=function(t,e){if(S(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new _(n)},b=v;b.l=w,b.i=S,b.w=function(t,e){return O(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var _=function(){function M(t){this.$L=w(t.locale,null,!0),this.parse(t),this.$x=this.$x||t.x||{},this[p]=!0}var m=M.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(b.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match($);if(r){var i=r[2]-1||0,s=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.init()},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},m.$utils=function(){return b},m.isValid=function(){return!(this.$d.toString()===l)},m.isSame=function(t,e){var n=O(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return O(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<O(t)},m.$g=function(t,e,n){return b.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!b.u(e)||e,f=b.p(t),l=function(t,e){var i=b.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?i:i.endOf(a)},$=function(t,e){return b.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,M=this.$M,m=this.$D,v="set"+(this.$u?"UTC":"");switch(f){case h:return r?l(1,0):l(31,11);case c:return r?l(1,M):l(0,M+1);case o:var g=this.$locale().weekStart||0,D=(y<g?y+7:y)-g;return l(r?m-D:m+(6-D),M);case a:case d:return $(v+"Hours",0);case u:return $(v+"Minutes",1);case s:return $(v+"Seconds",2);case i:return $(v+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,o=b.p(t),f="set"+(this.$u?"UTC":""),l=(n={},n[a]=f+"Date",n[d]=f+"Date",n[c]=f+"Month",n[h]=f+"FullYear",n[u]=f+"Hours",n[s]=f+"Minutes",n[i]=f+"Seconds",n[r]=f+"Milliseconds",n)[o],$=o===a?this.$D+(e-this.$W):e;if(o===c||o===h){var y=this.clone().set(d,1);y.$d[l]($),y.init(),this.$d=y.set(d,Math.min(this.$D,y.daysInMonth())).$d}else l&&this.$d[l]($);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[b.p(t)]()},m.add=function(r,f){var d,l=this;r=Number(r);var $=b.p(f),y=function(t){var e=O(l);return b.w(e.date(e.date()+Math.round(t*r)),l)};if($===c)return this.set(c,this.$M+r);if($===h)return this.set(h,this.$y+r);if($===a)return y(1);if($===o)return y(7);var M=(d={},d[s]=e,d[u]=n,d[i]=t,d)[$]||1,m=this.$d.getTime()+r*M;return b.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||l;var r=t||"YYYY-MM-DDTHH:mm:ssZ",i=b.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,c=n.months,f=n.meridiem,h=function(t,n,i,s){return t&&(t[n]||t(e,r))||i[n].slice(0,s)},d=function(t){return b.s(s%12||12,t,"0")},$=f||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r};return r.replace(y,(function(t,r){return r||function(t){switch(t){case"YY":return String(e.$y).slice(-2);case"YYYY":return b.s(e.$y,4,"0");case"M":return a+1;case"MM":return b.s(a+1,2,"0");case"MMM":return h(n.monthsShort,a,c,3);case"MMMM":return h(c,a);case"D":return e.$D;case"DD":return b.s(e.$D,2,"0");case"d":return String(e.$W);case"dd":return h(n.weekdaysMin,e.$W,o,2);case"ddd":return h(n.weekdaysShort,e.$W,o,3);case"dddd":return o[e.$W];case"H":return String(s);case"HH":return b.s(s,2,"0");case"h":return d(1);case"hh":return d(2);case"a":return $(s,u,!0);case"A":return $(s,u,!1);case"m":return String(u);case"mm":return b.s(u,2,"0");case"s":return String(e.$s);case"ss":return b.s(e.$s,2,"0");case"SSS":return b.s(e.$ms,3,"0");case"Z":return i}return null}(t)||i.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(r,d,l){var $,y=this,M=b.p(d),m=O(r),v=(m.utcOffset()-this.utcOffset())*e,g=this-m,D=function(){return b.m(y,m)};switch(M){case h:$=D()/12;break;case c:$=D();break;case f:$=D()/3;break;case o:$=(g-v)/6048e5;break;case a:$=(g-v)/864e5;break;case u:$=g/n;break;case s:$=g/e;break;case i:$=g/t;break;default:$=g}return l?$:b.a($)},m.daysInMonth=function(){return this.endOf(c).$D},m.$locale=function(){return D[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=w(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return b.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},M}(),k=_.prototype;return O.prototype=k,[["$ms",r],["$s",i],["$m",s],["$H",u],["$W",a],["$M",c],["$y",h],["$D",d]].forEach((function(t){k[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),O.extend=function(t,e){return t.$i||(t(e,_,O),t.$i=!0),O},O.locale=w,O.isDayjs=S,O.unix=function(t){return O(1e3*t)},O.en=D[g],O.Ls=D,O.p={},O})); }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); }) -return __REQUIRE__(1724049949958); +return __REQUIRE__(1729495434246); })() //miniprogram-npm-outsideDeps=[] //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/miniprogram_npm/js-md5/index.js b/miniprogram_npm/js-md5/index.js new file mode 100644 index 0000000..72c75b1 --- /dev/null +++ b/miniprogram_npm/js-md5/index.js @@ -0,0 +1,889 @@ +module.exports = (function() { +var __MODS__ = {}; +var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; }; +var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; }; +var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } }; +var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; }; +__DEFINE__(1729495434247, function(require, module, exports) { +/** + * [js-md5]{@link https://github.com/emn178/js-md5} + * + * @namespace md5 + * @version 0.8.3 + * @author Chen, Yi-Cyuan [emn178@gmail.com] + * @copyright Chen, Yi-Cyuan 2014-2023 + * @license MIT + */ +(function () { + + + var INPUT_ERROR = 'input is invalid type'; + var FINALIZE_ERROR = 'finalize already called'; + var WINDOW = typeof window === 'object'; + var root = WINDOW ? window : {}; + if (root.JS_MD5_NO_WINDOW) { + WINDOW = false; + } + var WEB_WORKER = !WINDOW && typeof self === 'object'; + var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; + if (NODE_JS) { + root = global; + } else if (WEB_WORKER) { + root = self; + } + var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports; + var AMD = typeof define === 'function' && define.amd; + var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; + var HEX_CHARS = '0123456789abcdef'.split(''); + var EXTRA = [128, 32768, 8388608, -2147483648]; + var SHIFT = [0, 8, 16, 24]; + var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64']; + var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); + + var blocks = [], buffer8; + if (ARRAY_BUFFER) { + var buffer = new ArrayBuffer(68); + buffer8 = new Uint8Array(buffer); + blocks = new Uint32Array(buffer); + } + + var isArray = Array.isArray; + if (root.JS_MD5_NO_NODE_JS || !isArray) { + isArray = function (obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; + }; + } + + var isView = ArrayBuffer.isView; + if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) { + isView = function (obj) { + return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; + }; + } + + // [message: string, isString: bool] + var formatMessage = function (message) { + var type = typeof message; + if (type === 'string') { + return [message, true]; + } + if (type !== 'object' || message === null) { + throw new Error(INPUT_ERROR); + } + if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { + return [new Uint8Array(message), false]; + } + if (!isArray(message) && !isView(message)) { + throw new Error(INPUT_ERROR); + } + return [message, false]; + } + + /** + * @method hex + * @memberof md5 + * @description Output hash as hex string + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {String} Hex string + * @example + * md5.hex('The quick brown fox jumps over the lazy dog'); + * // equal to + * md5('The quick brown fox jumps over the lazy dog'); + */ + /** + * @method digest + * @memberof md5 + * @description Output hash as bytes array + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {Array} Bytes array + * @example + * md5.digest('The quick brown fox jumps over the lazy dog'); + */ + /** + * @method array + * @memberof md5 + * @description Output hash as bytes array + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {Array} Bytes array + * @example + * md5.array('The quick brown fox jumps over the lazy dog'); + */ + /** + * @method arrayBuffer + * @memberof md5 + * @description Output hash as ArrayBuffer + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {ArrayBuffer} ArrayBuffer + * @example + * md5.arrayBuffer('The quick brown fox jumps over the lazy dog'); + */ + /** + * @method buffer + * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead. + * @memberof md5 + * @description Output hash as ArrayBuffer + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {ArrayBuffer} ArrayBuffer + * @example + * md5.buffer('The quick brown fox jumps over the lazy dog'); + */ + /** + * @method base64 + * @memberof md5 + * @description Output hash as base64 string + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {String} base64 string + * @example + * md5.base64('The quick brown fox jumps over the lazy dog'); + */ + var createOutputMethod = function (outputType) { + return function (message) { + return new Md5(true).update(message)[outputType](); + }; + }; + + /** + * @method create + * @memberof md5 + * @description Create Md5 object + * @returns {Md5} Md5 object. + * @example + * var hash = md5.create(); + */ + /** + * @method update + * @memberof md5 + * @description Create and update Md5 object + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {Md5} Md5 object. + * @example + * var hash = md5.update('The quick brown fox jumps over the lazy dog'); + * // equal to + * var hash = md5.create(); + * hash.update('The quick brown fox jumps over the lazy dog'); + */ + var createMethod = function () { + var method = createOutputMethod('hex'); + if (NODE_JS) { + method = nodeWrap(method); + } + method.create = function () { + return new Md5(); + }; + method.update = function (message) { + return method.create().update(message); + }; + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { + var type = OUTPUT_TYPES[i]; + method[type] = createOutputMethod(type); + } + return method; + }; + + var nodeWrap = function (method) { + var crypto = require('crypto') + var Buffer = require('buffer').Buffer; + var bufferFrom; + if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) { + bufferFrom = Buffer.from; + } else { + bufferFrom = function (message) { + return new Buffer(message); + }; + } + var nodeMethod = function (message) { + if (typeof message === 'string') { + return crypto.createHash('md5').update(message, 'utf8').digest('hex'); + } else { + if (message === null || message === undefined) { + throw new Error(INPUT_ERROR); + } else if (message.constructor === ArrayBuffer) { + message = new Uint8Array(message); + } + } + if (isArray(message) || isView(message) || + message.constructor === Buffer) { + return crypto.createHash('md5').update(bufferFrom(message)).digest('hex'); + } else { + return method(message); + } + }; + return nodeMethod; + }; + + /** + * @namespace md5.hmac + */ + /** + * @method hex + * @memberof md5.hmac + * @description Output hash as hex string + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {String} Hex string + * @example + * md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog'); + * // equal to + * md5.hmac('key', 'The quick brown fox jumps over the lazy dog'); + */ + + /** + * @method digest + * @memberof md5.hmac + * @description Output hash as bytes array + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {Array} Bytes array + * @example + * md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog'); + */ + /** + * @method array + * @memberof md5.hmac + * @description Output hash as bytes array + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {Array} Bytes array + * @example + * md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog'); + */ + /** + * @method arrayBuffer + * @memberof md5.hmac + * @description Output hash as ArrayBuffer + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {ArrayBuffer} ArrayBuffer + * @example + * md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog'); + */ + /** + * @method buffer + * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead. + * @memberof md5.hmac + * @description Output hash as ArrayBuffer + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {ArrayBuffer} ArrayBuffer + * @example + * md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog'); + */ + /** + * @method base64 + * @memberof md5.hmac + * @description Output hash as base64 string + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {String} base64 string + * @example + * md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog'); + */ + var createHmacOutputMethod = function (outputType) { + return function (key, message) { + return new HmacMd5(key, true).update(message)[outputType](); + }; + }; + + /** + * @method create + * @memberof md5.hmac + * @description Create HmacMd5 object + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @returns {HmacMd5} HmacMd5 object. + * @example + * var hash = md5.hmac.create('key'); + */ + /** + * @method update + * @memberof md5.hmac + * @description Create and update HmacMd5 object + * @param {String|Array|Uint8Array|ArrayBuffer} key key + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {HmacMd5} HmacMd5 object. + * @example + * var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog'); + * // equal to + * var hash = md5.hmac.create('key'); + * hash.update('The quick brown fox jumps over the lazy dog'); + */ + var createHmacMethod = function () { + var method = createHmacOutputMethod('hex'); + method.create = function (key) { + return new HmacMd5(key); + }; + method.update = function (key, message) { + return method.create(key).update(message); + }; + for (var i = 0; i < OUTPUT_TYPES.length; ++i) { + var type = OUTPUT_TYPES[i]; + method[type] = createHmacOutputMethod(type); + } + return method; + }; + + /** + * Md5 class + * @class Md5 + * @description This is internal class. + * @see {@link md5.create} + */ + function Md5(sharedMemory) { + if (sharedMemory) { + blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + this.blocks = blocks; + this.buffer8 = buffer8; + } else { + if (ARRAY_BUFFER) { + var buffer = new ArrayBuffer(68); + this.buffer8 = new Uint8Array(buffer); + this.blocks = new Uint32Array(buffer); + } else { + this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + } + } + this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0; + this.finalized = this.hashed = false; + this.first = true; + } + + /** + * @method update + * @memberof Md5 + * @instance + * @description Update hash + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {Md5} Md5 object. + * @see {@link md5.update} + */ + Md5.prototype.update = function (message) { + if (this.finalized) { + throw new Error(FINALIZE_ERROR); + } + + var result = formatMessage(message); + message = result[0]; + var isString = result[1]; + var code, index = 0, i, length = message.length, blocks = this.blocks; + var buffer8 = this.buffer8; + + while (index < length) { + if (this.hashed) { + this.hashed = false; + blocks[0] = blocks[16]; + blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + } + + if (isString) { + if (ARRAY_BUFFER) { + for (i = this.start; index < length && i < 64; ++index) { + code = message.charCodeAt(index); + if (code < 0x80) { + buffer8[i++] = code; + } else if (code < 0x800) { + buffer8[i++] = 0xc0 | (code >>> 6); + buffer8[i++] = 0x80 | (code & 0x3f); + } else if (code < 0xd800 || code >= 0xe000) { + buffer8[i++] = 0xe0 | (code >>> 12); + buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f); + buffer8[i++] = 0x80 | (code & 0x3f); + } else { + code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); + buffer8[i++] = 0xf0 | (code >>> 18); + buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f); + buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f); + buffer8[i++] = 0x80 | (code & 0x3f); + } + } + } else { + for (i = this.start; index < length && i < 64; ++index) { + code = message.charCodeAt(index); + if (code < 0x80) { + blocks[i >>> 2] |= code << SHIFT[i++ & 3]; + } else if (code < 0x800) { + blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3]; + blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } else if (code < 0xd800 || code >= 0xe000) { + blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3]; + blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } else { + code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); + blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3]; + blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3]; + blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; + } + } + } + } else { + if (ARRAY_BUFFER) { + for (i = this.start; index < length && i < 64; ++index) { + buffer8[i++] = message[index]; + } + } else { + for (i = this.start; index < length && i < 64; ++index) { + blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3]; + } + } + } + this.lastByteIndex = i; + this.bytes += i - this.start; + if (i >= 64) { + this.start = i - 64; + this.hash(); + this.hashed = true; + } else { + this.start = i; + } + } + if (this.bytes > 4294967295) { + this.hBytes += this.bytes / 4294967296 << 0; + this.bytes = this.bytes % 4294967296; + } + return this; + }; + + Md5.prototype.finalize = function () { + if (this.finalized) { + return; + } + this.finalized = true; + var blocks = this.blocks, i = this.lastByteIndex; + blocks[i >>> 2] |= EXTRA[i & 3]; + if (i >= 56) { + if (!this.hashed) { + this.hash(); + } + blocks[0] = blocks[16]; + blocks[16] = blocks[1] = blocks[2] = blocks[3] = + blocks[4] = blocks[5] = blocks[6] = blocks[7] = + blocks[8] = blocks[9] = blocks[10] = blocks[11] = + blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0; + } + blocks[14] = this.bytes << 3; + blocks[15] = this.hBytes << 3 | this.bytes >>> 29; + this.hash(); + }; + + Md5.prototype.hash = function () { + var a, b, c, d, bc, da, blocks = this.blocks; + + if (this.first) { + a = blocks[0] - 680876937; + a = (a << 7 | a >>> 25) - 271733879 << 0; + d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708; + d = (d << 12 | d >>> 20) + a << 0; + c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375; + c = (c << 17 | c >>> 15) + d << 0; + b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209; + b = (b << 22 | b >>> 10) + c << 0; + } else { + a = this.h0; + b = this.h1; + c = this.h2; + d = this.h3; + a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936; + a = (a << 7 | a >>> 25) + b << 0; + d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586; + d = (d << 12 | d >>> 20) + a << 0; + c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819; + c = (c << 17 | c >>> 15) + d << 0; + b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330; + b = (b << 22 | b >>> 10) + c << 0; + } + + a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897; + a = (a << 7 | a >>> 25) + b << 0; + d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426; + d = (d << 12 | d >>> 20) + a << 0; + c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341; + c = (c << 17 | c >>> 15) + d << 0; + b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983; + b = (b << 22 | b >>> 10) + c << 0; + a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416; + a = (a << 7 | a >>> 25) + b << 0; + d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417; + d = (d << 12 | d >>> 20) + a << 0; + c += (b ^ (d & (a ^ b))) + blocks[10] - 42063; + c = (c << 17 | c >>> 15) + d << 0; + b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162; + b = (b << 22 | b >>> 10) + c << 0; + a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682; + a = (a << 7 | a >>> 25) + b << 0; + d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101; + d = (d << 12 | d >>> 20) + a << 0; + c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290; + c = (c << 17 | c >>> 15) + d << 0; + b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329; + b = (b << 22 | b >>> 10) + c << 0; + a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510; + a = (a << 5 | a >>> 27) + b << 0; + d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632; + d = (d << 9 | d >>> 23) + a << 0; + c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713; + c = (c << 14 | c >>> 18) + d << 0; + b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302; + b = (b << 20 | b >>> 12) + c << 0; + a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691; + a = (a << 5 | a >>> 27) + b << 0; + d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083; + d = (d << 9 | d >>> 23) + a << 0; + c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335; + c = (c << 14 | c >>> 18) + d << 0; + b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848; + b = (b << 20 | b >>> 12) + c << 0; + a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438; + a = (a << 5 | a >>> 27) + b << 0; + d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690; + d = (d << 9 | d >>> 23) + a << 0; + c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961; + c = (c << 14 | c >>> 18) + d << 0; + b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501; + b = (b << 20 | b >>> 12) + c << 0; + a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467; + a = (a << 5 | a >>> 27) + b << 0; + d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784; + d = (d << 9 | d >>> 23) + a << 0; + c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473; + c = (c << 14 | c >>> 18) + d << 0; + b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734; + b = (b << 20 | b >>> 12) + c << 0; + bc = b ^ c; + a += (bc ^ d) + blocks[5] - 378558; + a = (a << 4 | a >>> 28) + b << 0; + d += (bc ^ a) + blocks[8] - 2022574463; + d = (d << 11 | d >>> 21) + a << 0; + da = d ^ a; + c += (da ^ b) + blocks[11] + 1839030562; + c = (c << 16 | c >>> 16) + d << 0; + b += (da ^ c) + blocks[14] - 35309556; + b = (b << 23 | b >>> 9) + c << 0; + bc = b ^ c; + a += (bc ^ d) + blocks[1] - 1530992060; + a = (a << 4 | a >>> 28) + b << 0; + d += (bc ^ a) + blocks[4] + 1272893353; + d = (d << 11 | d >>> 21) + a << 0; + da = d ^ a; + c += (da ^ b) + blocks[7] - 155497632; + c = (c << 16 | c >>> 16) + d << 0; + b += (da ^ c) + blocks[10] - 1094730640; + b = (b << 23 | b >>> 9) + c << 0; + bc = b ^ c; + a += (bc ^ d) + blocks[13] + 681279174; + a = (a << 4 | a >>> 28) + b << 0; + d += (bc ^ a) + blocks[0] - 358537222; + d = (d << 11 | d >>> 21) + a << 0; + da = d ^ a; + c += (da ^ b) + blocks[3] - 722521979; + c = (c << 16 | c >>> 16) + d << 0; + b += (da ^ c) + blocks[6] + 76029189; + b = (b << 23 | b >>> 9) + c << 0; + bc = b ^ c; + a += (bc ^ d) + blocks[9] - 640364487; + a = (a << 4 | a >>> 28) + b << 0; + d += (bc ^ a) + blocks[12] - 421815835; + d = (d << 11 | d >>> 21) + a << 0; + da = d ^ a; + c += (da ^ b) + blocks[15] + 530742520; + c = (c << 16 | c >>> 16) + d << 0; + b += (da ^ c) + blocks[2] - 995338651; + b = (b << 23 | b >>> 9) + c << 0; + a += (c ^ (b | ~d)) + blocks[0] - 198630844; + a = (a << 6 | a >>> 26) + b << 0; + d += (b ^ (a | ~c)) + blocks[7] + 1126891415; + d = (d << 10 | d >>> 22) + a << 0; + c += (a ^ (d | ~b)) + blocks[14] - 1416354905; + c = (c << 15 | c >>> 17) + d << 0; + b += (d ^ (c | ~a)) + blocks[5] - 57434055; + b = (b << 21 | b >>> 11) + c << 0; + a += (c ^ (b | ~d)) + blocks[12] + 1700485571; + a = (a << 6 | a >>> 26) + b << 0; + d += (b ^ (a | ~c)) + blocks[3] - 1894986606; + d = (d << 10 | d >>> 22) + a << 0; + c += (a ^ (d | ~b)) + blocks[10] - 1051523; + c = (c << 15 | c >>> 17) + d << 0; + b += (d ^ (c | ~a)) + blocks[1] - 2054922799; + b = (b << 21 | b >>> 11) + c << 0; + a += (c ^ (b | ~d)) + blocks[8] + 1873313359; + a = (a << 6 | a >>> 26) + b << 0; + d += (b ^ (a | ~c)) + blocks[15] - 30611744; + d = (d << 10 | d >>> 22) + a << 0; + c += (a ^ (d | ~b)) + blocks[6] - 1560198380; + c = (c << 15 | c >>> 17) + d << 0; + b += (d ^ (c | ~a)) + blocks[13] + 1309151649; + b = (b << 21 | b >>> 11) + c << 0; + a += (c ^ (b | ~d)) + blocks[4] - 145523070; + a = (a << 6 | a >>> 26) + b << 0; + d += (b ^ (a | ~c)) + blocks[11] - 1120210379; + d = (d << 10 | d >>> 22) + a << 0; + c += (a ^ (d | ~b)) + blocks[2] + 718787259; + c = (c << 15 | c >>> 17) + d << 0; + b += (d ^ (c | ~a)) + blocks[9] - 343485551; + b = (b << 21 | b >>> 11) + c << 0; + + if (this.first) { + this.h0 = a + 1732584193 << 0; + this.h1 = b - 271733879 << 0; + this.h2 = c - 1732584194 << 0; + this.h3 = d + 271733878 << 0; + this.first = false; + } else { + this.h0 = this.h0 + a << 0; + this.h1 = this.h1 + b << 0; + this.h2 = this.h2 + c << 0; + this.h3 = this.h3 + d << 0; + } + }; + + /** + * @method hex + * @memberof Md5 + * @instance + * @description Output hash as hex string + * @returns {String} Hex string + * @see {@link md5.hex} + * @example + * hash.hex(); + */ + Md5.prototype.hex = function () { + this.finalize(); + + var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3; + + return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] + + HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] + + HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] + + HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] + + HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] + + HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] + + HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] + + HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] + + HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] + + HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] + + HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] + + HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] + + HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] + + HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] + + HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] + + HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F]; + }; + + /** + * @method toString + * @memberof Md5 + * @instance + * @description Output hash as hex string + * @returns {String} Hex string + * @see {@link md5.hex} + * @example + * hash.toString(); + */ + Md5.prototype.toString = Md5.prototype.hex; + + /** + * @method digest + * @memberof Md5 + * @instance + * @description Output hash as bytes array + * @returns {Array} Bytes array + * @see {@link md5.digest} + * @example + * hash.digest(); + */ + Md5.prototype.digest = function () { + this.finalize(); + + var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3; + return [ + h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF, + h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF, + h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF, + h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF + ]; + }; + + /** + * @method array + * @memberof Md5 + * @instance + * @description Output hash as bytes array + * @returns {Array} Bytes array + * @see {@link md5.array} + * @example + * hash.array(); + */ + Md5.prototype.array = Md5.prototype.digest; + + /** + * @method arrayBuffer + * @memberof Md5 + * @instance + * @description Output hash as ArrayBuffer + * @returns {ArrayBuffer} ArrayBuffer + * @see {@link md5.arrayBuffer} + * @example + * hash.arrayBuffer(); + */ + Md5.prototype.arrayBuffer = function () { + this.finalize(); + + var buffer = new ArrayBuffer(16); + var blocks = new Uint32Array(buffer); + blocks[0] = this.h0; + blocks[1] = this.h1; + blocks[2] = this.h2; + blocks[3] = this.h3; + return buffer; + }; + + /** + * @method buffer + * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead. + * @memberof Md5 + * @instance + * @description Output hash as ArrayBuffer + * @returns {ArrayBuffer} ArrayBuffer + * @see {@link md5.buffer} + * @example + * hash.buffer(); + */ + Md5.prototype.buffer = Md5.prototype.arrayBuffer; + + /** + * @method base64 + * @memberof Md5 + * @instance + * @description Output hash as base64 string + * @returns {String} base64 string + * @see {@link md5.base64} + * @example + * hash.base64(); + */ + Md5.prototype.base64 = function () { + var v1, v2, v3, base64Str = '', bytes = this.array(); + for (var i = 0; i < 15;) { + v1 = bytes[i++]; + v2 = bytes[i++]; + v3 = bytes[i++]; + base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] + + BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] + + BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] + + BASE64_ENCODE_CHAR[v3 & 63]; + } + v1 = bytes[i]; + base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] + + BASE64_ENCODE_CHAR[(v1 << 4) & 63] + + '=='; + return base64Str; + }; + + /** + * HmacMd5 class + * @class HmacMd5 + * @extends Md5 + * @description This is internal class. + * @see {@link md5.hmac.create} + */ + function HmacMd5(key, sharedMemory) { + var i, result = formatMessage(key); + key = result[0]; + if (result[1]) { + var bytes = [], length = key.length, index = 0, code; + for (i = 0; i < length; ++i) { + code = key.charCodeAt(i); + if (code < 0x80) { + bytes[index++] = code; + } else if (code < 0x800) { + bytes[index++] = (0xc0 | (code >>> 6)); + bytes[index++] = (0x80 | (code & 0x3f)); + } else if (code < 0xd800 || code >= 0xe000) { + bytes[index++] = (0xe0 | (code >>> 12)); + bytes[index++] = (0x80 | ((code >>> 6) & 0x3f)); + bytes[index++] = (0x80 | (code & 0x3f)); + } else { + code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff)); + bytes[index++] = (0xf0 | (code >>> 18)); + bytes[index++] = (0x80 | ((code >>> 12) & 0x3f)); + bytes[index++] = (0x80 | ((code >>> 6) & 0x3f)); + bytes[index++] = (0x80 | (code & 0x3f)); + } + } + key = bytes; + } + + if (key.length > 64) { + key = (new Md5(true)).update(key).array(); + } + + var oKeyPad = [], iKeyPad = []; + for (i = 0; i < 64; ++i) { + var b = key[i] || 0; + oKeyPad[i] = 0x5c ^ b; + iKeyPad[i] = 0x36 ^ b; + } + + Md5.call(this, sharedMemory); + + this.update(iKeyPad); + this.oKeyPad = oKeyPad; + this.inner = true; + this.sharedMemory = sharedMemory; + } + HmacMd5.prototype = new Md5(); + + HmacMd5.prototype.finalize = function () { + Md5.prototype.finalize.call(this); + if (this.inner) { + this.inner = false; + var innerHash = this.array(); + Md5.call(this, this.sharedMemory); + this.update(this.oKeyPad); + this.update(innerHash); + Md5.prototype.finalize.call(this); + } + }; + + var exports = createMethod(); + exports.md5 = exports; + exports.md5.hmac = createHmacMethod(); + + if (COMMON_JS) { + module.exports = exports; + } else { + /** + * @method md5 + * @description Md5 hash function, export to global in browsers. + * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash + * @returns {String} md5 hashes + * @example + * md5(''); // d41d8cd98f00b204e9800998ecf8427e + * md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6 + * md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0 + * + * // It also supports UTF-8 encoding + * md5('涓枃'); // a7bac2239fcdcb3a067903d8077c4a07 + * + * // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer` + * md5([]); // d41d8cd98f00b204e9800998ecf8427e + * md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e + */ + root.md5 = exports; + if (AMD) { + define(function () { + return exports; + }); + } + } +})(); + +}, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); }) +return __REQUIRE__(1729495434247); +})() +//miniprogram-npm-outsideDeps=["crypto","buffer"] +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/miniprogram_npm/js-md5/index.js.map b/miniprogram_npm/js-md5/index.js.map new file mode 100644 index 0000000..f574fbc --- /dev/null +++ b/miniprogram_npm/js-md5/index.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["md5.js"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["/**\n * [js-md5]{@link https://github.com/emn178/js-md5}\n *\n * @namespace md5\n * @version 0.8.3\n * @author Chen, Yi-Cyuan [emn178@gmail.com]\n * @copyright Chen, Yi-Cyuan 2014-2023\n * @license MIT\n */\n(function () {\n \n\n var INPUT_ERROR = 'input is invalid type';\n var FINALIZE_ERROR = 'finalize already called';\n var WINDOW = typeof window === 'object';\n var root = WINDOW ? window : {};\n if (root.JS_MD5_NO_WINDOW) {\n WINDOW = false;\n }\n var WEB_WORKER = !WINDOW && typeof self === 'object';\n var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;\n if (NODE_JS) {\n root = global;\n } else if (WEB_WORKER) {\n root = self;\n }\n var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;\n var AMD = typeof define === 'function' && define.amd;\n var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';\n var HEX_CHARS = '0123456789abcdef'.split('');\n var EXTRA = [128, 32768, 8388608, -2147483648];\n var SHIFT = [0, 8, 16, 24];\n var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];\n var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');\n\n var blocks = [], buffer8;\n if (ARRAY_BUFFER) {\n var buffer = new ArrayBuffer(68);\n buffer8 = new Uint8Array(buffer);\n blocks = new Uint32Array(buffer);\n }\n\n var isArray = Array.isArray;\n if (root.JS_MD5_NO_NODE_JS || !isArray) {\n isArray = function (obj) {\n return Object.prototype.toString.call(obj) === '[object Array]';\n };\n }\n\n var isView = ArrayBuffer.isView;\n if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {\n isView = function (obj) {\n return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;\n };\n }\n\n // [message: string, isString: bool]\n var formatMessage = function (message) {\n var type = typeof message;\n if (type === 'string') {\n return [message, true];\n }\n if (type !== 'object' || message === null) {\n throw new Error(INPUT_ERROR);\n }\n if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {\n return [new Uint8Array(message), false];\n }\n if (!isArray(message) && !isView(message)) {\n throw new Error(INPUT_ERROR);\n }\n return [message, false];\n }\n\n /**\n * @method hex\n * @memberof md5\n * @description Output hash as hex string\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {String} Hex string\n * @example\n * md5.hex('The quick brown fox jumps over the lazy dog');\n * // equal to\n * md5('The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method digest\n * @memberof md5\n * @description Output hash as bytes array\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {Array} Bytes array\n * @example\n * md5.digest('The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method array\n * @memberof md5\n * @description Output hash as bytes array\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {Array} Bytes array\n * @example\n * md5.array('The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method arrayBuffer\n * @memberof md5\n * @description Output hash as ArrayBuffer\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {ArrayBuffer} ArrayBuffer\n * @example\n * md5.arrayBuffer('The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method buffer\n * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.\n * @memberof md5\n * @description Output hash as ArrayBuffer\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {ArrayBuffer} ArrayBuffer\n * @example\n * md5.buffer('The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method base64\n * @memberof md5\n * @description Output hash as base64 string\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {String} base64 string\n * @example\n * md5.base64('The quick brown fox jumps over the lazy dog');\n */\n var createOutputMethod = function (outputType) {\n return function (message) {\n return new Md5(true).update(message)[outputType]();\n };\n };\n\n /**\n * @method create\n * @memberof md5\n * @description Create Md5 object\n * @returns {Md5} Md5 object.\n * @example\n * var hash = md5.create();\n */\n /**\n * @method update\n * @memberof md5\n * @description Create and update Md5 object\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {Md5} Md5 object.\n * @example\n * var hash = md5.update('The quick brown fox jumps over the lazy dog');\n * // equal to\n * var hash = md5.create();\n * hash.update('The quick brown fox jumps over the lazy dog');\n */\n var createMethod = function () {\n var method = createOutputMethod('hex');\n if (NODE_JS) {\n method = nodeWrap(method);\n }\n method.create = function () {\n return new Md5();\n };\n method.update = function (message) {\n return method.create().update(message);\n };\n for (var i = 0; i < OUTPUT_TYPES.length; ++i) {\n var type = OUTPUT_TYPES[i];\n method[type] = createOutputMethod(type);\n }\n return method;\n };\n\n var nodeWrap = function (method) {\n var crypto = require('crypto')\n var Buffer = require('buffer').Buffer;\n var bufferFrom;\n if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) {\n bufferFrom = Buffer.from;\n } else {\n bufferFrom = function (message) {\n return new Buffer(message);\n };\n }\n var nodeMethod = function (message) {\n if (typeof message === 'string') {\n return crypto.createHash('md5').update(message, 'utf8').digest('hex');\n } else {\n if (message === null || message === undefined) {\n throw new Error(INPUT_ERROR);\n } else if (message.constructor === ArrayBuffer) {\n message = new Uint8Array(message);\n }\n }\n if (isArray(message) || isView(message) ||\n message.constructor === Buffer) {\n return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');\n } else {\n return method(message);\n }\n };\n return nodeMethod;\n };\n\n /**\n * @namespace md5.hmac\n */\n /**\n * @method hex\n * @memberof md5.hmac\n * @description Output hash as hex string\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {String} Hex string\n * @example\n * md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');\n * // equal to\n * md5.hmac('key', 'The quick brown fox jumps over the lazy dog');\n */\n\n /**\n * @method digest\n * @memberof md5.hmac\n * @description Output hash as bytes array\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {Array} Bytes array\n * @example\n * md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method array\n * @memberof md5.hmac\n * @description Output hash as bytes array\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {Array} Bytes array\n * @example\n * md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method arrayBuffer\n * @memberof md5.hmac\n * @description Output hash as ArrayBuffer\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {ArrayBuffer} ArrayBuffer\n * @example\n * md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method buffer\n * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.\n * @memberof md5.hmac\n * @description Output hash as ArrayBuffer\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {ArrayBuffer} ArrayBuffer\n * @example\n * md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');\n */\n /**\n * @method base64\n * @memberof md5.hmac\n * @description Output hash as base64 string\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {String} base64 string\n * @example\n * md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');\n */\n var createHmacOutputMethod = function (outputType) {\n return function (key, message) {\n return new HmacMd5(key, true).update(message)[outputType]();\n };\n };\n\n /**\n * @method create\n * @memberof md5.hmac\n * @description Create HmacMd5 object\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @returns {HmacMd5} HmacMd5 object.\n * @example\n * var hash = md5.hmac.create('key');\n */\n /**\n * @method update\n * @memberof md5.hmac\n * @description Create and update HmacMd5 object\n * @param {String|Array|Uint8Array|ArrayBuffer} key key\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {HmacMd5} HmacMd5 object.\n * @example\n * var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');\n * // equal to\n * var hash = md5.hmac.create('key');\n * hash.update('The quick brown fox jumps over the lazy dog');\n */\n var createHmacMethod = function () {\n var method = createHmacOutputMethod('hex');\n method.create = function (key) {\n return new HmacMd5(key);\n };\n method.update = function (key, message) {\n return method.create(key).update(message);\n };\n for (var i = 0; i < OUTPUT_TYPES.length; ++i) {\n var type = OUTPUT_TYPES[i];\n method[type] = createHmacOutputMethod(type);\n }\n return method;\n };\n\n /**\n * Md5 class\n * @class Md5\n * @description This is internal class.\n * @see {@link md5.create}\n */\n function Md5(sharedMemory) {\n if (sharedMemory) {\n blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =\n blocks[4] = blocks[5] = blocks[6] = blocks[7] =\n blocks[8] = blocks[9] = blocks[10] = blocks[11] =\n blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;\n this.blocks = blocks;\n this.buffer8 = buffer8;\n } else {\n if (ARRAY_BUFFER) {\n var buffer = new ArrayBuffer(68);\n this.buffer8 = new Uint8Array(buffer);\n this.blocks = new Uint32Array(buffer);\n } else {\n this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n }\n }\n this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;\n this.finalized = this.hashed = false;\n this.first = true;\n }\n\n /**\n * @method update\n * @memberof Md5\n * @instance\n * @description Update hash\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {Md5} Md5 object.\n * @see {@link md5.update}\n */\n Md5.prototype.update = function (message) {\n if (this.finalized) {\n throw new Error(FINALIZE_ERROR);\n }\n\n var result = formatMessage(message);\n message = result[0];\n var isString = result[1];\n var code, index = 0, i, length = message.length, blocks = this.blocks;\n var buffer8 = this.buffer8;\n\n while (index < length) {\n if (this.hashed) {\n this.hashed = false;\n blocks[0] = blocks[16];\n blocks[16] = blocks[1] = blocks[2] = blocks[3] =\n blocks[4] = blocks[5] = blocks[6] = blocks[7] =\n blocks[8] = blocks[9] = blocks[10] = blocks[11] =\n blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;\n }\n\n if (isString) {\n if (ARRAY_BUFFER) {\n for (i = this.start; index < length && i < 64; ++index) {\n code = message.charCodeAt(index);\n if (code < 0x80) {\n buffer8[i++] = code;\n } else if (code < 0x800) {\n buffer8[i++] = 0xc0 | (code >>> 6);\n buffer8[i++] = 0x80 | (code & 0x3f);\n } else if (code < 0xd800 || code >= 0xe000) {\n buffer8[i++] = 0xe0 | (code >>> 12);\n buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);\n buffer8[i++] = 0x80 | (code & 0x3f);\n } else {\n code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));\n buffer8[i++] = 0xf0 | (code >>> 18);\n buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);\n buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);\n buffer8[i++] = 0x80 | (code & 0x3f);\n }\n }\n } else {\n for (i = this.start; index < length && i < 64; ++index) {\n code = message.charCodeAt(index);\n if (code < 0x80) {\n blocks[i >>> 2] |= code << SHIFT[i++ & 3];\n } else if (code < 0x800) {\n blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];\n blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];\n } else if (code < 0xd800 || code >= 0xe000) {\n blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];\n blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];\n blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];\n } else {\n code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));\n blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];\n blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];\n blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];\n blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];\n }\n }\n }\n } else {\n if (ARRAY_BUFFER) {\n for (i = this.start; index < length && i < 64; ++index) {\n buffer8[i++] = message[index];\n }\n } else {\n for (i = this.start; index < length && i < 64; ++index) {\n blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];\n }\n }\n }\n this.lastByteIndex = i;\n this.bytes += i - this.start;\n if (i >= 64) {\n this.start = i - 64;\n this.hash();\n this.hashed = true;\n } else {\n this.start = i;\n }\n }\n if (this.bytes > 4294967295) {\n this.hBytes += this.bytes / 4294967296 << 0;\n this.bytes = this.bytes % 4294967296;\n }\n return this;\n };\n\n Md5.prototype.finalize = function () {\n if (this.finalized) {\n return;\n }\n this.finalized = true;\n var blocks = this.blocks, i = this.lastByteIndex;\n blocks[i >>> 2] |= EXTRA[i & 3];\n if (i >= 56) {\n if (!this.hashed) {\n this.hash();\n }\n blocks[0] = blocks[16];\n blocks[16] = blocks[1] = blocks[2] = blocks[3] =\n blocks[4] = blocks[5] = blocks[6] = blocks[7] =\n blocks[8] = blocks[9] = blocks[10] = blocks[11] =\n blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;\n }\n blocks[14] = this.bytes << 3;\n blocks[15] = this.hBytes << 3 | this.bytes >>> 29;\n this.hash();\n };\n\n Md5.prototype.hash = function () {\n var a, b, c, d, bc, da, blocks = this.blocks;\n\n if (this.first) {\n a = blocks[0] - 680876937;\n a = (a << 7 | a >>> 25) - 271733879 << 0;\n d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;\n d = (d << 12 | d >>> 20) + a << 0;\n c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375;\n c = (c << 17 | c >>> 15) + d << 0;\n b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209;\n b = (b << 22 | b >>> 10) + c << 0;\n } else {\n a = this.h0;\n b = this.h1;\n c = this.h2;\n d = this.h3;\n a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;\n a = (a << 7 | a >>> 25) + b << 0;\n d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;\n d = (d << 12 | d >>> 20) + a << 0;\n c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;\n c = (c << 17 | c >>> 15) + d << 0;\n b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;\n b = (b << 22 | b >>> 10) + c << 0;\n }\n\n a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;\n a = (a << 7 | a >>> 25) + b << 0;\n d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;\n d = (d << 12 | d >>> 20) + a << 0;\n c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;\n c = (c << 17 | c >>> 15) + d << 0;\n b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;\n b = (b << 22 | b >>> 10) + c << 0;\n a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;\n a = (a << 7 | a >>> 25) + b << 0;\n d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;\n d = (d << 12 | d >>> 20) + a << 0;\n c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;\n c = (c << 17 | c >>> 15) + d << 0;\n b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;\n b = (b << 22 | b >>> 10) + c << 0;\n a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;\n a = (a << 7 | a >>> 25) + b << 0;\n d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;\n d = (d << 12 | d >>> 20) + a << 0;\n c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;\n c = (c << 17 | c >>> 15) + d << 0;\n b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;\n b = (b << 22 | b >>> 10) + c << 0;\n a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;\n a = (a << 5 | a >>> 27) + b << 0;\n d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;\n d = (d << 9 | d >>> 23) + a << 0;\n c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;\n c = (c << 14 | c >>> 18) + d << 0;\n b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;\n b = (b << 20 | b >>> 12) + c << 0;\n a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;\n a = (a << 5 | a >>> 27) + b << 0;\n d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;\n d = (d << 9 | d >>> 23) + a << 0;\n c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;\n c = (c << 14 | c >>> 18) + d << 0;\n b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;\n b = (b << 20 | b >>> 12) + c << 0;\n a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;\n a = (a << 5 | a >>> 27) + b << 0;\n d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;\n d = (d << 9 | d >>> 23) + a << 0;\n c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;\n c = (c << 14 | c >>> 18) + d << 0;\n b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;\n b = (b << 20 | b >>> 12) + c << 0;\n a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;\n a = (a << 5 | a >>> 27) + b << 0;\n d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;\n d = (d << 9 | d >>> 23) + a << 0;\n c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;\n c = (c << 14 | c >>> 18) + d << 0;\n b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;\n b = (b << 20 | b >>> 12) + c << 0;\n bc = b ^ c;\n a += (bc ^ d) + blocks[5] - 378558;\n a = (a << 4 | a >>> 28) + b << 0;\n d += (bc ^ a) + blocks[8] - 2022574463;\n d = (d << 11 | d >>> 21) + a << 0;\n da = d ^ a;\n c += (da ^ b) + blocks[11] + 1839030562;\n c = (c << 16 | c >>> 16) + d << 0;\n b += (da ^ c) + blocks[14] - 35309556;\n b = (b << 23 | b >>> 9) + c << 0;\n bc = b ^ c;\n a += (bc ^ d) + blocks[1] - 1530992060;\n a = (a << 4 | a >>> 28) + b << 0;\n d += (bc ^ a) + blocks[4] + 1272893353;\n d = (d << 11 | d >>> 21) + a << 0;\n da = d ^ a;\n c += (da ^ b) + blocks[7] - 155497632;\n c = (c << 16 | c >>> 16) + d << 0;\n b += (da ^ c) + blocks[10] - 1094730640;\n b = (b << 23 | b >>> 9) + c << 0;\n bc = b ^ c;\n a += (bc ^ d) + blocks[13] + 681279174;\n a = (a << 4 | a >>> 28) + b << 0;\n d += (bc ^ a) + blocks[0] - 358537222;\n d = (d << 11 | d >>> 21) + a << 0;\n da = d ^ a;\n c += (da ^ b) + blocks[3] - 722521979;\n c = (c << 16 | c >>> 16) + d << 0;\n b += (da ^ c) + blocks[6] + 76029189;\n b = (b << 23 | b >>> 9) + c << 0;\n bc = b ^ c;\n a += (bc ^ d) + blocks[9] - 640364487;\n a = (a << 4 | a >>> 28) + b << 0;\n d += (bc ^ a) + blocks[12] - 421815835;\n d = (d << 11 | d >>> 21) + a << 0;\n da = d ^ a;\n c += (da ^ b) + blocks[15] + 530742520;\n c = (c << 16 | c >>> 16) + d << 0;\n b += (da ^ c) + blocks[2] - 995338651;\n b = (b << 23 | b >>> 9) + c << 0;\n a += (c ^ (b | ~d)) + blocks[0] - 198630844;\n a = (a << 6 | a >>> 26) + b << 0;\n d += (b ^ (a | ~c)) + blocks[7] + 1126891415;\n d = (d << 10 | d >>> 22) + a << 0;\n c += (a ^ (d | ~b)) + blocks[14] - 1416354905;\n c = (c << 15 | c >>> 17) + d << 0;\n b += (d ^ (c | ~a)) + blocks[5] - 57434055;\n b = (b << 21 | b >>> 11) + c << 0;\n a += (c ^ (b | ~d)) + blocks[12] + 1700485571;\n a = (a << 6 | a >>> 26) + b << 0;\n d += (b ^ (a | ~c)) + blocks[3] - 1894986606;\n d = (d << 10 | d >>> 22) + a << 0;\n c += (a ^ (d | ~b)) + blocks[10] - 1051523;\n c = (c << 15 | c >>> 17) + d << 0;\n b += (d ^ (c | ~a)) + blocks[1] - 2054922799;\n b = (b << 21 | b >>> 11) + c << 0;\n a += (c ^ (b | ~d)) + blocks[8] + 1873313359;\n a = (a << 6 | a >>> 26) + b << 0;\n d += (b ^ (a | ~c)) + blocks[15] - 30611744;\n d = (d << 10 | d >>> 22) + a << 0;\n c += (a ^ (d | ~b)) + blocks[6] - 1560198380;\n c = (c << 15 | c >>> 17) + d << 0;\n b += (d ^ (c | ~a)) + blocks[13] + 1309151649;\n b = (b << 21 | b >>> 11) + c << 0;\n a += (c ^ (b | ~d)) + blocks[4] - 145523070;\n a = (a << 6 | a >>> 26) + b << 0;\n d += (b ^ (a | ~c)) + blocks[11] - 1120210379;\n d = (d << 10 | d >>> 22) + a << 0;\n c += (a ^ (d | ~b)) + blocks[2] + 718787259;\n c = (c << 15 | c >>> 17) + d << 0;\n b += (d ^ (c | ~a)) + blocks[9] - 343485551;\n b = (b << 21 | b >>> 11) + c << 0;\n\n if (this.first) {\n this.h0 = a + 1732584193 << 0;\n this.h1 = b - 271733879 << 0;\n this.h2 = c - 1732584194 << 0;\n this.h3 = d + 271733878 << 0;\n this.first = false;\n } else {\n this.h0 = this.h0 + a << 0;\n this.h1 = this.h1 + b << 0;\n this.h2 = this.h2 + c << 0;\n this.h3 = this.h3 + d << 0;\n }\n };\n\n /**\n * @method hex\n * @memberof Md5\n * @instance\n * @description Output hash as hex string\n * @returns {String} Hex string\n * @see {@link md5.hex}\n * @example\n * hash.hex();\n */\n Md5.prototype.hex = function () {\n this.finalize();\n\n var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;\n\n return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +\n HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +\n HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +\n HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +\n HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +\n HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +\n HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +\n HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +\n HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +\n HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +\n HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +\n HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +\n HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +\n HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +\n HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +\n HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];\n };\n\n /**\n * @method toString\n * @memberof Md5\n * @instance\n * @description Output hash as hex string\n * @returns {String} Hex string\n * @see {@link md5.hex}\n * @example\n * hash.toString();\n */\n Md5.prototype.toString = Md5.prototype.hex;\n\n /**\n * @method digest\n * @memberof Md5\n * @instance\n * @description Output hash as bytes array\n * @returns {Array} Bytes array\n * @see {@link md5.digest}\n * @example\n * hash.digest();\n */\n Md5.prototype.digest = function () {\n this.finalize();\n\n var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;\n return [\n h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,\n h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,\n h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,\n h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF\n ];\n };\n\n /**\n * @method array\n * @memberof Md5\n * @instance\n * @description Output hash as bytes array\n * @returns {Array} Bytes array\n * @see {@link md5.array}\n * @example\n * hash.array();\n */\n Md5.prototype.array = Md5.prototype.digest;\n\n /**\n * @method arrayBuffer\n * @memberof Md5\n * @instance\n * @description Output hash as ArrayBuffer\n * @returns {ArrayBuffer} ArrayBuffer\n * @see {@link md5.arrayBuffer}\n * @example\n * hash.arrayBuffer();\n */\n Md5.prototype.arrayBuffer = function () {\n this.finalize();\n\n var buffer = new ArrayBuffer(16);\n var blocks = new Uint32Array(buffer);\n blocks[0] = this.h0;\n blocks[1] = this.h1;\n blocks[2] = this.h2;\n blocks[3] = this.h3;\n return buffer;\n };\n\n /**\n * @method buffer\n * @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.\n * @memberof Md5\n * @instance\n * @description Output hash as ArrayBuffer\n * @returns {ArrayBuffer} ArrayBuffer\n * @see {@link md5.buffer}\n * @example\n * hash.buffer();\n */\n Md5.prototype.buffer = Md5.prototype.arrayBuffer;\n\n /**\n * @method base64\n * @memberof Md5\n * @instance\n * @description Output hash as base64 string\n * @returns {String} base64 string\n * @see {@link md5.base64}\n * @example\n * hash.base64();\n */\n Md5.prototype.base64 = function () {\n var v1, v2, v3, base64Str = '', bytes = this.array();\n for (var i = 0; i < 15;) {\n v1 = bytes[i++];\n v2 = bytes[i++];\n v3 = bytes[i++];\n base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +\n BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +\n BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +\n BASE64_ENCODE_CHAR[v3 & 63];\n }\n v1 = bytes[i];\n base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +\n BASE64_ENCODE_CHAR[(v1 << 4) & 63] +\n '==';\n return base64Str;\n };\n\n /**\n * HmacMd5 class\n * @class HmacMd5\n * @extends Md5\n * @description This is internal class.\n * @see {@link md5.hmac.create}\n */\n function HmacMd5(key, sharedMemory) {\n var i, result = formatMessage(key);\n key = result[0];\n if (result[1]) {\n var bytes = [], length = key.length, index = 0, code;\n for (i = 0; i < length; ++i) {\n code = key.charCodeAt(i);\n if (code < 0x80) {\n bytes[index++] = code;\n } else if (code < 0x800) {\n bytes[index++] = (0xc0 | (code >>> 6));\n bytes[index++] = (0x80 | (code & 0x3f));\n } else if (code < 0xd800 || code >= 0xe000) {\n bytes[index++] = (0xe0 | (code >>> 12));\n bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));\n bytes[index++] = (0x80 | (code & 0x3f));\n } else {\n code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));\n bytes[index++] = (0xf0 | (code >>> 18));\n bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));\n bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));\n bytes[index++] = (0x80 | (code & 0x3f));\n }\n }\n key = bytes;\n }\n\n if (key.length > 64) {\n key = (new Md5(true)).update(key).array();\n }\n\n var oKeyPad = [], iKeyPad = [];\n for (i = 0; i < 64; ++i) {\n var b = key[i] || 0;\n oKeyPad[i] = 0x5c ^ b;\n iKeyPad[i] = 0x36 ^ b;\n }\n\n Md5.call(this, sharedMemory);\n\n this.update(iKeyPad);\n this.oKeyPad = oKeyPad;\n this.inner = true;\n this.sharedMemory = sharedMemory;\n }\n HmacMd5.prototype = new Md5();\n\n HmacMd5.prototype.finalize = function () {\n Md5.prototype.finalize.call(this);\n if (this.inner) {\n this.inner = false;\n var innerHash = this.array();\n Md5.call(this, this.sharedMemory);\n this.update(this.oKeyPad);\n this.update(innerHash);\n Md5.prototype.finalize.call(this);\n }\n };\n\n var exports = createMethod();\n exports.md5 = exports;\n exports.md5.hmac = createHmacMethod();\n\n if (COMMON_JS) {\n module.exports = exports;\n } else {\n /**\n * @method md5\b\n * @description Md5 hash function, export to global in browsers.\n * @param {String|Array|Uint8Array|ArrayBuffer} message message to hash\n * @returns {String} md5 hashes\n * @example\n * md5(''); // d41d8cd98f00b204e9800998ecf8427e\n * md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6\n * md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0\n *\n * // It also supports UTF-8 encoding\n * md5('涓枃'); // a7bac2239fcdcb3a067903d8077c4a07\n *\n * // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`\n * md5([]); // d41d8cd98f00b204e9800998ecf8427e\n * md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e\n */\n root.md5 = exports;\n if (AMD) {\n define(function () {\n return exports;\n });\n }\n }\n})();\n"]} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 80d843e..793a7cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "js-md5": "^0.8.3", "tdesign-miniprogram": "^1.4.2" } }, @@ -13,6 +14,11 @@ "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.12.tgz", "integrity": "sha512-Rt2g+nTbLlDWZTwwrIXjy9MeiZmSDI375FvZs72ngxx8PDC6YXOeR3q5LAuPzjZQxhiWdRKac7RKV+YyQYfYIg==" }, + "node_modules/js-md5": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/js-md5/-/js-md5-0.8.3.tgz", + "integrity": "sha512-qR0HB5uP6wCuRMrWPTrkMaev7MJZwJuuw4fnwAzRgP4J4/F8RwtodOKpGp4XpqsLBFzzgqIO42efFAyz2Et6KQ==" + }, "node_modules/tdesign-miniprogram": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/tdesign-miniprogram/-/tdesign-miniprogram-1.4.2.tgz", diff --git a/package.json b/package.json index 132dfea..7634911 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "dependencies": { + "js-md5": "^0.8.3", "tdesign-miniprogram": "^1.4.2" } } diff --git a/pages/feedback/feedback.js b/pages/feedback/feedback.js index d98f891..8c95e94 100644 --- a/pages/feedback/feedback.js +++ b/pages/feedback/feedback.js @@ -1,5 +1,8 @@ const audio = wx.createInnerAudioContext() const recorderManager = wx.getRecorderManager() +const { + BASEURL +} = require('../../api/config') Page({ data: { isRefreshing: false, @@ -18,13 +21,14 @@ width: 160, height: 160, }, - originFiles: [ - ], + originFiles: [], feedBackList: Array(19).fill({ createTime: "2023-05-06 12:36:25", responseTime: "2023-05-07 12:36:25" }), - contentValue:''//鍙嶉璇︽儏 + contentValue: '', //鍙嶉璇︽儏 + accSavePath: '', //涓婁紶鐨勯煶棰戞枃浠舵帴鍙h繑鍥炵殑鍦板潃 + photoSavePath: [] //涓婁紶鐨勭収鐗囨枃浠惰繑鍥炵殑鍦板潃 }, onLoad() { @@ -65,7 +69,7 @@ time: 3000 }) } else { - + that.setData({ voiceTime: voiceTime, isShowVoiceMask: false, @@ -78,47 +82,9 @@ } = res; //杩欓噷鏉惧紑鎸夐挳 浼氳繑鍥炲綍闊虫湰鍦拌矾寰� audio.src = tempFilePath console.log(tempFilePath); + that.upACC(tempFilePath); } - //涓婁紶褰曞埗鐨勯煶棰戝埌鏈嶅姟鍣� - // wx.uploadFile({ - // url: '鎺ュ彛鍦板潃' + api.voice, //鎺ュ彛鍦板潃 - // name: 'file', //涓婁紶鏂囦欢鍚� - // filePath: tempFilePath, - // success: function (res) { //鍚庡彴杩斿洖缁欏墠绔瘑鍒悗鐨勬枃瀛� - // var model = res.data - // var modeljson = JSON.parse(model) - // if (modeljson.status_code == 500) { - // wx.showToast({ - // title: '璇煶杞崲澶辫触', - // image: '/assets/image/icon/fail@2x.png' - // }) - // return false; - // } - // if (modeljson.meta.status_code === 200 && !modeljson.data.err_msg) { - // var saymessage = modeljson.data.message; - // wx.setStorageSync('sayinfo', saymessage) - // that.setData({ - // inpvalue: saymessage - // }) - // setTimeout(() =>{ - // wx.navigateTo({ - // url: '../loding/loding' - // }) - - // },2000) - // setTimeout(() => { - // wx.hideLoading(); - // }, 100) - // } else if (modeljson.data.err_msg) { - // wx.showToast({ - // title: '璇峰ぇ澹拌璇�', - // image: '/assets/image/icon/fail@2x.png' - // }) - // return false; - // } - // } - // }) }); recorderManager.onStart(() => { console.log('褰曢煶寮�濮�'); @@ -126,6 +92,18 @@ recorderManager.onError((err) => { console.log('褰曢煶閿欒', err); }); + }, + //涓婁紶闊抽鏂囦欢 + upACC(tempFilePath) { + //涓婁紶褰曞埗鐨勯煶棰戝埌鏈嶅姟鍣� + wx.uploadFile({ + url: BASEURL + "wx/webFile/upPhone", //鎺ュ彛鍦板潃 + name: 'file.acc', //涓婁紶鏂囦欢鍚� + filePath: tempFilePath, + success: function (res) { //鍚庡彴杩斿洖缁欏墠绔瘑鍒悗鐨勬枃瀛� + + } + }) }, handleRemove(e) { console.log("handleRemove"); @@ -135,13 +113,28 @@ const { originFiles } = this.data; + let imgPath = e.detail.file.url; + const updatedFiles = this.data.originFiles.map((file) => { + //褰撲笂浼犲け璐ョ偣鍑绘椂閲嶆柊涓婁紶 + if (file.url === imgPath && file.uploadTask) { + file.uploadTask.abort(); + } + }); originFiles.splice(index, 1); this.setData({ originFiles, }); + }, - handleClick() { + handleClick(e) { console.log("handleClick"); + let imgPath = e.detail.file.url; + const updatedFiles = this.data.originFiles.map((file) => { + //褰撲笂浼犲け璐ョ偣鍑绘椂閲嶆柊涓婁紶 + if (file.url === imgPath && file.status === "reload") { + this.onUploadPhoto(imgPath); + } + }); }, handleAdd(e) { console.log("handleAdd"); @@ -151,27 +144,70 @@ const { originFiles } = this.data; - this.setData({ - originFiles: [...originFiles, ...files], // 姝ゆ椂璁剧疆浜� fileList 涔嬪悗鎵嶄細灞曠ず閫夋嫨鐨勫浘鐗� + const updatedList = files.map(item => { + return { + ...item, + status: 'loading', + uploadTask: this.onUploadPhoto(e.detail.files[0].url) + }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁 }); + // 鏇存柊鍒楄〃鏁版嵁 + this.setData({ + originFiles: [...originFiles, ...updatedList], // 姝ゆ椂璁剧疆浜� fileList 涔嬪悗鎵嶄細灞曠ず閫夋嫨鐨勫浘鐗� + }); + }, + handleSuccess(e) { + }, /** * 涓婁紶鍥剧墖 */ - onUpload() { - wx.uploadFile({ - url: 'https://example.weixin.qq.com/upload', // 浠呬负绀轰緥锛岄潪鐪熷疄鐨勬帴鍙e湴鍧� - filePath: file.url, + onUploadPhoto(imgPath) { + const uploadTask = wx.uploadFile({ + url: BASEURL + "wx/webFile/upPhone", // 浠呬负绀轰緥锛岄潪鐪熷疄鐨勬帴鍙e湴鍧� + filePath: imgPath, name: 'file', - formData: { - user: 'test' - }, success: () => { - this.setData({ - [`fileList[${length}].status`]: 'done', - }); + }, + fail: (err) => { + // 澶勭悊涓婁紶澶辫触鐨勯�昏緫 + const updatedFiles = this.data.originFiles.map((file) => { + if (file.url === imgPath) { + return { + ...file, + percent: progress, + status: "reload", // 涓婁紶澶辫触鐘舵�� + }; + } + return file; + }); + this.setData({ + originFiles: updatedFiles, + }); + } }); + if (uploadTask) { + uploadTask.onProgressUpdate((res) => { + //澶勭悊 + const progress = Math.round((res.progress / 100) * 100) + const updatedFiles = this.data.originFiles.map((file) => { + if (file.url === imgPath) { + return { + ...file, + percent: progress, + status: progress < 100 ? 'loading' : undefined, // 鏇存柊鐘舵�� + uploadTask: progress < 100 ? file.uploadTask : undefined, // 淇濇寔鎴栧垹闄ploadTask + }; + } + return file; + }); + this.setData({ + originFiles: updatedFiles, + }); + }); + } + return uploadTask; }, //鎸変綇鎸夐挳 startHandel() { @@ -296,7 +332,7 @@ isRefreshing: false }); }, - feelBack(){ + feelBack() { wx.showLoading({ title: '姝e湪鎻愪氦...', // 鍔犺浇鎻愮ず鏂囧瓧 mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false @@ -340,11 +376,11 @@ // } }); }, - handleDelete(){ - this.setData({ - isShowVoiceView:false, - voiceTime:0, - }) + handleDelete() { + this.setData({ + isShowVoiceView: false, + voiceTime: 0, + }) } }); \ No newline at end of file diff --git a/pages/home/home.js b/pages/home/home.js index c9b92e3..cbba07e 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -4,6 +4,7 @@ get, post } = require('../../api/request.js'); +const app = getApp(); Page({ /** @@ -15,8 +16,8 @@ myItem: {}, waterIntakeName: "", image: "/images/ic_head_bg.jpg", - userPhone: "000****0000", - userName: "鏈煡", + userPhone: "鏈櫥褰�", + userName: "鐐瑰嚮鐧诲綍", scrollViewHeight: 0, listData: [], isRefreshing: false, @@ -28,13 +29,22 @@ }, errorDialogTitle: "鍏抽榾閿欒", showForceConfirm: false, //鏄惁寮哄埗寮�闃� - lastIntakeName: "" + lastIntakeName: "", + isLogin: false, //鏄惁宸茬粡鐧诲綍 }, openValve: function (e) { - wx.navigateTo({ - url: '/pages/waterIntake/waterIntake', - }) + if (this.data.isLogin) { + wx.navigateTo({ + url: '/pages/waterIntake/waterIntake', + }) + } else { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) + } + }, calculateScrollViewHeight: function () { wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => { @@ -45,15 +55,22 @@ }).exec(); }, startPullDownRefresh() { - if (!this.data.isWXRefreshing) { - var self = this; - console.log(this.data.isRefreshing); - this.setData({ - isRefreshing: true - }); - this.getOpenList(); - + if(this.data.isLogin){ + if (!this.data.isWXRefreshing) { + var self = this; + console.log(this.data.isRefreshing); + this.setData({ + isRefreshing: true + }); + this.getOpenList(); + } + }else{ + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) } + }, //鑾峰彇鐢ㄦ埛鏁版嵁 @@ -68,16 +85,10 @@ console.error('Failed to fetch data:', error); }); }, - - - /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId - - // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚 wx.nextTick(() => { this.calculateScrollViewHeight(); @@ -92,37 +103,90 @@ }) this.getOpenList(); } - this.initData(); + }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ onReady() { - + //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId + if (storage.isHasKeySync("sessionId")) { + const app = getApp(); + storage.getItem('sessionId').then((data) => { + app.globalData.sessionId = data; + if (app.globalData.sessionId) { + this.getOpenList(); + this.getUserDataBySession(); + } + }).catch((err) => {}); + storage.getItem('clientId').then((data) => { + app.globalData.clientId = data; + }).catch((err) => {}); + } else { + //鏈湴娌℃湁缂撳瓨寰俊鐧诲綍 + this.wxLogin(); + } }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず - */ - onShow() { - + wxLogin() { + const that = this; + wx.login({ + success: function (res) { + if (res.code) { + var code = res.code; + console.log(code); + // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid + that.codeLogin(code); + } else { + console.log('鐧诲綍澶辫触锛�' + res.errMsg); + } + } + }); }, + //寰俊code鐧诲綍 + codeLogin(codeData) { + wx.showLoading({ + title: '姝e湪鐧诲綍璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const data = { + code: codeData, //涓存椂鐧诲綍鍑瘉 + }; + post({ + url: "wx/client/code_login", + data: data, + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + if (response.code === "0001") { + //鍋囧涓虹┖鍒欒烦杞埌缁戝畾鐣岄潰 + if (response.content.client.clientId === "") { + wx.navigateTo({ + url: '/pages/wxbind/wxbind' + }) + } else { + //缂撳瓨鍦ㄦ湰鍦� + this.setData({ + isLogin: true + }) + getApp().globalData.sessionId = response.content.client.sessionId + storage.setItem("sessionId", response.content.client.sessionId) + getApp().globalData.clientId = response.content.client.clientId + storage.setItem("clientId", response.content.client.clientId) + this.initData(); + } + } else { - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() { - + } + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + }); }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 - */ - onUnload() { - - }, - /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ @@ -137,49 +201,45 @@ // 鏁版嵁璇锋眰瀹屾垚鍚庯紝鍋滄涓嬫媺鍒锋柊鐨勫姩鐢� this.getOpenList(); }, - - /** - * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� - */ - onReachBottom() { - - }, - - /** - * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� - */ - onShareAppMessage() { - - }, // 鍏呭�� recharge() { - wx.navigateTo({ - url: '/pages/rechargeCard/rechargeCard', - }) - // wx.showToast({ - // title: '鏆傛湭寮�鏀�', - // icon: 'none' - // }) + if (this.data.isLogin) { + wx.navigateTo({ + url: '/pages/rechargeCard/rechargeCard', + }) + } else { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) + } }, //寮�鍏抽榾璁板綍 openValveList() { - wx.navigateTo({ - url: '/pages/valveList/valveList', - }) - // wx.showToast({ - // title: '鏆傛湭寮�鏀�', - // icon: 'none' - // }) + if (this.data.isLogin) { + wx.navigateTo({ + url: '/pages/valveList/valveList', + }) + } else { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) + } + }, //闂鍙嶉 feedBack() { - // wx.showToast({ - // title: '鏆傛湭寮�鏀�', - // icon: 'none' - // }) - wx.navigateTo({ - url: '/pages/feedback/feedback', - }) + if (this.data.isLogin) { + wx.navigateTo({ + url: '/pages/feedback/feedback', + }) + } else { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) + } }, handleChange(e) { const item = e.currentTarget.dataset.item; @@ -235,20 +295,20 @@ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� wx.hideLoading(); this.getOpenList(); - if(response.content.data.success){ + if (response.content.data.success) { wx.showToast({ title: '鍏抽榾鎴愬姛', icon: 'success', duration: 3000 }) - }else{ + } else { wx.showToast({ title: '鍏抽榾澶辫触', icon: 'error', duration: 3000 }) } - + }).catch(error => { wx.hideLoading(); this.setData({ @@ -277,6 +337,7 @@ isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 }) + this.updateDisplayText(); }).catch(err => { // 閿欒鍥炶皟 this.setData({ @@ -312,7 +373,8 @@ get(params).then(data => { this.setData({ userName: data.content.clientName, - userPhone: this.maskPhoneNumber(data.content.phone) + userPhone: this.maskPhoneNumber(data.content.phone), + isLogin: true }) }).catch(err => { // 閿欒鍥炶皟 @@ -348,16 +410,13 @@ if (res.result.startsWith("content://")) { let jsonStr = res.result.replace("content://", "") try { - that.saveData(jsonStr) } catch (error) { console.error('Error parsing JSON:', error); } - } else { that.postOppenValva(res.result) } - }, fail(err) { console.error(err); @@ -372,7 +431,7 @@ this.postOppenValva(this.data.lastIntakeName, true) }, /** - * + * 鎵爜寮�闃�璋冪敤寮�闃�鎺ュ彛 * @param {*} intakeName */ postOppenValva(intakeName, isforce) { @@ -435,8 +494,7 @@ //杩涘叆鐣岄潰鑾峰彇鐣岄潰鏁版嵁 initData() { const app = getApp(); - console.log("tag>>>>:" +app.globalData.tag) - + console.log("tag>>>>:" + app.globalData.tag) if (storage.isHasKeySync("userData")) { storage.getItem('userData').then((data) => { let jsonObj = JSON.parse(data); @@ -453,9 +511,105 @@ this.getOpenList(); console.log('Failed to load parameter:false'); } - + }, - onDelete(){ - + //寮哄埗鍒犻櫎 + onDelete(e) { + const item = e.currentTarget.dataset.item; + const that = this; + wx.showLoading({ + title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + that.setData({ + lastIntakeName: intakeName + }) + const data = { + vcNum: item.vcNum, //鍙栨按鍙D + rtuAddr: item.rtuAddr, //闃�鎺у櫒鍦板潃 + }; + post({ + url: "wx/valve/deleteUnclosed", + data: data, + timeout: 180000 + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + //閲嶆柊鑾峰彇鍒楄〃鍒锋柊鏁版嵁 + this.getOpenList(); + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + }); + }, + //淇敼鎸夐挳鏂囧瓧 + updateDisplayText() { + const updatedList = this.data.listData.map(item => { + let displayText = ''; + if (item.planned) { + displayText = '鍙栨秷'; + } else { + displayText = "鍏抽榾" + } + return { + ...item, + displayText + }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁 + }); + // 鏇存柊鍒楄〃鏁版嵁 + this.setData({ + listData: updatedList + }); + }, + //瑙g粦 + unbind() { + //娓呯┖鏁版嵁 + this.setData({ + userPhone: "璇风櫥褰�", + userName: "鏈櫥褰�", + listData: [] + }) + wx.showLoading({ + title: '姝e湪瑙g粦璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const data = { + sessionId: getApp().globalData.sessionId //鍙栨按鍙D + }; + post({ + url: 'wx/client/unbind', + data: data, + useParams: true + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + //娓呯┖鏁版嵁 + this.setData({ + userPhone: "璇风櫥褰�", + userName: "鏈櫥褰�", + listData: [], + isLogin:false + }) + app.globalData.sessionId = ""; + app.globalData.clientId = "" + storage.removeItem("sessionId") + storage.removeItem("clientId") + wx.showToast({ + title: '瑙g粦鎴愬姛', + icon: 'success', + duration: 3000 + }) + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + }); } }) \ No newline at end of file diff --git a/pages/home/home.wxml b/pages/home/home.wxml index 5fab6fa..b1ca00f 100644 --- a/pages/home/home.wxml +++ b/pages/home/home.wxml @@ -5,11 +5,11 @@ <view class="head-top"> <t-avatar class="avatar-example" image="{{image}}" size="120rpx" /> <view class="head-text-wrapper"> - <text>{{userName}}</text> - <text class="head-bottom">{{userPhone}}</text> + <text bind:tap="wxLogin">{{userName}}</text> + <text wx:if="{{isLogin}}" class="head-bottom">{{userPhone}}</text> </view> <view class="head-button-wrapper"> - <text class="unbind" bind:tap="">瑙g粦</text> + <text wx:if="{{isLogin}}" class="unbind" bind:tap="unbind">瑙g粦</text> <text class="head-bottom" bind:tap="feedBack">鑱旂郴瀹㈡湇</text> </view> <view class="scen-view" bind:tap="scenCode"> @@ -42,7 +42,7 @@ <view class="bottom-title"> <text class="bottom-title-text">蹇�熷叧闃�</text> - <text class="refresh-button" bind:tap="startPullDownRefresh">鍒锋柊</text> + <text class="refresh-button" bind:tap="startPullDownRefresh">鍒锋柊</text> </view> <view class="divider"></view> <!-- refresher-enabled="true" refresher-threshold="50" --> @@ -67,7 +67,7 @@ <text class="item-button" bind:tap="handleChange" data-item="{{item}}">鍏抽榾</text> </view> </view> - <view slot="right" class="delete-btn" bind:tap="onDelete">鍒犻櫎</view> + <view slot="right" class="delete-btn" bind:tap="onDelete" data-item="{{item}}">{{item.displayText}}</view> </t-swipe-cell> </view> </view> diff --git a/pages/home/home.wxss b/pages/home/home.wxss index bf6de6e..ee6fa2a 100644 --- a/pages/home/home.wxss +++ b/pages/home/home.wxss @@ -386,6 +386,3 @@ margin-bottom: 2rpx; width: 100wh; } -.swipe-cell-base{ - -} \ No newline at end of file diff --git a/pages/rechargeCard/rechargeCard.js b/pages/rechargeCard/rechargeCard.js index 9b634f2..9377c0c 100644 --- a/pages/rechargeCard/rechargeCard.js +++ b/pages/rechargeCard/rechargeCard.js @@ -1,4 +1,5 @@ // pages/rechargeCard/rechargeCard.js +//铏氭嫙鍗″垪琛� const { get, post @@ -13,69 +14,40 @@ content: '纭' }, currentTab: 0, // 褰撳墠鏄剧ず鐨勮〃鏍硷紝榛樿涓虹涓�涓〃鏍� - allCardPoints: [{ - "id": "string", - "inUse": 0, - "inUseName": "string", - "money": 110, - "vcNum": "200030000000" - }, { - "id": "string", - "inUse": 0, - "inUseName": "string", - "money": 110, - "vcNum": "200030000000" - }, { - "id": "string", - "inUse": 0, - "inUseName": "string", - "money": 110, - "vcNum": "200030000000" - }, { - "id": "string", - "inUse": 0, - "inUseName": "string", - "money": 110, - "vcNum": "200030000000" - }, { - "id": "string", - "inUse": 1, - "inUseName": "string", - "money": 110, - "vcNum": "200030000000" - }], + allCardPoints: [], allWaterPoints: [{ "id": "string", "inUse": 1, "inUseName": "string", "money": 110, "vcNum": "200030000000" - },{ + }, { "id": "string", "inUse": 1, "inUseName": "string", "money": 110, "vcNum": "200030000000" - },{ + }, { "id": "string", "inUse": 1, "inUseName": "string", "money": 110, "vcNum": "200030000000" - },{ + }, { "id": "string", "inUse": 1, "inUseName": "string", "money": 110, "vcNum": "200030000000" - },{ + }, { "id": "string", "inUse": 1, "inUseName": "string", "money": 110, "vcNum": "200030000000" }], - showDialog: false + showDialog: false, + isWXRefreshing: false }, // 鍒囨崲 Tabs switchTab: function (e) { @@ -89,7 +61,7 @@ */ onLoad(options) { this.getCardList(); - this.getWaterCardList(); + // this.getWaterCardList(); }, /** @@ -124,7 +96,10 @@ * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - + this.setData({ + isWXRefreshing: true + }) + this.getCardList(); }, /** @@ -148,11 +123,13 @@ } }) .then((data) => { + this.setData({ + isWXRefreshing: false + }); if (data.success && data.code === "0001") { this.setData({ allCardPoints: data.content }); - this.updateDisplayText(); } else { wx.showToast({ title: data.msg, @@ -161,6 +138,9 @@ console.log('Failed to add item:'); }) .catch((error) => { + this.setData({ + isWXRefreshing: false + }); console.error('Failed to add item:', error); }); }, @@ -187,21 +167,106 @@ console.error('Failed to add item:', error); }); }, - rechargeCard(item) { + rechargeCard(event) { wx.navigateTo({ - url: '/pages/rechargeMoney/rechargMoney' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓 + url: '/pages/rechargeMoney/rechargMoney?vcId='+event.currentTarget.dataset.item.id // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓 }); }, - ruinCard() { - this.setData({ - showDialog: true - }) + ruinCard(item) { + const mItem = item.currentTarget.dataset.item; + + if (mItem.money > 0) { + //閲戦澶т簬0涓嶈兘閿�鍗� + this.setData({ + showDialog: true + }) + } else { + //閲戦绛変簬0鎵嶅彲閿�鍗� + this.deleteID(mItem.id); + } }, closeDialog() { this.setData({ showDialog: false }) - } + }, + //娣诲姞铏氭嫙鍗� + handleClick() { + wx.showLoading({ + title: '姝e湪娣诲姞璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const data = { + clientId: getApp().globalData.clientId, //涓存椂鐧诲綍鍑瘉 + }; + post({ + url: "wx/virtual_card/add_vc", + data: data, + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + if (response.code === "0001") { + wx.showToast({ + title: '娣诲姞鎴愬姛', + icon: 'success', + duration: 3000 + }) + this.getCardList(); + } + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + wx.showToast({ + title: '娣诲姞澶辫触', + icon: 'error', + duration: 2000 + }) + }); + }, + //娉ㄩ攢铏氭嫙鍗� + deleteID(vcId) { + wx.showLoading({ + title: '姝e湪閿�鍗¤绋嶅��...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const data = { + clientId: getApp().globalData.clientId, //涓存椂鐧诲綍鍑瘉 + vcId: vcId //铏氭嫙鍗d + }; + post({ + url: "wx/virtual_card/cancel", + data: data, + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + if (response.code === "0001") { + wx.showToast({ + title: '閿�鍗℃垚鍔�', + icon: 'success', + duration: 3000 + }) + this.getCardList(); + } + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + wx.showToast({ + title: '娉ㄩ攢澶辫触', + icon: 'error', + duration: 2000 + }) + }); + }, + + }) \ No newline at end of file diff --git a/pages/rechargeCard/rechargeCard.json b/pages/rechargeCard/rechargeCard.json index 84ea31a..48caeb0 100644 --- a/pages/rechargeCard/rechargeCard.json +++ b/pages/rechargeCard/rechargeCard.json @@ -1,5 +1,9 @@ { + "component": true, "usingComponents": { - "t-dialog": "tdesign-miniprogram/dialog/dialog" - } + "t-dialog": "tdesign-miniprogram/dialog/dialog", + "t-fab": "tdesign-miniprogram/fab/fab" + }, + "navigationBarTitleText": "铏氭嫙鍗�", + "navigationBarTextStyle": "white" } \ No newline at end of file diff --git a/pages/rechargeCard/rechargeCard.wxml b/pages/rechargeCard/rechargeCard.wxml index 79d2c9d..d095c82 100644 --- a/pages/rechargeCard/rechargeCard.wxml +++ b/pages/rechargeCard/rechargeCard.wxml @@ -1,19 +1,19 @@ <!--pages/rechargeCard/rechargeCard.wxml 鍏呭�肩晫闈�--> <view class="container"> <!-- 椤堕儴 Tabs --> - <view class="tabs"> - <view class="tab" bindtap="switchTab" data-tab="0" id="tab0"> + <!-- <view class="tabs"> --> + <!-- <view class="tab" bindtap="switchTab" data-tab="0" id="tab0"> 铏氭嫙鍗� <view class="indicator" wx:if="{{currentTab === 0}}"></view> - </view> - <view class="tab" bindtap="switchTab" data-tab="1" id="tab1"> + </view> --> + <!-- <view class="tab" bindtap="switchTab" data-tab="1" id="tab1"> 姘村崱 <view class="indicator" wx:if="{{currentTab === 1}}"></view> - </view> - </view> + </view> --> + <!-- </view> --> <!-- 铏氭嫙鍗� --> - <scroll-view class="list-container" wx:if="{{currentTab === 0}}" scroll-y="true" scroll-x="false"> + <scroll-view class="list-container" wx:if="{{currentTab === 0}}" scroll-y="true" refresher-enabled="true" bindrefresherrefresh="onPullDownRefresh" scroll-x="false" refresher-triggered="{{isWXRefreshing}}"> <block wx:if="{{allCardPoints.length > 0}}" wx:for="{{allCardPoints}}" wx:key="index"> <view class="{{item.inUse===false?'item':'item-gray'}}"> <view class="item-card"> @@ -28,18 +28,18 @@ <text class="item-balance-text-yuan">鍏�</text> </view> <view class="button-view"> - <text wx:if="{{item.inUse==0}}" class="ruinCard" bind:tap="ruinCard">閿�鍗�</text> - <text wx:if="{{item.inUse==0}}" class="recharge" bind:tap="rechargeCard">鍏呭��</text> + <text wx:if="{{item.inUse==0}}" class="ruinCard" data-item="{{item}}" bind:tap="ruinCard">閿�鍗�</text> + <text wx:if="{{item.inUse==0}}" class="recharge" data-item="{{item}}" bind:tap="rechargeCard">鍏呭��</text> </view> </view> </view> </block> - + <view wx:if="{{allCardPoints.length === 0}}" class="noMore-View"> <image class="noMore-img" src="/images/no_more.svg" /> <text class="noMore-text">娌℃湁鏁版嵁</text> </view> - <t-dialog visible="{{showDialog}}" content="鎮ㄨ繕鏈変綑棰濇湭浣跨敤锛屽闇�閿�鍗★紝璇峰厛浣跨敤瀹屾垨閫�娆惧悗鎵嶅彲鎿嶄綔銆�" confirm-btn="{{ confirmBtn }}" bind:confirm="closeDialog" /> + </scroll-view> <!-- 姘村崱 --> @@ -61,4 +61,6 @@ </scroll-view> </view> + <t-fab icon="gesture-add" text="娣诲姞铏氭嫙鍗�" bind:click="handleClick" bind:move="handleMove" aria-label="澧炲姞" usingCustomNavbar draggable y-bounds="{{[0, 32]}}" style="--td-primary-color-7:#2D8BF7"></t-fab> + <t-dialog visible="{{showDialog}}" content="鎮ㄨ繕鏈変綑棰濇湭浣跨敤锛屽闇�閿�鍗★紝璇峰厛浣跨敤瀹屾垨閫�娆惧悗鎵嶅彲鎿嶄綔銆�" confirm-btn="{{ confirmBtn }}" bind:confirm="closeDialog" /> </view> \ No newline at end of file diff --git a/pages/rechargeCard/rechargeCard.wxss b/pages/rechargeCard/rechargeCard.wxss index 2457a03..d87e5f7 100644 --- a/pages/rechargeCard/rechargeCard.wxss +++ b/pages/rechargeCard/rechargeCard.wxss @@ -170,7 +170,8 @@ } .waterIntake-recharge { - margin-left: auto; /* 灏嗘寜閽帹鍒板鍣ㄦ渶鍙充晶 */ + margin-left: auto; + /* 灏嗘寜閽帹鍒板鍣ㄦ渶鍙充晶 */ cursor: pointer; background-color: #32CD32; color: white; diff --git a/pages/rechargeMoney/rechargMoney.js b/pages/rechargeMoney/rechargMoney.js index dfc163e..88e106e 100644 --- a/pages/rechargeMoney/rechargMoney.js +++ b/pages/rechargeMoney/rechargMoney.js @@ -1,4 +1,10 @@ // pages/rechargeMoney/rechargMoney.js +//鍏呭�肩晫闈� +const { + get, + post +} = require('../../api/request.js'); +const md5 = require('js-md5'); Page({ /** @@ -10,37 +16,29 @@ userCode: "15584236", balance: "1025鍏�", activeIndex: -1, - allRechargeList: [{ - time: "2024-05-12:20:20", - type: "杩滅▼", - morny: "500鍏�" - }, { - time: "2024-05-12:20:20", - type: "杩滅▼", - morny: "500鍏�" - }, { - time: "2024-05-12:20:20", - type: "杩滅▼", - morny: "500鍏�" - }, { - time: "2024-05-12:20:20", - type: "杩滅▼", - morny: "500鍏�" - }] + isClickable: false, + allRechargeList: [], + vcId: "", + pageCurr: 1, //鍏呭�艰褰曞綋鍓嶉〉鐮� + pageSize: 20, //鍏呭�艰褰曟瘡椤佃褰曟暟 + loading: false, //鏄惁姝e湪鍔犺浇 + hasMore: true, }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - + this.setData({ + vcId: options.vcId + }) }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ onReady() { - + this.getRechargList() }, /** @@ -68,7 +66,10 @@ * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ onPullDownRefresh() { - + this.setData({ + pageCurr: 1 + }) + this.getRechargList() }, /** @@ -90,10 +91,123 @@ if (index !== undefined) { this.setData({ activeIndex: parseInt(index), + isClickable: true }); } }, - onPullDownRefresh() { - console.log("onPullDownRefresh") + //鍒涘缓璁㈠崟骞惰皟璧锋敮浠� + creatOrder() { + if (!this.data.isClickable) { + return; + } + const data = { + sessionId: getApp().globalData.sessionId, + vcId: this.data.vcId, //铏氭嫙鍗D + rechargeAmount: 1 //锛堝崟浣嶆槸鍒嗭級 + }; + console.log("postCloseValaue" + data); + post({ + url: "wx/payment/placeOrder", + data: data + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + this.getOrderSign(response.content.prepay_id) + }).catch(error => { + if (error.code === "1002") {} + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + }); + }, + //鑾峰彇璁㈠崟杩斿洖鐨刾repay_id鐨勭鍚� + getOrderSign(id) { + const params = { + url: 'wx/payment/signAgain', + data: { + prepayId: id + } + }; + get(params).then(data => { + // 璋冭捣鏀粯 + wx.requestPayment({ + timeStamp: data.content.timeStamp, + nonceStr: data.content.nonceStr, + package: data.content.package, + signType: data.content.signType, + paySign: data.content.paySign, + success(res) { + console.log('鏀粯鎴愬姛', res); + }, + fail(err) { + console.log('鏀粯澶辫触', err); + } + }); + }).catch(err => { + wx.showToast({ + title: err.msg, + icon: 'error', + duration: 3000 + }) + }); + }, + //鑾峰彇鍏呭�艰褰� + getRechargList() { + const params = { + url: 'wx/virtual_card/getVcRechargeRecords', + data: { + vcId: this.data.vcId, + pageCurr: this.data.pageCurr, + pageSize: this.data.pageSize, + } + }; + get(params).then(data => { + this.setData({ + allRechargeList:this.data.allRechargeList.concat( data.content.obj), + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + loading: false, + hasMore: !data.content.obj.pageTotal === this.data.pageCurr + }) + this.updateDisplayText(); + }).catch(err => { + // 閿欒鍥炶皟 + this.setData({ + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + loading: false + }) + wx.showToast({ + title: err.msg, + icon: 'error', + duration: 3000 + }) + }); + }, + // 鐢熸垚鏀粯绛惧悕鐨勫嚱鏁� + generatePaySign(params) { + const sortedKeys = Object.keys(params).sort(); + const stringToSign = sortedKeys.map(key => `${key}=${params[key]}`).join('&') + `&key=your-mch-key`; + return md5(stringToSign).toUpperCase(); + }, + //鍔犺浇鏇村 + loadMore() { + if (this.data.hasMore && !this.data.loading) { + this.setData({ + loading: true, + pageCurr: this.data.pageCurr + 1 + }) + this.getRechargList(); + } + }, + updateDisplayText() { + const updatedList = this.data.allRechargeList.map(item => { + let morny = item.rechargeAmount / 100 + "鍏�" + return { + ...item, + morny + }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁 + }); + // 鏇存柊鍒楄〃鏁版嵁 + this.setData({ + allRechargeList: updatedList + }); } }) \ No newline at end of file diff --git a/pages/rechargeMoney/rechargMoney.wxml b/pages/rechargeMoney/rechargMoney.wxml index ae395e1..413765b 100644 --- a/pages/rechargeMoney/rechargMoney.wxml +++ b/pages/rechargeMoney/rechargMoney.wxml @@ -57,17 +57,18 @@ </view> <view class="rechage-view"> - <view class="rechage{{activeIndex === -1 ? 'active' : ''}}"> - <text class="rechage-text">鍏呭��</text> + <view class="rechage{{activeIndex === -1 ? 'active' : ''}}" disabled="{{isClickable}}" bind:tap="creatOrder"> + <text class="rechage-text" >鍏呭��</text> </view> </view> <view class="rechageList-view"> <text class="rechageList-view-head">鍏呭�艰褰�</text> - <scroll-view class="list-container" scroll-y="true" scroll-x="false" refresher-enabled="true" refresher-threshold="50" bindrefresherrefresh="onPullDownRefresh"> + <scroll-view class="list-container" scroll-y="true" scroll-x="false" refresher-enabled="true" refresher-threshold="50" + bindrefresherrefresh="onPullDownRefresh" refresher-triggered="{{isWXRefreshing}}" bindscrolltolower="loadMore"> <block wx:if="{{allRechargeList.length > 0}}" wx:for="{{allRechargeList}}" wx:key="index"> <view class="itemList"> - <text class="item-card-text">{{item.time}}</text> + <text class="item-card-text">{{item.rechargeTime}}</text> <text class="item-card-text">{{item.type}}</text> <text class="item-card-text">{{item.morny}}</text> </view> @@ -76,6 +77,7 @@ <image class="noMore-img" src="/images/no_more.svg" /> <text class="noMore-text">娌℃湁鏁版嵁</text> </view> + <view wx:if="{{loading}}" class="loading">鍔犺浇涓�...</view> <!-- 鍔犺浇鎸囩ず鍣� --> </scroll-view> diff --git a/pages/rechargeMoney/rechargMoney.wxss b/pages/rechargeMoney/rechargMoney.wxss index 438e59a..8a6b7ca 100644 --- a/pages/rechargeMoney/rechargMoney.wxss +++ b/pages/rechargeMoney/rechargMoney.wxss @@ -179,4 +179,9 @@ .item-card-text { font-size: 35rpx; +} + +.loading { + text-align: center; + padding: 20px; } \ No newline at end of file diff --git a/pages/valveList/valveList.js b/pages/valveList/valveList.js index 2a416af..59ff542 100644 --- a/pages/valveList/valveList.js +++ b/pages/valveList/valveList.js @@ -1,37 +1,54 @@ // pages/valveList/valveList.js 寮�鍏抽榾璁板綍 +const { + get, + post +} = require('../../api/request.js'); + Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { - listData: [{ + listVirtualData: [{ intakeNum: "1023356646612", - watername:"娴嬭瘯", - startTime:"2024.10.15 12:23", - endTime:"2024.10.15 16:23" + watername: "娴嬭瘯", + startTime: "2024.10.15 12:23", + endTime: "2024.10.15 16:23" }, { intakeNum: "1023356646612", - watername:"娴嬭瘯1", - startTime:"2024.10.15 12:23", - endTime:"2024.10.15 16:23" + watername: "娴嬭瘯1", + startTime: "2024.10.15 12:23", + endTime: "2024.10.15 16:23" }, { intakeNum: "1023356646612", - watername:"娴嬭瘯2", - startTime:"2024.10.15 12:23", - endTime:"2024.10.15 16:23" + watername: "娴嬭瘯2", + startTime: "2024.10.15 12:23", + endTime: "2024.10.15 16:23" }, { intakeNum: "1023356646612", - watername:"娴嬭瘯3", - startTime:"2024.10.15 12:23", - endTime:"2024.10.15 16:23" + watername: "娴嬭瘯3", + startTime: "2024.10.15 12:23", + endTime: "2024.10.15 16:23" }, { intakeNum: "1023356646612", - watername:"娴嬭瘯4", - startTime:"2024.10.15 12:23", - endTime:"2024.10.15 16:23" - }] + watername: "娴嬭瘯4", + startTime: "2024.10.15 12:23", + endTime: "2024.10.15 16:23" + }], + listPhysicalData: [], + currentTab: 0, + isVirtualRefreshing: false, //铏氭嫙鍗″埛鏂颁腑 + isPhysicalRefreshing: false, //瀹炰綋鍗″埛鏂颁腑 + physicalPageCurr: 1, //瀹炰綋鍗″綋鍓嶉〉鏁� + pageSize: 20, + virtualPageCurr: 1, //铏氭嫙鍗″綋鍓嶉〉鏁� + virtualhasMore: true, + physicalHasMore: true, + virtualIsLoding: false, + physicalIsLoding: false, + }, /** @@ -45,7 +62,8 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ onReady() { - + this.getPhysicalListData(); + this.getVirtualListData(); }, /** @@ -88,5 +106,117 @@ */ onShareAppMessage() { + }, + switchTab(e) { + const tab = parseInt(e.currentTarget.dataset.tab); + this.setData({ + currentTab: tab + }); + }, + //铏氭嫙鍗″埛鏂� + onPullVirtualDownRefresh() { + this.setData({ + isVirtualRefreshing: true, + }) + this.getVirtualListData(); + }, + //瀹炰綋鍗″埛鏂� + onPullPhysicalDownRefresh() { + this.setData({ + isPhysicalRefreshing: true, + }) + this.getPhysicalListData(); + }, + //鑾峰彇瀹炰綋鍗″垪琛� + getPhysicalListData() { + get({ + url: 'wx/intake/getCardOpenClose', + data: { + // clientId: getApp().globalData.clientId, + pageCurr: this.data.physicalPageCurr, + pageSize: this.data.pageSize + } + }) + .then((data) => { + this.setData({ + isPhysicalRefreshing: false, + physicalIsLoding: false + }); + if (data.success && data.code === "0001") { + this.setData({ + listPhysicalData: data.content.obj, + physicalHasMore: !data.content.obj.pageTotal === this.data.physicalPageCurr, + + }); + } else { + wx.showToast({ + title: data.msg, + }) + } + console.log('Failed to add item:'); + }) + .catch((error) => { + this.setData({ + isWXRefreshing: false + }); + console.error('Failed to add item:', error); + }); + }, + //鑾峰彇铏氭嫙鍗″紑鍏抽榾璁板綍 + getVirtualListData() { + get({ + url: 'wx/intake/getVcCardOpenClose', + data: { + clientId: getApp().globalData.clientId, + pageCurr: this.data.physicalPageCurr, + pageSize: this.data.pageSize + } + }) + .then((data) => { + this.setData({ + isVirtualRefreshing: false, + virtualIsLoding: false + }); + if (data.success && data.code === "0001") { + this.setData({ + listPhysicalData: data.content.obj, + physicalHasMore: !data.content.obj.pageTotal === this.data.virtualPageCurr, + + }); + } else { + wx.showToast({ + title: data.msg, + }) + } + console.log('Failed to add item:'); + }) + .catch((error) => { + this.setData({ + isWXRefreshing: false + }); + console.error('Failed to add item:', error); + }); + }, + //鍔犺浇鏇村鐨勫疄浣撳崱 + loadPhysicalMore() { + if (this.data.physicalHasMore) { + this.setData({ + physicalIsLoding: true, + physicalPageCurr: this.data.physicalPageCurr + 1 + }) + this.getPhysicalListData(); + } + }, + //鍔犺浇鏇村鐨勮櫄鎷熷崱 + loadVirtualMore() { + if (this.data.virtualhasMore) { + this.setData({ + virtualIsLoding: true, + virtualPageCurr: this.data.virtualPageCurr + 1 + }) + this.getVirtualListData(); + } + } + }) \ No newline at end of file diff --git a/pages/valveList/valveList.wxml b/pages/valveList/valveList.wxml index ac3d700..d8b95b8 100644 --- a/pages/valveList/valveList.wxml +++ b/pages/valveList/valveList.wxml @@ -1,23 +1,35 @@ <!--pages/valveList/valveList.wxml 寮�鍏抽榾璁板綍--> -<view> - <scroll-view class="list-container" scroll-y="true" scroll-x="false"> - <block wx:if="{{listData.length > 0}}" wx:for="{{listData}}" wx:key="index"> - <view class="list-item" wx:for="{{listData}}" wx:for-item="item" wx:for-index="index"> +<view class="container"> + <!-- 椤堕儴 Tabs --> + <view class="tabs"> + <view class="tab" bindtap="switchTab" data-tab="0" id="tab0"> + 铏氭嫙鍗� + <view class="indicator" wx:if="{{currentTab === 0}}"></view> + </view> + <view class="tab" bindtap="switchTab" data-tab="1" id="tab1"> + 姘村崱 + <view class="indicator" wx:if="{{currentTab === 1}}"></view> + </view> + </view> + <scroll-view class="list-container" wx:if="{{currentTab === 0}}" scroll-y="true" scroll-x="false" refresher-enabled="true" bindrefresherrefresh="onPullVirtualDownRefresh" scroll-x="false" refresher-triggered="{{isVirtualRefreshing}}" bindscrolltolower="loadVirtualMore"> + <block wx:if="{{listVirtualData.length > 0}}" wx:for="{{listVirtualData}}" wx:key="index"> + <view class="list-item" > <!-- <image class="item-img" src="/images/pipeline.svg" /> --> <view class="item-time"> <text class="item-text">娑堣垂閲戦锛�</text> <view> - <text class="item-morny">50</text> + <text class="item-morny">{{item.expense}}</text> <text class="item-text"> 鍏�</text> </view> </view> - <text class="item-text">铏氭嫙鍗$紪鍙凤細{{item.intakeNum}}</text> - <text class="item-text">鍙栨按鍙e悕绉帮細{{item.watername}}</text> - <text class="item-text">寮�闃�鏃堕棿锛歿{item.startTime}}</text> - <text class="item-text">鍏抽榾鏃堕棿锛歿{item.endTime}}</text> + <text class="item-text">姘村崱缂栧彿锛歿{item.cardNum}}</text> + <text class="item-text">鍙栨按鍙g紪鍙凤細{{item.intakeNum}}</text> + <text class="item-text">寮�闃�绫诲瀷锛歿{item.openType}}</text> + <text class="item-text">寮�闃�鏃堕棿锛歿{item.openTime}}</text> + <text class="item-text">鍏抽榾鏃堕棿锛歿{item.closeTime}}</text> <view class="item-time"> - <text class="item-text">鐢ㄦ按鏃堕暱锛�120 鍒嗛挓</text> - <text class="item-text">鐢ㄦ按閲忥細2 m鲁</text> + <text class="item-text">鐢ㄦ按鏃堕暱锛歿{item.duration}}鍒嗛挓</text> + <text class="item-text">鐢ㄦ按閲忥細{{item.amount}} m鲁</text> </view> </view> @@ -26,5 +38,36 @@ <image class="noMore-img" src="/images/no_more.svg" /> <text class="noMore-text">娌℃湁鏁版嵁</text> </view> + <view wx:if="{{virtualIsLoding}}" class="loading">鍔犺浇涓�...</view> <!-- 鍔犺浇鎸囩ず鍣� --> + </scroll-view> + + <scroll-view class="list-container" wx:else scroll-y="true" scroll-x="false" refresher-enabled="true" bindrefresherrefresh="onPullPhysicalDownRefresh" scroll-x="false" refresher-triggered="{{isPhysicalRefreshing}}" bindscrolltolower="loadPhysicalMore"> + <block wx:if="{{listPhysicalData.length > 0}}" wx:for="{{listPhysicalData}}" wx:key="index"> + <view class="list-item" > + <!-- <image class="item-img" src="/images/pipeline.svg" /> --> + <view class="item-time"> + <text class="item-text">娑堣垂閲戦锛�</text> + <view> + <text class="item-morny">{{item.expense}}</text> + <text class="item-text"> 鍏�</text> + </view> + </view> + <text class="item-text">姘村崱缂栧彿锛歿{item.cardNum}}</text> + <text class="item-text">鍙栨按鍙g紪鍙凤細{{item.intakeNum}}</text> + <text class="item-text">寮�闃�绫诲瀷锛歿{item.openType}}</text> + <text class="item-text">寮�闃�鏃堕棿锛歿{item.openTime}}</text> + <text class="item-text">鍏抽榾鏃堕棿锛歿{item.closeTime}}</text> + <view class="item-time"> + <text class="item-text">鐢ㄦ按鏃堕暱锛歿{item.duration}}鍒嗛挓</text> + <text class="item-text">鐢ㄦ按閲忥細{{item.amount}} m鲁</text> + </view> + + </view> + </block> + <view wx:if="{{listData.length === 0}}" class="noMore-View"> + <image class="noMore-img" src="/images/no_more.svg" /> + <text class="noMore-text">娌℃湁鏁版嵁</text> + </view> + <view wx:if="{{physicalIsLoding}}" class="loading">鍔犺浇涓�...</view> <!-- 鍔犺浇鎸囩ず鍣� --> </scroll-view> </view> \ No newline at end of file diff --git a/pages/valveList/valveList.wxss b/pages/valveList/valveList.wxss index babafeb..809cd29 100644 --- a/pages/valveList/valveList.wxss +++ b/pages/valveList/valveList.wxss @@ -1,4 +1,16 @@ /* pages/valveList/valveList.wxss */ +.container { + display: flex; + flex-direction: column; + height: 100vh; + width: 100%; + padding-left: 20rpx; + padding-right: 20rpx; + padding-top: 5rpx; + padding-bottom: 5rpx; + background-color: #fff; +} + .list-item { display: flex; flex-direction: column; @@ -26,4 +38,35 @@ color: #FFFF00; font-size: 50rpx; font-weight: bold; +} + +.tab { + font-size: 16px; + padding: 10px; + cursor: pointer; + position: relative; + width: 50%; + /* Tabs 骞冲垎鏁翠釜妯悜灞忓箷 */ + text-align: center; + /* 鏂囧瓧灞呬腑 */ +} + +.tabs { + display: flex; + justify-content: space-around; + position: relative; + width: 100%; + border-bottom: 1px solid #eee; + /* Tabs 鍗犳弧鏁翠釜妯悜灞忓箷 */ +} + +.indicator { + width: 100%; + height: 3px; + background-color: #1890FF; + position: absolute; + bottom: 0; + left: 0; + transform: translateX(0); + /* 鍒濆鍖栦綅缃� */ } \ No newline at end of file diff --git a/pages/wxbind/wxbind.js b/pages/wxbind/wxbind.js index d0ee79f..5a1ecb9 100644 --- a/pages/wxbind/wxbind.js +++ b/pages/wxbind/wxbind.js @@ -1,5 +1,10 @@ // pages/wxbind/wxbind.js const app = getApp(); +const { + get, + post +} = require('../../api/request.js'); +const storage = require('../../utils/storage.js'); Page({ /** @@ -7,10 +12,13 @@ */ data: { mobile: '', - code: '', + phoneCode: '', codeSent: false, countdown: 60, isButtonEnabled: false + }, + onLoad(options) { + }, bindMobileInput(e) { this.setData({ @@ -20,17 +28,18 @@ bindCodeInput(e) { this.setData({ - code: e.detail.value - }, this.checkButtonState); + phoneCode: e.detail.value + }); + this.checkButtonState(); }, checkButtonState() { const { mobile, - code + phoneCode } = this.data; - const isButtonEnabled = mobile.length === 11 && code.length == 6; + const isButtonEnabled = mobile.length === 11 && phoneCode.length == 6; this.setData({ - isButtonEnabled + isButtonEnabled: isButtonEnabled }); console.log(isButtonEnabled); }, @@ -43,19 +52,19 @@ }); return; } - + if (this.data.mobile.length != 11) { + wx.showToast({ + title: '璇疯緭鍏ュ畬鏁存墜鏈哄彿', + icon: 'none', + duration: 2000, + }); + return; + } // 鍦ㄨ繖閲屽鐞嗗彂閫侀獙璇佺爜鐨勯�昏緫锛屽彲浠ヨ皟鐢ㄥ悗鍙版帴鍙e疄鐜� - // 浠ヤ笅鏄竴涓畝鍗曠殑绀轰緥锛屼粎浣滃弬鑰� - wx.showToast({ - title: '楠岃瘉鐮佸凡鍙戦��', - icon: 'success', - duration: 2000, - }); - + this.postCode(); this.setData({ codeSent: true, }); - // 鍚姩鍊掕鏃� this.startCountdown(); }, @@ -77,26 +86,76 @@ } }, 1000); }, - bind: function () { + bindSuccess: function () { if (!this.data.isButtonEnabled) return; wx.showToast({ title: '缁戝畾鎴愬姛', icon: 'success' }); // 璺宠浆鍒� TabBar 椤甸潰 - wx.switchTab({ + wx.navigateTo({ url: '/pages/home/home' // 杩欓噷濉啓浣犳兂瑕佽烦杞殑 TabBar 椤甸潰璺緞 }); }, + //鑾峰彇楠岃瘉鐮� postCode: function () { - post('/items', { name: 'New Item' }) + const params = { + url: 'wx/client/send_sms?phoneNumber=' + this.data.mobile + }; + post(params) .then((data) => { - this.setData({ - items: [...this.data.items, data] + wx.showToast({ + title: '楠岃瘉鐮佸凡鍙戦��', + icon: 'success', + duration: 2000, }); }) .catch((error) => { console.error('Failed to add item:', error); }); + }, + + bind() { + this.wsLogin(); + }, + wsLogin() { + wx.login({ + success: res => { + if (res.code) { + console.log('鐧诲綍鎴愬姛锛岃幏鍙栧埌鐨刢ode:', res.code); + // 鍙戦�� res.code 鍒板悗鍙版湇鍔″櫒鎹㈠彇 openId, sessionKey, unionId + this.verify(res.code) + } else { + console.log('鐧诲綍澶辫触锛�' + res.errMsg); + } + } + }); + }, + //鐢ㄦ埛缁戝畾 + verify(wxCode) { + const params = { + url: 'wx/client/verify', + data: { + phoneNumber: this.data.mobile, + securityCode: this.data.phoneCode, + code: wxCode + } + }; + post(params) + .then((data) => { + getApp().globalData.sessionId = data.content.sessionId + storage.setItem("sessionId", data.content.sessionId) + getApp().globalData.clientId = data.content.clientId + storage.setItem("clientId", data.content.clientId) + this.bindSuccess(); + }) + .catch((error) => { + wx.showToast({ + title: error.msg, + icon: 'error', + duration: 3000, + }); + console.error('Failed to add item:', error); + }); } }) \ No newline at end of file diff --git a/pages/wxlogin/wxlogin.js b/pages/wxlogin/wxlogin.js index 2669ff4..81782fe 100644 --- a/pages/wxlogin/wxlogin.js +++ b/pages/wxlogin/wxlogin.js @@ -1,26 +1,68 @@ // pages/wxlogin/wxlogin.js +const { + get, + post +} = require('../../api/request.js'); Page({ data: { userInfo: null }, - /** + /** * 鑾峰彇寰俊code */ getCode: function (e) { + const that = this; wx.login({ success: function (res) { if (res.code) { var code = res.code; console.log(code); - wx.navigateTo({ - url: '/pages/wxbind/wxbind' - }) // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid + that.codeLogin(code); } else { console.log('鐧诲綍澶辫触锛�' + res.errMsg); } } }); + }, + //寰俊code鐧诲綍 + codeLogin(codeData) { + wx.showLoading({ + title: '姝e湪鐧诲綍璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const data = { + code: codeData, //涓存椂鐧诲綍鍑瘉 + }; + post({ + url: "wx/client/code_login", + data: data, + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + //閲嶆柊鑾峰彇鍒楄〃鍒锋柊鏁版嵁 + if (response.code === "0001") { + if (response.content.client.clientId === "") { + wx.navigateTo({ + url: '/pages/wxbind/wxbind' + }) + } else { + wx.navigateTo({ + url: '/pages/home/home' + }) + } + } else { + + } + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + }); } + }) \ No newline at end of file -- Gitblit v1.8.0