Merge branch 'wyfMain-dev-sqlite' into wyfMain-dev-useBase
This commit is contained in:
commit
f056ebd176
21
src/main.js
21
src/main.js
@ -99,6 +99,27 @@ export function createApp() {
|
||||
location.reload(true)
|
||||
}
|
||||
|
||||
//检查聊天页面是否可用
|
||||
window.checkChatWebviewAvailable = () => {
|
||||
let OAWebView = plus.webview.all()
|
||||
OAWebView.forEach((webview, index) => {
|
||||
if (webview.id === 'webviewId1') {
|
||||
webview.evalJS(`doneCheckChatWebviewAvailable()`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//获取从base传来的多选视频列表
|
||||
window.getBaseMulVideo = (videoList) => {
|
||||
const videos = JSON.parse(decodeURIComponent(videoList))
|
||||
console.error('=====videos', videos)
|
||||
if(videos.length > 0){
|
||||
const videoUri = videos[0]
|
||||
console.error('=====videoUri', videoUri)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
window.message = ['success', 'error', 'warning'].reduce((acc, type) => {
|
||||
acc[type] = (message) => {
|
||||
if (typeof message === 'string') {
|
||||
|
@ -162,6 +162,12 @@ const photoActionsSelect = (index) => {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// let OAWebView = plus.webview.all()
|
||||
// OAWebView.forEach((webview, index) => {
|
||||
// if (webview.id === 'webviewId1') {
|
||||
// webview.evalJS(`getPlusVideoPicker()`)
|
||||
// }
|
||||
// })
|
||||
uni.chooseVideo({
|
||||
sourceType: ['album'],
|
||||
compressed: true,
|
||||
@ -317,7 +323,9 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => {
|
||||
virtualList.value.unshift(newItem)
|
||||
|
||||
try {
|
||||
const result = await uploadImg(form, (e) => onProgressFn(e, randomId))
|
||||
const result = await uploadImg(form, (e) =>
|
||||
onProgressFn(e, randomId),
|
||||
)
|
||||
console.log('视频上传完成,结果:', result)
|
||||
|
||||
if (result.status === 0) {
|
||||
@ -369,7 +377,7 @@ const onUploadImageVideo = async (file, type = 'image', fileUrl) => {
|
||||
uploadsStore.updateUploadStatus(false)
|
||||
message.error('获取视频信息失败')
|
||||
resolve('')
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -5,8 +5,106 @@ import lodash from 'lodash'
|
||||
import { ref } from 'vue'
|
||||
import { createGlobalState, useStorage } from '@vueuse/core'
|
||||
import { uniStorage } from '@/utils/uniStorage.js'
|
||||
import { initDatabase } from './sqlite'
|
||||
|
||||
export const useDialogueListStore = createGlobalState(() => {
|
||||
const testDatabase = async () => {
|
||||
// 初始化数据库
|
||||
let chatDatabase = {
|
||||
eventType: 'openDatabase',
|
||||
eventParams: {
|
||||
name: 'chat',
|
||||
path: '_doc/chat.db',
|
||||
},
|
||||
}
|
||||
let chatDBexecuteSql = {
|
||||
eventType: 'executeSql',
|
||||
eventParams: {
|
||||
name: 'chat',
|
||||
sql: `CREATE TABLE IF NOT EXISTS talk_records (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
msg_id TEXT NOT NULL,
|
||||
sequence INTEGER NOT NULL,
|
||||
talk_type INTEGER NOT NULL DEFAULT 1,
|
||||
msg_type INTEGER NOT NULL DEFAULT 1,
|
||||
user_id INTEGER NOT NULL DEFAULT 0,
|
||||
receiver_id INTEGER NOT NULL DEFAULT 0,
|
||||
is_revoke INTEGER NOT NULL DEFAULT 0,
|
||||
is_mark INTEGER NOT NULL DEFAULT 0,
|
||||
quote_id TEXT NOT NULL,
|
||||
extra TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
biz_date TEXT
|
||||
)`,
|
||||
},
|
||||
}
|
||||
|
||||
const content = {
|
||||
content: "我试试传送文件和图片是不是一个接口",
|
||||
name: "测试excel1.xlsx",
|
||||
path: "https://cdn-test.szjixun.cn/fonchain-chat/chat/file/multipart/20250307/727a2371-ffc4-46da-b953-a7d449ff82ff-测试excel1.xlsx",
|
||||
size: 9909,
|
||||
drive: 3
|
||||
};
|
||||
const extra = JSON.stringify(content);
|
||||
|
||||
let chatDBexecuteSql2 = {
|
||||
eventType: 'executeSql',
|
||||
eventParams: {
|
||||
name: 'chat',
|
||||
sql: 'INSERT INTO talk_records (msg_id, sequence, talk_type, msg_type, user_id, receiver_id, is_revoke, is_mark, quote_id, extra, created_at, updated_at, biz_date) VALUES ("'+'77b715fb30f54f739a255a915ef72445'+'", 166, 2, 1, 1774, 888890, 0, 0, "'+''+'", "'+extra+'", "'+'2025-03-06T15:57:07.000Z'+'", "'+'2025-03-06T15:57:07.000Z'+'", "'+'20250306'+'")',
|
||||
},
|
||||
}
|
||||
let chatDBSelectSql = {
|
||||
eventType: 'selectSql',
|
||||
eventParams: {
|
||||
name: 'chat',
|
||||
sql: `SELECT * FROM talk_records ORDER BY sequence DESC LIMIT 20`,
|
||||
},
|
||||
}
|
||||
let chatDBIsOpenDatabase = {
|
||||
eventType: 'isOpenDatabase',
|
||||
eventParams: {
|
||||
name: 'chat',
|
||||
path: '_doc/chat.db',
|
||||
},
|
||||
}
|
||||
document.addEventListener('plusready', () => {
|
||||
let OAWebView = plus.webview.all()
|
||||
OAWebView.forEach((webview, index) => {
|
||||
if (webview.id === 'webviewId1') {
|
||||
webview.evalJS(
|
||||
`operateSQLite('${encodeURIComponent(
|
||||
JSON.stringify(chatDatabase),
|
||||
)}')`,
|
||||
)
|
||||
webview.evalJS(
|
||||
`operateSQLite('${encodeURIComponent(
|
||||
JSON.stringify(chatDBexecuteSql),
|
||||
)}')`,
|
||||
)
|
||||
webview.evalJS(
|
||||
`operateSQLite('${encodeURIComponent(
|
||||
JSON.stringify(chatDBexecuteSql2),
|
||||
)}')`,
|
||||
)
|
||||
webview.evalJS(
|
||||
`operateSQLite('${encodeURIComponent(
|
||||
JSON.stringify(chatDBSelectSql),
|
||||
)}')`,
|
||||
)
|
||||
webview.evalJS(
|
||||
`operateSQLite('${encodeURIComponent(
|
||||
JSON.stringify(chatDBIsOpenDatabase),
|
||||
)}')`,
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
testDatabase()
|
||||
|
||||
const dialogueList = useStorage('dialogueList', [], uniStorage)
|
||||
// const dialogueList = ref([])
|
||||
const zpagingRef = ref()
|
||||
@ -32,7 +130,7 @@ export const useDialogueListStore = createGlobalState(() => {
|
||||
talk: {
|
||||
username: dialogue.talk.username,
|
||||
talk_type: dialogue.talk.talk_type,
|
||||
receiver_id: dialogue.talk.receiver_id
|
||||
receiver_id: dialogue.talk.receiver_id,
|
||||
},
|
||||
online: dialogue.online,
|
||||
records: dialogue.records || [],
|
||||
@ -43,7 +141,7 @@ export const useDialogueListStore = createGlobalState(() => {
|
||||
isDismiss: dialogue.isDismiss,
|
||||
isQuit: dialogue.isQuit,
|
||||
unreadNum: dialogue.unreadNum,
|
||||
members: dialogue.members.map(member => ({
|
||||
members: dialogue.members.map((member) => ({
|
||||
id: member.id,
|
||||
nickname: member.nickname,
|
||||
avatar: member.avatar,
|
||||
@ -55,9 +153,9 @@ export const useDialogueListStore = createGlobalState(() => {
|
||||
key: member.key,
|
||||
erp_user_id: member.erp_user_id,
|
||||
is_mute: member.is_mute,
|
||||
is_mine: member.is_mine
|
||||
is_mine: member.is_mine,
|
||||
})),
|
||||
forwardType: dialogue.forwardType
|
||||
forwardType: dialogue.forwardType,
|
||||
}
|
||||
dialogueList.value.push(newDialogue)
|
||||
} else {
|
||||
|
100
src/store/modules/sqlite.js
Normal file
100
src/store/modules/sqlite.js
Normal file
@ -0,0 +1,100 @@
|
||||
// 初始化数据库
|
||||
export const initDatabase = async () => {
|
||||
try {
|
||||
const isOpen = await plus.sqlite.isOpenDatabase({
|
||||
name: 'chat',
|
||||
path: '_doc/chat.db'
|
||||
})
|
||||
|
||||
if (!isOpen) {
|
||||
await plus.sqlite.openDatabase({
|
||||
name: 'chat',
|
||||
path: '_doc/chat.db'
|
||||
})
|
||||
|
||||
await plus.sqlite.executeSql({
|
||||
name: 'chat',
|
||||
sql: `
|
||||
CREATE TABLE IF NOT EXISTS talk_records (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
msg_id TEXT NOT NULL,
|
||||
sequence INTEGER NOT NULL,
|
||||
talk_type INTEGER NOT NULL DEFAULT 1,
|
||||
msg_type INTEGER NOT NULL DEFAULT 1,
|
||||
user_id INTEGER NOT NULL DEFAULT 0,
|
||||
receiver_id INTEGER NOT NULL DEFAULT 0,
|
||||
is_revoke INTEGER NOT NULL DEFAULT 0,
|
||||
is_mark INTEGER NOT NULL DEFAULT 0,
|
||||
quote_id TEXT NOT NULL,
|
||||
extra TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
biz_date TEXT
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uk_msgid ON talk_records(msg_id);
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_user_id_receiver_id_sequence ON talk_records(user_id, receiver_id, sequence);
|
||||
CREATE INDEX IF NOT EXISTS idx_receiver_id ON talk_records(receiver_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_created_at ON talk_records(created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_updated_at ON talk_records(updated_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_biz_date ON talk_records(biz_date);
|
||||
`
|
||||
})
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('数据库初始化失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 添加消息记录
|
||||
export const sqlAddRecord = async (message) => {
|
||||
try {
|
||||
await plus.sqlite.executeSql({
|
||||
name: 'chat',
|
||||
sql: `INSERT INTO talk_records (
|
||||
msg_id, sequence, talk_type, msg_type, user_id, receiver_id,
|
||||
is_revoke, is_mark, quote_id, extra, created_at, updated_at, biz_date
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
args: [
|
||||
message.msg_id,
|
||||
message.sequence,
|
||||
message.talk_type,
|
||||
message.msg_type,
|
||||
message.user_id,
|
||||
message.receiver_id,
|
||||
message.is_revoke || 0,
|
||||
message.is_mark || 0,
|
||||
message.quote_id || '',
|
||||
JSON.stringify(message.extra),
|
||||
message.created_at,
|
||||
message.updated_at,
|
||||
message.biz_date
|
||||
]
|
||||
})
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('添加消息失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 查询消息记录
|
||||
export const sqlGetRecord = async (receiverId, page = 1, pageSize = 20) => {
|
||||
try {
|
||||
const result = await plus.sqlite.selectSql({
|
||||
name: 'chat',
|
||||
sql: `SELECT * FROM talk_records
|
||||
WHERE receiver_id = ?
|
||||
ORDER BY sequence DESC
|
||||
LIMIT ? OFFSET ?`,
|
||||
args: [receiverId, pageSize, (page - 1) * pageSize]
|
||||
})
|
||||
return result
|
||||
} catch (error) {
|
||||
console.error('查询消息失败:', error)
|
||||
return []
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user