common.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. data
  102. })
  103. }
  104. export function getJson(url,data) {
  105. return request({
  106. url: process.env.VUE_APP_BASE_API + url + data,
  107. method: 'get'
  108. })
  109. }
  110. export function PostDataByNames(data) {
  111. return request({
  112. url: '/authdata/PostDataByNames',
  113. method: 'post',
  114. data
  115. })
  116. }
  117. export function ExecDataByConfig(data) {
  118. return request({
  119. url: '/authdata/ExecDataByConfig',
  120. method: 'post',
  121. data
  122. })
  123. }
  124. export function getDorm(data) {
  125. return request({
  126. url: '/authdata/getDorm',
  127. method: 'post',
  128. timeout: 6000000,
  129. data
  130. })
  131. }
  132. export function removeimage(data) {
  133. return request({
  134. url: '/authdata/removeimage',
  135. method: 'post',
  136. data
  137. })
  138. }
  139. export function getRecuData(data) {
  140. return request({
  141. url: '/authdata/GetRecuDataByName',
  142. method: 'post',
  143. data
  144. })
  145. }
  146. export function Autogeneration(data) {
  147. return request({
  148. url: '/authdata/autogeneration',
  149. method: 'post',
  150. data
  151. })
  152. }
  153. export function failproccess(data, notify) {
  154. if (data.data.includes('Duplicate')) {
  155. notify({
  156. title: '失败',
  157. message: '不可以录入重复数据',
  158. type: 'error',
  159. duration: 2000
  160. })
  161. } else {
  162. notify({
  163. title: '失败',
  164. message: '数据存在错误,请校验好重新录入,不可以录入数据',
  165. type: 'error',
  166. duration: 2000
  167. })
  168. }
  169. }
  170. export function UpdateDataRelation(data) {
  171. return request({
  172. url: '/authdata/UpdateDataRelation',
  173. method: 'post',
  174. data
  175. })
  176. }
  177. export function transData(a, idStr, pidStr, chindrenStr) {
  178. var r = []; var hash = {}; var id = idStr; var pid = pidStr; var children = chindrenStr; var i = 0; var j = 0; var len = a.length
  179. for (; i < len; i++) {
  180. hash[a[i][id]] = a[i]
  181. }
  182. for (; j < len; j++) {
  183. var aVal = a[j]; var hashVP = hash[aVal[pid]]
  184. if (hashVP) {
  185. !hashVP[children] && (hashVP[children] = [])
  186. hashVP[children].push(aVal)
  187. } else {
  188. r.push(aVal)
  189. }
  190. }
  191. return r
  192. }
  193. export function checkButtons(buttonsList, PermissionButtons) {
  194. // console.log(PermissionButtons)
  195. for (let i = 0; i < buttonsList.length; i++) {
  196. // if (buttonsList[i].path === PermissionButtons && buttonsList[i].menu_id && buttonsList[i].path) { // path不为空且menu_id不为空时返回true
  197. if (buttonsList[i].path === PermissionButtons && buttonsList[i].editbutton === 1) { // path不为空且menu_id不为空时返回true
  198. return true
  199. }
  200. }
  201. return false
  202. }
  203. export function formatJson(filterVal, jsonData) {
  204. return jsonData.map(v =>
  205. filterVal.map(j => {
  206. if (j === 'timestamp') {
  207. return parseTime(v[j])
  208. } else {
  209. return v[j]
  210. }
  211. })
  212. )
  213. }
  214. export function DownloadExcel(data, filename) {
  215. const content = data
  216. const blob = new Blob([content])
  217. const fileName = filename + '.xlsx'
  218. if ('download' in document.createElement('a')) { // 非IE下载
  219. const elink = document.createElement('a')
  220. elink.download = fileName
  221. elink.style.display = 'none'
  222. elink.href = URL.createObjectURL(blob)
  223. document.body.appendChild(elink)
  224. elink.click()
  225. URL.revokeObjectURL(elink.href) // 释放URL 对象
  226. document.body.removeChild(elink)
  227. } else { // IE10+下载
  228. navigator.msSaveBlob(blob, fileName)
  229. }
  230. }
  231. // 取小数
  232. export function formatNum(f, digit) {
  233. var m = Math.pow(10, digit);
  234. return parseInt(f * m, 10) / m;
  235. }
  236. export function compareSort(property){
  237. return function(a,b){
  238. var value1 = a[property];
  239. var value2 = b[property];
  240. return value1 - value2;
  241. }
  242. }
  243. //将日期转换成一年中的第几周
  244. export function getYearWeek(date) {
  245. //按照国际标准
  246. let time,
  247. week,
  248. checkDate = new Date(date);
  249. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  250. time = checkDate.getTime();
  251. checkDate.setMonth(0);
  252. checkDate.setDate(1);
  253. week = Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  254. return week;
  255. }
  256. //返回格式 2019年第23周,特别注意跨年一周的问题
  257. export function getYearAndWeek(date, anotherDate) {
  258. let week = getYearWeek(date);
  259. let year = date.substring(0, 4);
  260. let anotherYear = anotherDate.substring(0, 4);
  261. //处理跨年特殊日期
  262. if (anotherDate > date) {
  263. let betweenDay = getBetweenDay(new Date(date), new Date(anotherDate));
  264. if (betweenDay == 7 && anotherYear != year) {
  265. if (week == 1) {
  266. year = parseInt(year) + 1;
  267. }
  268. }
  269. } else {
  270. let betweenDay = getBetweenDay(new Date(anotherDate), new Date(date));
  271. if (betweenDay == 7 && anotherYear != year) {
  272. if (week != 1) {
  273. year = parseInt(year) - 1;
  274. }
  275. }
  276. }
  277. return `${year}年第${week}周`;
  278. }
  279. export function getBetweenDay(beginDate, endDate) {
  280. let dateSpan = endDate - beginDate;
  281. dateSpan = Math.abs(dateSpan);
  282. let days = Math.floor(dateSpan / (24 * 3600 * 1000));
  283. return days + 1;
  284. }
  285. //获取当前count个周的起止日期,如:count=0 ,就是当前周,-1就是上周,以此类推
  286. export function getWeekStartAndEnd(count, currentDate) {
  287. //起止日期数组
  288. let resultArr = new Array();
  289. let millisecond = 1000 * 60 * 60 * 24;
  290. currentDate = new Date(currentDate.getTime() + millisecond * 7 * count);
  291. let week = currentDate.getDay();
  292. //减去的天数
  293. let minusDay = week != 0 ? week - 1 : 6;
  294. //获得当前周的第一天
  295. let currentWeekFirstDay = new Date(
  296. currentDate.getTime() - millisecond * minusDay
  297. );
  298. //获得当前周的最后一天
  299. let currentWeekLastDay = new Date(
  300. currentWeekFirstDay.getTime() + millisecond * 6
  301. );
  302. resultArr.push(currentWeekFirstDay.format());
  303. resultArr.push(currentWeekLastDay.format());
  304. return resultArr;
  305. }
  306. Date.prototype.format = function() {
  307. let s = "";
  308. let mouth =
  309. this.getMonth() + 1 >= 10
  310. ? this.getMonth() + 1
  311. : "0" + (this.getMonth() + 1);
  312. let day = this.getDate() >= 10 ? this.getDate() : "0" + this.getDate();
  313. s += this.getFullYear() + "-"; // 获取年份。
  314. s += mouth + "-"; // 获取月份。
  315. s += day; // 获取日。
  316. return s; // 返回日期。
  317. };
  318. /**
  319. * @param date 传入的日期
  320. * @param num 加减的天数,加为正,减为负
  321. * @returns 格式化后的日期
  322. */
  323. export function addDays(date, num) {
  324. date.setDate(date.getDate() + num);
  325. return date.format();
  326. }
  327. export function yearDay(long) {
  328. var time = new Date(long * 1000)
  329. var year = time.getFullYear()
  330. var month = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1)
  331. var date = time.getDate() < 10 ? '0' + time.getDate() : time.getDate()
  332. var yearday = { year, month, date }
  333. return yearday
  334. }
  335. // 计算一年中的每一周都是从几号到几号
  336. // 第一周为1月1日到 本年的 第一个周日
  337. // 第二周为 本年的 第一个周一 往后推到周日
  338. // 以此类推 再往后推52周。。。
  339. // 如果最后一周在12月31日之前,则本年有垮了54周,反之53周
  340. // 12月31 日不论是周几,都算为本周的最后一天
  341. // 参数年份 ,函数返回一个数组,数组里的对象包含 这一周的开始日期和结束日期
  342. export function whichWeek(year) {
  343. var d = new Date(year, 0, 1)
  344. while (d.getDay() != 1) {
  345. d.setDate(d.getDate() + 1)
  346. }
  347. const arr = []
  348. const longnum = d.setDate(d.getDate())
  349. if (longnum > +new Date(year, 0, 1)) {
  350. const obj = yearDay(+new Date(year, 0, 1) / 1000)
  351. obj.last = yearDay(longnum / 1000 - 86400)
  352. arr.push(obj)
  353. }
  354. const oneitem = yearDay(longnum / 1000)
  355. oneitem.last = yearDay(longnum / 1000 + 86400 * 6)
  356. arr.push(oneitem)
  357. var lastStr
  358. for (var i = 0; i < 51; i++) {
  359. const long = d.setDate(d.getDate() + 7)
  360. const obj = yearDay(long / 1000)
  361. obj.last = yearDay(long / 1000 + 86400 * 6)
  362. lastStr = long + 86400000 * 6
  363. arr.push(obj)
  364. }
  365. if (lastStr < +new Date(year + 1, 0, 1)) {
  366. const obj = yearDay(lastStr / 1000 + 86400)
  367. obj.last = yearDay(+new Date(year + 1, 0, 1) / 1000 - 86400)
  368. arr.push(obj)
  369. } else {
  370. arr[arr.length - 1].last = yearDay(+new Date(year + 1, 0, 1) / 1000 - 86400)
  371. }
  372. return arr
  373. }