index.js 14 KB

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