更新
This commit is contained in:
@@ -6,31 +6,31 @@ import {
|
|||||||
noticeCount,
|
noticeCount,
|
||||||
noticeList,
|
noticeList,
|
||||||
noticeRead,
|
noticeRead,
|
||||||
noticeRemove
|
noticeRemove,
|
||||||
} from '@/api/news.js'
|
} from "@/api/news.js";
|
||||||
import website from '@/config/website.js'
|
import website from "@/config/website.js";
|
||||||
const size = 20
|
const size = 20;
|
||||||
const handler = {
|
const handler = {
|
||||||
'0': {
|
0: {
|
||||||
count: noticeCount,
|
count: noticeCount,
|
||||||
getList: noticeList,
|
getList: noticeList,
|
||||||
read: noticeRead,
|
read: noticeRead,
|
||||||
remove: noticeRemove
|
remove: noticeRemove,
|
||||||
},
|
},
|
||||||
'1': {
|
1: {
|
||||||
count: inviteCount,
|
count: inviteCount,
|
||||||
getList: inviteList,
|
getList: inviteList,
|
||||||
read: inviteRead,
|
read: inviteRead,
|
||||||
remove: inviteRemove
|
remove: inviteRemove,
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
function getCount(data) {
|
function getCount(data) {
|
||||||
let sum = 0
|
let sum = 0;
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
sum += data[key]
|
sum += data[key];
|
||||||
}
|
}
|
||||||
return sum
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
let refreshTimer = null;
|
let refreshTimer = null;
|
||||||
@@ -42,101 +42,104 @@ function startRefreshToken(dispatch) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stopRefreshToken() {
|
function stopRefreshToken() {
|
||||||
clearInterval(refreshTimer)
|
clearInterval(refreshTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const news = {
|
const news = {
|
||||||
state: {
|
state: {
|
||||||
count: 0,
|
count: 0,
|
||||||
data: {
|
data: {
|
||||||
"0": {
|
0: {
|
||||||
id: "0",
|
id: "0",
|
||||||
title: "消息通知",
|
title: "消息通知",
|
||||||
icon: "../../../static/img/notice.svg",
|
icon: "../../../static/img/notice.svg",
|
||||||
page: {
|
page: {
|
||||||
current: 0,
|
current: 0,
|
||||||
size,
|
size,
|
||||||
total: size
|
total: size,
|
||||||
},
|
},
|
||||||
data: [],
|
data: [],
|
||||||
prop: {
|
prop: {
|
||||||
title: 'title',
|
title: "title",
|
||||||
desc: (value) => {
|
desc: (value) => {
|
||||||
if (value.data[0])
|
if (value.data[0]) return value.data[0][0]["desc"];
|
||||||
return value.data[0][0]['desc']
|
|
||||||
},
|
},
|
||||||
time: 'createTime',
|
time: "createTime",
|
||||||
isRead: 'isRead',
|
isRead: "isRead",
|
||||||
listDesc: 'desc',
|
listDesc: "desc",
|
||||||
},
|
},
|
||||||
navigateTo(item) {
|
navigateTo(item) {
|
||||||
uni.$once('getNewsDetail', (cb) => {
|
uni.$once("getNewsDetail", (cb) => {
|
||||||
cb(item)
|
cb(item);
|
||||||
})
|
});
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: "/pages/news/newsDetail?type=0"
|
url: "/pages/news/newsDetail?type=0",
|
||||||
})
|
});
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"1": {
|
},
|
||||||
|
1: {
|
||||||
id: "1",
|
id: "1",
|
||||||
title: "任务申请",
|
title: "任务申请",
|
||||||
icon: "../../../static/img/renwu.png",
|
icon: "../../../static/img/renwu.png",
|
||||||
page: {
|
page: {
|
||||||
current: 0,
|
current: 0,
|
||||||
size,
|
size,
|
||||||
total: size
|
total: size,
|
||||||
},
|
},
|
||||||
data: [],
|
data: [],
|
||||||
prop: {
|
prop: {
|
||||||
title: 'missionTitle',
|
title: "missionTitle",
|
||||||
desc: (value) => {
|
desc: (value) => {
|
||||||
if (value.data[0])
|
if (value.data[0])
|
||||||
return `您收到${value.data[0][0]['companyName']}的任务`
|
return `您收到${value.data[0][0]["companyName"]}的任务`;
|
||||||
},
|
},
|
||||||
time: 'createTime',
|
time: "createTime",
|
||||||
isRead: 'status',
|
isRead: "status",
|
||||||
listDesc: 'companyName',
|
listDesc: "companyName",
|
||||||
},
|
},
|
||||||
navigateTo(item, dispatch) {
|
navigateTo(item, dispatch) {
|
||||||
dispatch('readNew', {
|
dispatch("readNew", {
|
||||||
key: '1',
|
key: "1",
|
||||||
id: item.id
|
id: item.id,
|
||||||
})
|
});
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(item.missionNo)}&id=${encodeURIComponent(item.id)}`
|
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(
|
||||||
})
|
item.missionNo
|
||||||
}
|
)}&id=${encodeURIComponent(item.id)}`,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
"2": {
|
},
|
||||||
|
2: {
|
||||||
id: "1",
|
id: "1",
|
||||||
title: "岗位申请",
|
title: "岗位申请",
|
||||||
icon: "../../../static/img/job_recruit.svg",
|
icon: "../../../static/img/job_recruit.svg",
|
||||||
page: {
|
page: {
|
||||||
current: 0,
|
current: 0,
|
||||||
size,
|
size,
|
||||||
total: size
|
total: size,
|
||||||
},
|
},
|
||||||
data: [],
|
data: [],
|
||||||
prop: {
|
prop: {
|
||||||
title: 'missionTitle',
|
title: "missionTitle",
|
||||||
desc: (value) => {
|
desc: (value) => {
|
||||||
if (value.data[0])
|
if (value.data[0])
|
||||||
return `您收到${value.data[0][0]['companyName']}的任务`
|
return `您收到${value.data[0][0]["companyName"]}的任务`;
|
||||||
},
|
},
|
||||||
time: 'createTime',
|
time: "createTime",
|
||||||
isRead: 'status',
|
isRead: "status",
|
||||||
listDesc: 'companyName',
|
listDesc: "companyName",
|
||||||
},
|
},
|
||||||
navigateTo(item, dispatch) {
|
navigateTo(item, dispatch) {
|
||||||
dispatch('readNew', {
|
dispatch("readNew", {
|
||||||
key: '1',
|
key: "1",
|
||||||
id: item.id
|
id: item.id,
|
||||||
})
|
});
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(item.missionNo)}&id=${encodeURIComponent(item.id)}`
|
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(
|
||||||
})
|
item.missionNo
|
||||||
}
|
)}&id=${encodeURIComponent(item.id)}`,
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// "3": {
|
// "3": {
|
||||||
// id: "1",
|
// id: "1",
|
||||||
@@ -168,206 +171,167 @@ const news = {
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
"4": {
|
4: {
|
||||||
id: "1",
|
id: "1",
|
||||||
title: "个人户申请",
|
title: "个人户申请",
|
||||||
icon: "../../../static/img/own_recruit.svg",
|
icon: "../../../static/img/own_recruit.svg",
|
||||||
page: {
|
page: {
|
||||||
current: 0,
|
current: 0,
|
||||||
size,
|
size,
|
||||||
total: size
|
total: size,
|
||||||
},
|
},
|
||||||
data: [],
|
data: [],
|
||||||
prop: {
|
prop: {
|
||||||
title: 'missionTitle',
|
title: "missionTitle",
|
||||||
desc: (value) => {
|
desc: (value) => {
|
||||||
if (value.data[0])
|
if (value.data[0])
|
||||||
return `您收到${value.data[0][0]['companyName']}的任务`
|
return `您收到${value.data[0][0]["companyName"]}的任务`;
|
||||||
},
|
},
|
||||||
time: 'createTime',
|
time: "createTime",
|
||||||
isRead: 'status',
|
isRead: "status",
|
||||||
listDesc: 'companyName',
|
listDesc: "companyName",
|
||||||
},
|
},
|
||||||
navigateTo(item, dispatch) {
|
navigateTo(item, dispatch) {
|
||||||
dispatch('readNew', {
|
dispatch("readNew", {
|
||||||
key: '1',
|
key: "1",
|
||||||
id: item.id
|
id: item.id,
|
||||||
})
|
});
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(item.missionNo)}&id=${encodeURIComponent(item.id)}`
|
url: `/pages/projectInfo/projectInfo?type=1&missionNo=${encodeURIComponent(
|
||||||
})
|
item.missionNo
|
||||||
}
|
)}&id=${encodeURIComponent(item.id)}`,
|
||||||
}
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
unread: {
|
unread: {
|
||||||
"0": 0,
|
0: 0,
|
||||||
"1": 0
|
1: 0,
|
||||||
},
|
},
|
||||||
allUnread: 0,
|
allUnread: 0,
|
||||||
dic: {}
|
dic: {},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
newsInit({
|
newsInit({ dispatch }) {
|
||||||
dispatch
|
const ps = [];
|
||||||
}) {
|
ps.push(dispatch("getUnreadNum"));
|
||||||
const ps = []
|
|
||||||
ps.push(dispatch('getUnreadNum'))
|
|
||||||
|
|
||||||
for (let key in handler) {
|
for (let key in handler) {
|
||||||
ps.push(dispatch('newsReload', key))
|
ps.push(dispatch("newsReload", key));
|
||||||
}
|
}
|
||||||
return Promise.all(ps)
|
return Promise.all(ps);
|
||||||
},
|
},
|
||||||
newsReload({
|
newsReload({ dispatch, commit }, id) {
|
||||||
dispatch,
|
commit("CLEAR_NEWS_DATA", id);
|
||||||
commit
|
return dispatch("newsGetNextPage", id);
|
||||||
}, id) {
|
|
||||||
commit('CLEAR_NEWS_DATA', id)
|
|
||||||
return dispatch('newsGetNextPage', id)
|
|
||||||
},
|
},
|
||||||
getUnreadNum({
|
getUnreadNum({ commit }) {
|
||||||
commit
|
|
||||||
}) {
|
|
||||||
for (let key in handler) {
|
for (let key in handler) {
|
||||||
handler[key].count().then((result) => {
|
handler[key].count().then((result) => {
|
||||||
commit('SET_UNREADNUM', {
|
commit("SET_UNREADNUM", {
|
||||||
id: key,
|
id: key,
|
||||||
count: result
|
count: result,
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
newsGetNextPage({
|
newsGetNextPage({ state, commit }, id) {
|
||||||
state,
|
const item = state.data[id];
|
||||||
commit
|
const page = item.page;
|
||||||
}, id) {
|
const current = page.current + 1;
|
||||||
const item = state.data[id]
|
|
||||||
const page = item.page
|
|
||||||
const current = page.current + 1
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (parseInt(page.total / page.size) + 1 < current) {
|
if (parseInt(page.total / page.size) + 1 < current) {
|
||||||
resolve()
|
resolve();
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
handler[id].getList(current, page.size).then(res => {
|
handler[id]
|
||||||
|
.getList(current, page.size)
|
||||||
|
.then((res) => {
|
||||||
const data = res.data.data;
|
const data = res.data.data;
|
||||||
commit('ADD_NEWS_DATA', {
|
commit("ADD_NEWS_DATA", {
|
||||||
id,
|
id,
|
||||||
data: data.records,
|
data: data.records,
|
||||||
current,
|
current,
|
||||||
total: data.total
|
total: data.total,
|
||||||
})
|
});
|
||||||
resolve(res)
|
resolve(res);
|
||||||
}).catch(reject)
|
|
||||||
})
|
})
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
removeNew({
|
removeNew({ commit }, { id, key, group, index }) {
|
||||||
commit
|
return new Promise((resolve, reject) => {
|
||||||
}, {
|
commit("REMOVE_NEWS", {
|
||||||
id,
|
id,
|
||||||
key,
|
key,
|
||||||
group,
|
group,
|
||||||
index
|
index,
|
||||||
}) {
|
});
|
||||||
return new Promise((resolve, reject) => {
|
handler[key].remove(id).then(resolve, reject);
|
||||||
commit('REMOVE_NEWS', {
|
});
|
||||||
id,
|
|
||||||
key,
|
|
||||||
group,
|
|
||||||
index
|
|
||||||
})
|
|
||||||
handler[key].remove(id).then(resolve, reject)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
readNew({
|
readNew({ commit }, { key, id }) {
|
||||||
commit
|
|
||||||
}, {
|
|
||||||
key,
|
|
||||||
id
|
|
||||||
}) {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
commit('READ_NEWS', {
|
commit("READ_NEWS", {
|
||||||
key,
|
key,
|
||||||
id
|
id,
|
||||||
})
|
});
|
||||||
handler[key].read(id).then(resolve, reject)
|
handler[key].read(id).then(resolve, reject);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
endRefreshNewsTimer() {
|
endRefreshNewsTimer() {
|
||||||
stopRefreshToken()
|
stopRefreshToken();
|
||||||
},
|
},
|
||||||
startRefreshNewsTimer({
|
startRefreshNewsTimer({ state, commit, dispatch }) {
|
||||||
state,
|
dispatch("newsInit").then(() => {
|
||||||
commit,
|
|
||||||
dispatch
|
|
||||||
}) {
|
|
||||||
dispatch('newsInit').then(() => {
|
|
||||||
startRefreshToken(dispatch);
|
startRefreshToken(dispatch);
|
||||||
})
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
SET_UNREADNUM: (state, {
|
SET_UNREADNUM: (state, { id, count }) => {
|
||||||
id,
|
state.unread[id] = count;
|
||||||
count
|
state.allUnread = getCount(state.unread);
|
||||||
}) => {
|
|
||||||
state.unread[id] = count
|
|
||||||
state.allUnread = getCount(state.unread)
|
|
||||||
},
|
},
|
||||||
CLEAR_NEWS_DATA: (state, id) => {
|
CLEAR_NEWS_DATA: (state, id) => {
|
||||||
state.data[id]?.page = {
|
state.data[id].page = {
|
||||||
current: 0,
|
current: 0,
|
||||||
size
|
size,
|
||||||
}
|
};
|
||||||
state.data[id].data = []
|
state.data[id].data = [];
|
||||||
},
|
},
|
||||||
ADD_NEWS_DATA: (state, {
|
ADD_NEWS_DATA: (state, { id, data, current, total }) => {
|
||||||
id,
|
data.forEach((item) => {
|
||||||
data,
|
state.dic[item.id] = item;
|
||||||
current,
|
});
|
||||||
total
|
state.data[id].page.total = total;
|
||||||
}) => {
|
state.data[id].page.current = current;
|
||||||
data.forEach(item => {
|
|
||||||
state.dic[item.id] = item
|
|
||||||
})
|
|
||||||
state.data[id].page.total = total
|
|
||||||
state.data[id].page.current = current
|
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
state.data[id].data.push(data)
|
state.data[id].data.push(data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
REMOVE_NEWS: (state, {
|
REMOVE_NEWS: (state, { id, key, group, index }) => {
|
||||||
id,
|
const readProp = state.data[key].prop["isRead"];
|
||||||
key,
|
|
||||||
group,
|
|
||||||
index
|
|
||||||
}) => {
|
|
||||||
const readProp = state.data[key].prop['isRead']
|
|
||||||
if (state.dic[id][readProp] === 0) {
|
if (state.dic[id][readProp] === 0) {
|
||||||
state.unread[key]--
|
state.unread[key]--;
|
||||||
state.allUnread--
|
state.allUnread--;
|
||||||
}
|
}
|
||||||
state.dic[id] = undefined
|
state.dic[id] = undefined;
|
||||||
const data = state.data[key].data
|
const data = state.data[key].data;
|
||||||
data[group].splice(index, 1)
|
data[group].splice(index, 1);
|
||||||
if (data[group].length === 0) {
|
if (data[group].length === 0) {
|
||||||
data.splice(group, 1)
|
data.splice(group, 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
READ_NEWS: (state, {
|
READ_NEWS: (state, { key, id }) => {
|
||||||
key,
|
const readProp = state.data[key].prop["isRead"];
|
||||||
id
|
|
||||||
}) => {
|
|
||||||
const readProp = state.data[key].prop['isRead']
|
|
||||||
if (state.dic[id][readProp] === 0) {
|
if (state.dic[id][readProp] === 0) {
|
||||||
state.dic[id][readProp] = 1
|
state.dic[id][readProp] = 1;
|
||||||
state.unread[key]--
|
state.unread[key]--;
|
||||||
state.allUnread--
|
state.allUnread--;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
},
|
||||||
|
getters: {},
|
||||||
}
|
|
||||||
};
|
};
|
||||||
export default news;
|
export default news;
|
||||||
|
|||||||
Reference in New Issue
Block a user