【优化】:mall 客服表情包存放到本地使用
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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<{
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = {
 | 
			
		||||
 
 | 
			
		||||
@@ -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 () => {
 | 
			
		||||
 
 | 
			
		||||
@@ -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] = []
 | 
			
		||||
  }
 | 
			
		||||
  emojiPage[Math.floor(index / 30) + 1].push(item)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
// 后端上传地址
 | 
			
		||||
const staticUrl = import.meta.env.VITE_STATIC_URL
 | 
			
		||||
// 后缀
 | 
			
		||||
const suffix = '/static/img/chat/emoji/'
 | 
			
		||||
 | 
			
		||||
// 处理表情
 | 
			
		||||
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
 | 
			
		||||
          }"/>`
 | 
			
		||||
        )
 | 
			
		||||
      })
 | 
			
		||||
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)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return newData
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获得所有表情
 | 
			
		||||
export function getEmojiList(): Emoji[] {
 | 
			
		||||
  return emojiList.map((item) => ({
 | 
			
		||||
    url: staticUrl + suffix + item.file,
 | 
			
		||||
    name: item.name
 | 
			
		||||
  })) as Emoji[]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function selEmojiFile(name: string) {
 | 
			
		||||
  for (const index in emojiList) {
 | 
			
		||||
    if (emojiList[index].name === name) {
 | 
			
		||||
      return emojiList[index].file
 | 
			
		||||
  // 初始化
 | 
			
		||||
  onMounted(async () => {
 | 
			
		||||
    if (isEmpty(emojiPathList.value)) {
 | 
			
		||||
      await getStaticEmojiPath()
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  // 处理表情
 | 
			
		||||
  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 false
 | 
			
		||||
 | 
			
		||||
  // 获得所有表情
 | 
			
		||||
  function getEmojiList(): Emoji[] {
 | 
			
		||||
    return emojiList.map((item) => ({
 | 
			
		||||
      url: selEmojiFile(item.name),
 | 
			
		||||
      name: item.name
 | 
			
		||||
    })) as Emoji[]
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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 { replaceEmoji, getEmojiList }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/a.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/aini.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 2.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/aixin.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/baiyan.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/bizui.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/buhaoyisi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/bukesiyi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.9 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/dajing.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/danao.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/daxiao.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/dianzan.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 1.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/emo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/esi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/fadai.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/fankun.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/feiwen.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 6.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/fennu.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/ganga.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/ganmao.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.6 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/hanyan.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 2.9 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/haochi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/hongxin.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/huaixiao.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/jingkong.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/jingshu.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.6 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/jingya.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/kaixin.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.9 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/keai.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.0 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/keshui.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.9 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/kun.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.4 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/lengku.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/liuhan.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.7 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/liukoushui.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.0 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/liulei.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/mengbi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.3 KiB  | 
| 
		 After Width: | Height: | Size: 2.9 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/nanguo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 3.8 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/outu.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/shengqi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/shuizhuo.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/tianshi.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.1 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/xiaodiaoya.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.2 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/xiaoku.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.6 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/xinsui.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.3 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/xiong.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.4 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/yiwen.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.5 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/yun.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 5.9 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								src/views/mall/promotion/kefu/components/images/ziya.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 4.0 KiB  |