common.js 10 KB

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