index.js 16 KB

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