chat-utils.js 518 B

123456789101112131415161718192021
  1. /**
  2. * 保存聊天記錄到本地緩存(與 $appKit.send / runtime-bridge 統一前綴)
  3. */
  4. import { STORAGE } from '@/core/constants/storage-keys'
  5. export function setChat(data, send) {
  6. const uid = send === 'send' ? data.to_id : data.form.id
  7. const key = STORAGE.chatMsgPrefix + uid
  8. uni.getStorage({
  9. key,
  10. success(res) {
  11. const arr = res.data.slice(-96)
  12. arr.push(data)
  13. uni.setStorageSync(key, arr)
  14. },
  15. fail() {
  16. uni.setStorageSync(key, [data])
  17. }
  18. })
  19. return data
  20. }