1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150 |
- <template>
- <div class="chat-index">
- <!--左边选项-->
- <ul class="chat-menu">
- <li class="self">
- <img :src="userInfo.userimg">
- </li>
- <li :class="{active:chatTap=='dialog'}" @click="chatTap='dialog'">
- <Icon type="md-text" />
- <em v-if="unreadTotal > 0" class="chat-num">{{unreadTotal}}</em>
- </li>
- <li :class="{active:chatTap=='team'}" @click="chatTap='team'">
- <Icon type="md-person" />
- </li>
- </ul>
- <!--对话列表-->
- <ul class="chat-user" :style="{display:chatTap=='dialog'?'flex':'none'}">
- <li class="sreach">
- <Input placeholder="搜索" prefix="ios-search" v-model="dialogSearch"/>
- </li>
- <li class="lists">
- <ul>
- <li v-for="(dialog, index) in dialogListsS"
- :key="index"
- :class="{active:dialog.username==dialogTarget.username}"
- @click="openDialog(dialog)">
- <img :src="dialog.userimg">
- <div class="user-msg-box">
- <div class="user-msg-title">
- <span><user-view :username="dialog.username" placement="right" @on-result="(n)=>{dialog['nickname']=n}"/></span>
- <em>{{formatCDate(dialog.lastdate)}}</em>
- </div>
- <div class="user-msg-text">{{dialog.lasttext}}</div>
- </div>
- <em v-if="dialog.unread > 0" class="user-msg-num">{{dialog.unread}}</em>
- </li>
- <li v-if="dialogNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
- <li v-else-if="dialogLists.length == 0" class="chat-none">{{dialogNoDataText}}</li>
- </ul>
- </li>
- </ul>
- <!--联系人列表-->
- <ul class="chat-team" :style="{display:chatTap=='team'?'flex':'none'}">
- <li class="sreach">
- <Input placeholder="搜索" prefix="ios-search" v-model="teamSearch"/>
- </li>
- <li class="lists">
- <ul>
- <li v-for="(lists, key) in teamLists">
- <div class="team-label">{{key}}</div>
- <ul>
- <li v-for="(item, index) in teamListsS(lists)" :key="index" @click="openDialog(item, true)">
- <img :src="item.userimg">
- <div class="team-username"><user-view :username="item.username" placement="right" @on-result="(n)=>{item['nickname']=n}"/></div>
- </li>
- </ul>
- </li>
- <li v-if="teamNoDataText==$L('数据加载中.....')" class="chat-none"><w-loading/></li>
- <li v-else-if="Object.keys(teamLists).length == 0" class="chat-none">{{teamNoDataText}}</li>
- <li v-if="teamHasMorePages" class="chat-more" @click="getTeamLists(true)">加载更多...</li>
- </ul>
- </li>
- </ul>
- <!--对话窗口-->
- <div class="chat-message" :style="{display:(chatTap=='dialog'&&dialogTarget.username)?'block':'none'}">
- <div class="manage-title">
- <user-view :username="dialogTarget.username"/>
- <Dropdown class="manage-title-right" placement="bottom-end" trigger="click" @on-click="dialogDropdown" transfer>
- <Icon type="ios-more"/>
- <DropdownMenu slot="list">
- <DropdownItem name="delete">删除对话</DropdownItem>
- <DropdownItem name="clear">清除聊天记录</DropdownItem>
- </DropdownMenu>
- </Dropdown>
- </div>
- <ScrollerY ref="manageLists" class="manage-lists" @on-scroll="messageListsScroll">
- <div ref="manageBody" class="manage-body">
- <div v-if="messageHasMorePages" class="manage-more" @click="getDialogMessage(true)">加载更多...</div>
- <div v-if="messageNoDataText==$L('数据加载中.....')" class="manage-more"><w-loading/></div>
- <div v-else-if="messageNoDataText" class="manage-more">{{messageNoDataText}}</div>
- <chat-message v-for="(info, index) in messageLists" :key="index" :info="info"></chat-message>
- </div>
- <div class="manage-lists-message-new" v-if="messageNew > 0" @click="messageBottomGo(true)">有{{messageNew}}条新消息</div>
- </ScrollerY>
- <div class="manage-send" @click="clickDialog(dialogTarget.username)">
- <textarea ref="textarea" class="manage-input" v-model="messageText" placeholder="请输入要发送的消息" @keydown="messageSend($event)"></textarea>
- </div>
- <div class="manage-quick">
- <emoji-picker @emoji="messageInsertText" :search="messageEmojiSearch">
- <div slot="emoji-invoker" slot-scope="{ events: { click: clickEvent } }" @click.stop="clickEvent">
- <Icon class="quick-item" type="ios-happy-outline" />
- </div>
- <div slot="emoji-picker" slot-scope="{ emojis, insert, display }">
- <div class="emoji-box">
- <Input class="emoji-input" placeholder="搜索" v-model="messageEmojiSearch" prefix="ios-search"/>
- <div>
- <div v-for="(emojiGroup, category) in emojis" :key="category">
- <h5>{{ category }}</h5>
- <div class="emojis">
- <span v-for="(emoji, emojiName) in emojiGroup" :key="emojiName" @click="insert(emoji)" :title="emojiName">{{ emoji }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </emoji-picker>
- <Icon class="quick-item" type="ios-photos-outline" @click="$refs.messageUpload.handleClick()"/>
- <img-upload ref="messageUpload" class="message-upload" type="callback" @on-callback="messageInsertImage" num="3" :otherParams="{from:'chat'}"></img-upload>
- </div>
- </div>
- </div>
- </template>
- <style lang="scss">
- .chat-notice-box {
- display: flex;
- align-items: flex-start;
- .chat-notice-userimg {
- width: 42px;
- height: 42px;
- border-radius: 4px;
- }
- .ivu-notice-with-desc {
- flex: 1;
- padding: 0 12px;
- }
- .ivu-notice-desc {
- word-break:break-all;
- line-height: 1.3;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- overflow:hidden;
- -webkit-box-orient: vertical;
- }
- }
- </style>
- <style lang="scss" scoped>
- .chat-index {
- display: flex;
- flex-direction: row;
- align-items: flex-start;
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- .chat-none {
- height: auto;
- color: #666666;
- padding: 22px 8px;
- text-align: center;
- justify-content: center;
- margin: 0 !important;
- &:before {
- display: none;
- }
- }
- .chat-more {
- color: #666666;
- padding: 18px 0;
- text-align: center;
- cursor: pointer;
- margin: 0 !important;
- &:hover {
- color: #444444;
- }
- }
- .chat-menu {
- background-color: rgba(28, 29, 31, 0.92);
- width: 68px;
- height: 100%;
- padding-top: 20px;
- li {
- position: relative;
- padding: 12px 0;
- text-align: center;
- font-size: 28px;
- color: #919193;
- background-color: transparent;
- cursor: pointer;
- &.self {
- img {
- width: 36px;
- height: 36px;
- border-radius: 3px;
- }
- }
- &.active {
- color: #ffffff;
- background-color: rgba(255, 255, 255, 0.06);
- }
- .chat-num {
- position: absolute;
- top: 50%;
- left: 50%;
- height: auto;
- line-height: normal;
- color: #ffffff;
- background-color: #ff0000;
- text-align: center;
- border-radius: 10px;
- padding: 1px 5px;
- font-size: 12px;
- transform: scale(0.9) translate(5px, -20px);
- }
- }
- }
- .chat-user {
- display: flex;
- flex-direction: column;
- width: 248px;
- height: 100%;
- background-color: #ffffff;
- border-right: 1px solid #ededed;
- > li {
- position: relative;
- &.sreach {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 62px;
- margin: 0;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- }
- &.lists {
- flex: 1;
- overflow: auto;
- transform: translateZ(0);
- > ul {
- > li {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 70px;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- &.active {
- &:before {
- top: 0;
- height: 100%;
- }
- }
- img {
- width: 42px;
- height: 42px;
- border-radius: 4px;
- }
- .user-msg-box {
- flex: 1;
- display: flex;
- flex-direction: column;
- padding-left: 12px;
- .user-msg-title {
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- line-height: 24px;
- span {
- flex: 1;
- max-width: 130px;
- color: #333333;
- font-size: 14px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- em {
- color: #999999;
- font-size: 12px;
- }
- }
- .user-msg-text {
- max-width: 170px;
- color: #999999;
- font-size: 12px;
- line-height: 24px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- .user-msg-num {
- position: absolute;
- top: 6px;
- left: 44px;
- height: auto;
- line-height: normal;
- color: #ffffff;
- background-color: #ff0000;
- text-align: center;
- border-radius: 10px;
- padding: 1px 5px;
- font-size: 12px;
- transform: scale(0.9);
- border: 1px solid #ffffff;
- }
- }
- }
- .chat-team {
- display: flex;
- flex-direction: column;
- width: 248px;
- height: 100%;
- background-color: #ffffff;
- border-right: 1px solid #ededed;
- > li {
- position: relative;
- &.sreach {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 62px;
- margin: 0;
- padding: 0 12px;
- position: relative;
- cursor: pointer;
- &:before {
- content: "";
- position: absolute;
- left: 0;
- right: 0;
- bottom: 0;
- height: 1px;
- background-color: rgba(0, 0, 0, 0.06);
- }
- }
- &.lists {
- flex: 1;
- overflow: auto;
- transform: translateZ(0);
- > ul {
- > li {
- margin-left: 24px;
- position: relative;
- .team-label {
- padding-left: 4px;
- margin-top: 6px;
- margin-bottom: 6px;
- height: 34px;
- line-height: 34px;
- border-bottom: 1px solid #efefef;
- }
- > ul {
- > li {
- display: flex;
- flex-direction: row;
- align-items: center;
- height: 52px;
- cursor: pointer;
- img {
- width: 30px;
- height: 30px;
- border-radius: 3px;
- }
- .team-username {
- padding: 0 12px;
- font-size: 14px;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- }
- }
- }
- }
- }
- }
- }
- .chat-message {
- flex: 1;
- height: 100%;
- background-color: #F3F3F3;
- position: relative;
- .manage-title {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 3;
- width: 100%;
- height: 62px;
- padding: 0 20px;
- line-height: 62px;
- font-size: 16px;
- font-weight: 500;
- text-align: left;
- background: #ffffff;
- border-bottom: 1px solid #ededed;
- .manage-title-right {
- position: absolute;
- top: 0;
- right: 0;
- z-index: 9;
- width: 62px;
- height: 62px;
- line-height: 62px;
- text-align: center;
- font-size: 22px;
- color: #242424;
- }
- }
- .manage-lists {
- position: absolute;
- left: 0;
- top: 62px;
- z-index: 1;
- bottom: 120px;
- width: 100%;
- overflow: auto;
- padding: 8px 0;
- background-color: #E8EBF2;
- .manage-more {
- color: #666666;
- padding: 8px 0;
- text-align: center;
- cursor: pointer;
- &:hover {
- color: #444444;
- }
- }
- .manage-lists-message-new {
- position: fixed;
- bottom: 130px;
- right: 20px;
- color: #ffffff;
- background-color: rgba(0, 0, 0, 0.6);
- padding: 6px 12px;
- border-radius: 16px;
- font-size: 12px;
- cursor: pointer;
- }
- }
- .manage-send {
- position: absolute;
- left: 0;
- bottom: 0;
- z-index: 2;
- display: flex;
- width: 100%;
- height: 120px;
- background-color: #ffffff;
- border-top: 1px solid #e4e4e4;
- .manage-input,.manage-input:focus {
- flex: 1;
- -webkit-appearance: none;
- font-size: 14px;
- box-sizing: border-box;
- padding: 0;
- margin: 38px 10px 6px;
- border: 0;
- line-height: 20px;
- box-shadow: none;
- resize:none;
- outline: 0;
- }
- .manage-join,
- .manage-spin {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: #ffffff;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- }
- .manage-quick {
- position: absolute;
- z-index: 2;
- left: 0;
- right: 0;
- bottom: 79px;
- padding: 8px;
- display: flex;
- align-items: center;
- .quick-item {
- color: #444444;
- font-size: 24px;
- margin-right: 12px;
- }
- .emoji-box {
- position: absolute;
- left: 0;
- bottom: 40px;
- max-height: 320px;
- width: 100%;
- overflow: auto;
- background-color: #ffffff;
- padding: 12px;
- border-bottom: 1px solid #efefef;
- .emoji-input {
- margin: 6px 0;
- }
- h5 {
- padding: 0;
- margin: 8px 0 0 0;
- color: #b1b1b1;
- text-transform: uppercase;
- font-size: 14px;
- cursor: default;
- font-weight: normal;
- }
- .emojis {
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- &:after {
- content: "";
- flex: auto;
- }
- span {
- padding: 2px 4px;
- cursor: pointer;
- font-size: 22px;
- &:hover {
- background: #ececec;
- cursor: pointer;
- }
- }
- }
- }
- .message-upload {
- display: none;
- width: 0;
- height: 0;
- overflow: hidden;
- }
- }
- @media screen and (max-width: 768px) {
- .manage-lists {
- bottom: 96px;
- .manage-lists-message-new {
- bottom: 106px;
- }
- }
- .manage-send {
- height: 96px;
- }
- .manage-quick {
- bottom: 54px;
- .quick-item {
- font-size: 24px;
- margin-right: 8px;
- }
- }
- }
- }
- }
- </style>
- <script>
- import EmojiPicker from 'vue-emoji-picker'
- import DrawerTabsContainer from "../DrawerTabsContainer";
- import ScrollerY from "../../../_components/ScrollerY";
- import ChatMessage from "./message";
- import ImgUpload from "../ImgUpload";
- export default {
- name: 'ChatIndex',
- components: {ImgUpload, ChatMessage, EmojiPicker, ScrollerY, DrawerTabsContainer},
- props: {
- value: {
- default: 0
- },
- openWindow: {
- type: Boolean,
- default: false
- },
- },
- data () {
- return {
- loadIng: 0,
- userInfo: {},
- chatTap: 'dialog',
- dialogSearch: '',
- dialogTarget: {},
- dialogLists: [],
- dialogNoDataText: '',
- teamSearch: '',
- teamReady: false,
- teamLists: {},
- teamNoDataText: '',
- teamCurrentPage: 1,
- teamHasMorePages: false,
- autoBottom: true,
- messageNew: 0,
- messageText: '',
- messageLists: [],
- messageNoDataText: '',
- messageEmojiSearch: '',
- messageCurrentPage: 1,
- messageHasMorePages: false,
- unreadTotal: 0,
- }
- },
- created() {
- this.dialogNoDataText = this.$L("数据加载中.....");
- this.teamNoDataText = this.$L("数据加载中.....");
- this.messageNoDataText = this.$L("数据加载中.....");
- },
- mounted() {
- let resCall = () => {
- if ($A.getToken() === false) {
- return;
- }
- $A.WS.sendTo('unread', (res) => {
- if (res.status === 1) {
- this.unreadTotal = $A.runNum(res.message);
- } else {
- this.unreadTotal = 0;
- }
- });
- this.getDialogLists();
- this.messageBottomAuto();
- };
- this.userInfo = $A.getUserInfo((res, isLogin) => {
- if (this.userInfo.id != res.id) {
- this.userInfo = res;
- resCall();
- }
- }, false);
- resCall();
- //
- $A.WS.setOnMsgListener("chat/index", (msgDetail) => {
- if (msgDetail.sender == $A.getUserName()) {
- return;
- }
- if (msgDetail.messageType != 'send') {
- return;
- }
- //
- let data = $A.jsonParse(msgDetail.content);
- let lasttext;
- switch (data.type) {
- case 'text':
- lasttext = data['text'];
- break;
- case 'image':
- lasttext = '[图片]';
- break;
- default:
- lasttext = '[未知类型]';
- break;
- }
- this.addDialog({
- username: data.username,
- userimg: data.userimg,
- lasttext: lasttext,
- lastdate: data.indate
- }, msgDetail.sender != this.dialogTarget.username || !this.openWindow);
- if (msgDetail.sender == this.dialogTarget.username) {
- this.addMessageData(data, true);
- }
- if (!this.openWindow) {
- this.$Notice.close('chat-notice');
- this.$Notice.open({
- name: 'chat-notice',
- duration: 0,
- render: h => {
- return h('div', {
- class: 'chat-notice-box',
- on: {
- click: () => {
- this.$Notice.close('chat-notice');
- this.$emit("on-open-notice", data.username);
- this.clickDialog(data.username);
- }
- }
- }, [
- h('img', { class: 'chat-notice-userimg', attrs: { src: data.userimg } }),
- h('div', { class: 'ivu-notice-with-desc' }, [
- h('div', { class: 'ivu-notice-title' }, [
- h('UserView', { props: { username: data.username } })
- ]),
- h('div', { class: 'ivu-notice-desc' }, lasttext)
- ])
- ])
- }
- });
- }
- });
- },
- watch: {
- chatTap(val) {
- if (val === 'team' && this.teamReady == false) {
- this.teamReady = true;
- this.getTeamLists();
- } else if (val === 'dialog') {
- this.autoBottom = true;
- this.$nextTick(() => {
- this.messageBottomGo();
- });
- }
- },
- unreadTotal(val) {
- if (val < 0) {
- this.unreadTotal = 0;
- return;
- }
- this.$emit('input', val);
- },
- dialogTarget: {
- handler: function () {
- let username = this.dialogTarget.username;
- if (username === this.__dialogTargetUsername) {
- return;
- }
- this.__dialogTargetUsername = username;
- this.getDialogMessage();
- },
- deep: true
- }
- },
- computed: {
- dialogListsS() {
- return this.dialogLists.filter(item => {
- return (item.username + "").indexOf(this.dialogSearch) > -1 || (item.lasttext + "").indexOf(this.dialogSearch) > -1 || (item.nickname + "").indexOf(this.dialogSearch) > -1
- });
- },
- teamListsS() {
- return function (lists) {
- return lists.filter(item => {
- return (item.username + "").indexOf(this.teamSearch) > -1 || (item.nickname + "").indexOf(this.teamSearch) > -1
- });
- }
- }
- },
- methods: {
- formatCDate(v) {
- let string = '';
- if ($A.runNum(v) > 0) {
- if ($A.formatDate('Ymd') === $A.formatDate('Ymd', v)) {
- string = $A.formatDate('H:i', v)
- } else if ($A.formatDate('Y') === $A.formatDate('Y', v)) {
- string = $A.formatDate('m-d', v)
- } else {
- string = $A.formatDate('Y-m-d', v)
- }
- }
- return string || '';
- },
- getDialogLists() {
- this.loadIng++;
- this.dialogNoDataText = this.$L("数据加载中.....");
- $A.aAjax({
- url: 'chat/dialog/lists',
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.dialogNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (res.ret === 1) {
- this.dialogLists = res.data;
- this.dialogNoDataText = this.$L("没有相关的数据");
- } else {
- this.dialogLists = [];
- this.dialogNoDataText = res.msg
- }
- }
- });
- },
- getDialogMessage(isNextPage = false) {
- if (isNextPage === true) {
- if (!this.messageHasMorePages) {
- return;
- }
- this.messageCurrentPage+= 1;
- } else {
- this.messageCurrentPage = 1;
- this.autoBottom = true;
- this.messageNew = 0;
- this.messageLists = [];
- }
- this.messageHasMorePages = false;
- //
- let username = this.dialogTarget.username;
- this.loadIng++;
- this.messageNoDataText = this.$L("数据加载中.....");
- $A.aAjax({
- url: 'chat/message/lists',
- data: {
- username: username,
- page: this.messageCurrentPage,
- pagesize: 30
- },
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.messageNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (username != this.dialogTarget.username) {
- return;
- }
- if (res.ret === 1) {
- let tempId = "notice_" + $A.randomString(6);
- let tempLists = res.data.lists;
- if (isNextPage) {
- this.addMessageData({
- id: tempId,
- type: 'notice',
- notice: '历史消息',
- }, false, isNextPage);
- } else {
- tempLists = tempLists.reverse();
- }
- tempLists.forEach((item) => {
- this.addMessageData(Object.assign(item.message, {
- id: item.id,
- username: item.username,
- userimg: item.userimg,
- indate: item.indate,
- }), false, isNextPage);
- });
- if (isNextPage) {
- this.$nextTick(() => {
- let tempObj = $A('div[data-id="' + tempId + '"]');
- if (tempObj.length > 0) {
- this.$refs.manageLists.scrollTo(tempObj.offset().top - tempObj.height() - 24, false);
- }
- });
- }
- this.messageNoDataText = '';
- this.messageHasMorePages = res.data.hasMorePages;
- } else {
- this.messageNoDataText = res.msg
- this.messageHasMorePages = false;
- }
- }
- });
- },
- getTeamLists(isNextPage = false) {
- if (isNextPage === true) {
- if (!this.teamHasMorePages) {
- return;
- }
- this.teamCurrentPage+= 1;
- } else {
- this.teamCurrentPage = 1;
- }
- this.teamHasMorePages = false;
- //
- this.loadIng++;
- this.teamNoDataText = this.$L("数据加载中.....");
- $A.aAjax({
- url: 'users/team/lists',
- data: {
- sorts: {
- key: 'username',
- order: 'asc'
- },
- firstchart: 1,
- page: this.teamCurrentPage,
- pagesize: 100,
- },
- complete: () => {
- this.loadIng--;
- },
- error: () => {
- this.teamNoDataText = this.$L("数据加载失败!");
- },
- success: (res) => {
- if (res.ret === 1) {
- res.data.lists.forEach((item) => {
- if (typeof this.teamLists[item.firstchart] === "undefined") {
- this.$set(this.teamLists, item.firstchart, []);
- }
- this.teamLists[item.firstchart].push(item);
- });
- this.teamNoDataText = this.$L("没有相关的数据");
- this.teamHasMorePages = res.data.hasMorePages;
- //
- if (this.teamHasMorePages && res.data.currentPage < 5) {
- this.getTeamLists(true);
- }
- } else {
- this.teamLists = {};
- this.teamNoDataText = res.msg
- this.teamHasMorePages = false;
- }
- }
- });
- },
- addDialog(data, plusUnread = false) {
- if (!data.username) {
- return;
- }
- let lists = this.dialogLists.filter((item) => {return item.username == data.username});
- if (lists.length > 0) {
- data.unread = $A.runNum(lists[0].unread);
- this.dialogLists = this.dialogLists.filter((item) => {return item.username != data.username});
- } else {
- data.unread = 0;
- }
- if (plusUnread) {
- data.unread += 1;
- this.unreadTotal += 1;
- }
- this.dialogLists.unshift(data);
- },
- openDialog(user, autoAddDialog = false) {
- if (autoAddDialog === true) {
- let lists = this.dialogLists.filter((item) => {return item.username == user.username});
- if (lists.length === 0) {
- this.addDialog(user);
- }
- }
- this.chatTap = 'dialog';
- this.dialogTarget = user;
- if (typeof user.unread === "number" && user.unread > 0) {
- this.unreadTotal -= user.unread;
- this.$set(user, 'unread', 0);
- $A.WS.sendTo('read', user.username);
- }
- },
- clickDialog(username) {
- let lists = this.dialogLists.filter((item) => {return item.username == username});
- if (lists.length > 0) {
- this.openDialog(lists[0]);
- }
- },
- dialogDropdown(type) {
- switch (type) {
- case 'clear':
- case 'delete':
- this.$Modal.confirm({
- title: '确认操作',
- content: type === 'delete' ? '你确定要删除此对话吗?' : '你确定要清除聊天记录吗?',
- loading: true,
- onOk: () => {
- let username = this.dialogTarget.username;
- $A.aAjax({
- url: 'chat/dialog/clear',
- data: {
- username: username,
- delete: type === 'delete' ? 1 : 0
- },
- error: () => {
- this.$Modal.remove();
- alert(this.$L('网络繁忙,请稍后再试!'));
- },
- success: (res) => {
- this.$Modal.remove();
- if (res.ret === 1) {
- if (type === 'delete') {
- this.dialogLists = this.dialogLists.filter((item) => {return item.username != username});
- this.dialogTarget = {};
- } else {
- this.$set(this.dialogTarget, 'lasttext', '');
- this.getDialogMessage();
- }
- }
- setTimeout(() => {
- if (res.ret === 1) {
- this.$Message.success(res.msg);
- } else {
- this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
- }
- }, 350);
- }
- });
- }
- });
- break;
- }
- },
- messageListsScroll(res) {
- if (res.directionreal === 'up') {
- if (res.scrollE < 10) {
- this.autoBottom = true;
- }
- } else if (res.directionreal === 'down') {
- this.autoBottom = false;
- }
- },
- messageBottomAuto() {
- let randString = $A.randomString(8);
- window.__messageBottomAuto = randString;
- setTimeout(() => {
- if (randString === window.__messageBottomAuto) {
- window.__messageBottomAuto = null;
- if (this.autoBottom) {
- this.messageBottomGo();
- }
- this.messageBottomAuto();
- }
- }, 1000);
- },
- messageBottomGo(animation = false) {
- this.$nextTick(() => {
- this.messageNew = 0;
- if (typeof this.$refs.manageLists !== "undefined") {
- this.$refs.manageLists.scrollTo(this.$refs.manageBody.clientHeight, animation);
- this.autoBottom = true;
- }
- });
- },
- messageInsertText(emoji) {
- this.messageText+= emoji;
- },
- messageInsertImage(lists) {
- for (let i = 0; i < lists.length; i++) {
- let item = lists[i];
- if (typeof item === 'object' && typeof item.url === "string") {
- let data = {
- type: 'image',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- url: item.url
- };
- $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
- this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
- });
- //
- this.addDialog(Object.assign(this.dialogTarget, {
- lasttext: '[图片]',
- lastdate: data.indate
- }));
- this.openDialog(this.dialogTarget);
- this.addMessageData(data, true);
- }
- }
- },
- addMessageData(data, animation = false, isUnshift = false) {
- data.self = data.username === this.userInfo.username;
- let sikp = false;
- if (data.id) {
- this.messageLists.some((item, index) => {
- if (item.id == data.id) {
- this.messageLists.splice(index, 1, data);
- return sikp = true;
- }
- });
- if (sikp) {
- return;
- }
- }
- if (isUnshift) {
- this.messageLists.unshift(data);
- } else {
- this.messageLists.push(data);
- if (this.autoBottom) {
- this.messageBottomGo(animation);
- } else {
- this.messageNew++;
- }
- }
- },
- messageSend(e) {
- if (e.keyCode == 13) {
- if (e.shiftKey) {
- return;
- }
- e.preventDefault();
- this.messageSubmit();
- }
- },
- messageSubmit() {
- let text = this.messageText.trim();
- if ($A.count(text) > 0) {
- let data = {
- type: 'text',
- username: this.userInfo.username,
- userimg: this.userInfo.userimg,
- indate: Math.round(new Date().getTime() / 1000),
- text: text
- };
- $A.WS.sendTo('user', this.dialogTarget.username, data, (res) => {
- this.$set(data, res.status === 1 ? 'id' : 'error', res.message)
- });
- //
- this.addDialog(Object.assign(this.dialogTarget, {
- lasttext: text,
- lastdate: data.indate
- }));
- this.openDialog(this.dialogTarget);
- this.addMessageData(data, true);
- }
- this.$nextTick(() => {
- this.messageText = "";
- });
- },
- }
- }
- </script>
|