index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /**
  2. * @author chuzhixin 1204505056@qq.com
  3. * @description 导入所有 vuex 模块,自动加入namespaced:true,用于解决vuex命名冲突,请勿修改。
  4. */
  5. import { createStore } from 'vuex'
  6. import * as api from '@/api/publicList'
  7. import ElMessage from 'element-plus'
  8. const files = require.context('./modules', false, /\.js$/)
  9. const modules = {}
  10. files.keys().forEach((key) => {
  11. modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
  12. })
  13. Object.keys(modules).forEach((key) => {
  14. modules[key]['namespaced'] = true
  15. })
  16. export default createStore({
  17. modules,
  18. state: {
  19. query: null,
  20. siteId: 1, //公共api请求参数->siteId
  21. siteList: [], //公共api站点下拉列表存储->siteId
  22. deviceList: [], //公共站点下拉列表
  23. monthList: [], //公共每月最后一天信息存储
  24. dateList: [], //公共每月当天信息存储
  25. timeProcessing: '',
  26. Time_Data: [], //公共api请求参数->Time_Data
  27. timearr: [], //公共处理开始时间和结束时间中的时间段天数 值存储
  28. Time_All: [], //公共时间 返回数组 -> 年月日时分秒 时间戳
  29. queryType: '', //设备监控--->数据报表api请求参数->queryType
  30. run_off_Status: null, //设备监控--->运行状态统计->echarts->OFF次数分布和运行状态曲线图表 api信息存储
  31. se_defaultTime: [], //设备监控--->历史趋势时间选择器v-model
  32. th_defaultTime: [], //设备监控--->数据报表时间选择器v-model
  33. fh_defaultTime: [], //设备监控--->运行状态统计时间选择器v-model
  34. // tableHeight:0,//公共table监听高度变化
  35. // echartHeight:0,//公共ehcarts监听高度变化
  36. basicInfoSiteName: '', // 站点基本信息
  37. basicInfoConst: 1, // 站点弹窗
  38. siteManageLabelCom: '', //站点管理,树结构label传值
  39. /**评估报告指标趋势**/
  40. realScoreLineObj: [], //图表数据
  41. realScoreLineDataTime: [], //图表时间线
  42. realScoreLineName: ''
  43. },
  44. mutations: {
  45. /**
  46. * @公共站点下拉列表
  47. * @param {*} state
  48. */
  49. async publicSiteList(state) {
  50. await api
  51. .SiteList({})
  52. .then((requset) => {
  53. if (requset.status === 'SUCCESS') {
  54. state.siteList = requset.data
  55. } else {
  56. ElMessage.error(requset.msg)
  57. }
  58. })
  59. },
  60. /**
  61. * @公共左侧树状设备
  62. * @param {*} state
  63. */
  64. publicDeviceList(state) {
  65. if (state.siteId != "" && state.siteId != null) {
  66. api
  67. .dataManagementDeviceList({ siteId: state.siteId })
  68. .then((requset) => {
  69. if (requset.status === 'SUCCESS') {
  70. state.deviceList = []
  71. requset.data.map((val) => {
  72. // if (val.children.length > 0) {
  73. state.deviceList.push({
  74. deviceCode: val.deviceCode,
  75. deviceName: val.deviceName,
  76. id: val.id,
  77. children: val.children.length > 0 ?
  78. val.children.map((val) => {
  79. return {
  80. deviceCode: val.variableCoding,
  81. deviceName: val.variableName,
  82. id: val.id,
  83. }
  84. }) : val.children,
  85. })
  86. // }
  87. })
  88. } else {
  89. ElMessage.error(requset.msg)
  90. }
  91. })
  92. } else {
  93. state.deviceList = []
  94. }
  95. },
  96. /**
  97. * @公共api请求参数siteId
  98. * @param {*}} state
  99. * @param {*} val
  100. */
  101. increment(state, val) {
  102. state.siteId = val
  103. },
  104. /**
  105. * @公共处理时区方法
  106. */
  107. TimeAll_function(state, time) {
  108. state.Time_Data = []
  109. for (let i in time) {
  110. var Y = time[i].getFullYear() < 10 ? '0' + time[i].getFullYear() : time[i].getFullYear()
  111. var M = (time[i].getMonth() + 1) < 10 ? '0' + (time[i].getMonth() + 1) : (time[i].getMonth() + 1)
  112. var D = time[i].getDate() < 10 ? '0' + time[i].getDate() : time[i].getDate()
  113. var HH = time[i].getHours() < 10 ? '0' + time[i].getHours() : time[i].getHours()
  114. var MM = time[i].getMinutes() < 10 ? '0' + time[i].getMinutes() : time[i].getMinutes()
  115. var SS = time[i].getSeconds() < 10 ? '0' + time[i].getSeconds() : time[i].getSeconds()
  116. // console.log(Y + '-' + M + '-' + D + ' ' + HH + ':' + MM + ':' + SS)
  117. state.Time_Data.push(Y + '-' + M + '-' + D + ' ' + HH + ':' + MM + ':' + SS)
  118. }
  119. },
  120. /**
  121. * @公共处理开始时间和结束时间中的时间段天数
  122. * @param {*} state
  123. * @param {*} begin 开始时间和结束时间
  124. */
  125. getAll(state, begin) {
  126. let arr1 = begin[0].split("-");
  127. let arr2 = begin[1].split("-");
  128. let arr1_ = new Date();
  129. let arrTime = [];
  130. arr1_.setUTCFullYear(arr1[0], arr1[1] - 1, arr1[2]);
  131. let arr2_ = new Date();
  132. arr2_.setUTCFullYear(arr2[0], arr2[1] - 1, arr2[2]);
  133. let unixDb = arr1_.getTime();
  134. let unixDe = arr2_.getTime();
  135. for (let k = unixDb; k <= unixDe;) {
  136. arrTime.push(datetimeparse(k, "YY-MM-DD"));
  137. k = k + 24 * 60 * 60 * 1000;
  138. }
  139. state.timearr = arrTime
  140. // return arrTime;
  141. // 时间格式处理
  142. function datetimeparse(timestamp, format, prefix) {
  143. if (typeof timestamp == "string") {
  144. timestamp = Number(timestamp);
  145. }
  146. //转换时区
  147. let currentZoneTime = new Date(timestamp);
  148. let currentTimestamp = currentZoneTime.getTime();
  149. let offsetZone = currentZoneTime.getTimezoneOffset() / 60; //如果offsetZone>0是西区,西区晚
  150. let offset = null;
  151. //客户端时间与服务器时间保持一致,固定北京时间东八区。
  152. offset = offsetZone + 8;
  153. currentTimestamp = currentTimestamp + offset * 3600 * 1000;
  154. let newtimestamp = null;
  155. if (currentTimestamp) {
  156. if (currentTimestamp.toString().length === 13) {
  157. newtimestamp = currentTimestamp.toString();
  158. } else if (currentTimestamp.toString().length === 10) {
  159. newtimestamp = currentTimestamp + "000";
  160. } else {
  161. newtimestamp = null;
  162. }
  163. } else {
  164. newtimestamp = null;
  165. }
  166. let dateobj = newtimestamp ?
  167. new Date(parseInt(newtimestamp)) :
  168. new Date();
  169. let YYYY = dateobj.getFullYear();
  170. let MM =
  171. dateobj.getMonth() > 8 ?
  172. dateobj.getMonth() + 1 :
  173. "0" + (dateobj.getMonth() + 1);
  174. let DD =
  175. dateobj.getDate() > 9 ? dateobj.getDate() : "0" + dateobj.getDate();
  176. let HH =
  177. dateobj.getHours() > 9 ? dateobj.getHours() : "0" + dateobj.getHours();
  178. let mm =
  179. dateobj.getMinutes() > 9 ?
  180. dateobj.getMinutes() :
  181. "0" + dateobj.getMinutes();
  182. let ss =
  183. dateobj.getSeconds() > 9 ?
  184. dateobj.getSeconds() :
  185. "0" + dateobj.getSeconds();
  186. let output = "";
  187. let separator = "/";
  188. if (format) {
  189. separator = format.match(/-/) ? "-" : "/";
  190. output += format.match(/yy/i) ? YYYY : "";
  191. output += format.match(/MM/) ?
  192. (output.length ? separator : "") + MM :
  193. "";
  194. output += format.match(/dd/i) ?
  195. (output.length ? separator : "") + DD :
  196. "";
  197. output += format.match(/hh/i) ? (output.length ? " " : "") + HH : "";
  198. output += format.match(/mm/) ? (output.length ? ":" : "") + mm : "";
  199. output += format.match(/ss/i) ? (output.length ? ":" : "") + ss : "";
  200. } else {
  201. output += YYYY + separator + MM + separator + DD;
  202. }
  203. output = prefix ? prefix + output : output;
  204. return newtimestamp ? output : "";
  205. }
  206. },
  207. /**
  208. * @公共echarts图表下载
  209. */
  210. getConnectedDataURL(state, refs) {
  211. state || refs
  212. var url = refs[0].getConnectedDataURL({
  213. pixelRatio: 15,
  214. backgroundColor: "black",
  215. excludeComponents: ["toolbox"],
  216. type: "png",
  217. });
  218. var $a = document.createElement("a");
  219. var type = "png";
  220. //图片名称
  221. $a.download = refs[1] + "." + type;
  222. $a.target = "_blank";
  223. $a.href = url;
  224. if (typeof MouseEvent === "function") {
  225. var evt = new MouseEvent("click", {
  226. view: window,
  227. bubbles: true,
  228. cancelable: false,
  229. });
  230. $a.dispatchEvent(evt);
  231. }
  232. },
  233. /**
  234. * @公共时间 返回数组 -> 年月日时分秒 时间戳
  235. */
  236. getTimeAll(state) {
  237. const time = new Date();
  238. const Y = time.getFullYear(); //年
  239. const M = time.getMonth(); //月
  240. const D = time.getDate(); //日
  241. const HH = time.getHours(); //时,
  242. const MM = time.getMinutes(); //分
  243. const SS = time.getSeconds(); //秒
  244. const timestamp = new Date().getTime(); //时间戳
  245. state.Time_All = [Y, M, D, HH, MM, SS, timestamp]
  246. state.se_defaultTime = [new Date(Y, M, D, 0, 0, 0), new Date()] //设备监控--->历史趋势时间选择器v-model //home设备总数
  247. state.th_defaultTime = [new Date(Y, M, D, 0, 0, 0), new Date()] //设备监控--->数据报表时间选择器v-model //home运维管理
  248. state.fh_defaultTime = [new Date(Y, M, 1, 0, 0, 0), new Date()] //设备监控--->运行状态统计时间选择器v-model //概览 -> 告警统计折线图
  249. },
  250. /**
  251. * @处理公共时间搓 返回数组 -> 年月日时分秒 时间戳
  252. */
  253. getTimestampAll(state, timestamp) {
  254. function add0(m) { return m < 10 ? '0' + m : m }
  255. const time = new Date(timestamp);
  256. const Y = time.getFullYear(); //年
  257. const M = time.getMonth(); //月
  258. const D = time.getDate(); //日
  259. const HH = time.getHours(); //时,
  260. const MM = time.getMinutes(); //分
  261. const SS = time.getSeconds(); //秒
  262. state.timeProcessing = Y + '-' + add0(M + 1) + '-' + add0(D) + ' ' + add0(HH) + ':' + add0(MM) + ':' + add0(SS);
  263. },
  264. /**
  265. * @公共获取某月的第一天和最后一天
  266. */
  267. getCurrentMonthLast(state, timeAll) {
  268. var date1 = timeAll;
  269. date1.setDate(1);
  270. var month1 = parseInt(date1.getMonth() + 1);
  271. var day1 = date1.getDate();
  272. if (month1 < 10) {
  273. month1 = '0' + month1
  274. }
  275. if (day1 < 10) {
  276. day1 = '0' + day1
  277. }
  278. var date = timeAll;
  279. var currentMonth = date.getMonth();
  280. var nextMonth = ++currentMonth;
  281. var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
  282. var oneDay = 1000 * 60 * 60 * 24;
  283. var lastTime = new Date(nextMonthFirstDay - oneDay);
  284. var month = parseInt(lastTime.getMonth() + 1);
  285. var day = lastTime.getDate();
  286. if (month < 10) {
  287. month = '0' + month
  288. }
  289. if (day < 10) {
  290. day = '0' + day
  291. }
  292. state.monthList = [date1.getFullYear() + '-' + month1 + '-' + day1, date.getFullYear() + '-' + month + '-' + day]
  293. },
  294. /**
  295. * @获取当天日期
  296. */
  297. getNowFormatDate(state, timeAll) {
  298. var date = timeAll;
  299. var seperator1 = "-";
  300. var year = date.getFullYear();
  301. var month = date.getMonth() + 1;
  302. var strDate = date.getDate();
  303. if (month >= 1 && month <= 9) {
  304. month = "0" + month;
  305. }
  306. if (strDate >= 0 && strDate <= 9) {
  307. strDate = "0" + strDate;
  308. }
  309. var currentdate = year + seperator1 + month + seperator1 + strDate;
  310. state.dateList = currentdate
  311. }
  312. }
  313. })