Files
ruo-shan-cloud-pharmacy/miniprogram/package-live/volc-mini-sdk/components/chat/chat-edit/chat-edit.js
T
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
29 KiB
JavaScript

"use strict";var _constant=require("../../../utils/constant"),_comment=require("../../../utils/comment"),_dynamicEmoji=require("../../../utils/dynamic-emoji"),_imageUpload=require("../../../utils/image-upload"),_notification=require("../../../utils/notification"),_theme=require("../../../utils/theme"),_autoReply=require("../../../utils/autoReply"),_constants=require("./constants"),_icons=require("./icons"),_utils=require("./utils"),_featureProcess=require("../../../utils/feature-process"),_excluded=["TextContent","ContentType","source"];function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}function _iterableToArrayLimit(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,r,a,i,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(o=a.call(n)).done)&&(s.push(o.value),s.length!==t);c=!0);}catch(e){l=!0,r=e}finally{try{if(!c&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(l)throw r}}return s}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,o=Object.defineProperty||function(e,t,n){e[t]=n.value},r="function"==typeof Symbol?Symbol:{},a=r.iterator||"@@iterator",i=r.asyncIterator||"@@asyncIterator",s=r.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function l(e,t,n,r){var a=t&&t.prototype instanceof d?t:d,i=Object.create(a.prototype),s=new S(r||[]);return o(i,"_invoke",{value:C(e,n,s)}),i}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=l;var m={};function d(){}function h(){}function p(){}var f={};c(f,a,function(){return this});var g=Object.getPrototypeOf,y=g&&g(g(j([])));y&&y!==t&&n.call(y,a)&&(f=y);var v=p.prototype=d.prototype=Object.create(f);function _(e){["next","throw","return"].forEach(function(t){c(e,t,function(e){return this._invoke(t,e)})})}function I(e,t){function r(o,a,i,s){var c=u(e[o],e,a);if("throw"!==c.type){var l=c.arg,m=l.value;return m&&"object"==_typeof(m)&&n.call(m,"__await")?t.resolve(m.__await).then(function(e){r("next",e,i,s)},function(e){r("throw",e,i,s)}):t.resolve(m).then(function(e){l.value=e,i(l)},function(e){return r("throw",e,i,s)})}s(c.arg)}var a;o(this,"_invoke",{value:function(e,n){function o(){return new t(function(t,o){r(e,n,t,o)})}return a=a?a.then(o,o):o()}})}function C(e,t,n){var o="suspendedStart";return function(r,a){if("executing"===o)throw new Error("Generator is already running");if("completed"===o){if("throw"===r)throw a;return{value:void 0,done:!0}}for(n.method=r,n.arg=a;;){var i=n.delegate;if(i){var s=T(i,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===o)throw o="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o="executing";var c=u(e,t,n);if("normal"===c.type){if(o=n.done?"completed":"suspendedYield",c.arg===m)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o="completed",n.method="throw",n.arg=c.arg)}}}function T(e,t){var n=t.method,o=e.iterator[n];if(void 0===o)return t.delegate=null,"throw"===n&&e.iterator.return&&(t.method="return",t.arg=void 0,T(e,t),"throw"===t.method)||"return"!==n&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;var r=u(o,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,m;var a=r.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,m):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,m)}function b(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(b,this),this.reset(!0)}function j(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,r=function t(){for(;++o<e.length;)if(n.call(e,o))return t.value=e[o],t.done=!1,t;return t.value=void 0,t.done=!0,t};return r.next=r}}return{next:w}}function w(){return{value:void 0,done:!0}}return h.prototype=p,o(v,"constructor",{value:p,configurable:!0}),o(p,"constructor",{value:h,configurable:!0}),h.displayName=c(p,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,s,"GeneratorFunction")),e.prototype=Object.create(v),e},e.awrap=function(e){return{__await:e}},_(I.prototype),c(I.prototype,i,function(){return this}),e.AsyncIterator=I,e.async=function(t,n,o,r,a){void 0===a&&(a=Promise);var i=new I(l(t,n,o,r),a);return e.isGeneratorFunction(n)?i:i.next().then(function(e){return e.done?e.value:i.next()})},_(v),c(v,s,"Generator"),c(v,a,function(){return this}),c(v,"toString",function(){return"[object Generator]"}),e.keys=function(e){var t=Object(e),n=[];for(var o in t)n.push(o);return n.reverse(),function e(){for(;n.length;){var o=n.pop();if(o in t)return e.value=o,e.done=!1,e}return e.done=!0,e}},e.values=j,S.prototype={constructor:S,reset:function(e){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(E),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function o(n,o){return i.type="throw",i.arg=e,t.next=n,o&&(t.method="next",t.arg=void 0),!!o}for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r],i=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(e,t){for(var o=this.tryEntries.length-1;o>=0;--o){var r=this.tryEntries[o];if(r.tryLoc<=this.prev&&n.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var a=r;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,m):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),m},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),E(n),m}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var o=n.completion;if("throw"===o.type){var r=o.arg;E(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:j(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),m}},e}function asyncGeneratorStep(e,t,n,o,r,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(o,r)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise(function(o,r){var a=e.apply(t,n);function i(e){asyncGeneratorStep(a,o,r,i,s,"next",e)}function s(e){asyncGeneratorStep(a,o,r,i,s,"throw",e)}i(void 0)})}}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _objectWithoutProperties(e,t){if(null==e)return{};var n,o,r=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o<a.length;o++)n=a[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var n,o,r={},a=Object.keys(e);for(o=0;o<a.length;o++)n=a[o],t.indexOf(n)>=0||(r[n]=e[n]);return r}function _defineProperty(e,t,n){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var DEFAULT_PANEL_HEIGHT=300,KEYBOARD_HEIGHT_STORAGE_KEY="volc_live_mini_chat_keyboard_height";Component({properties:{sdkInstance:{type:Object,value:null},isLandscape:{type:Boolean,value:!1},externalEditorCloseSignal:{type:Number,value:0}},data:{CommentConfig:{},chatValue:"",chatLength:0,IsSendCommentEnable:void 0,sendChatTime:0,InvalidToken:!0,entering:!1,lastKeyboardHeight:0,panelHeight:DEFAULT_PANEL_HEIGHT,backgroundColor:"",safeAreaInsetBottom:0,platform:"",system:"",emojiPanelSections:[],showEmojiPanel:!1,focusInput:!1,showEmojiEntry:!1,showImageEntry:!1,showCloseEntry:!1,emojiTriggerIcon:_icons.EMOJI_TRIGGER_ICON,emojiTriggerIconDark:_icons.EMOJI_TRIGGER_ICON_DARK,keyboardTriggerIcon:_icons.KEYBOARD_TRIGGER_ICON,keyboardTriggerIconDark:_icons.KEYBOARD_TRIGGER_ICON_DARK,imageTriggerIcon:_icons.IMAGE_TRIGGER_ICON,imageTriggerIconDark:_icons.IMAGE_TRIGGER_ICON_DARK},lifetimes:{created:function(){this._emojiSets=[]},attached:function(){try{var e=wx.getSystemInfoSync(),t=Number(wx.getStorageSync(KEYBOARD_HEIGHT_STORAGE_KEY)||0);this.setData({safeAreaInsetBottom:e.screenHeight-e.safeArea.bottom,platform:e.platform,lastKeyboardHeight:t>0?t:0,panelHeight:t>0?t:DEFAULT_PANEL_HEIGHT})}catch(e){console.error("getSystemInfoSync failed",e)}},detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null}},observers:{sdkInstance:function(e){if(e){this.sdkInstance=e,this.store=e.store;var t=this,n=!1;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({liveInfo:function(e){var o,r,a=t.data.IsSendCommentEnable,i=null!==(o=null==e?void 0:e.CommentConfig)&&void 0!==o?o:{},s=i.IsSendCommentEnable,c=i.IsWelcomeMessageEnable,l=i.WelcomeMessageContent,u=i.WelcomeMessageTitle;if(void 0!==s){void 0!==a&&a!==s&&t.showMockComment(_constants.CommentType.MuteAll,{IsSendCommentEnable:1===s}),(0,_notification.isOpenSwitch)(c)&&l&&u&&!n&&(t.showMockComment(_constants.CommentType.Welcome,{WelcomeContent:l,WelcomeTitle:u}),n=!0);var m=((null==e?void 0:e.Basic)||{}).ColorThemeIndex;t.setData({CommentConfig:(null==e?void 0:e.CommentConfig)||{},IsSendCommentEnable:s,backgroundColor:(0,_theme.getThemeColor)(m).Fill_7,showImageEntry:1===Number((null==e||null===(r=e.CommentConfig)||void 0===r?void 0:r.IsImageCommentEnable)||0)})}},mainInfo:function(e){var n;t.setData({InvalidToken:2!==(null==e?void 0:e.mode),showCloseEntry:!0===(null==e||null===(n=e.options)||void 0===n?void 0:n.showChatInputCloseButton)})},"chat.emojiSets":function(e){t.updateEmojiSets(e||[])}})}},entering:function(e){this.triggerEvent("editorstatechange",{entering:e})},externalEditorCloseSignal:function(e){e&&this.data.entering&&this.handleOutsideTap()}},methods:{activateTextEditor:function(){var e=this;this.setData({entering:!0,showEmojiPanel:!1,focusInput:!1},function(){e.setData({focusInput:!0})})},getCommentTypeLabel:function(e){var t;return(_defineProperty(t={},_comment.MessageContentType.Text,"text"),_defineProperty(t,_comment.MessageContentType.Emoji,"emoji"),_defineProperty(t,_comment.MessageContentType.BigEmoji,"bigEmoji"),_defineProperty(t,_comment.MessageContentType.Photo,"photo"),t)[e]||"unknown"},buildCommentTeaPayload:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.TextContent,n=void 0===t?"":t,o=e.ContentType,r=void 0===o?_comment.MessageContentType.Text:o,a=e.source,i=void 0===a?"unknown":a,s=_objectWithoutProperties(e,_excluded);return _objectSpread({source:i,textContent:String(n||""),contentType:r,contentTypeLabel:this.getCommentTypeLabel(r)},s)},reportCommentTea:function(e){var t,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};null===(t=this.sdkInstance)||void 0===t||null===(n=t.reportTea)||void 0===n||n.call(t,e,o)},getKeyboardHeight:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=this.data,n=t.platform,o=t.safeAreaInsetBottom;return e<=0?0:"ios"===n?Math.max(0,e-o):e},getPanelHeight:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return e>0?e:this.data.lastKeyboardHeight||this.data.panelHeight||DEFAULT_PANEL_HEIGHT},updateEmojiSets:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this._emojiSets=t,t.length?this.data.showEmojiPanel?this.setData({emojiPanelSections:(0,_utils.buildEmojiPanelSections)(t),showEmojiEntry:!0,showEmojiPanel:!0}):null!==(e=this.data.emojiPanelSections)&&void 0!==e&&e.length?this.setData({emojiPanelSections:[],showEmojiEntry:!0}):this.data.showEmojiEntry||this.setData({showEmojiEntry:!0}):this.disableEmojiEntry()},disableEmojiEntry:function(){var e;(this.data.showEmojiPanel||this.data.showEmojiEntry||null!==(e=this.data.emojiPanelSections)&&void 0!==e&&e.length)&&this.setData({entering:!1,panelHeight:DEFAULT_PANEL_HEIGHT,showEmojiPanel:!1,focusInput:!1,emojiPanelSections:[],showEmojiEntry:!1})},closeEditor:function(e){this.setData({entering:!1,panelHeight:DEFAULT_PANEL_HEIGHT,showEmojiPanel:!1,focusInput:!1},e)},chatInputChange:function(e){var t,n=(null===(t=e.detail)||void 0===t?void 0:t.value)||"";this.setData({chatValue:n,chatLength:n.length})},triggerCommentCheck:function(){2!==this.store.get("mainInfo").mode&&this.triggerEvent("commentCheck")},handleInputActivatorTap:function(){(0,_featureProcess.lockFeatureProcess)(this.sdkInstance,_featureProcess.LockFeatureMap.Comment)||(2!==this.data.IsSendCommentEnable?this.canSendComment()?this.activateTextEditor():this.triggerCommentCheck():wx.showToast({title:"互动聊天未开启",icon:"none"}))},handleInputTap:function(){this.data.entering&&!this.data.focusInput&&this.setData({focusInput:!0})},handleInputFocus:function(){this.setData({showEmojiPanel:!1}),this.data.focusInput||this.setData({focusInput:!0})},bindblur:function(){},handleKeyboardHeightChange:function(e){var t,n=this.getKeyboardHeight((null==e||null===(t=e.detail)||void 0===t?void 0:t.height)||0),o=n>0?n:this.data.lastKeyboardHeight;if(n>0&&n!==this.data.lastKeyboardHeight)try{wx.setStorageSync(KEYBOARD_HEIGHT_STORAGE_KEY,n)}catch(e){console.error("persist keyboard height failed",e)}this.setData({lastKeyboardHeight:o,panelHeight:this.getPanelHeight(o)})},handleOutsideTap:function(){this.closeEditor()},handleCloseTap:function(){this.closeEditor()},canSendComment:function(){return 1===this.data.IsSendCommentEnable&&!this.data.InvalidToken},checkSendInterval:function(){var e=this.data.CommentConfig.VoiceInterval,t=void 0===e?3:e;return!(Date.now()-this.data.sendChatTime<1e3*t&&(wx.showToast({title:"评论过于频繁,请稍后再试",icon:"none"}),1))},createSendCommentParams:function(e){var t=e.TextContent,n=e.ContentType,o=e.md5,r=e.LocalId,a=this.store.get("mainInfo").activityId,i=this.store.get("userInfo"),s=i.userId,c=i.levelId;return{ActivityId:a,Comment:_objectSpread(_objectSpread({TextContent:t,UserId:parseInt(s),LevelId:c,ContentType:n},o?{md5:o}:{}),r?{LocalId:r}:{})}},requestSendCommentSafely:function(e){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var o,r,a,i,s,c,l;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return r=e.TextContent,a=e.ContentType,i=e.md5,s=e.LocalId,c="function"==typeof(null===(o=t.sdkInstance)||void 0===o?void 0:o.requestStrict)?t.sdkInstance.requestStrict.bind(t.sdkInstance):t.sdkInstance.request.bind(t.sdkInstance),n.prev=2,n.next=5,c(_constant.REQUEST_URL_MAP.SEND_COMMENT,{method:"POST",data:t.createSendCommentParams({TextContent:r,ContentType:a,md5:i,LocalId:s})});case 5:return l=n.sent,n.abrupt("return",[l,null]);case 9:return n.prev=9,n.t0=n.catch(2),n.abrupt("return",[null,n.t0]);case 12:case"end":return n.stop()}},n,null,[[2,9]])}))()},sendComment:function(e){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var o,r,a,i,s,c,l,u,m,d,h,p,f,g,y,v,_,I,C,T,b,E,S;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.TextContent,r=e.ContentType,a=void 0===r?_comment.MessageContentType.Text:r,i=e.md5,s=e.LocalId,c=t.store.get("userInfo"),l=c.userId,u=c.username,m=c.levelId,d=c.avatarUrl,h=t.buildCommentTeaPayload({TextContent:o,ContentType:a,LocalId:s,md5:i,source:"sendComment"}),t.reportCommentTea("mini_sdk_comment_send",_objectSpread(_objectSpread({},h),{},{stage:"start"})),n.next=6,t.requestSendCommentSafely({TextContent:o,ContentType:a,md5:i,LocalId:s});case 6:return p=n.sent,f=_slicedToArray(p,2),g=f[0],y=f[1],v=(null==g?void 0:g.H5MsgId)||Date.now(),y?t.reportCommentTea("mini_sdk_comment_send",_objectSpread(_objectSpread({},h),{},{stage:"fail",errorMessage:(null==y?void 0:y.message)||"发送失败",errorCode:(null==y?void 0:y.code)||""})):((0,_autoReply.addH5MsgIdToCache)(g.H5MsgId),t.sdkInstance.countSendCommentNumber(),null===(_=t.sdkInstance)||void 0===_||null===(I=_.reportBusiness)||void 0===I||I.call(_,"send_comment",{Count:1}),t.reportCommentTea("mini_sdk_comment_send",_objectSpread(_objectSpread({},h),{},{stage:"success",h5MsgId:v}))),C=(null==g?void 0:g.AvatarUrl)||d||"",T=(null==g?void 0:g.Nickname)||u||"",s?t.finalizeMockComment(s,{H5MsgId:v,username:T,userId:l,levelId:m,avatarUrl:C,TextContent:o,ContentType:a,md5:i,AutoReply:null==g?void 0:g.AutoReply}):(S=t.store.get("chat.chatList")||[],t.showMockComment(_constants.CommentType.Mock,{H5MsgId:v,_formerMsgId_:null===(b=S[S.length-1])||void 0===b||null===(E=b.Common)||void 0===E?void 0:E.MsgId,username:T,userId:l,levelId:m,avatarUrl:C,TextContent:o,ContentType:a,LocalId:s,md5:i,AutoReply:null==g?void 0:g.AutoReply})),t.setData({sendChatTime:Date.now()}),n.abrupt("return",y?{H5MsgId:v,Nickname:u||"",localOnly:!0}:g);case 17:case"end":return n.stop()}},n)}))()},bindconfirm:function(e){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var o,r,a,i,s,c,l,u,m,d,h;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(r=((null===(o=e.detail)||void 0===o?void 0:o.value)||t.data.chatValue||"").trim()){n.next=4;break}return wx.showToast({title:"内容不可为空",icon:"none"}),n.abrupt("return");case 4:if(t.checkSendInterval()){n.next=6;break}return n.abrupt("return");case 6:return n.prev=6,s=(0,_comment.normalizeOutgoingEmojiText)(r,t._emojiSets||[]),c=/\[[^\]]+\]/.test(s),n.next=11,t.sendComment({TextContent:s,ContentType:c?_comment.MessageContentType.Emoji:_comment.MessageContentType.Text});case 11:l=(0,_dynamicEmoji.getSingleDynamicEmojiToken)(r),u=(null===(a=t.store)||void 0===a?void 0:a.get("liveInfo.MessageSwitch"))||{},m=(0,_notification.isNotificationSendTypeEnabled)(u,_notification.NOTIFICATION_SEND_TYPE.DYNAMIC_EMOJI),d=!1!==(null===(i=t.store)||void 0===i?void 0:i.get("notification.isNotificationOpen")),t.store&&l&&m&&d&&(h=t.store.get("notification.queueDynamicEmojiArea")||[],t.store.set("notification.queueDynamicEmojiArea",h.concat({__id:"local-dynamic-emoji-".concat(Date.now(),"-").concat(l),token:l}))),t.setData({chatValue:"",chatLength:0}),t.closeEditor(),n.next=24;break;case 20:n.prev=20,n.t0=n.catch(6),console.error("send text comment error",n.t0),wx.showToast({title:(null===n.t0||void 0===n.t0?void 0:n.t0.message)||"发送失败",icon:"none"});case 24:case"end":return n.stop()}},n,null,[[6,20]])}))()},handleSendTap:function(){this.data.chatLength&&this.bindconfirm({detail:{value:this.data.chatValue}})},handleEmojiTrigger:function(){var e;(0,_featureProcess.lockFeatureProcess)(this.sdkInstance,_featureProcess.LockFeatureMap.Comment)||(this.canSendComment()?null!==(e=this.data.emojiPanelSections)&&void 0!==e&&e.length?this.setData({showEmojiPanel:!0,entering:!0,panelHeight:this.getPanelHeight(),focusInput:!1}):this.setData({emojiPanelSections:(0,_utils.buildEmojiPanelSections)(this._emojiSets||[]),showEmojiPanel:!0,entering:!0,panelHeight:this.getPanelHeight(),focusInput:!1}):this.triggerCommentCheck())},handleKeyboardTrigger:function(){(0,_featureProcess.lockFeatureProcess)(this.sdkInstance,_featureProcess.LockFeatureMap.Comment)||this.setData({focusInput:!0,showEmojiPanel:!1,entering:!0,panelHeight:this.getPanelHeight()})},catchNone:function(){},handleChooseImage:function(){var e=this;return _asyncToGenerator(_regeneratorRuntime().mark(function t(){var n,o,r,a,i,s,c,l,u,m,d,h,p;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(0,_featureProcess.lockFeatureProcess)(e.sdkInstance,_featureProcess.LockFeatureMap.Comment)){t.next=2;break}return t.abrupt("return");case 2:if(e.canSendComment()){t.next=5;break}return e.triggerCommentCheck(),t.abrupt("return");case 5:return n="",t.prev=6,t.next=9,new Promise(function(e,t){wx.chooseMedia({count:1,mediaType:["image"],sourceType:["album","camera"],success:e,fail:t})});case 9:if(r=t.sent,null!=(a=null==r||null===(o=r.tempFiles)||void 0===o?void 0:o[0])&&a.tempFilePath){t.next=13;break}return t.abrupt("return");case 13:if(i=a.fileType&&a.fileType.includes("/")?a.fileType:(0,_utils.getImageMimeType)(a.tempFilePath),_comment.IMAGE_COMMENT_LIMIT.mimeTypes.includes(i)){t.next=17;break}return wx.showToast({title:"仅支持 PNG/JPG/JPEG 图片",icon:"none"}),t.abrupt("return");case 17:if(!(a.size>_comment.IMAGE_COMMENT_LIMIT.size)){t.next=20;break}return wx.showToast({title:"请选择大小小于8M的图片",icon:"none"}),t.abrupt("return");case 20:if(e.checkSendInterval()){t.next=22;break}return t.abrupt("return");case 22:return n="image_".concat(Date.now()),s=e.store.get("userInfo"),c=s.userId,l=s.username,u=s.levelId,m=e.buildCommentTeaPayload({TextContent:a.tempFilePath,ContentType:_comment.MessageContentType.Photo,LocalId:n,source:"imageUpload",fileSize:a.size,mimeType:i}),e.showMockComment(_constants.CommentType.Mock,{TextContent:a.tempFilePath,ContentType:_comment.MessageContentType.Photo,LocalId:n,username:l,userId:c,levelId:u,uploadStatus:_constants.UploadStatus.Uploading,TextContentExtra:[a.tempFilePath]}),e.closeEditor(),d=e.store.get("mainInfo"),h=d.activityId,e.reportCommentTea("mini_sdk_comment_image_upload",_objectSpread(_objectSpread({},m),{},{stage:"start"})),t.next=31,(0,_imageUpload.uploadCommentImage)({sdkInstance:e.sdkInstance,activityId:h,filePath:a.tempFilePath,fileName:a.tempFilePath.split("/").pop()||"comment-image.png",userId:c});case 31:return p=t.sent,e.updateMockComment(n,{TextContent:p.uri,TextContentExtra:[a.tempFilePath],_uploadStatus_:_constants.UploadStatus.Success}),e.reportCommentTea("mini_sdk_comment_image_upload",_objectSpread(_objectSpread({},m),{},{stage:"success"})),t.next=36,e.sendComment({TextContent:p.uri,ContentType:_comment.MessageContentType.Photo,md5:p.md5,LocalId:n});case 36:t.next=46;break;case 38:if(t.prev=38,t.t0=t.catch(6),!(0,_utils.isChooseImageCancelled)(t.t0)){t.next=42;break}return t.abrupt("return");case 42:n&&e.updateMockComment(n,{_uploadStatus_:_constants.UploadStatus.Failed}),e.reportCommentTea("mini_sdk_comment_image_upload",_objectSpread(_objectSpread({},e.buildCommentTeaPayload({TextContent:"",ContentType:_comment.MessageContentType.Photo,LocalId:n,source:"imageUpload"})),{},{stage:"fail",errorMessage:(null===t.t0||void 0===t.t0?void 0:t.t0.message)||"图片发送失败",errorCode:(null===t.t0||void 0===t.t0?void 0:t.t0.code)||""})),console.error("upload image comment error",t.t0),wx.showToast({title:(null===t.t0||void 0===t.t0?void 0:t.t0.message)||"图片发送失败",icon:"none"});case 46:case"end":return t.stop()}},t,null,[[6,38]])}))()},selectEmoji:function(e){var t,n,o=this,r=e.currentTarget.dataset,a=r.setIndex,i=r.emojiIndex,s=null===(t=this._emojiSets)||void 0===t?void 0:t[a],c=null==s||null===(n=s.Emojis)||void 0===n?void 0:n[i];if(s&&c&&2!==c.EmojiStatus){var l=(0,_utils.getDisplayName)(c.EmojiName),u=(0,_utils.getDisplayName)(s.EmojiSetName),m=1===s.IsSystemEmojiSet?"[".concat(l,"]"):"[".concat(u,":").concat(l,"]");if(c.EmojiType!==_comment.EMOJI_TYPE.BIG&&s.EmojiSetType!==_comment.EMOJI_TYPE.BIG){var d="".concat(this.data.chatValue||"").concat(m);d.length>200||this.setData({chatValue:d,chatLength:d.length})}else{if(!this.checkSendInterval())return;this.sendComment({TextContent:String(c.EmojiId),ContentType:_comment.MessageContentType.BigEmoji}).then(function(){o.closeEditor()}).catch(function(e){console.error("send big emoji error",e),wx.showToast({title:(null==e?void 0:e.message)||"发送失败",icon:"none"})})}}},updateMockComment:function(e,t){var n=(this.store.get("chat.chatList")||[]).map(function(n){var o;return(null==n||null===(o=n.Extra)||void 0===o?void 0:o.LocalId)!==e?n:_objectSpread(_objectSpread({},n),{},{Extra:_objectSpread(_objectSpread({},n.Extra),t)})});this.store.set("chat.chatList",n)},finalizeMockComment:function(e,t){var n,o,r=this.store.get("chat.chatList")||[],a=null,i=r.map(function(n){var o,r,i,s,c,l;return(null==n||null===(o=n.Extra)||void 0===o?void 0:o.LocalId)!==e?n:a=_objectSpread(_objectSpread({},n),{},{isMock:!0,Common:_objectSpread(_objectSpread({},n.Common),{},{H5MsgId:null!==(r=null!==(i=t.H5MsgId)&&void 0!==i?i:null===(s=n.Common)||void 0===s?void 0:s.H5MsgId)&&void 0!==r?r:0,MsgId:t.H5MsgId?Number(t.H5MsgId):null===(c=n.Common)||void 0===c?void 0:c.MsgId}),Extra:_objectSpread(_objectSpread({},n.Extra),{},{TextContent:t.TextContent,ContentType:t.ContentType,md5:t.md5,IsOwn:1,_uploadStatus_:_constants.UploadStatus.Success,User:_objectSpread(_objectSpread({},(null===(l=n.Extra)||void 0===l?void 0:l.User)||{}),{},{Nickname:t.username,UserId:t.userId,LevelId:t.levelId,AvatarUrl:t.avatarUrl||""})})})});this.store.set("chat.chatList",i),a&&this.store.set("chat.addComment",{data:[a],isSend:!0});var s=(0,_autoReply.normalizeAutoReplyInfo)(t.AutoReply,null===(n=a)||void 0===n||null===(o=n.Common)||void 0===o?void 0:o.MsgId);s&&a&&(0,_autoReply.scheduleAutoReplyFallback)(this.store,s,a)},showMockComment:function(e,t){var n,o,r,a=Date.now(),i={isMock:!0,Common:{MsgId:a,CreateTime:a,H5MsgId:String(a)},Extra:{ContentType:null!==(n=t.ContentType)&&void 0!==n?n:_comment.MessageContentType.Text,TextContent:t.TextContent,TextContentExtra:t.TextContentExtra||[],LocalId:t.LocalId,md5:t.md5,User:{Nickname:"",Email:""},IsDelete:!1,TextContentCn:"",IsSilence:0,TextContentEn:"",TextContentJp:"",TextContentKo:"",IsSelfLike:!1,LikeCount:0,IsPresenter:!0,_operationInfo_:null,_uploadStatus_:t.uploadStatus||_constants.UploadStatus.Success}};e===_constants.CommentType.MuteAll&&(i.Extra.TextContent=t.IsSendCommentEnable?"主持人已开启互动聊天":"主持人已关闭互动聊天",i.Extra._operationInfo_={IsSendCommentEnable:t.IsSendCommentEnable}),e===_constants.CommentType.Welcome&&(i.Extra.TextContent=t.WelcomeContent,i.Extra.User.Nickname=t.WelcomeTitle,i.Extra._welcomeInfo_={IsWelcomeEnable:!0}),e===_constants.CommentType.Mock&&(i.Common.H5MsgId=null!==(o=t.H5MsgId)&&void 0!==o?o:0,i.Common._formerMsgId_=null!==(r=t._formerMsgId_)&&void 0!==r?r:0,i.Common.MsgId=t.H5MsgId?Number(t.H5MsgId):a,i.Extra.IsPresenter=!1,i.Extra.IsOwn=1,i.Extra.User={Nickname:t.username,UserId:t.userId,LevelId:t.levelId,AvatarUrl:t.avatarUrl||""});var s={Data:[i],HotData:null,ImageFileDownloadInfo:null};this.sdkInstance.updateComment(s,!0);var c=(0,_autoReply.normalizeAutoReplyInfo)(t.AutoReply,i.Common.MsgId);c&&(0,_autoReply.scheduleAutoReplyFallback)(this.store,c,i)}}});