123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- import {getUserInfo} from "@/api/modules/account";
- import {getSignTime, getSignSearch} from "@/api/modules/sign";
- import {ElMessage} from "element-plus";
- import {getSeatDutyPersonSearch} from "@/api/modules/seat";
- import {getConfigConfigKey, editConfigEditConfigKey} from "@/api/modules/config";
- import * as Handle from "@/views/staging/common/handle";
- import {YMD, YMDHms} from '@/utils/util'
- import {getDailyReportSearch} from "@/api/modules/daily";
- import {getWeekReportSearch} from "@/api/modules/weekly";
- const state = {
- apiProxy: {
- ztptApi: 'api-ztpt', // 总体平台基本接口
- },
- userInfo: <any>{},
- userRoleList: [],
- timestamp: new Date().getTime(),
- tempTimestamp: new Date().getTime(),
- weekStart: 6, // 日历起始日期,周六
- weeklySubmitDay: 5, // 周报提交日期,周五
- dutyInfo: {},
- publicConfig: {
- 'sign.begin.time': '',
- 'sign.remind.time': '',
- 'sign.end.time': '',
- 'log.submit.time': '',
- 'log.remind.time': '',
- 'week.submit.date': '',
- 'week.submit.time': '',
- 'week.remind.time': '',
- },
- signInfo: null,
- dailyInfo: null,
- weeklyInfo: null,
- projectFirstDate: new Date(window.cusConfig.projectFirstDate),
- }
- const getters = {
- isZBY: (state) => {
- return state.userRoleList.some(v => v.permissionValue === 'ZBY')
- },
- isZBGL: (state) => {
- return state.userRoleList.some(v => v.permissionValue === 'ZBGL')
- },
- userRoleStr: (state) => {
- return state.userRoleList.map(v => v.permissionValue).join(',')
- },
- isWeeklyDay: (state) => {
- return new Date(state.timestamp).getDay() === state.weeklySubmitDay
- },
- yearWeeks: (state) => {
- const arr: any = []
- const map = new Map()
- let index = 0
- for (let year = state.projectFirstDate.getFullYear(); year <= new Date(state.timestamp).getFullYear(); year++) {
- let num = 1
- let firstWeeklyDate = new Date(year, 0, 1)
- while (firstWeeklyDate.getDay() !== state.weeklySubmitDay) {
- firstWeeklyDate = new Date(firstWeeklyDate.getTime() + Handle.oneDayTime)
- }
- let start = new Date(firstWeeklyDate.getTime() - Handle.oneDayTime * 6)
- while (new Date(start).getTime() < new Date(year + 1, 0, 1).getTime()) {
- const end = new Date(start).getTime() + Handle.oneDayTime * 6
- if (end >= state.projectFirstDate.getTime() && end <= state.timestamp) {
- const obj = {
- index: index,
- date: [new Date(start), new Date(end)],
- dateStr: [YMD(new Date(start)), YMD(new Date(end))],
- yearWeekStr: `${year}年第${num}周`,
- weekStr: `第${num}周`,
- yearWeekSelectValue: `${year}年第${num}周(${YMD(start)}~${YMD(end)})`,
- weekSelectValue: `第${num}周(${YMD(start)}~${YMD(end)})`,
- isToday: (new Date(start).getTime() <= new Date(state.timestamp).getTime()) && (new Date(end + Handle.oneDayTime).getTime() > new Date(state.timestamp).getTime()),
- year: year,
- week: num,
- id: `${year}_${num}`
- }
- arr.push(obj)
- map.set(obj.id, obj)
- index++
- }
- start = new Date(end + Handle.oneDayTime)
- num++
- }
- }
- return {
- list: arr, map: map
- }
- }
- }
- const mutations = {
- SET_USER_INFO(state: any, data: any) {
- state.userInfo = data
- state.userRoleList = data.roles
- },
- SET_TIMESTAMP(state: any, data: any) {
- state.timestamp = new Date(data).getTime()
- state.tempTimestamp = new Date(data).getTime()
- setInterval(() => {
- state.timestamp += 1000
- if (new Date(state.tempTimestamp).getDay() !== new Date(state.timestamp).getDay()) {
- state.tempTimestamp = new Date(state.timestamp).getTime()
- state.signInfo = null
- }
- }, 1000)
- },
- SET_DUTY_INFO(state: any, data: any) {
- state.dutyInfo = data
- },
- SET_PUBLIC_CONFIG(state: any, {data, key}) {
- state.publicConfig[key] = data
- },
- SET_SIGN_INFO(state: any, data) {
- state.signInfo = data
- },
- SET_DAILY_INFO(state: any, data) {
- state.dailyInfo = data
- },
- SET_WEEKLY_INFO(state: any, data) {
- state.weeklyInfo = data
- },
- }
- const actions = {
- LOAD_USER_INFO({ commit }: any, refresh: boolean = false) {
- return new Promise((resolve, reject) => {
- if (refresh || !state.userInfo?.id) {
- getUserInfo().then((res) => {
- if (res.code === 200) {
- commit('SET_USER_INFO', res.data)
- resolve(res.data)
- } else {
- reject(res.message)
- }
- })
- } else {
- resolve(state.userInfo)
- }
- })
- },
- LOAD_TIMESTAMP({ commit }: any) {
- getSignTime().then((res) => {
- if (res.code === 200) {
- commit('SET_TIMESTAMP', new Date(res.data))
- } else {
- ElMessage.error(res.message)
- }
- })
- },
- LOAD_DUTY_INFO({ commit }: any) {
- getSeatDutyPersonSearch().then((res) => {
- if (res.code === 200) {
- if (res.data) {
- commit('SET_DUTY_INFO', res.data)
- } else {
- ElMessage.error('缺少值班人员')
- }
- } else {
- ElMessage.error(res.message)
- }
- })
- },
- LOAD_PUBLIC_CONFIG({ commit }: any, {key, value}) {
- const initKey = (k, resolve) => {
- getConfigConfigKey(k).then((res) => {
- if (res.code === 200) {
- commit('SET_PUBLIC_CONFIG', {key: k, data: res.message})
- resolve(res.message)
- } else {
- ElMessage.error(res.message)
- }
- })
- }
- return new Promise((resolve, reject) => {
- if (value) {
- editConfigEditConfigKey({
- configKey: key,
- configValue: value
- }).then(res => {
- if (res.code === 200) {
- ElMessage.success(res.message)
- initKey(key, resolve)
- } else {
- ElMessage.error(res.message)
- }
- })
- } else {
- initKey(key, resolve)
- }
- })
- },
- LOAD_SIGN_INFO({ commit }: any) {
- return new Promise((resolve, reject) => {
- getSignSearch().then((res) => {
- if (res.code === 200) {
- commit('SET_SIGN_INFO', res.data)
- resolve(res.message)
- } else {
- ElMessage.error(res.message)
- }
- })
- })
- },
- LOAD_DAILY_INFO({ commit }: any) {
- return new Promise((resolve, reject) => {
- getDailyReportSearch().then((res) => {
- if (res.code === 200) {
- commit('SET_DAILY_INFO', res.data)
- resolve(res.message)
- } else {
- ElMessage.error(res.message)
- }
- })
- })
- },
- LOAD_WEEKLY_INFO({ commit }: any) {
- return new Promise((resolve, reject) => {
- getWeekReportSearch({
- year: getters.yearWeeks(state).list[getters.yearWeeks(state).list.length - 1]?.year,
- weekTime: getters.yearWeeks(state).list[getters.yearWeeks(state).list.length - 1]?.week,
- }).then((res) => {
- if (res.code === 200) {
- commit('SET_WEEKLY_INFO', res.data)
- resolve(res.message)
- } else {
- ElMessage.error(res.message)
- }
- })
- })
- },
- }
- export default {
- namespaced: true,
- state,
- getters,
- mutations,
- actions
- }
|