老产品前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.5 KiB

4 years ago
import Vue from "vue";
import Vuex from "vuex";
import cloneDeep from "lodash/cloneDeep";
import user from "./modules/user";
import app from "./modules/app";
import tagsView from "./modules/tagsView";
3 years ago
import { requestPost } from "@/js/dai/request";
3 years ago
import { dateFormats } from "@/utils/index";
4 years ago
4 years ago
Vue.use(Vuex);
3 years ago
let interTimer = null
4 years ago
export default new Vuex.Store({
namespaced: true,
state: {
// 导航条, 布局风格, defalut(白色) / colorful(鲜艳)
4 years ago
navbarLayoutType: "colorful",
4 years ago
// 侧边栏, 布局皮肤, default(白色) / dark(黑色)
4 years ago
sidebarLayoutSkin: "dark",
4 years ago
// 侧边栏, 折叠状态
sidebarFold: false,
// 侧边栏, 菜单
sidebarMenuList: [],
4 years ago
sidebarMenuActiveName: "",
LevelOneMenuActiveName: "",
4 years ago
sidebarActiveSubMenuList: [],
// 内容, 是否需要刷新
contentIsNeedRefresh: false,
// 内容, 标签页(默认添加首页)
contentTabs: [
{
4 years ago
...window.SITE_CONFIG["contentTabDefault"],
4 years ago
name: "indexWork",
4 years ago
title: "首页",
4 years ago
},
4 years ago
],
4 years ago
contentTabsActiveName: "indexWork",
4 years ago
mainShuju: {
menuList: [],
activeName: "",
},
3 years ago
tipsList: [],
3 years ago
tipsTime: [],
4 years ago
inIframe: window.self !== window.top,
4 years ago
},
modules: {
user,
app,
4 years ago
tagsView,
4 years ago
},
mutations: {
// 重置vuex本地储存状态
4 years ago
resetStore(state) {
4 years ago
Object.keys(state).forEach((key) => {
4 years ago
state[key] = cloneDeep(window.SITE_CONFIG["storeState"][key]);
});
},
3 years ago
SET_TIPS_LIST(state, tipsList) {
let _list = state.tipsList
3 years ago
// state.tipsList = _list.concat(tipsList)
state.tipsList = tipsList
3 years ago
},
SET_TIPS_TIME(state, time) {
state.tipsTime = time
}
4 years ago
},
3 years ago
actions: {
3 years ago
clearInter() {
clearInterval(interTimer)
},
setInterval({ commit, dispatch, state }) {
interTimer = setInterval(() => {
const _t = dateFormats('YYYY-mm-dd HH:MM', (new Date(new Date().toLocaleDateString()).getTime()))
const _tt = new Date(_t).getTime()
console.log('230000---', _t)
const t = dateFormats('YYYY-mm-dd HH:MM', (new Date().getTime()))
const nt = new Date(t).getTime()
// 判断当前时间是否为 00:00
if (nt == _tt) {
dispatch('setTipsTime')
return
}
let times = state.tipsTime
console.log('nt---000', nt)
state.tipsTime.forEach((item, index) => {
const _t = new Date(item).getTime()
if (_t == nt) {
clearInterval(interTimer)
dispatch('setTipsList', item)
times.splice(index, 1)
commit('SET_TIPS_TIME', times)
}
})
}, 10000)
},
3 years ago
setTipsList({ commit }, time) {
return new Promise(async (resolve, reject) => {
const url = '/gov/project/memoAttr/memosToRemind'
const params = {
remindTime: time || ''
}
const { data, code, msg } = await requestPost(url, params)
if (code === 0) {
commit('SET_TIPS_LIST', data)
resolve()
} else reject(msg)
})
},
3 years ago
setTipsTime({ commit, dispatch }) {
3 years ago
return new Promise(async (resolve, reject) => {
3 years ago
if (interTimer) clearInterval(interTimer)
3 years ago
const url = '/gov/project/memoAttr/memoTime'
const { data, code, msg } = await requestPost(url)
if (code === 0) {
3 years ago
3 years ago
commit('SET_TIPS_TIME', data)
3 years ago
if (data.length > 0) dispatch('setInterval')
3 years ago
resolve()
} else reject(msg)
})
}
}
4 years ago
});