common.js 9.9 KB

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