app.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import {getUserInfo} from "@/api/modules/account";
  2. import {getSignTime, getSignSearch} from "@/api/modules/sign";
  3. import {ElMessage} from "element-plus";
  4. import {getSeatDutyPersonSearch} from "@/api/modules/seat";
  5. import {getConfigConfigKey, editConfigEditConfigKey} from "@/api/modules/config";
  6. import * as Handle from "@/views/staging/common/handle";
  7. import {YMD, YMDHms} from '@/utils/util'
  8. import {getDailyReportSearch} from "@/api/modules/daily";
  9. import {getWeekReportSearch} from "@/api/modules/weekly";
  10. const state = {
  11. apiProxy: {
  12. ztptApi: 'api-ztpt', // 总体平台基本接口
  13. },
  14. userInfo: <any>{},
  15. userRoleList: [],
  16. timestamp: new Date().getTime(),
  17. tempTimestamp: new Date().getTime(),
  18. weekStart: 6, // 日历起始日期,周六
  19. weeklySubmitDay: 5, // 周报提交日期,周五
  20. dutyInfo: {},
  21. publicConfig: {
  22. 'sign.begin.time': '',
  23. 'sign.remind.time': '',
  24. 'sign.end.time': '',
  25. 'log.submit.time': '',
  26. 'log.remind.time': '',
  27. 'week.submit.date': '',
  28. 'week.submit.time': '',
  29. 'week.remind.time': '',
  30. },
  31. signInfo: null,
  32. dailyInfo: null,
  33. weeklyInfo: null,
  34. projectFirstDate: new Date('2023-11-24 00:00:00'),
  35. }
  36. const getters = {
  37. isZBY: (state) => {
  38. return state.userRoleList.some(v => v.permissionValue === 'ZBY')
  39. },
  40. isZBGL: (state) => {
  41. return state.userRoleList.some(v => v.permissionValue === 'ZBGL')
  42. },
  43. userRoleStr: (state) => {
  44. return state.userRoleList.map(v => v.permissionValue).join(',')
  45. },
  46. isWeeklyDay: (state) => {
  47. return new Date(state.timestamp).getDay() === state.weeklySubmitDay
  48. },
  49. yearWeeks: (state) => {
  50. const arr: any = []
  51. const map = new Map()
  52. let index = 0
  53. for (let year = state.projectFirstDate.getFullYear(); year <= new Date(state.timestamp).getFullYear(); year++) {
  54. let num = 1
  55. let firstWeeklyDate = new Date(year, 0, 1)
  56. while (firstWeeklyDate.getDay() !== state.weeklySubmitDay) {
  57. firstWeeklyDate = new Date(firstWeeklyDate.getTime() + Handle.oneDayTime)
  58. }
  59. let start = new Date(firstWeeklyDate.getTime() - Handle.oneDayTime * 6)
  60. while (new Date(start).getTime() < new Date(year + 1, 0, 1).getTime()) {
  61. const end = new Date(start).getTime() + Handle.oneDayTime * 6
  62. if (end >= state.projectFirstDate.getTime() && end <= state.timestamp) {
  63. const obj = {
  64. index: index,
  65. date: [new Date(start), new Date(end)],
  66. dateStr: [YMD(new Date(start)), YMD(new Date(end))],
  67. yearWeekStr: `${year}年第${num}周`,
  68. weekStr: `第${num}周`,
  69. yearWeekSelectValue: `${year}年第${num}周(${YMD(start)}~${YMD(end)})`,
  70. weekSelectValue: `第${num}周(${YMD(start)}~${YMD(end)})`,
  71. isToday: (new Date(start).getTime() <= new Date(state.timestamp).getTime()) && (new Date(end + Handle.oneDayTime).getTime() > new Date(state.timestamp).getTime()),
  72. year: year,
  73. week: num,
  74. id: `${year}_${num}`
  75. }
  76. arr.push(obj)
  77. map.set(obj.id, obj)
  78. index++
  79. }
  80. start = new Date(end + Handle.oneDayTime)
  81. num++
  82. }
  83. }
  84. return {
  85. list: arr, map: map
  86. }
  87. }
  88. }
  89. const mutations = {
  90. SET_USER_INFO(state: any, data: any) {
  91. state.userInfo = data
  92. state.userRoleList = data.roles
  93. },
  94. SET_TIMESTAMP(state: any, data: any) {
  95. state.timestamp = new Date(data).getTime()
  96. state.tempTimestamp = new Date(data).getTime()
  97. setInterval(() => {
  98. state.timestamp += 1000
  99. if (new Date(state.tempTimestamp).getDay() !== new Date(state.timestamp).getDay()) {
  100. state.tempTimestamp = new Date(state.timestamp).getTime()
  101. state.signInfo = null
  102. }
  103. }, 1000)
  104. },
  105. SET_DUTY_INFO(state: any, data: any) {
  106. state.dutyInfo = data
  107. },
  108. SET_PUBLIC_CONFIG(state: any, {data, key}) {
  109. state.publicConfig[key] = data
  110. },
  111. SET_SIGN_INFO(state: any, data) {
  112. state.signInfo = data
  113. },
  114. SET_DAILY_INFO(state: any, data) {
  115. state.dailyInfo = data
  116. },
  117. SET_WEEKLY_INFO(state: any, data) {
  118. state.weeklyInfo = data
  119. },
  120. }
  121. const actions = {
  122. LOAD_USER_INFO({ commit }: any, refresh: boolean = false) {
  123. return new Promise((resolve, reject) => {
  124. if (refresh || !state.userInfo?.id) {
  125. getUserInfo().then((res) => {
  126. if (res.code === 200) {
  127. commit('SET_USER_INFO', res.data)
  128. resolve(res.data)
  129. } else {
  130. reject(res.message)
  131. }
  132. })
  133. } else {
  134. resolve(state.userInfo)
  135. }
  136. })
  137. },
  138. LOAD_TIMESTAMP({ commit }: any) {
  139. getSignTime().then((res) => {
  140. if (res.code === 200) {
  141. commit('SET_TIMESTAMP', new Date(res.data))
  142. } else {
  143. ElMessage.error(res.message)
  144. }
  145. })
  146. },
  147. LOAD_DUTY_INFO({ commit }: any) {
  148. getSeatDutyPersonSearch().then((res) => {
  149. if (res.code === 200) {
  150. if (res.data) {
  151. commit('SET_DUTY_INFO', res.data)
  152. } else {
  153. ElMessage.error('缺少值班人员')
  154. }
  155. } else {
  156. ElMessage.error(res.message)
  157. }
  158. })
  159. },
  160. LOAD_PUBLIC_CONFIG({ commit }: any, {key, value}) {
  161. const initKey = (k, resolve) => {
  162. getConfigConfigKey(k).then((res) => {
  163. if (res.code === 200) {
  164. commit('SET_PUBLIC_CONFIG', {key: k, data: res.message})
  165. resolve(res.message)
  166. } else {
  167. ElMessage.error(res.message)
  168. }
  169. })
  170. }
  171. return new Promise((resolve, reject) => {
  172. if (value) {
  173. editConfigEditConfigKey({
  174. configKey: key,
  175. configValue: value
  176. }).then(res => {
  177. if (res.code === 200) {
  178. ElMessage.success(res.message)
  179. initKey(key, resolve)
  180. } else {
  181. ElMessage.error(res.message)
  182. }
  183. })
  184. } else {
  185. initKey(key, resolve)
  186. }
  187. })
  188. },
  189. LOAD_SIGN_INFO({ commit }: any) {
  190. return new Promise((resolve, reject) => {
  191. getSignSearch().then((res) => {
  192. if (res.code === 200) {
  193. commit('SET_SIGN_INFO', res.data)
  194. resolve(res.message)
  195. } else {
  196. ElMessage.error(res.message)
  197. }
  198. })
  199. })
  200. },
  201. LOAD_DAILY_INFO({ commit }: any) {
  202. return new Promise((resolve, reject) => {
  203. getDailyReportSearch().then((res) => {
  204. if (res.code === 200) {
  205. commit('SET_DAILY_INFO', res.data)
  206. resolve(res.message)
  207. } else {
  208. ElMessage.error(res.message)
  209. }
  210. })
  211. })
  212. },
  213. LOAD_WEEKLY_INFO({ commit }: any) {
  214. return new Promise((resolve, reject) => {
  215. getWeekReportSearch().then((res) => {
  216. if (res.code === 200) {
  217. commit('SET_WEEKLY_INFO', res.data)
  218. resolve(res.message)
  219. } else {
  220. ElMessage.error(res.message)
  221. }
  222. })
  223. })
  224. },
  225. }
  226. export default {
  227. namespaced: true,
  228. state,
  229. getters,
  230. mutations,
  231. actions
  232. }