From e306a170238c9e61e2ac803c5dc61173ef4c8355 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 8 Jun 2021 17:26:15 +0800 Subject: [PATCH] no message --- app/Http/Controllers/Api/DialogController.php | 3 + app/Http/Controllers/Api/UsersController.php | 3 +- .../assets/js/pages/manage/messenger.vue | 75 ++++++- resources/assets/js/store/mutations.js | 3 + resources/assets/sass/messenger-wrapper.scss | 191 ++++++++++++------ 5 files changed, 206 insertions(+), 69 deletions(-) diff --git a/app/Http/Controllers/Api/DialogController.php b/app/Http/Controllers/Api/DialogController.php index 54301d33..ff3029ac 100755 --- a/app/Http/Controllers/Api/DialogController.php +++ b/app/Http/Controllers/Api/DialogController.php @@ -87,6 +87,9 @@ class DialogController extends AbstractController } // $userid = intval(Request::input('userid')); + if ($userid == $user->userid) { + return Base::retError('不能对话自己'); + } // $dialog = WebSocketDialog::checkUserDialog($user->userid, $userid); if (empty($dialog)) { diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index d259aa8c..87b69bb4 100755 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -244,6 +244,7 @@ class UsersController extends AbstractController // $user->save(); User::token($user); + User::AZUpdate($user->userid); return Base::retSuccess('修改成功', $user); } @@ -340,7 +341,7 @@ class UsersController extends AbstractController */ public function search() { - $builder = User::select(['userid', 'email', 'nickname', 'userimg']); + $builder = User::select(['userid', 'email', 'nickname', 'profession', 'userimg', 'az']); // $keys = Request::input('where'); if (is_array($keys)) { diff --git a/resources/assets/js/pages/manage/messenger.vue b/resources/assets/js/pages/manage/messenger.vue index 97cce867..3ffc0f2f 100644 --- a/resources/assets/js/pages/manage/messenger.vue +++ b/resources/assets/js/pages/manage/messenger.vue @@ -10,7 +10,7 @@
-
- - + +
@@ -65,8 +78,13 @@ export default { components: {DialogWrapper}, data() { return { - dialogKey: '', + tabActive: 'dialog', + dialogLoad: 0, + dialogKey: '', + + contactsLoad: 0, + contactsLists: null, } }, @@ -102,6 +120,14 @@ export default { }, }, + watch: { + tabActive(val) { + if (val && this.contactsLists === null) { + this.getContactsList(); + } + } + }, + methods: { openDialog(dialog) { this.$store.state.method.setStorage('messengerDialogId', dialog.id) @@ -116,6 +142,45 @@ export default { } }, + openContacts(user) { + this.$store.commit("openDialogUser", user.userid); + this.tabActive = 'dialog'; + }, + + getContactsList() { + if (this.contactsLists === null) { + this.contactsLists = {}; + } + this.contactsLoad++; + $A.apiAjax({ + url: 'users/search', + data: { + take: 50 + }, + complete: () => { + this.contactsLoad--; + }, + success: ({ret, data, msg}) => { + if (ret === 1) { + data.some((user) => { + if (user.userid === this.userId) { + return false; + } + let az = user.az ? user.az.toUpperCase() : "#"; + if (typeof this.contactsLists[az] === "undefined") this.contactsLists[az] = []; + // + let index = this.contactsLists[az].findIndex(({userid}) => userid === user.userid); + if (index > -1) { + this.contactsLists[az].splice(index, 1, user); + } else { + this.contactsLists[az].push(user); + } + }); + } + } + }); + }, + formatTime(date) { let time = Math.round(new Date(date).getTime() / 1000), string = ''; @@ -154,7 +219,7 @@ export default { } } return null; - } + }, } } diff --git a/resources/assets/js/store/mutations.js b/resources/assets/js/store/mutations.js index 5f98831a..7d74b137 100644 --- a/resources/assets/js/store/mutations.js +++ b/resources/assets/js/store/mutations.js @@ -274,6 +274,9 @@ export default { * @param userid */ openDialogUser(state, userid) { + if (userid === state.userId) { + return; + } $A.apiAjax({ url: 'dialog/open/user', data: { diff --git a/resources/assets/sass/messenger-wrapper.scss b/resources/assets/sass/messenger-wrapper.scss index cd5253a6..1c366735 100644 --- a/resources/assets/sass/messenger-wrapper.scss +++ b/resources/assets/sass/messenger-wrapper.scss @@ -51,80 +51,145 @@ overflow-x: hidden; overflow-y: auto; > ul { - > li { - display: flex; - flex-direction: row; - align-items: center; - height: 80px; - padding: 0 12px; - position: relative; - cursor: pointer; - &.active { - background-color: #F4F5F7; - } - .user-avatar, - .icon-avatar { - width: 46px; - height: 46px; - flex-grow: 0; - flex-shrink: 0; - } - .icon-avatar { - line-height: 46px; - border-radius: 50%; - font-size: 26px; - background-color: #61B2F9; - color: #ffffff; - } - .dialog-box { - flex: 1; + &.dialog { + > li { display: flex; - flex-direction: column; - padding-left: 12px; - .dialog-title { + flex-direction: row; + align-items: center; + height: 80px; + padding: 0 12px; + position: relative; + cursor: pointer; + list-style: none; + &.active { + background-color: #F4F5F7; + } + &.loading { + margin: 0; + height: 52px; 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; + justify-content: center; + .common-loading { + width: 20px; + height: 20px; + margin: 0; + } + } + .user-avatar, + .icon-avatar { + width: 46px; + height: 46px; + flex-grow: 0; + flex-shrink: 0; + } + .icon-avatar { + line-height: 46px; + border-radius: 50%; + font-size: 26px; + background-color: #61B2F9; + color: #ffffff; + } + .dialog-box { + flex: 1; + display: flex; + flex-direction: column; + padding-left: 12px; + .dialog-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; + } + > i { + margin-left: 8px; + transform: scale(0.9); + font-size: 12px; + color: #87d068; + } + > em { + margin-left: 8px; + font-style: normal; + color: #999999; + font-size: 12px; + } + } + .dialog-text { + max-width: 170px; + color: #999999; + font-size: 12px; + line-height: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } - > i { - margin-left: 8px; - transform: scale(0.9); - font-size: 12px; - color: #87d068; - } - > em { - margin-left: 8px; - font-style: normal; - color: #999999; - font-size: 12px; - } } - .dialog-text { - max-width: 170px; - color: #999999; + .dialog-num { + position: absolute; + top: 10px; + left: 42px; font-size: 12px; - line-height: 24px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; + transform: scale(0.8); } } - .dialog-num { - position: absolute; - top: 10px; - left: 42px; - font-size: 12px; - transform: scale(0.8); + } + &.contacts { + > li { + list-style: none; + margin-left: 24px; + position: relative; + .label { + padding-left: 4px; + margin-top: 6px; + margin-bottom: 6px; + height: 34px; + line-height: 34px; + border-bottom: 1px solid #efefef; + } + &.loading { + margin: 0; + height: 52px; + display: flex; + align-items: center; + justify-content: center; + .common-loading { + width: 20px; + height: 20px; + margin: 0; + } + } + > ul { + > li { + list-style: none; + display: flex; + flex-direction: row; + align-items: center; + height: 52px; + cursor: pointer; + .avatar { + flex-grow: 0; + flex-shrink: 0; + width: 30px; + height: 30px; + } + .nickname { + padding: 0 12px; + font-size: 14px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } + } } } }