flat: 消息

This commit is contained in:
史典卓
2025-05-15 14:17:51 +08:00
parent 5333254c58
commit a93907018c
40 changed files with 875 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
// BaseStore.js - 基础Store类
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
// import UniStorageHelper from '../common/UniStorageHelper'
import useChatGroupDBStore from './userChatGroupStore'
import config from '@/config'
@@ -29,7 +30,12 @@ class BaseStore {
}
}
initDB() {
// // #ifdef H5
this.db = new IndexedDBHelper(this.dbName, config.DBversion);
// // #endif
// // #ifndef H5
// this.db = new UniStorageHelper(this.dbName, config.DBversion);
// // #endif
this.db.openDB([{
name: 'record',
keyPath: "id",

View File

@@ -38,7 +38,8 @@ const useDictStore = defineStore("dict", () => {
sex: [],
affiliation: [],
industry: [],
nature: []
nature: [],
noticeType: []
})
// political_affiliation
const getDictData = async (dictType, dictName) => {
@@ -49,7 +50,8 @@ const useDictStore = defineStore("dict", () => {
return data
})
}
const [education, experience, area, scale, sex, affiliation, nature] = await Promise.all([
const [education, experience, area, scale, sex, affiliation, nature, noticeType] =
await Promise.all([
getDictSelectOption('education'),
getDictSelectOption('experience'),
getDictSelectOption('area', true),
@@ -57,6 +59,7 @@ const useDictStore = defineStore("dict", () => {
getDictSelectOption('app_sex'),
getDictSelectOption('political_affiliation'),
getDictSelectOption('company_nature'),
getDictSelectOption('sys_notice_type'),
]);
state.education = education;
@@ -66,6 +69,7 @@ const useDictStore = defineStore("dict", () => {
state.sex = sex;
state.affiliation = affiliation;
state.nature = nature
state.noticeType = noticeType
complete.value = true
getIndustryDict() // 获取行业
} catch (error) {

84
stores/useReadMsg.js Normal file
View File

@@ -0,0 +1,84 @@
// store/useReadMsg.js
import {
defineStore
} from 'pinia'
import {
ref,
computed,
watch
} from 'vue'
import {
msg,
$api,
} from '../common/globalFunction';
export const useReadMsg = defineStore('readMsg', () => {
const msgList = ref([])
// 计算总未读数量,基于 notReadCount 字段
const unreadCount = computed(() =>
msgList.value.reduce((sum, msg) => sum + (msg.notReadCount || 0), 0)
)
// 未读消息列表
const unreadMsgList = computed(() =>
msgList.value.filter(msg => msg.notReadCount > 0)
)
// 设置 TabBar 角标
function updateTabBarBadge() {
const count = unreadCount.value
if (count === 0) {
uni.removeTabBarBadge({
index: 3
}) // 替换为你消息页面的 TabBar index
} else {
uni.setTabBarBadge({
index: 3,
text: count > 99 ? '99+' : String(count)
})
}
}
// 拉取消息列表
async function fetchMessages() {
try {
$api.createRequest('/app/notice/info', {
isRead: 1
}, "GET").then((res) => {
msgList.value = res.data || []
updateTabBarBadge()
})
} catch (err) {
console.error('获取消息失败:', err)
}
}
// 设置为已读
async function markAsRead(item, index) {
const msg = msgList.value[index]
if (!msg || msg.isRead === 1) return
try {
let params = {
id: msg.noticeId
}
$api.createRequest('/app/notice/read?id=' + msg.noticeId, params, "POST").then((res) => {
msgList.value[index].isRead = 1
updateTabBarBadge()
})
} catch (err) {
console.error('设置消息已读失败:', err)
}
}
return {
msgList,
unreadMsgList,
unreadCount,
fetchMessages,
markAsRead,
updateTabBarBadge
}
})

View File

@@ -4,7 +4,6 @@ import {
import {
ref
} from 'vue'
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
import useDictStore from '@/stores/useDictStore';
import jobAnalyzer from '@/utils/jobAnalyzer';
import {

View File

@@ -6,11 +6,14 @@ import {
} from 'vue'
import {
createRequest
} from '../utils/request';
} from '@/utils/request';
import similarityJobs from '@/utils/similarity_Job.js';
import {
UUID
} from "@/lib/uuid-min.js";
import {
useReadMsg
} from '@/stores/useReadMsg';
// 简历完成度计算
function getResumeCompletionPercentage(resume) {
@@ -97,6 +100,8 @@ const useUserStore = defineStore("user", () => {
const loginSetToken = async (value) => {
token.value = value
uni.setStorageSync('token', value);
// 获取消息列表
useReadMsg().fetchMessages()
// 获取用户信息
return getUserResume()
}

View File

@@ -6,7 +6,6 @@ import {
ref,
toRaw
} from 'vue'
import IndexedDBHelper from '@/common/IndexedDBHelper.js'
import baseDB from './BaseDBStore';
import {
msg,