common.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. import request from '@/utils/request'
  2. import parseTime from '@/utils/index.js'
  3. export function checkDates(data) {
  4. return request({
  5. url: '/authdata/checkDates',
  6. method: 'post',
  7. data
  8. })
  9. }
  10. export function GetDataByName(data) {
  11. return request({
  12. url: '/authdata/GetDataByName',
  13. method: 'post',
  14. data
  15. })
  16. }
  17. export function processAnalysist(data) {
  18. return request({
  19. url: '/authdata/processAnalysist',
  20. method: 'post',
  21. data
  22. })
  23. }
  24. export function ExeSqlJiade(data) {
  25. return request({
  26. url: '/authdata/exesql',
  27. method: 'post',
  28. data
  29. })
  30. }
  31. export function dashboardListJiade(data) {
  32. return request({
  33. url: '/authdata/Dashboards',
  34. method: 'post',
  35. data
  36. })
  37. }
  38. export function updateDashboardJiade(data) {
  39. return request({
  40. url: '/authdata/Updatedashboard',
  41. method: 'post',
  42. data
  43. })
  44. }
  45. export function GetReportform(data) {
  46. return request({
  47. url: '/authdata/GetReportform',
  48. method: 'post',
  49. timeout: 600000,
  50. data
  51. })
  52. }
  53. export function requestbyname(data, requestname) {
  54. return request({
  55. url: '/authdata/' + requestname,
  56. method: 'post',
  57. data
  58. })
  59. }
  60. export function GetDataByNameXlsx(data) {
  61. return request({
  62. url: '/authdata/GetDataByName',
  63. method: 'post',
  64. data,
  65. responseType: 'blob'
  66. })
  67. }
  68. export function GetDataByNames(data) {
  69. return request({
  70. url: '/authdata/GetDataByNames',
  71. method: 'post',
  72. data
  73. })
  74. }
  75. export function PostDataByName(data) {
  76. return request({
  77. url: '/authdata/PostDataByName',
  78. method: 'post',
  79. data
  80. })
  81. }
  82. export function GetUpkeepPlan(data) {
  83. return request({
  84. url: '/authdata/GetUpkeepPlan',
  85. method: 'post',
  86. data
  87. })
  88. }
  89. export function GetAccount(data) {
  90. return request({
  91. url: '/authdata/GetAccount',
  92. method: 'post',
  93. timeout: 600000,
  94. data
  95. })
  96. }
  97. export function postJson(url,data) {
  98. return request({
  99. url: process.env.VUE_APP_BASE_API + url,
  100. method: 'post',
  101. timeout: 600000,
  102. data
  103. })
  104. }
  105. export function postJson2(url,data) {
  106. return request({
  107. url: url,
  108. method: 'post',
  109. timeout: 600000,
  110. data
  111. })
  112. }
  113. export function getJson(url,data) {
  114. return request({
  115. url: process.env.VUE_APP_BASE_API + url + data,
  116. method: 'get'
  117. })
  118. }
  119. export function getData(url,data) {
  120. return request({
  121. url: url,
  122. method: 'post',
  123. timeout: 600000,
  124. data
  125. })
  126. }
  127. export function PostDataByNames(data) {
  128. return request({
  129. url: '/authdata/PostDataByNames',
  130. method: 'post',
  131. data
  132. })
  133. }
  134. export function ExecDataByConfig(data) {
  135. return request({
  136. url: '/authdata/ExecDataByConfig',
  137. method: 'post',
  138. data
  139. })
  140. }
  141. export function getDorm(data) {
  142. return request({
  143. url: '/authdata/getDorm',
  144. method: 'post',
  145. timeout: 6000000,
  146. data
  147. })
  148. }
  149. export function removeimage(data) {
  150. return request({
  151. url: '/authdata/removeimage',
  152. method: 'post',
  153. data
  154. })
  155. }
  156. export function getRecuData(data) {
  157. return request({
  158. url: '/authdata/GetRecuDataByName',
  159. method: 'post',
  160. data
  161. })
  162. }
  163. export function Autogeneration(data) {
  164. return request({
  165. url: '/authdata/autogeneration',
  166. method: 'post',
  167. data
  168. })
  169. }
  170. export function failproccess(data, notify) {
  171. if (data.data.includes('Duplicate')) {
  172. notify({
  173. title: '失败',
  174. message: '不可以录入重复数据',
  175. type: 'error',
  176. duration: 2000
  177. })
  178. } else {
  179. notify({
  180. title: '失败',
  181. message: '数据存在错误,请校验好重新录入,不可以录入数据',
  182. type: 'error',
  183. duration: 2000
  184. })
  185. }
  186. }
  187. export function UpdateDataRelation(data) {
  188. return request({
  189. url: '/authdata/UpdateDataRelation',
  190. method: 'post',
  191. data
  192. })
  193. }
  194. export function transData(a, idStr, pidStr, chindrenStr) {
  195. var r = []; var hash = {}; var id = idStr; var pid = pidStr; var children = chindrenStr; var i = 0; var j = 0; var len = a.length
  196. for (; i < len; i++) {
  197. hash[a[i][id]] = a[i]
  198. }
  199. for (; j < len; j++) {
  200. var aVal = a[j]; var hashVP = hash[aVal[pid]]
  201. if (hashVP) {
  202. !hashVP[children] && (hashVP[children] = [])
  203. hashVP[children].push(aVal)
  204. } else {
  205. r.push(aVal)
  206. }
  207. }
  208. return r
  209. }
  210. export function checkButtons(buttonsList, PermissionButtons) {
  211. // console.log(PermissionButtons)
  212. for (let i = 0; i < buttonsList.length; i++) {
  213. // if (buttonsList[i].path === PermissionButtons && buttonsList[i].menu_id && buttonsList[i].path) { // path不为空且menu_id不为空时返回true
  214. if (buttonsList[i].path === PermissionButtons && buttonsList[i].editbutton === 1) { // path不为空且menu_id不为空时返回true
  215. return true
  216. }
  217. }
  218. return false
  219. }
  220. export function formatJson(filterVal, jsonData) {
  221. return jsonData.map(v =>
  222. filterVal.map(j => {
  223. if (j === 'timestamp') {
  224. return parseTime(v[j])
  225. } else {
  226. return v[j]
  227. }
  228. })
  229. )
  230. }
  231. export function DownloadExcel(data, filename) {
  232. const content = data
  233. const blob = new Blob([content])
  234. const fileName = filename + '.xlsx'
  235. if ('download' in document.createElement('a')) { // 非IE下载
  236. const elink = document.createElement('a')
  237. elink.download = fileName
  238. elink.style.display = 'none'
  239. elink.href = URL.createObjectURL(blob)
  240. document.body.appendChild(elink)
  241. elink.click()
  242. URL.revokeObjectURL(elink.href) // 释放URL 对象
  243. document.body.removeChild(elink)
  244. } else { // IE10+下载
  245. navigator.msSaveBlob(blob, fileName)
  246. }
  247. }
  248. // 取小数
  249. // export function formatNum(f, digit) {
  250. // var m = Math.pow(10, digit);
  251. // return parseInt(f * m, 10) / m;
  252. // }
  253. export function formatNum(value, n) {
  254. console.log(value, n,'====')
  255. var f = Math.round(value*Math.pow(10,n))/Math.pow(10,n);
  256. var s = f.toString();
  257. var rs = s.indexOf('.');
  258. if(rs < 0) {
  259. if(n==0){
  260. s = s
  261. }else{
  262. s += '.';
  263. }
  264. }
  265. for(var i = s.length - s.indexOf('.'); i <= n; i++){
  266. s += "0";
  267. }
  268. return s;
  269. }
  270. export function compareSort(property){
  271. return function(a,b){
  272. var value1 = a[property];
  273. var value2 = b[property];
  274. return value1 - value2;
  275. }
  276. }
  277. //将日期转换成一年中的第几周
  278. export function getYearWeek(date) {
  279. //按照国际标准
  280. let time,
  281. week,
  282. checkDate = new Date(date);
  283. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  284. time = checkDate.getTime();
  285. checkDate.setMonth(0);
  286. checkDate.setDate(1);
  287. week = Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  288. return week;
  289. }
  290. //返回格式 2019年第23周,特别注意跨年一周的问题
  291. export function getYearAndWeek(date, anotherDate) {
  292. let week = getYearWeek(date);
  293. let year = date.substring(0, 4);
  294. let anotherYear = anotherDate.substring(0, 4);
  295. //处理跨年特殊日期
  296. if (anotherDate > date) {
  297. let betweenDay = getBetweenDay(new Date(date), new Date(anotherDate));
  298. if (betweenDay == 7 && anotherYear != year) {
  299. if (week == 1) {
  300. year = parseInt(year) + 1;
  301. }
  302. }
  303. } else {
  304. let betweenDay = getBetweenDay(new Date(anotherDate), new Date(date));
  305. if (betweenDay == 7 && anotherYear != year) {
  306. if (week != 1) {
  307. year = parseInt(year) - 1;
  308. }
  309. }
  310. }
  311. return `${year}年第${week}周`;
  312. }
  313. export function getBetweenDay(beginDate, endDate) {
  314. let dateSpan = endDate - beginDate;
  315. dateSpan = Math.abs(dateSpan);
  316. let days = Math.floor(dateSpan / (24 * 3600 * 1000));
  317. return days + 1;
  318. }
  319. //获取当前count个周的起止日期,如:count=0 ,就是当前周,-1就是上周,以此类推
  320. export function getWeekStartAndEnd(count, currentDate) {
  321. //起止日期数组
  322. let resultArr = new Array();
  323. let millisecond = 1000 * 60 * 60 * 24;
  324. currentDate = new Date(currentDate.getTime() + millisecond * 7 * count);
  325. let week = currentDate.getDay();
  326. //减去的天数
  327. let minusDay = week != 0 ? week - 1 : 6;
  328. //获得当前周的第一天
  329. let currentWeekFirstDay = new Date(
  330. currentDate.getTime() - millisecond * minusDay
  331. );
  332. //获得当前周的最后一天
  333. let currentWeekLastDay = new Date(
  334. currentWeekFirstDay.getTime() + millisecond * 6
  335. );
  336. resultArr.push(currentWeekFirstDay.format());
  337. resultArr.push(currentWeekLastDay.format());
  338. return resultArr;
  339. }
  340. Date.prototype.format = function() {
  341. let s = "";
  342. let mouth =
  343. this.getMonth() + 1 >= 10
  344. ? this.getMonth() + 1
  345. : "0" + (this.getMonth() + 1);
  346. let day = this.getDate() >= 10 ? this.getDate() : "0" + this.getDate();
  347. s += this.getFullYear() + "-"; // 获取年份。
  348. s += mouth + "-"; // 获取月份。
  349. s += day; // 获取日。
  350. return s; // 返回日期。
  351. };
  352. /**
  353. * @param date 传入的日期
  354. * @param num 加减的天数,加为正,减为负
  355. * @returns 格式化后的日期
  356. */
  357. export function addDays(date, num) {
  358. date.setDate(date.getDate() + num);
  359. return date.format();
  360. }
  361. export function yearDay(long) {
  362. var time = new Date(long * 1000)
  363. var year = time.getFullYear()
  364. var month = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)
  365. var date = time.getDate() < 10 ? '0' + time.getDate() : time.getDate()
  366. var yearday = { year, month, date }
  367. return yearday
  368. }
  369. // 计算一年中的每一周都是从几号到几号
  370. // 第一周为1月1日到 本年的 第一个周日
  371. // 第二周为 本年的 第一个周一 往后推到周日
  372. // 以此类推 再往后推52周。。。
  373. // 如果最后一周在12月31日之前,则本年有垮了54周,反之53周
  374. // 12月31 日不论是周几,都算为本周的最后一天
  375. // 参数年份 ,函数返回一个数组,数组里的对象包含 这一周的开始日期和结束日期
  376. export function whichWeek(year) {
  377. var d = new Date(year, 0, 1)
  378. while (d.getDay() != 1) {
  379. d.setDate(d.getDate() + 1)
  380. }
  381. const arr = []
  382. const longnum = d.setDate(d.getDate())
  383. if (longnum > +new Date(year, 0, 1)) {
  384. const obj = yearDay(+new Date(year, 0, 1) / 1000)
  385. obj.last = yearDay(longnum / 1000 - 86400)
  386. arr.push(obj)
  387. }
  388. const oneitem = yearDay(longnum / 1000)
  389. oneitem.last = yearDay(longnum / 1000 + 86400 * 6)
  390. arr.push(oneitem)
  391. var lastStr
  392. for (var i = 0; i < 51; i++) {
  393. const long = d.setDate(d.getDate() + 7)
  394. const obj = yearDay(long / 1000)
  395. obj.last = yearDay(long / 1000 + 86400 * 6)
  396. lastStr = long + 86400000 * 6
  397. arr.push(obj)
  398. }
  399. if (lastStr < +new Date(year + 1, 0, 1)) {
  400. const obj = yearDay(lastStr / 1000 + 86400)
  401. obj.last = yearDay(+new Date(year + 1, 0, 1) / 1000 - 86400)
  402. arr.push(obj)
  403. } else {
  404. arr[arr.length - 1].last = yearDay(+new Date(year + 1, 0, 1) / 1000 - 86400)
  405. }
  406. return arr
  407. }