From 5b0bb45e52edc797d944fba50acc1c1b86a8dcc1 Mon Sep 17 00:00:00 2001 From: adonis Date: Thu, 30 Jul 2026 18:33:08 +0330 Subject: [PATCH] added chat 2 --- package.json | 3 +- src/App.vue | 89 +- src/api/chat.ts | 6 + .../BasicPacks/tools/icons/icons.json | 6 +- src/components/SupportMessengerPicker.vue | 9 +- src/composables/useSupportMessenger.ts | 67 +- src/layouts/composables/useAppNavigation.ts | 5 + src/layouts/mobile/MobileAppLayout.vue | 6 +- src/models/login.ts | 3 + src/models/support.ts | 77 + src/router/index.ts | 6 + src/utils/chat.ts | 1576 ++++++++++++++++ src/utils/index.ts | 24 +- src/views/base/home/components/AppHeader.vue | 37 +- .../base/user/composables/useUserPage.ts | 14 + .../base/user/desktop/DesktopUserView.vue | 6 + .../user/desktop/styles/desktop-user.less | 18 + .../components/SupportChatComposer.vue | 806 ++++++++ .../support/components/SupportChatHeader.vue | 130 ++ .../components/SupportChatMessages.vue | 1678 +++++++++++++++++ src/views/support/index.vue | 702 +++++++ 21 files changed, 5243 insertions(+), 25 deletions(-) create mode 100644 src/api/chat.ts create mode 100644 src/models/support.ts create mode 100644 src/utils/chat.ts create mode 100644 src/views/support/components/SupportChatComposer.vue create mode 100644 src/views/support/components/SupportChatHeader.vue create mode 100644 src/views/support/components/SupportChatMessages.vue create mode 100644 src/views/support/index.vue diff --git a/package.json b/package.json index f877f1e..28e29d2 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "vue3-apexcharts": "^1.4.4", "vue3-lazyload": "^0.3.8", "vue3-odometer": "^0.1.3", - "vue3-otp-input": "^0.4.1" + "vue3-otp-input": "^0.4.1", + "wavesurfer.js": "^7.12.6" }, "devDependencies": { "@rushstack/eslint-patch": "^1.3.2", diff --git a/src/App.vue b/src/App.vue index 4fecfe4..792692d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -46,7 +46,7 @@
پشتیبانی + + {{ supportChatUnreadCount > 99 ? '99+' : supportChatUnreadCount }} +
@@ -85,7 +91,9 @@ import { colors } from './themeConfig' import pkg from '../package.json' import { getDisplayAppVersion } from '@/config/config-cache' -import { computed, defineAsyncComponent, h, onMounted, ref } from 'vue' +import { computed, defineAsyncComponent, h, onMounted, ref, watch } from 'vue' +import { useRoute } from 'vue-router' +import { message } from 'ant-design-vue' import img_topGradiant from '@/views/login/assets/img/gr_top_white.svg' import img_pattern from '@/views/login/assets/img/pattern.svg' import { LoadingOutlined } from '@ant-design/icons-vue' @@ -97,6 +105,10 @@ import { useDraggableFloatingButton } from '@/utils/useDraggableFloatingButton' import { useApplyDesktopLayoutClass } from '@/layouts/composables/useAppLayout' import { usePwaInstall } from '@/composables/usePwaInstall' import PwaInstallGuideModal from '@/components/pwa/PwaInstallGuideModal.vue' +import { useUserStore } from '@/store/userStore' +import { useSettingsStore } from '@/store/settingsStore' +import { connectChatIfExists, disconnectChat, isSettingFlagOn, unreadSupportCount, useChatService } from '@/utils/chat' +import { getToken } from '@/utils' import img_bottomGradiant from '@/views/login/assets/img/gr_bottom_white.svg' import logoFull from '@/assets/img/logo_full_.png' @@ -113,6 +125,7 @@ const indicator = h(LoadingOutlined, { }) const displayVersion = getDisplayAppVersion(pkg.version) const showSplash = ref(true) +const route = useRoute() useApplyDesktopLayoutClass() @@ -127,6 +140,7 @@ const { supportPickerAnchor, supportMessengerEntries, messengerMeta, + isChatEnabled, hasMessengerLink: showSupportButton, openMessengerEntry, openSupportMessenger, @@ -135,6 +149,10 @@ const { const supportButtonEl = ref(null) const pickerAnchorEl = computed(() => supportPickerAnchor.value ?? supportButtonEl.value) +const supportChatUnreadCount = computed(() => + isChatEnabled.value ? Number(unreadSupportCount.value) || 0 : 0, +) + const supportIcon = computed(() => messengerMeta.value.icon) const supportAccentColor = computed(() => @@ -171,6 +189,54 @@ onMounted(async () => { }, 2000) }) +const userStore = useUserStore() +const settingsStore = useSettingsStore() +const { latestIncomingNotification } = useChatService() +let lastConnectedChatSessionKey = '' +let lastSupportToastAt = 0 + +watch( + () => [ + userStore.userInfo?.chat_room_id, + userStore.userInfo?.chat_user_id, + settingsStore.getSettingByKey('chat_api_key'), + settingsStore.getSettingByKey('show_to_users_chat'), + settingsStore.getSettingByKey('has_chat'), + getToken(), + ], + async ([roomId, chatUserId, chatApiKey, chatAdminFlag, chatCustomerFlag, token]) => { + const chatOn = + isSettingFlagOn(chatAdminFlag) && isSettingFlagOn(chatCustomerFlag) + if (!token || !chatOn || !chatApiKey || !roomId || !chatUserId) { + lastConnectedChatSessionKey = '' + disconnectChat() + return + } + + const sessionKey = `${roomId}:${chatUserId}:${chatApiKey}` + if (lastConnectedChatSessionKey === sessionKey) return + + try { + await connectChatIfExists() + lastConnectedChatSessionKey = sessionKey + } catch (error) { + lastConnectedChatSessionKey = '' + console.error('connectChatIfExists failed:', error) + } + }, + { immediate: true }, +) + +watch(latestIncomingNotification, (payload) => { + if (!payload) return + if (payload.at === lastSupportToastAt) return + lastSupportToastAt = payload.at + message.info({ + content: `پیام جدید پشتیبانی: ${payload.body}`, + duration: 3, + }) +}) + \ No newline at end of file diff --git a/src/views/support/components/SupportChatHeader.vue b/src/views/support/components/SupportChatHeader.vue new file mode 100644 index 0000000..7f737c7 --- /dev/null +++ b/src/views/support/components/SupportChatHeader.vue @@ -0,0 +1,130 @@ + + + + + \ No newline at end of file diff --git a/src/views/support/components/SupportChatMessages.vue b/src/views/support/components/SupportChatMessages.vue new file mode 100644 index 0000000..128ac45 --- /dev/null +++ b/src/views/support/components/SupportChatMessages.vue @@ -0,0 +1,1678 @@ + + + + + diff --git a/src/views/support/index.vue b/src/views/support/index.vue new file mode 100644 index 0000000..ee00960 --- /dev/null +++ b/src/views/support/index.vue @@ -0,0 +1,702 @@ + + + + +