- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
"use strict";function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.uploadCommentImage=exports.getImageSTSToken=exports.checkImageUpload=void 0;var _ttUploaderMiniprogram=_interopRequireDefault(require("../lib/tt-uploader-miniprogram")),_constant=require("./constant"),_md=require("../lib/md5");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _regeneratorRuntime(){_regeneratorRuntime=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,o){var i=e&&e.prototype instanceof p?e:p,a=Object.create(i.prototype),u=new S(o||[]);return n(a,"_invoke",{value:I(t,r,u)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function p(){}function h(){}function d(){}var v={};c(v,i,function(){return this});var y=Object.getPrototypeOf,m=y&&y(y(L([])));m&&m!==e&&r.call(m,i)&&(v=m);var g=d.prototype=p.prototype=Object.create(v);function _(t){["next","throw","return"].forEach(function(e){c(t,e,function(t){return this._invoke(e,t)})})}function w(t,e){function o(n,i,a,u){var c=l(t[n],t,i);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==_typeof(f)&&r.call(f,"__await")?e.resolve(f.__await).then(function(t){o("next",t,a,u)},function(t){o("throw",t,a,u)}):e.resolve(f).then(function(t){s.value=t,a(s)},function(t){return o("throw",t,a,u)})}u(c.arg)}var i;n(this,"_invoke",{value:function(t,r){function n(){return new e(function(e,n){o(t,r,e,n)})}return i=i?i.then(n,n):n()}})}function I(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(a,r);if(u){if(u===f)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===f)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function x(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var o=l(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function L(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return h.prototype=d,n(g,"constructor",{value:d,configurable:!0}),n(d,"constructor",{value:h,configurable:!0}),h.displayName=c(d,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,u,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},_(w.prototype),c(w.prototype,a,function(){return this}),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then(function(t){return t.done?t.value:a.next()})},_(g),c(g,u,"Generator"),c(g,i,function(){return this}),c(g,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=L,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(b),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),b(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;b(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function _asyncToGenerator(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){asyncGeneratorStep(i,n,o,a,u,"next",t)}function u(t){asyncGeneratorStep(i,n,o,a,u,"throw",t)}a(void 0)})}}var IMAGE_X_SERVICE_ID="xtjplaems7",IMAGE_X_APP_ID=425533,IMAGE_X_UPLOAD_HOST="".concat(IMAGE_X_SERVICE_ID,".up.imagex-accelerate.volces.com"),readFile=function(t){return new Promise(function(e,r){wx.getFileSystemManager().readFile({filePath:t,success:function(t){var r=t.data;return e(r)},fail:r})})},getFileSize=function(t){return new Promise(function(e,r){wx.getFileSystemManager().stat({path:t,success:function(t){var r;return e((null==t||null===(r=t.stats)||void 0===r?void 0:r.size)||0)},fail:r})})},binaryStringFromArrayBuffer=function(t){for(var e=new Uint8Array(t),r=[],n=0;n<e.length;n+=32768)r.push(String.fromCharCode.apply(null,e.subarray(n,n+32768)));return r.join("")},getFileExtension=function(t){var e=String(t||"").match(/\.([^.]+)$/);return e?".".concat(e[1].toLowerCase()):""},createImageUploader=function(t){var e=t.activityId,r=t.userId;return new _ttUploaderMiniprogram.default({appId:IMAGE_X_APP_ID,userId:String(r||e||"anonymous"),imageConfig:{serviceId:IMAGE_X_SERVICE_ID},uploadHost:IMAGE_X_UPLOAD_HOST,noLog:!0})},startImageUpload=function(t){var e,r=t.activityId,n=t.filePath,o=t.fileName,i=t.stsToken,a=t.userId;return new Promise((e=_asyncToGenerator(_regeneratorRuntime().mark(function t(e,u){var c,s,l,f;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return c=!1,s=function(t){return function(e){c||(c=!0,t(e))}},t.prev=2,(l=createImageUploader({activityId:r,userId:a})).on("complete",s(function(t){var r=Array.isArray(null==t?void 0:t.uploadResult)?t.uploadResult[0]:null==t?void 0:t.uploadResult,n=(null==r?void 0:r.Uri)||(null==r?void 0:r.ImageUri)||(null==r?void 0:r.SourceUri)||"";n?e(n):u(new Error("图片上传结果缺少 URI"))})),l.on("error",s(function(t){u(new Error((null==t?void 0:t.message)||"图片上传失败"))})),t.t0=l,t.t1=n,t.next=10,getFileSize(n);case 10:if(t.t2=t.sent,t.t3=i,t.t4=IMAGE_X_SERVICE_ID,t.t5=getFileExtension(o||n),t.t6={path:t.t1,size:t.t2,stsToken:t.t3,serviceId:t.t4,fileExtension:t.t5},f=t.t0.addImageXFile.call(t.t0,t.t6)){t.next=19;break}return u(new Error("图片上传任务创建失败")),t.abrupt("return");case 19:l.start(f),t.next=25;break;case 22:t.prev=22,t.t7=t.catch(2),u(t.t7);case 25:case"end":return t.stop()}},t,null,[[2,22]])})),function(t,r){return e.apply(this,arguments)}))},getImageSTSToken=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark(function t(e,r){var n;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n="function"==typeof(null==e?void 0:e.requestStrict)?e.requestStrict.bind(e):e.request.bind(e),t.abrupt("return",n(_constant.REQUEST_URL_MAP.IMAGE_STS_GET,{method:"GET",data:{ActivityId:r}}));case 2:case"end":return t.stop()}},t)}));return function(e,r){return t.apply(this,arguments)}}();exports.getImageSTSToken=getImageSTSToken;var checkImageUpload=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark(function t(e,r,n){var o,i,a,u;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,readFile(n);case 2:return o=t.sent,i=(0,_md.hexMD5)(binaryStringFromArrayBuffer(o)),a="function"==typeof(null==e?void 0:e.requestStrict)?e.requestStrict.bind(e):e.request.bind(e),t.next=7,a(_constant.REQUEST_URL_MAP.IMAGE_UPLOAD_CHECK,{method:"GET",data:{ActivityId:r,Md5:i}});case 7:return u=t.sent,t.abrupt("return",{uri:(null==u?void 0:u.Uri)||"",md5:i});case 9:case"end":return t.stop()}},t)}));return function(e,r,n){return t.apply(this,arguments)}}();exports.checkImageUpload=checkImageUpload;var uploadCommentImage=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){var r,n,o,i,a,u,c,s;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.sdkInstance,n=e.activityId,o=e.filePath,i=e.fileName,a=e.userId,t.next=3,checkImageUpload(r,n,o);case 3:if(!(u=t.sent).uri){t.next=6;break}return t.abrupt("return",{uri:u.uri,md5:u.md5});case 6:return t.next=8,getImageSTSToken(r,n);case 8:return c=t.sent,t.next=11,startImageUpload({activityId:n,filePath:o,fileName:i,stsToken:c,userId:a});case 11:return s=t.sent,t.abrupt("return",{uri:s,md5:u.md5});case 13:case"end":return t.stop()}},t)}));return function(e){return t.apply(this,arguments)}}();exports.uploadCommentImage=uploadCommentImage; |