Răsfoiți Sursa

【优化】:mall 客服表情包存放到本地使用

puhui999 9 luni în urmă
părinte
comite
b0b62eb250
53 a modificat fișierele cu 58 adăugiri și 49 ștergeri
  1. 0 4
      .env.local
  2. 2 1
      src/views/mall/promotion/kefu/components/EmojiSelectPopover.vue
  3. 3 1
      src/views/mall/promotion/kefu/components/KeFuChatBox.vue
  4. 2 1
      src/views/mall/promotion/kefu/components/KeFuConversationBox.vue
  5. 51 42
      src/views/mall/promotion/kefu/components/emoji.ts
  6. BIN
      src/views/mall/promotion/kefu/components/images/a.png
  7. BIN
      src/views/mall/promotion/kefu/components/images/aini.png
  8. BIN
      src/views/mall/promotion/kefu/components/images/aixin.png
  9. BIN
      src/views/mall/promotion/kefu/components/images/baiyan.png
  10. BIN
      src/views/mall/promotion/kefu/components/images/bizui.png
  11. BIN
      src/views/mall/promotion/kefu/components/images/buhaoyisi.png
  12. BIN
      src/views/mall/promotion/kefu/components/images/bukesiyi.png
  13. BIN
      src/views/mall/promotion/kefu/components/images/dajing.png
  14. BIN
      src/views/mall/promotion/kefu/components/images/danao.png
  15. BIN
      src/views/mall/promotion/kefu/components/images/daxiao.png
  16. BIN
      src/views/mall/promotion/kefu/components/images/dianzan.png
  17. BIN
      src/views/mall/promotion/kefu/components/images/emo.png
  18. BIN
      src/views/mall/promotion/kefu/components/images/esi.png
  19. BIN
      src/views/mall/promotion/kefu/components/images/fadai.png
  20. BIN
      src/views/mall/promotion/kefu/components/images/fankun.png
  21. BIN
      src/views/mall/promotion/kefu/components/images/feiwen.png
  22. BIN
      src/views/mall/promotion/kefu/components/images/fennu.png
  23. BIN
      src/views/mall/promotion/kefu/components/images/ganga.png
  24. BIN
      src/views/mall/promotion/kefu/components/images/ganmao.png
  25. BIN
      src/views/mall/promotion/kefu/components/images/hanyan.png
  26. BIN
      src/views/mall/promotion/kefu/components/images/haochi.png
  27. BIN
      src/views/mall/promotion/kefu/components/images/hongxin.png
  28. BIN
      src/views/mall/promotion/kefu/components/images/huaixiao.png
  29. BIN
      src/views/mall/promotion/kefu/components/images/jingkong.png
  30. BIN
      src/views/mall/promotion/kefu/components/images/jingshu.png
  31. BIN
      src/views/mall/promotion/kefu/components/images/jingya.png
  32. BIN
      src/views/mall/promotion/kefu/components/images/kaixin.png
  33. BIN
      src/views/mall/promotion/kefu/components/images/keai.png
  34. BIN
      src/views/mall/promotion/kefu/components/images/keshui.png
  35. BIN
      src/views/mall/promotion/kefu/components/images/kun.png
  36. BIN
      src/views/mall/promotion/kefu/components/images/lengku.png
  37. BIN
      src/views/mall/promotion/kefu/components/images/liuhan.png
  38. BIN
      src/views/mall/promotion/kefu/components/images/liukoushui.png
  39. BIN
      src/views/mall/promotion/kefu/components/images/liulei.png
  40. BIN
      src/views/mall/promotion/kefu/components/images/mengbi.png
  41. BIN
      src/views/mall/promotion/kefu/components/images/mianwubiaoqing.png
  42. BIN
      src/views/mall/promotion/kefu/components/images/nanguo.png
  43. BIN
      src/views/mall/promotion/kefu/components/images/outu.png
  44. BIN
      src/views/mall/promotion/kefu/components/images/shengqi.png
  45. BIN
      src/views/mall/promotion/kefu/components/images/shuizhuo.png
  46. BIN
      src/views/mall/promotion/kefu/components/images/tianshi.png
  47. BIN
      src/views/mall/promotion/kefu/components/images/xiaodiaoya.png
  48. BIN
      src/views/mall/promotion/kefu/components/images/xiaoku.png
  49. BIN
      src/views/mall/promotion/kefu/components/images/xinsui.png
  50. BIN
      src/views/mall/promotion/kefu/components/images/xiong.png
  51. BIN
      src/views/mall/promotion/kefu/components/images/yiwen.png
  52. BIN
      src/views/mall/promotion/kefu/components/images/yun.png
  53. BIN
      src/views/mall/promotion/kefu/components/images/ziya.png

+ 0 - 4
.env.local

@@ -29,9 +29,5 @@ VITE_BASE_PATH=/
 # 商城H5会员端域名
 VITE_MALL_H5_DOMAIN='http://localhost:3000'
 
-# TODO puhui999:这个可以不走 cdn 地址么?
-# 客户端静态资源地址 空=默认使用服务端指定的CDN资源地址前缀 | local=本地  |  http(s)://xxx.xxx=自定义静态资源地址前缀
-VITE_STATIC_URL = https://file.sheepjs.com
-
 # 验证码的开关
 VITE_APP_CAPTCHA_ENABLE=false

+ 2 - 1
src/views/mall/promotion/kefu/components/EmojiSelectPopover.vue

@@ -26,8 +26,9 @@
 
 <script lang="ts" setup>
 defineOptions({ name: 'EmojiSelectPopover' })
-import { Emoji, getEmojiList } from './emoji'
+import { Emoji, useEmoji } from './emoji'
 
+const { getEmojiList } = useEmoji()
 const emojiList = computed(() => getEmojiList())
 
 const emits = defineEmits<{

+ 3 - 1
src/views/mall/promotion/kefu/components/KeFuChatBox.vue

@@ -89,13 +89,14 @@ import { ElScrollbar as ElScrollbarType } from 'element-plus'
 import { KeFuMessageApi, KeFuMessageRespVO } from '@/api/mall/promotion/kefu/message'
 import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
 import EmojiSelectPopover from './EmojiSelectPopover.vue'
-import { Emoji, replaceEmoji } from './emoji'
+import { Emoji, useEmoji } from './emoji'
 import { KeFuMessageContentTypeEnum } from './constants'
 import { isEmpty } from '@/utils/is'
 import { UserTypeEnum } from '@/utils/constants'
 import { createImageViewer } from '@/components/ImageViewer'
 
 defineOptions({ name: 'KeFuMessageBox' })
+const { replaceEmoji } = useEmoji()
 const messageTool = useMessage()
 const message = ref('') // 消息
 const messageList = ref<KeFuMessageRespVO[]>([]) // 消息列表
@@ -130,6 +131,7 @@ const handleSendMessage = async () => {
   // 1. 校验消息是否为空
   if (isEmpty(unref(message.value))) {
     messageTool.warning('请输入消息后再发送哦!')
+    return
   }
   // 2. 组织发送消息
   const msg = {

+ 2 - 1
src/views/mall/promotion/kefu/components/KeFuConversationBox.vue

@@ -35,11 +35,12 @@
 
 <script lang="ts" setup>
 import { KeFuConversationApi, KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
-import { replaceEmoji } from '@/views/mall/promotion/kefu/components/emoji'
+import { useEmoji } from './emoji'
 import { formatDate, getNowDateTime } from '@/utils/formatTime'
 import { KeFuMessageContentTypeEnum } from '@/views/mall/promotion/kefu/components/constants'
 
 defineOptions({ name: 'KeFuConversationBox' })
+const { replaceEmoji } = useEmoji()
 const activeConversationIndex = ref(-1) // 选中的会话
 const conversationList = ref<KeFuConversationRespVO[]>([]) // 会话列表
 const getConversationList = async () => {

+ 51 - 42
src/views/mall/promotion/kefu/components/emoji.ts

@@ -1,4 +1,6 @@
-export const emojiList = [
+import { isEmpty } from '@/utils/is'
+
+const emojiList = [
   { name: '[笑掉牙]', file: 'xiaodiaoya.png' },
   { name: '[可爱]', file: 'keai.png' },
   { name: '[冷酷]', file: 'lengku.png' },
@@ -54,53 +56,60 @@ export interface Emoji {
   url: string
 }
 
-export const emojiPage = {}
-emojiList.forEach((item, index) => {
-  if (!emojiPage[Math.floor(index / 30) + 1]) {
-    emojiPage[Math.floor(index / 30) + 1] = []
+export const useEmoji = () => {
+  const emojiPathList = ref<any[]>([])
+  // 加载本地图片
+  const getStaticEmojiPath = async () => {
+    const pathList = import.meta.glob(
+      '@/views/mall/promotion/kefu/components/images/*.{png,jpg,jpeg,svg}'
+    )
+    for (const path in pathList) {
+      const imageModule: any = await pathList[path]()
+      emojiPathList.value.push(imageModule.default)
+    }
   }
-  emojiPage[Math.floor(index / 30) + 1].push(item)
-})
-
-// 后端上传地址
-const staticUrl = import.meta.env.VITE_STATIC_URL
-// 后缀
-const suffix = '/static/img/chat/emoji/'
+  // 初始化
+  onMounted(async () => {
+    if (isEmpty(emojiPathList.value)) {
+      await getStaticEmojiPath()
+    }
+  })
 
-// 处理表情
-export function replaceEmoji(data: string) {
-  let newData = data
-  if (typeof newData !== 'object') {
-    const reg = /\[(.+?)\]/g // [] 中括号
-    const zhEmojiName = newData.match(reg)
-    if (zhEmojiName) {
-      zhEmojiName.forEach((item) => {
-        const emojiFile = selEmojiFile(item)
-        newData = newData.replace(
-          item,
-          `<img class="chat-img" style="width: 24px;height: 24px;margin: 0 3px;" src="${
-            staticUrl + suffix + emojiFile
-          }"/>`
-        )
-      })
+  // 处理表情
+  function replaceEmoji(data: string) {
+    let newData = data
+    if (typeof newData !== 'object') {
+      const reg = /\[(.+?)\]/g // [] 中括号
+      const zhEmojiName = newData.match(reg)
+      if (zhEmojiName) {
+        zhEmojiName.forEach((item) => {
+          const emojiFile = selEmojiFile(item)
+          newData = newData.replace(
+            item,
+            `<img class="chat-img" style="width: 24px;height: 24px;margin: 0 3px;" src="${emojiFile}"/>`
+          )
+        })
+      }
     }
+    return newData
   }
-  return newData
-}
 
-// 获得所有表情
-export function getEmojiList(): Emoji[] {
-  return emojiList.map((item) => ({
-    url: staticUrl + suffix + item.file,
-    name: item.name
-  })) as Emoji[]
-}
+  // 获得所有表情
+  function getEmojiList(): Emoji[] {
+    return emojiList.map((item) => ({
+      url: selEmojiFile(item.name),
+      name: item.name
+    })) as Emoji[]
+  }
 
-function selEmojiFile(name: string) {
-  for (const index in emojiList) {
-    if (emojiList[index].name === name) {
-      return emojiList[index].file
+  function selEmojiFile(name: string) {
+    for (const emoji of emojiList) {
+      if (emoji.name === name) {
+        return emojiPathList.value.find((item: string) => item.indexOf(emoji.file) > -1)
+      }
     }
+    return false
   }
-  return false
+
+  return { replaceEmoji, getEmojiList }
 }

BIN
src/views/mall/promotion/kefu/components/images/a.png


BIN
src/views/mall/promotion/kefu/components/images/aini.png


BIN
src/views/mall/promotion/kefu/components/images/aixin.png


BIN
src/views/mall/promotion/kefu/components/images/baiyan.png


BIN
src/views/mall/promotion/kefu/components/images/bizui.png


BIN
src/views/mall/promotion/kefu/components/images/buhaoyisi.png


BIN
src/views/mall/promotion/kefu/components/images/bukesiyi.png


BIN
src/views/mall/promotion/kefu/components/images/dajing.png


BIN
src/views/mall/promotion/kefu/components/images/danao.png


BIN
src/views/mall/promotion/kefu/components/images/daxiao.png


BIN
src/views/mall/promotion/kefu/components/images/dianzan.png


BIN
src/views/mall/promotion/kefu/components/images/emo.png


BIN
src/views/mall/promotion/kefu/components/images/esi.png


BIN
src/views/mall/promotion/kefu/components/images/fadai.png


BIN
src/views/mall/promotion/kefu/components/images/fankun.png


BIN
src/views/mall/promotion/kefu/components/images/feiwen.png


BIN
src/views/mall/promotion/kefu/components/images/fennu.png


BIN
src/views/mall/promotion/kefu/components/images/ganga.png


BIN
src/views/mall/promotion/kefu/components/images/ganmao.png


BIN
src/views/mall/promotion/kefu/components/images/hanyan.png


BIN
src/views/mall/promotion/kefu/components/images/haochi.png


BIN
src/views/mall/promotion/kefu/components/images/hongxin.png


BIN
src/views/mall/promotion/kefu/components/images/huaixiao.png


BIN
src/views/mall/promotion/kefu/components/images/jingkong.png


BIN
src/views/mall/promotion/kefu/components/images/jingshu.png


BIN
src/views/mall/promotion/kefu/components/images/jingya.png


BIN
src/views/mall/promotion/kefu/components/images/kaixin.png


BIN
src/views/mall/promotion/kefu/components/images/keai.png


BIN
src/views/mall/promotion/kefu/components/images/keshui.png


BIN
src/views/mall/promotion/kefu/components/images/kun.png


BIN
src/views/mall/promotion/kefu/components/images/lengku.png


BIN
src/views/mall/promotion/kefu/components/images/liuhan.png


BIN
src/views/mall/promotion/kefu/components/images/liukoushui.png


BIN
src/views/mall/promotion/kefu/components/images/liulei.png


BIN
src/views/mall/promotion/kefu/components/images/mengbi.png


BIN
src/views/mall/promotion/kefu/components/images/mianwubiaoqing.png


BIN
src/views/mall/promotion/kefu/components/images/nanguo.png


BIN
src/views/mall/promotion/kefu/components/images/outu.png


BIN
src/views/mall/promotion/kefu/components/images/shengqi.png


BIN
src/views/mall/promotion/kefu/components/images/shuizhuo.png


BIN
src/views/mall/promotion/kefu/components/images/tianshi.png


BIN
src/views/mall/promotion/kefu/components/images/xiaodiaoya.png


BIN
src/views/mall/promotion/kefu/components/images/xiaoku.png


BIN
src/views/mall/promotion/kefu/components/images/xinsui.png


BIN
src/views/mall/promotion/kefu/components/images/xiong.png


BIN
src/views/mall/promotion/kefu/components/images/yiwen.png


BIN
src/views/mall/promotion/kefu/components/images/yun.png


BIN
src/views/mall/promotion/kefu/components/images/ziya.png