index.js 15 KB

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