diff --git a/examples/App.vue b/examples/App.vue index 891a993..5e8ba5f 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -28,10 +28,7 @@
/g,"\r\n").replace(/<\/div>|<\/p>/g,""))},_checkSubmitDisabled:function(){this.submitDisabled=!this.$refs.textarea.innerHTML.trim()},_handleSend:function(e){var t=this.getFormatValue();this.$emit("send",t),this.clear(),this._checkSubmitDisabled()},_handleChangeFile:function(e){var t=this,n=this.$refs.fileInput;Array.from(n.files).forEach(function(e){t.$emit("upload",e)}),n.value=""},clear:function(){this.$refs.textarea.innerHTML=""},initEmoji:function(e){Ie=e,this.$forceUpdate()}}},Te=$e,Ee=(n("49c2"),Object(C["a"])(Te,ve,be,!1,null,null,null)),De=Ee.exports,Pe={name:"LemonMessages",components:{},props:{reverseUserId:String,timeRange:{type:Number,default:1},timeFormat:{type:Function,default:function(e){return oe(e)}},messages:{type:Array,default:function(){return[]}}},data:function(){return{loading:!1,loadend:!1}},render:function(){var e=this,t=arguments[0];return t("div",{class:"lemon-messages",ref:"wrap",on:{scroll:this._handleScroll}},[t("div",{class:["lemon-messages__load","lemon-messages__load--".concat(this.loadend?"end":"ing")]},[this.loadend?this._renderLoadEnd():this._renderLoading()]),this.messages.map(function(n,i){var a=[],r="lemon-message-".concat(n.type),s=e.messages[i-1];return s&&e.msecRange&&n.sendTime-s.sendTime>e.msecRange&&a.push(t("lemon-message-event",X()([{},{attrs:{message:{id:"__time__",type:"event",content:e.timeFormat(n.sendTime)}}}]))),a.push(t(r,X()([{ref:"message",refInFor:!0},{attrs:{timeFormat:e.msecRange>0?function(){}:e.timeFormat,message:n,reverse:e.reverseUserId==n.fromUser.id,hiddenTitle:!1}}]))),a})])},computed:{msecRange:function(){return 1e3*this.timeRange*60}},watch:{},methods:{_renderLoading:function(){var e=this.$createElement;return e("i",{class:"lemon-icon-loading lemonani-spin"})},_renderLoadEnd:function(){var e=this.$createElement;return e("span",["暂无消息"])},resetLoadState:function(){this.loading=!1,this.loadend=!1},_handleScroll:function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(t){var n,i,a=this;return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:if(n=t.target,0!=n.scrollTop||0!=this.loading||0!=this.loadend){e.next=7;break}return this.loading=!0,e.next=5,this.$nextTick();case 5:i=n.scrollHeight,this.$emit("reach-top",function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:return e.next=2,a.$nextTick();case 2:n.scrollTop=n.scrollHeight-i,a.loading=!1,a.loadend=!!t;case 5:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}());case 7:case"end":return e.stop()}},e,this)}));function t(t){return e.apply(this,arguments)}return t}(),scrollToBottom:function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:return e.next=2,this.$nextTick();case 2:t=this.$refs.wrap,t&&(t.scrollTop=t.scrollHeight);case 4:case"end":return e.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},created:function(){},mounted:function(){}},Fe=Pe,Le=(n("436f"),Object(C["a"])(Fe,xe,_e,!1,null,null,null)),Ue=Le.exports,Re={name:"lemonMessageBasic",props:{message:{type:Object,default:function(){return{}}},timeFormat:{type:Function,default:function(){return""}},reverse:Boolean,hiddenTitle:Boolean},data:function(){return{}},render:function(){var e=arguments[0],t=this.message,n=t.fromUser,i=t.status,a=t.sendTime;return e("div",{class:["lemon-message",{"lemon-message--reverse":this.reverse,"lemon-message--hidden-title":this.hiddenTitle}]},[e("div",{class:"lemon-message__avatar"},[e("lemon-avatar",{attrs:{size:36,shape:"square",src:n.avatar},on:{click:function(){console.log("message avatar click")}}})]),e("div",{class:"lemon-message__inner"},[e("div",{class:"lemon-message__title"},[e("span",{on:{click:function(){console.log("message displayname click")}}},[n.displayName]),e("span",{class:"lemon-message__time"},[this.timeFormat(a)])]),e("div",{class:"lemon-message__content",on:{click:function(){console.log("message content click")}}},[this.useScopedSlots("content",this.message)]),e("div",{class:"lemon-message__status"},[this._renderStatue(i)])])])},created:function(){},mounted:function(){},computed:{},watch:{},methods:{_renderStatue:function(e){var t=this.$createElement;return"going"==e?t("i",{class:"lemon-icon-loading lemonani-spin"}):"failed"==e?t("i",{class:"lemon-icon-prompt",attrs:{title:"重发消息"},style:{color:"#ff2525",cursor:"pointer"}}):void 0},useScopedSlots:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this;return i.$scopedSlots[e]?i.$scopedSlots[e](t):n}}},Ne=Re,Be=(n("fbd1"),Object(C["a"])(Ne,ye,we,!1,null,null,null)),Ae=Be.exports,He={inject:["IMUI"],methods:{}};function Ve(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function Ke(e){for(var t=1;t /g,"\r\n").replace(/<\/div>|<\/p>/g,""))},_checkSubmitDisabled:function(){this.submitDisabled=!this.$refs.textarea.innerHTML.trim()},_handleSend:function(e){var t=this.getFormatValue();this.$emit("send",t),this.clear(),this._checkSubmitDisabled()},_handleChangeFile:function(e){var t=this,n=this.$refs.fileInput;Array.from(n.files).forEach(function(e){t.$emit("upload",e)}),n.value=""},clear:function(){this.$refs.textarea.innerHTML=""},initEmoji:function(e){Ie=e,this.$forceUpdate()}}},Te=$e,Ee=(n("49c2"),Object(C["a"])(Te,ve,be,!1,null,null,null)),De=Ee.exports,Pe={name:"LemonMessages",components:{},props:{reverseUserId:String,timeRange:{type:Number,default:1},timeFormat:{type:Function,default:function(e){return oe(e)}},messages:{type:Array,default:function(){return[]}}},data:function(){return{loading:!1,loadend:!1}},render:function(){var e=this,t=arguments[0];return t("div",{class:"lemon-messages",ref:"wrap",on:{scroll:this._handleScroll}},[t("div",{class:["lemon-messages__load","lemon-messages__load--".concat(this.loadend?"end":"ing")]},[this.loadend?this._renderLoadEnd():this._renderLoading()]),this.messages.map(function(n,i){var a=[],r="lemon-message-".concat(n.type),s=e.messages[i-1];return s&&e.msecRange&&n.sendTime-s.sendTime>e.msecRange&&a.push(t("lemon-message-event",X()([{},{attrs:{message:{id:"__time__",type:"event",content:e.timeFormat(n.sendTime)}}}]))),a.push(t(r,X()([{ref:"message",refInFor:!0},{attrs:{timeFormat:e.msecRange>0?function(){}:e.timeFormat,message:n,reverse:e.reverseUserId==n.fromUser.id,hiddenTitle:!1}}]))),a})])},computed:{msecRange:function(){return 1e3*this.timeRange*60}},watch:{},methods:{_renderLoading:function(){var e=this.$createElement;return e("i",{class:"lemon-icon-loading lemonani-spin"})},_renderLoadEnd:function(){var e=this.$createElement;return e("span",["暂无消息"])},resetLoadState:function(){this.loading=!1,this.loadend=!1},_handleScroll:function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(t){var n,i,a=this;return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:if(n=t.target,0!=n.scrollTop||0!=this.loading||0!=this.loadend){e.next=7;break}return this.loading=!0,e.next=5,this.$nextTick();case 5:i=n.scrollHeight,this.$emit("reach-top",function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:return e.next=2,a.$nextTick();case 2:n.scrollTop=n.scrollHeight-i,a.loading=!1,a.loadend=!!t;case 5:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}());case 7:case"end":return e.stop()}},e,this)}));function t(t){return e.apply(this,arguments)}return t}(),scrollToBottom:function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:return e.next=2,this.$nextTick();case 2:t=this.$refs.wrap,t&&(t.scrollTop=t.scrollHeight);case 4:case"end":return e.stop()}},e,this)}));function t(){return e.apply(this,arguments)}return t}()},created:function(){},mounted:function(){}},Fe=Pe,Le=(n("436f"),Object(C["a"])(Fe,xe,ye,!1,null,null,null)),Re=Le.exports,Ue={name:"lemonMessageBasic",props:{message:{type:Object,default:function(){return{}}},timeFormat:{type:Function,default:function(){return""}},reverse:Boolean,hiddenTitle:Boolean},data:function(){return{}},render:function(){var e=arguments[0],t=this.message,n=t.fromUser,i=t.status,a=t.sendTime;return e("div",{class:["lemon-message",{"lemon-message--reverse":this.reverse,"lemon-message--hidden-title":this.hiddenTitle}]},[e("div",{class:"lemon-message__avatar"},[e("lemon-avatar",{attrs:{size:36,shape:"square",src:n.avatar},on:{click:function(){console.log("message avatar click")}}})]),e("div",{class:"lemon-message__inner"},[e("div",{class:"lemon-message__title"},[e("span",{on:{click:function(){console.log("message displayname click")}}},[n.displayName]),e("span",{class:"lemon-message__time"},[this.timeFormat(a)])]),e("div",{class:"lemon-message__content",on:{click:function(){console.log("message content click")}}},[this.useScopedSlots("content",this.message)]),e("div",{class:"lemon-message__status"},[this._renderStatue(i)])])])},created:function(){},mounted:function(){},computed:{},watch:{},methods:{_renderStatue:function(e){var t=this.$createElement;return"going"==e?t("i",{class:"lemon-icon-loading lemonani-spin"}):"failed"==e?t("i",{class:"lemon-icon-prompt",attrs:{title:"重发消息"},style:{color:"#ff2525",cursor:"pointer"}}):void 0},useScopedSlots:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this;return i.$scopedSlots[e]?i.$scopedSlots[e](t):n}}},Ne=Ue,Be=(n("fbd1"),Object(C["a"])(Ne,_e,we,!1,null,null,null)),Ae=Be.exports,Ve={inject:["IMUI"],methods:{}};function He(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,i)}return n}function qe(e){for(var t=1;t'):"[!".concat(t,"]")})},messageViewToBottom:function(){this.$refs.messages.scrollToBottom()},changeContact:function(e,t){var n=this;this.currentContactId==e&&(this.currentContactId=void 0),t&&this.changeMenu(t),this.currentContactId=e,this.$emit("change-contact",this.currentContact),ae(this.currentContact.renderContainer)||this._menuIsMessages()&&(At.has(e)||this.$refs.messages.resetLoadState(),Ht[e]?this.messageViewToBottom():this.$emit("pull-messages",this.currentContact,function(t,i){n._addMessage(t,e,0),n.messageViewToBottom()}))},removeMessage:function(e,t){var n=this.findMessageIndexById(e,t);-1!==n&&(Ht[t].splice(n,1),this.forceUpdateMessage())},updateMessage:function(e,t,n){var i=this.findMessageIndexById(e,t);-1!==i&&(Ht[t][i]=Lt({},Ht[t][i],{},n),this.forceUpdateMessage(e))},forceUpdateMessage:function(e){if(e){var t=this.$refs.messages.$refs.message;if(t){var n=t.find(function(t){return t.$attrs.message.id==e});n&&n.$forceUpdate()}}else this.$refs.messages.$forceUpdate()},_customContainerReady:function(e,t,n){ae(e)&&!t.has(n)&&t.set(n,e.call(this))},changeMenu:function(e){this.$emit("change-menu",e),this.activeSidebar=e;var t=this.currentMenu.renderContainer;this._customContainerReady(t,Bt,e)},initEmoji:function(e){this.$refs.editor.initEmoji(e),e[0].label&&(e=e.flatMap(function(e){return e.children})),e.forEach(function(e){var t=e.name,n=e.src;return Vt[t]=n})},initMenus:function(e){var t=this.$createElement,n=[{name:_t,title:"聊天",unread:0,click:null,render:function(e){return t("i",{class:"lemon-icon-message"})},isBottom:!1},{name:yt,title:"通讯录",unread:0,click:null,render:function(e){return t("i",{class:"lemon-icon-addressbook"})},isBottom:!1}],i=[];if(Array.isArray(e)){var a={lastMessages:0,contacts:1},r=Object.keys(a);i=e.map(function(e){return r.includes(e.name)?Lt({},n[a[e.name]],{},e,{},{renderContainer:null}):e})}else i=n;this.menus=i},initContacts:function(e){var t;(t=this.contacts).push.apply(t,Object(xt["a"])(e)),this.sortContacts()},sortContacts:function(){this.contacts.sort(function(e,t){return e.index.localeCompare(t.index)})},updateContact:function(e,t){delete t.id,delete t.toContactId;var n=this.findContactIndexById(e);if(-1!==n){var i=t.unread;te(i)&&(0!==i.indexOf("+")&&0!==i.indexOf("-")||(t.unread=parseInt(i)+parseInt(this.contacts[n].unread))),this.$set(this.contacts,n,Lt({},this.contacts[n],{},t))}},findContactIndexById:function(e){return this.contacts.findIndex(function(t){return t.id==e})},findMessageIndexById:function(e,t){var n=Ht[t];return ie(n)?-1:n.findIndex(function(t){return t.id==e})},findMessageById:function(e,t){var n=this.findMessageIndexById(e,t);if(-1!==n)return Ht[t][n]},getContacts:function(){return this.contacts},getMessages:function(){return Ht},openrenderContainer:function(e){},changeDrawer:function(e){this.drawerVisible=!this.drawerVisible,1==this.drawerVisible&&this.openDrawer(e)},openDrawer:function(e){Kt=e||new Function,this.drawerVisible=!0},closeDrawer:function(){this.drawerVisible=!1}}},Yt=Wt,zt=(n("9b01"),Object(C["a"])(Yt,Ut,Rt,!1,null,null,null)),Gt=zt.exports,Qt=(n("6a2b"),"0.1"),qt=[Gt,Se,Ue,De,J,z,V,N,T,Ae,qe,at,pt,bt],Jt=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1];qt.forEach(function(t){e.component(t.name,t)})};"undefined"!==typeof window&&window.Vue&&Jt(window.Vue);var Zt={version:Qt,install:Jt};i["a"].use(Zt),i["a"].config.productionTip=!1,new i["a"]({render:function(e){return e(k)}}).$mount("#app")},cfab:function(e,t,n){"use strict";var i=n("15cf"),a=n.n(i);a.a},dbdc:function(e,t,n){"use strict";var i=n("7802"),a=n.n(i);a.a},e86c:function(e,t,n){},ed4b:function(e,t,n){"use strict";var i=n("a215"),a=n.n(i);a.a},fbd1:function(e,t,n){"use strict";var i=n("820e"),a=n.n(i);a.a}});
\ No newline at end of file
diff --git a/examples/dist/js/index.e213c5da.js b/examples/dist/js/index.e213c5da.js
new file mode 100644
index 0000000..3745c90
--- /dev/null
+++ b/examples/dist/js/index.e213c5da.js
@@ -0,0 +1 @@
+(function(e){function t(t){for(var i,s,o=t[0],c=t[1],l=t[2],m=0,d=[];m
')),this._saveLastRange()},_handleSelectFile:function(){var e=Object(E["a"])(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){while(1)switch(e.prev=e.next){case 0:return this.accept=t,e.next=3,this.$nextTick();case 3:this.$refs.fileInput.click();case 4:case"end":return e.stop()}},e,this)}));function t(t){return e.apply(this,arguments)}return t}(),_handlePaste:function(e){e.preventDefault();var t=e.clipboardData,n=t.getData("text");ke(n,"insertText")},_handleKeyup:function(e){this._saveLastRange()},_handleKeydown:function(e){e.keyCode},getFormatValue:function(){return me(this.$refs.textarea.innerHTML.replace(/
|<\/br>/,"").replace(/'):"[!".concat(t,"]")})},messageViewToBottom:function(){this.$refs.messages.scrollToBottom()},changeContact:function(e,t){var n=this;this.currentContactId==e&&(this.currentContactId=void 0),t&&this.changeMenu(t),this.currentContactId=e,this.$emit("change-contact",this.currentContact),ae(this.currentContact.renderContainer)||this._menuIsMessages()&&(At.has(e)||this.$refs.messages.resetLoadState(),Vt[e]?this.messageViewToBottom():this.$emit("pull-messages",this.currentContact,function(t,i){n._addMessage(t,e,0),n.messageViewToBottom()}))},removeMessage:function(e,t){var n=this.findMessageIndexById(e,t);-1!==n&&(Vt[t].splice(n,1),this.forceUpdateMessage())},updateMessage:function(e,t,n){var i=this.findMessageIndexById(e,t);-1!==i&&(Vt[t][i]=Lt({},Vt[t][i],{},n),this.forceUpdateMessage(e))},forceUpdateMessage:function(e){if(e){var t=this.$refs.messages.$refs.message;if(t){var n=t.find(function(t){return t.$attrs.message.id==e});n&&n.$forceUpdate()}}else this.$refs.messages.$forceUpdate()},_customContainerReady:function(e,t,n){ae(e)&&!t.has(n)&&t.set(n,e.call(this))},changeMenu:function(e){this.$emit("change-menu",e),this.activeSidebar=e;var t=this.currentMenu.renderContainer;this._customContainerReady(t,Bt,e)},initEmoji:function(e){this.$refs.editor.initEmoji(e),e[0].label&&(e=e.flatMap(function(e){return e.children})),e.forEach(function(e){var t=e.name,n=e.src;return Ht[t]=n})},initMenus:function(e){var t=this.$createElement,n=[{name:yt,title:"聊天",unread:0,click:null,render:function(e){return t("i",{class:"lemon-icon-message"})},isBottom:!1},{name:_t,title:"通讯录",unread:0,click:null,render:function(e){return t("i",{class:"lemon-icon-addressbook"})},isBottom:!1}],i=[];if(Array.isArray(e)){var a={lastMessages:0,contacts:1},r=Object.keys(a);i=e.map(function(e){return r.includes(e.name)?Lt({},n[a[e.name]],{},e,{},{renderContainer:null}):e})}else i=n;this.menus=i},initContacts:function(e){var t;(t=this.contacts).push.apply(t,Object(xt["a"])(e)),this.sortContacts()},sortContacts:function(){this.contacts.sort(function(e,t){return e.index.localeCompare(t.index)})},updateContact:function(e,t){delete t.id,delete t.toContactId;var n=this.findContactIndexById(e);if(-1!==n){var i=t.unread;te(i)&&(0!==i.indexOf("+")&&0!==i.indexOf("-")||(t.unread=parseInt(i)+parseInt(this.contacts[n].unread))),this.$set(this.contacts,n,Lt({},this.contacts[n],{},t))}},findContactIndexById:function(e){return this.contacts.findIndex(function(t){return t.id==e})},findMessageIndexById:function(e,t){var n=Vt[t];return ie(n)?-1:n.findIndex(function(t){return t.id==e})},findMessageById:function(e,t){var n=this.findMessageIndexById(e,t);if(-1!==n)return Vt[t][n]},getContacts:function(){return this.contacts},getMessages:function(){return Vt},openrenderContainer:function(e){},changeDrawer:function(e){this.drawerVisible=!this.drawerVisible,1==this.drawerVisible&&this.openDrawer(e)},openDrawer:function(e){qt=e||new Function,this.drawerVisible=!0},closeDrawer:function(){this.drawerVisible=!1}}},Wt=Kt,zt=(n("9b01"),Object(C["a"])(Wt,Rt,Ut,!1,null,null,null)),Yt=zt.exports,Gt=(n("6a2b"),"0.1"),Qt=[Yt,Se,Re,De,J,z,H,N,T,Ae,Qe,at,pt,bt],Jt=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1];Qt.forEach(function(t){e.component(t.name,t)})};"undefined"!==typeof window&&window.Vue&&Jt(window.Vue);var Zt={version:Gt,install:Jt};i["a"].use(Zt),i["a"].config.productionTip=!1,new i["a"]({render:function(e){return e(k)}}).$mount("#app")},cfab:function(e,t,n){"use strict";var i=n("15cf"),a=n.n(i);a.a},dbdc:function(e,t,n){"use strict";var i=n("7802"),a=n.n(i);a.a},e86c:function(e,t,n){},ed4b:function(e,t,n){"use strict";var i=n("a215"),a=n.n(i);a.a},fbd1:function(e,t,n){"use strict";var i=n("820e"),a=n.n(i);a.a}});
\ No newline at end of file