index.js 16 KB

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