util.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. const constants = require('../utils/constants.js')
  2. // 转换时间
  3. const getDate = (year, month, day, hour, minute) => {
  4. const newyear = year.substr(0, year.length - 1);
  5. const setmonth = month.substr(0, month.length - 1);
  6. const newmonth = setmonth < 10 ? '0' + setmonth : setmonth;
  7. const setday = day.substr(0, day.length - 1);
  8. const newday = setday < 10 ? '0' + setday : setday;
  9. // const sethour = hour.substr(0, hour.length - 1);
  10. const newhour = hour < 10 ? '0' + hour : hour;
  11. // const setminute = minute.substr(0, minute.length - 1);
  12. const newminute = minute < 10 ? '0' + minute : minute;
  13. return newyear + '-' + newmonth + '-' + newday + ' ' + newhour + ":" + newminute;
  14. }
  15. // 将时间戳转换为时间
  16. const getobjDate = (date) => {
  17. let now;
  18. if (date) {
  19. now = new Date(date)
  20. } else {
  21. now = new Date()
  22. }
  23. let y = now.getFullYear(),
  24. m = now.getMonth() + 1,
  25. d = now.getDate(),
  26. h = now.getHours(), //获取当前小时数(0-23)
  27. f = now.getMinutes(),
  28. n = (Math.ceil((now.getMinutes()) / 10)) * 10; //获取当前分钟数(0-59) 取整数
  29. return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + (h < 10 ? "0" + h : h) + ":" + (f < 10 ? "0" + f : f);
  30. }
  31. const getobjDateApple = (date) => {
  32. let now;
  33. if (date) {
  34. now = new Date(date)
  35. } else {
  36. now = new Date()
  37. }
  38. let y = now.getFullYear(),
  39. m = now.getMonth() + 1,
  40. d = now.getDate(),
  41. h = now.getHours(), //获取当前小时数(0-23)
  42. f = now.getMinutes(),
  43. n = (Math.ceil((now.getMinutes()) / 10)) * 10; //获取当前分钟数(0-59) 取整数
  44. return y + "/" + (m < 10 ? "0" + m : m) + "/" + (d < 10 ? "0" + d : d) + " " + (h < 10 ? "0" + h : h) + ":" + (f < 10 ? "0" + f : f);
  45. }
  46. //根据年月 获取天数
  47. const mGetDate = (year, month) => {
  48. var d = new Date(year, month, 0);
  49. return d.getDate();
  50. }
  51. //根据时间2019-01-02 09:12 得到 ['2019','1','2','9','12']
  52. const getarrWithtime = (str) => {
  53. let arr = [];
  54. let arr1 = str.split(' ');
  55. let arr2 = (arr1[0]).split('-');
  56. let arr3 = arr1[1].split(':');
  57. arr = arr2.concat(arr3);
  58. arr[1] = arr[1].startsWith('0') ? arr[1].substr(1, arr[1].length) : arr[1];
  59. arr[2] = arr[2].startsWith('0') ? arr[2].substr(1, arr[2].length) : arr[2];
  60. arr[3] = arr[3].startsWith('0') ? arr[3].substr(1, arr[3].length) : arr[3];
  61. arr[4] = arr[4].startsWith('0') ? arr[4].substr(1, arr[4].length) : arr[4];
  62. return arr;
  63. }
  64. const getTime = date => {
  65. const year = date.getFullYear()
  66. const month = date.getMonth() + 1
  67. const day = date.getDate()
  68. const hour = date.getHours()
  69. const minute = date.getMinutes()
  70. const second = date.getSeconds()
  71. return [hour, minute, second].map(formatNumber).join(':')
  72. }
  73. const formatTime = date => {
  74. const year = date.getFullYear()
  75. const month = date.getMonth() + 1
  76. const day = date.getDate()
  77. const hour = date.getHours()
  78. const minute = date.getMinutes()
  79. const second = date.getSeconds()
  80. return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  81. }
  82. const formatDataTime = date => {
  83. const year = date.getFullYear()
  84. const month = date.getMonth() + 1
  85. const day = date.getDate()
  86. const hour = date.getHours()
  87. const minute = date.getMinutes()
  88. const second = date.getSeconds()
  89. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  90. }
  91. const transformTimestamp = timestamp => {
  92. let a = new Date(timestamp).getTime();
  93. const date = new Date(a);
  94. const year = date.getFullYear()
  95. const month = date.getMonth() + 1
  96. const day = date.getDate()
  97. const hour = date.getHours()
  98. const minute = date.getMinutes()
  99. const second = date.getSeconds()
  100. return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  101. }
  102. const formatDayTime = date => {
  103. const year = date.getFullYear()
  104. const month = date.getMonth() + 1
  105. const day = date.getDate()
  106. return [year, month, day].map(formatNumber).join('-')
  107. }
  108. const formatDayTimeMoth = date => {
  109. const year = date.getFullYear()
  110. const month = date.getMonth() + 1
  111. const day = '01'
  112. return [year, month, day].map(formatNumber).join('-')
  113. }
  114. const formatDayTimeApple = date => {
  115. const year = date.getFullYear()
  116. const month = date.getMonth() + 1
  117. const day = date.getDate()
  118. return [year, month, day].map(formatNumber).join('/')
  119. }
  120. const formatDayYm = date => {
  121. const year = date.getFullYear()
  122. const month = date.getMonth() + 1
  123. return year + '年' + month + '月'
  124. }
  125. const getGuid = function () {
  126. var s = [];
  127. var hexDigits = "0123456789abcdef";
  128. for (var i = 0; i < 36; i++) {
  129. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  130. }
  131. s[14] = "4";
  132. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
  133. s[8] = s[13] = s[18] = s[23] = "-";
  134. var uuid = s.join("");
  135. return uuid;
  136. }
  137. function getSpecifiedYear(num) {
  138. var myDate = new Date();
  139. var year = myDate.getFullYear() + num;
  140. var beginDate = year + "-01-01";
  141. var endDate = year + "-12-31";
  142. return [beginDate, endDate]
  143. }
  144. const formatNumber = n => {
  145. n = n.toString()
  146. return n[1] ? n : '0' + n
  147. }
  148. //浮点数加法运算解决精度问题
  149. function AddNumber(arg1, arg2) {
  150. arg1 = arg1.toString(), arg2 = arg2.toString();
  151. var arg1Arr = arg1.split("."), arg2Arr = arg2.split("."), d1 = arg1Arr.length == 2 ? arg1Arr[1] : "", d2 = arg2Arr.length == 2 ? arg2Arr[1] : "";
  152. var maxLen = Math.max(d1.length, d2.length);
  153. var m = Math.pow(10, maxLen);
  154. var result = Number(((arg1 * m + arg2 * m) / m).toFixed(maxLen));
  155. var d = arguments[2];
  156. return typeof d === "number" ? Number((result).toFixed(d)) : result;
  157. }
  158. // 两个浮点数相减
  159. function SubNumber(num1, num2) {
  160. var r1, r2, m;
  161. try {
  162. r1 = num1.toString().split('.')[1].length;
  163. } catch (e) {
  164. r1 = 0;
  165. }
  166. try {
  167. r2 = num2.toString().split(".")[1].length;
  168. } catch (e) {
  169. r2 = 0;
  170. }
  171. var m = Math.pow(10, Math.max(r1, r2));
  172. var n = (r1 >= r2) ? r1 : r2;
  173. return (Math.round(num1 * m - num2 * m) / m).toFixed(n);
  174. }
  175. function accMul(arg1, arg2) {
  176. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  177. try { m += s1.split(".")[1].length } catch (e) { }
  178. try { m += s2.split(".")[1].length } catch (e) { }
  179. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  180. }
  181. function except(arg1, arg2) {
  182. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  183. try { m += s1.split(".")[1].length } catch (e) { }
  184. try { m += s2.split(".")[1].length } catch (e) { }
  185. return Number(s1.replace(".", "")) / Number(s2.replace(".", "")) / Math.pow(10, m)
  186. }
  187. //获取当前时间 返回格式2021-12-14
  188. function getTodayTime() {
  189. var date = new Date();
  190. var time = (date.getFullYear() + 1) + "-" + (date.getMonth() + 1) + "-" + date.getDate()
  191. return time;
  192. }
  193. function fun_date(num) {
  194. var date1 = new Date();
  195. //今天时间
  196. var date2 = new Date(date1);
  197. date2.setDate(date1.getDate() + num);
  198. //num是正数表示之后的时间,num负数表示之前的时间,0表示今天
  199. var time2 = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
  200. return time2;
  201. }
  202. function getCurrentMonth() {
  203. var firstDate = new Date();
  204. var startDate = firstDate.getFullYear() + "-" + ((firstDate.getMonth() + 1) < 10 ? "0" : "") + (firstDate.getMonth() + 1) + "-" + "01";
  205. var date = new Date();
  206. var currentMonth = date.getMonth();
  207. var nextMonth = ++currentMonth;
  208. var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
  209. var oneDay = 1000 * 60 * 60 * 24;
  210. var lastDate = new Date(nextMonthFirstDay - oneDay);
  211. var endDate = lastDate.getFullYear() + "-" + ((lastDate.getMonth() + 1) < 10 ? "0" : "") + (lastDate.getMonth() + 1) + "-" + (lastDate.getDate() < 10 ? "0" : "") + lastDate.getDate();
  212. return [startDate, endDate]
  213. }
  214. function getCurrentDateMonth(cdate) {
  215. var firstDate = new Date(cdate);
  216. var startDate = firstDate.getFullYear() + "-" + ((firstDate.getMonth() + 1) < 10 ? "0" : "") + (firstDate.getMonth() + 1) + "-" + "01";
  217. var date = new Date(cdate);
  218. var currentMonth = date.getMonth();
  219. var nextMonth = ++currentMonth;
  220. var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
  221. var oneDay = 1000 * 60 * 60 * 24;
  222. var lastDate = new Date(nextMonthFirstDay - oneDay);
  223. var endDate = lastDate.getFullYear() + "-" + ((lastDate.getMonth() + 1) < 10 ? "0" : "") + (lastDate.getMonth() + 1) + "-" + (lastDate.getDate() < 10 ? "0" : "") + lastDate.getDate();
  224. return [startDate, endDate]
  225. }
  226. function calc10000(arr, keySet) {
  227. arr.forEach(it => {
  228. keySet.forEach(kIt => {
  229. if (it[kIt]) {
  230. it[kIt] = parseFloat(it[kIt] / 10000).toFixed(2)
  231. }
  232. })
  233. })
  234. return arr
  235. }
  236. function parseFloatFixed2(num) {
  237. return parseFloat(num).toFixed(2)
  238. }
  239. function getCurrentWeek(n) {
  240. /***参数都是以周一为基准的***/
  241. //上周的开始时间
  242. // //上周的结束时间
  243. // //本周的开始时间
  244. // //本周的结束时间
  245. var now = new Date();
  246. var year = now.getFullYear();
  247. //因为月份是从0开始的,所以获取这个月的月份数要加1才行
  248. var month = now.getMonth() + 1;
  249. var date = now.getDate();
  250. var day = now.getDay();
  251. //判断是否为周日,如果不是的话,就让今天的day-1(例如星期二就是2-1)
  252. if (day !== 0) {
  253. n = n + (day - 1);
  254. } else {
  255. n = n + day;
  256. }
  257. if (day) {
  258. //这个判断是为了解决跨年的问题
  259. if (month > 1) {
  260. month = month;
  261. }
  262. //这个判断是为了解决跨年的问题,月份是从0开始的
  263. else {
  264. year = year - 1;
  265. month = 12;
  266. }
  267. }
  268. now.setDate(now.getDate() - n);
  269. return now;
  270. }
  271. function drawAndShareImage(param) {
  272. const ctx = wx.createCanvasContext('qrcode')
  273. ctx.beginPath()
  274. ctx.clearRect(0, 0, param.canvasWidth, param.canvasHeight)
  275. ctx.setFillStyle('#fff')
  276. ctx.fillRect(0, 0, param.canvasWidth, param.canvasHeight)
  277. /** 背景图 */
  278. ctx.beginPath()
  279. ctx.drawImage(param.background, 0, 0, param.canvasWidth, param.canvasHeight)
  280. ctx.save();
  281. /** 二维码 */
  282. ctx.beginPath()
  283. ctx.arc(param.qrX, param.qrY, 0, 0, 0)
  284. ctx.fill()
  285. ctx.clip()
  286. ctx.drawImage(
  287. param.qrcode,
  288. 0, 0, 375, 375
  289. )
  290. ctx.restore()
  291. ctx.save()
  292. ctx.draw(false, () => {
  293. wx.canvasToTempFilePath({
  294. x: 100,
  295. y: 200,
  296. width: 50,
  297. height: 50,
  298. destWidth: 100,
  299. destHeight: 100,
  300. canvasId: 'qrcode',
  301. complete(res) { }
  302. })
  303. })
  304. }
  305. //日期转换
  306. Date.prototype.format = function (format) {
  307. var o = {
  308. "M+": this.getMonth() + 1, //month
  309. "d+": this.getDate(), //day
  310. "h+": this.getHours(), //hour
  311. "m+": this.getMinutes(), //minute
  312. "s+": this.getSeconds(), //second
  313. "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
  314. "S": this.getMilliseconds() //millisecond
  315. }
  316. if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
  317. (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  318. for (var k in o)
  319. if (new RegExp("(" + k + ")").test(format))
  320. format = format.replace(RegExp.$1,
  321. RegExp.$1.length == 1 ? o[k] :
  322. ("00" + o[k]).substr(("" + o[k]).length));
  323. return format;
  324. }
  325. Date.prototype.before = function (day) {
  326. var timestamp = Date.parse(this);
  327. var beforeTimestamp = timestamp - 86400000 * day;
  328. return new Date(beforeTimestamp);
  329. }
  330. Date.prototype.after = function (day) {
  331. var timestamp = Date.parse(this);
  332. var afterTimestamp = timestamp + 86400000 * day;
  333. return new Date(afterTimestamp);
  334. }
  335. //时间戳换成日期时间转
  336. function js_date_time(unixtime) {
  337. var date = new Date(unixtime);
  338. var y = date.getFullYear();
  339. var m = date.getMonth() + 1;
  340. m = m < 10 ? ('0' + m) : m;
  341. var d = date.getDate();
  342. d = d < 10 ? ('0' + d) : d;
  343. return y + '-' + m + '-' + d;
  344. }
  345. //时间戳换成日期时间转
  346. function js_month_time(unixtime) {
  347. var date = new Date(unixtime);
  348. var y = date.getFullYear();
  349. var m = date.getMonth() + 1;
  350. m = m < 10 ? ('0' + m) : m;
  351. var d = date.getDate();
  352. d = d < 10 ? ('0' + d) : d;
  353. let a = {
  354. first: y + '-' + m,
  355. second: y + m
  356. }
  357. return a;
  358. }
  359. function getYear(type, dates) {
  360. var dd = new Date();
  361. var n = dates || 0;
  362. var year = dd.getFullYear() + Number(n);
  363. var month = dd.getMonth() + Number(n);
  364. if (month != null && month != 11) {
  365. if (type == "s") {
  366. var day = year - 1 + "-11-30";
  367. };
  368. if (type == "e") {
  369. var day = year + "-12-01";
  370. };
  371. if (!type) {
  372. var day = year + "-01-01/" + year + "-12-31";
  373. };
  374. return day;
  375. } else if (month != null && month == 11) {
  376. if (type == "s") {
  377. var day = year + "-11-30";
  378. };
  379. if (type == "e") {
  380. var day = year + 1 + "-12-01";
  381. };
  382. if (!type) {
  383. var day = year + "-01-01/" + year + "-12-31";
  384. };
  385. return day;
  386. }
  387. }
  388. function timeForMat(count) {
  389. // 拼接时间
  390. const time1 = new Date()
  391. const time2 = new Date()
  392. if (count === 1) {
  393. time1.setTime(time1.getTime() - (24 * 60 * 60 * 1000))
  394. } else {
  395. if (count >= 0) {
  396. time1.setTime(time1.getTime())
  397. } else {
  398. if (count === -2) {
  399. time1.setTime(time1.getTime() + (24 * 60 * 60 * 1000) * 2)
  400. } else {
  401. time1.setTime(time1.getTime() + (24 * 60 * 60 * 1000))
  402. }
  403. }
  404. }
  405. const Y1 = time1.getFullYear()
  406. const M1 = ((time1.getMonth() + 1) > 9 ? (time1.getMonth() + 1) : '0' + (time1.getMonth() + 1))
  407. const D1 = (time1.getDate() > 9 ? time1.getDate() : '0' + time1.getDate())
  408. const timer1 = Y1 + '-' + M1 + '-' + D1 // 当前时间
  409. time2.setTime(time2.getTime() - (24 * 60 * 60 * 1000 * count))
  410. const Y2 = time2.getFullYear()
  411. const M2 = ((time2.getMonth() + 1) > 9 ? (time2.getMonth() + 1) : '0' + (time2.getMonth() + 1))
  412. const D2 = (time2.getDate() > 9 ? time2.getDate() : '0' + time2.getDate())
  413. const timer2 = Y2 + '-' + M2 + '-' + D2 // 以前的7天或者30天
  414. return [timer2, timer1]
  415. }
  416. /**
  417. * @desc : 复制
  418. * @date : 2022/7/29 16:49
  419. * @author : 周兴
  420. */
  421. function toCopy(value, label) {
  422. if (!value || !label) return;
  423. wx.setClipboardData({
  424. data: value,
  425. success: res => {
  426. wx.showToast({
  427. title: label + '已复制',
  428. duration: 1000,
  429. })
  430. }
  431. })
  432. }
  433. function numAdd(num1, num2) {
  434. var baseNum, baseNum1, baseNum2;
  435. try {
  436. baseNum1 = num1.toString().split(".")[1].length;
  437. } catch (e) {
  438. baseNum1 = 0;
  439. }
  440. try {
  441. baseNum2 = num2.toString().split(".")[1].length;
  442. } catch (e) {
  443. baseNum2 = 0;
  444. }
  445. baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
  446. return (num1 * baseNum + num2 * baseNum) / baseNum;
  447. }
  448. function numSub(num1, num2) {
  449. var baseNum, baseNum1, baseNum2;
  450. var precision;// 精度
  451. try {
  452. baseNum1 = num1.toString().split(".")[1].length;
  453. } catch (e) {
  454. baseNum1 = 0;
  455. }
  456. try {
  457. baseNum2 = num2.toString().split(".")[1].length;
  458. } catch (e) {
  459. baseNum2 = 0;
  460. }
  461. baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
  462. precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
  463. return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
  464. }
  465. function jumpPageDate(type) {
  466. let date = []
  467. if (type == 1) {
  468. date = [formatTime(new Date()).substring(0, 10), formatTime(new Date()).substring(0, 10)]
  469. }
  470. else if (type == 2) {
  471. date = [formatTime(getCurrentWeek(0)).substring(0, 10), formatTime(getCurrentWeek(-6)).substring(0, 10)]
  472. }
  473. else if (type == 3) {
  474. date = getCurrentMonth();
  475. } else if (type == 4) {
  476. let startYear = getYear("s", 0)
  477. let endYear = getYear("e", 0)
  478. //本年
  479. date = [formatTime(new Date(startYear)).substring(0, 10),
  480. formatTime(new Date(endYear)).substring(0, 10)]
  481. }
  482. else if (type == 6) {
  483. //近7
  484. date = timeForMat(7)
  485. }
  486. else if (type == 5) {
  487. //近30天
  488. date = timeForMat(30)
  489. } else if (type == -1) {
  490. let dateEnd = formatTime(new Date()).substring(0, 10)
  491. let startYear = new Date().getFullYear() - 1;
  492. let startMonth = new Date().getMonth() + 1 > 9 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1);
  493. let startDay = new Date().getDate() > 9 ? new Date().getDate() : '0' + new Date().getDate();
  494. if (startMonth === 2 && startDay === 29) {
  495. startDay = 28
  496. }
  497. date = [startYear + '/' + startMonth + '/' + startDay, dateEnd]
  498. } else if (type == -2) {
  499. let dateEnd = formatTime(new Date()).substring(0, 10)
  500. let startYear = new Date().getFullYear() + 1;
  501. let startMonth = new Date().getMonth() + 1 > 9 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1);
  502. let startDay = new Date().getDate() > 9 ? new Date().getDate() : '0' + new Date().getDate();
  503. if (startMonth === 2 && startDay === 29) {
  504. startDay = 28
  505. }
  506. date = [dateEnd, startYear + '/' + startMonth + '/' + startDay]
  507. }
  508. return date;
  509. }
  510. /**
  511. * @desc : 判断手机号格式
  512. * @author : 于继渤
  513. * @date : 2022/8/19 10:16
  514. */
  515. function isPoneAvailable(poneInput) {
  516. var myreg = constants.Mobile_Phone_Number_Regular_Expression
  517. if (!myreg.test(poneInput)) {
  518. return false;
  519. } else {
  520. return true;
  521. }
  522. }
  523. /**
  524. * @desc : 深度拷贝
  525. * @author : 于继渤
  526. * @date : 2022/8/19 10:16
  527. */
  528. function copyObj(obj) {
  529. var _obj = JSON.stringify(obj);
  530. var objClone = JSON.parse(_obj);
  531. return objClone;
  532. }
  533. /**
  534. * @desc : 直辖市更新
  535. * @author : 于继渤
  536. * @date : 2022/8/19 10:16
  537. */
  538. function updateProvince(location) {
  539. if (location.province && location.province != '' && typeof location.province == 'string') {
  540. let province = location.province
  541. if (province.indexOf('北京') != -1) {
  542. province = '北京'
  543. return location.province = province
  544. }
  545. if (province.indexOf('上海') != -1) {
  546. province = '上海'
  547. return location.province = province
  548. }
  549. if (province.indexOf('天津') != -1) {
  550. province = '天津'
  551. return location.province = province
  552. }
  553. if (province.indexOf('重庆') != -1) {
  554. province = '重庆'
  555. return location.province = province
  556. }
  557. } else {
  558. console.log('location', location)
  559. if (location.city) {
  560. let province = location.city.replace('市', '')
  561. return location.province = province
  562. }
  563. }
  564. }
  565. //判断数字是否为负数并转为负数
  566. function isNumberNegative(n) {
  567. if (!isNaN(n)) {
  568. let numberTemp = Number(0)
  569. if (n > 0) {
  570. console.log("正数");
  571. numberTemp = (Number(0) - Number(n))
  572. return numberTemp
  573. } else if (n < 0) {
  574. console.log("负数");
  575. return n
  576. } else {
  577. return n
  578. }
  579. } else {
  580. return Number(n)
  581. }
  582. }
  583. /**
  584. * @desc : 合并实体(供main.js)调用,其他地方,调用上面那个
  585. * @author : 周兴
  586. * @date : 2022/11/21 14:25
  587. */
  588. function objectMergeByMainJs(source, target) {
  589. if (typeof source !== 'object') {
  590. source = {};
  591. }
  592. if (Array.isArray(target)) {
  593. return source.slice();
  594. }
  595. if (!source['key']) {
  596. Object.keys(target).forEach((property) => {
  597. const targetProperty = target[property];
  598. if (typeof targetProperty === 'object') {
  599. source[property] = this.objectMergeByMainJs(source[property], targetProperty);
  600. } else {
  601. source[property] = targetProperty;
  602. }
  603. });
  604. }
  605. return source;
  606. }
  607. module.exports = {
  608. objectMergeByMainJs:objectMergeByMainJs,
  609. updateProvince: updateProvince,
  610. isPoneAvailable: isPoneAvailable,
  611. formatTime: formatTime,
  612. drawAndShareImage,
  613. fun_date,
  614. getCurrentWeek,
  615. getCurrentMonth,
  616. getCurrentDateMonth,
  617. getTime,
  618. getGuid,
  619. js_date_time,
  620. js_month_time,
  621. getDate,
  622. getobjDate,
  623. mGetDate,
  624. getarrWithtime,
  625. getSpecifiedYear,
  626. getTodayTime,
  627. formatDataTime,
  628. formatDayTime,
  629. transformTimestamp,
  630. getYear,
  631. timeForMat,
  632. AddNumber,
  633. accMul,
  634. except,
  635. toCopy,
  636. numAdd,
  637. numSub, formatDayYm, jumpPageDate, calc10000, parseFloatFixed2,
  638. formatDayTimeApple, getobjDateApple,
  639. formatDayTimeMoth: formatDayTimeMoth,
  640. copyObj,
  641. SubNumber,
  642. isNumberNegative
  643. }