jnpf.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. import CryptoJS from 'crypto-js'
  2. import request from '@/utils/request'
  3. import define from '@/utils/define'
  4. import {
  5. dayjs
  6. } from '@/uni_modules/iRainna-dayjs/js_sdk/dayjs.min.js'
  7. import md5Libs from "@/uni_modules/vk-uview-ui/libs/function/md5";
  8. const jnpf = {
  9. goBack() {
  10. uni.navigateBack()
  11. },
  12. // 跳链接
  13. jumpLink(urlAddress, pageTitle = "") {
  14. if (!urlAddress) return
  15. let url = '/pages/apply/externalLink/index?url=' + encodeURIComponent(urlAddress) + '&fullName= ' +
  16. pageTitle
  17. uni.navigateTo({
  18. url: url,
  19. })
  20. },
  21. /* 传参字符串转义 */
  22. encodeContent(key) {
  23. const encodeArr = [{
  24. code: '%',
  25. encode: '%25'
  26. }, {
  27. code: '?',
  28. encode: '%3F'
  29. }, {
  30. code: '#',
  31. encode: '%23'
  32. }, {
  33. code: '&',
  34. encode: '%26'
  35. }, {
  36. code: '=',
  37. encode: '%3D'
  38. }];
  39. return key.replace(/[%?#&=]/g, ($, index, str) => {
  40. for (const k of encodeArr) {
  41. if (k.code === $) {
  42. return k.encode;
  43. }
  44. }
  45. });
  46. },
  47. solveAddressParam(item, config) {
  48. let jnpfKey = config.jnpfKey
  49. item.urlAddress = item.urlAddress ? item.urlAddress : config.option.appUrlAddress
  50. if (!item.urlAddress) return
  51. let urlAddress = item.urlAddress
  52. const regex = /\${[^{}]+}/g;
  53. urlAddress = urlAddress.replace(regex, match => {
  54. const key = match.slice(2, -1);
  55. let value = '';
  56. if (jnpfKey === 'text') {
  57. return key == 'Field' || key == 'field' ? item.value : match
  58. }
  59. if (jnpfKey === 'timeAxis') {
  60. if (key == 'name') value = item['content'];
  61. if (key == 'timestamp') value = item['timestamp'];
  62. }
  63. if (jnpfKey === 'tableList') {
  64. return item[key] || match
  65. }
  66. if (jnpfKey === 'dataBoard') {
  67. return key == 'Field' || key == 'field' ? item.num : match
  68. }
  69. if (jnpfKey === 'rankList') {
  70. if (key === 'name') value = item.label;
  71. if (key === 'value') value = item.value.replace("¥ ", "");
  72. }
  73. // 图标替换
  74. if (jnpfKey === 'barChart' || jnpfKey === 'lineChart' || jnpfKey === 'pieChart' ||
  75. jnpfKey == 'radarChart' || jnpfKey === 'mapChart') {
  76. if (key === 'name') value = item.name;
  77. if (key === 'long') value = item.long;
  78. if (key === 'lat') value = item.lat;
  79. if (key === 'value') value = item.value;
  80. if (key === 'type') value = item.type;
  81. }
  82. return value || match;
  83. });
  84. item.urlAddress = urlAddress
  85. },
  86. handelFormat(format) {
  87. let formatObj = {
  88. 'yyyy': 'yyyy',
  89. 'yyyy-MM': 'yyyy-MM',
  90. 'yyyy-MM-dd': 'yyyy-MM-dd',
  91. 'yyyy-MM-dd HH:mm': 'yyyy-MM-dd HH:mm',
  92. 'yyyy-MM-dd HH:mm:ss': 'yyyy-MM-dd HH:mm:ss',
  93. 'HH:mm:ss': 'HH:mm:ss',
  94. "HH:mm": "HH:mm",
  95. 'YYYY': 'yyyy',
  96. 'YYYY-MM': 'yyyy-MM',
  97. 'YYYY-MM-DD': 'yyyy-MM-dd',
  98. 'YYYY-MM-DD HH:mm': 'yyyy-MM-dd HH:mm',
  99. 'YYYY-MM-DD HH:mm:ss': 'yyyy-MM-dd HH:mm:ss',
  100. }
  101. return formatObj[format]
  102. },
  103. toDate(v, format) {
  104. format = format ? format : "yyyy-MM-dd HH:mm:ss"
  105. if (!v) return "";
  106. var d = v;
  107. if (typeof v === 'string') {
  108. if (v.indexOf("/Date(") > -1)
  109. d = new Date(parseInt(v.replace("/Date(", "").replace(")/", ""), 10));
  110. else
  111. d = new Date(Date.parse(v.replace(/-/g, "/").replace("T", " ").split(".")[0]));
  112. } else {
  113. d = new Date(v)
  114. }
  115. var o = {
  116. "M+": d.getMonth() + 1,
  117. "d+": d.getDate(),
  118. "h+": d.getHours(),
  119. "H+": d.getHours(),
  120. "m+": d.getMinutes(),
  121. "s+": d.getSeconds(),
  122. "q+": Math.floor((d.getMonth() + 3) / 3),
  123. "S": d.getMilliseconds()
  124. };
  125. if (/(y+)/.test(format)) {
  126. format = format.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
  127. }
  128. for (var k in o) {
  129. if (new RegExp("(" + k + ")").test(format)) {
  130. format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" +
  131. o[k])
  132. .length));
  133. }
  134. }
  135. return format;
  136. },
  137. toFileSize(size) {
  138. if (size == null || size == "") {
  139. return "";
  140. }
  141. if (size < 1024.00)
  142. return jnpf.toDecimal(size) + " 字节";
  143. else if (size >= 1024.00 && size < 1048576)
  144. return jnpf.toDecimal(size / 1024.00) + " KB";
  145. else if (size >= 1048576 && size < 1073741824)
  146. return jnpf.toDecimal(size / 1024.00 / 1024.00) + " MB";
  147. else if (size >= 1073741824)
  148. return jnpf.toDecimal(size / 1024.00 / 1024.00 / 1024.00) + " GB";
  149. },
  150. toDecimal(num) {
  151. if (num == null) {
  152. num = "0";
  153. }
  154. num = num.toString().replace(/\$|\,/g, '');
  155. if (isNaN(num))
  156. num = "0";
  157. var sign = (num == (num = Math.abs(num)));
  158. num = Math.floor(num * 100 + 0.50000000001);
  159. var cents = num % 100;
  160. num = Math.floor(num / 100).toString();
  161. if (cents < 10)
  162. cents = "0" + cents;
  163. for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
  164. num = num.substring(0, num.length - (4 * i + 3)) + '' +
  165. num.substring(num.length - (4 * i + 3));
  166. return (((sign) ? '' : '-') + num + '.' + cents);
  167. },
  168. getScriptFunc(str) {
  169. // #ifndef MP
  170. let func = null
  171. try {
  172. func = eval(str)
  173. if (Object.prototype.toString.call(func) !== '[object Function]') return false;
  174. return func
  175. } catch (error) {
  176. console.log(error);
  177. return false
  178. }
  179. // #endif
  180. // #ifdef MP
  181. return false
  182. // #endif
  183. },
  184. interfaceDataHandler(data) {
  185. if (!data.dataProcessing) return data.data
  186. const dataHandler = this.getScriptFunc(data.dataProcessing)
  187. if (!dataHandler) return data.data
  188. return dataHandler(data.data)
  189. },
  190. toDateText(dateTimeStamp) {
  191. if (!dateTimeStamp) return ''
  192. let result = ''
  193. let minute = 1000 * 60; //把分,时,天,周,半个月,一个月用毫秒表示
  194. let hour = minute * 60;
  195. let day = hour * 24;
  196. let week = day * 7;
  197. let halfamonth = day * 15;
  198. let month = day * 30;
  199. let now = new Date().getTime(); //获取当前时间毫秒
  200. let diffValue = now - dateTimeStamp; //时间差
  201. if (diffValue < 0) return "刚刚"
  202. let minC = diffValue / minute; //计算时间差的分,时,天,周,月
  203. let hourC = diffValue / hour;
  204. let dayC = diffValue / day;
  205. let weekC = diffValue / week;
  206. let monthC = diffValue / month;
  207. if (monthC >= 1 && monthC <= 3) {
  208. result = " " + parseInt(monthC) + "月前"
  209. } else if (weekC >= 1 && weekC <= 3) {
  210. result = " " + parseInt(weekC) + "周前"
  211. } else if (dayC >= 1 && dayC <= 6) {
  212. result = " " + parseInt(dayC) + "天前"
  213. } else if (hourC >= 1 && hourC <= 23) {
  214. result = " " + parseInt(hourC) + "小时前"
  215. } else if (minC >= 1 && minC <= 59) {
  216. result = " " + parseInt(minC) + "分钟前"
  217. } else if (diffValue >= 0 && diffValue <= minute) {
  218. result = "刚刚"
  219. } else {
  220. let datetime = new Date();
  221. datetime.setTime(dateTimeStamp);
  222. let Nyear = datetime.getFullYear();
  223. let Nmonth = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime
  224. .getMonth() + 1;
  225. let Ndate = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
  226. let Nhour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
  227. let Nminute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
  228. let Nsecond = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
  229. result = Nyear + "-" + Nmonth + "-" + Ndate
  230. }
  231. return result;
  232. },
  233. //取整
  234. toRound(number) {
  235. var bite = 0;
  236. if (number < 10) {
  237. return 10;
  238. }
  239. if (number > 10 && number < 50) {
  240. return 50;
  241. }
  242. while (number >= 10) {
  243. number /= 10;
  244. bite += 1;
  245. }
  246. return Math.ceil(number) * Math.pow(10, bite);
  247. },
  248. getAmountChinese(val) {
  249. if (!val && val !== 0) return '';
  250. if (val == 0) return '零元整';
  251. const regExp = /[a-zA-Z]/;
  252. if (regExp.test(val)) return '数字较大溢出';
  253. let amount = +val;
  254. if (isNaN(amount)) return '';
  255. if (amount < 0) amount = Number(amount.toString().split('-')[1]);
  256. const NUMBER = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
  257. const N_UNIT1 = ['', '拾', '佰', '仟'];
  258. const N_UNIT2 = ['', '万', '亿', '兆'];
  259. const D_UNIT = ['角', '分', '厘', '毫'];
  260. let [integer, decimal] = amount.toString().split('.');
  261. if (integer && (integer.length > 15 || integer.indexOf('e') > -1)) return '数字较大溢出';
  262. let res = '';
  263. // 整数部分
  264. if (integer) {
  265. let zeroCount = 0;
  266. for (let i = 0, len = integer.length; i < len; i++) {
  267. const num = integer.charAt(i);
  268. const pos = len - i - 1; // 排除个位后 所处的索引位置
  269. const q = pos / 4;
  270. const m = pos % 4;
  271. if (num === '0') {
  272. zeroCount++;
  273. } else {
  274. if (zeroCount > 0 && m !== 3) res += NUMBER[0];
  275. zeroCount = 0;
  276. res += NUMBER[parseInt(num)] + N_UNIT1[m];
  277. }
  278. if (m == 0 && zeroCount < 4) res += N_UNIT2[Math.floor(q)];
  279. }
  280. }
  281. if (Number(integer) != 0) res += '元';
  282. // 小数部分
  283. if (parseInt(decimal)) {
  284. for (let i = 0; i < 4; i++) {
  285. const num = decimal.charAt(i);
  286. if (parseInt(num)) res += NUMBER[num] + D_UNIT[i];
  287. }
  288. } else {
  289. res += '整';
  290. }
  291. if (val < 0) res = '负数' + res;
  292. return res;
  293. },
  294. thousandsFormat(num) {
  295. if (num === 0) return '0';
  296. if (!num) return '';
  297. const numArr = num.toString().split('.');
  298. numArr[0] = numArr[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  299. return numArr.join('.');
  300. },
  301. base64: {
  302. encode(str, isEncodeURIComponent = true) {
  303. if (!str) return ''
  304. const newStr = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(str))
  305. return isEncodeURIComponent ? encodeURIComponent(newStr) : newStr
  306. },
  307. decode(str, isDecodeURIComponent = true) {
  308. if (!str) return ''
  309. const newStr = isDecodeURIComponent ? decodeURIComponent(str) : str
  310. const result = CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(newStr))
  311. return result
  312. }
  313. },
  314. idGenerator() {
  315. let quotient = (new Date() - new Date('2020-08-01'))
  316. quotient += Math.ceil(Math.random() * 1000)
  317. const chars = '0123456789ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz';
  318. const charArr = chars.split("")
  319. const radix = chars.length;
  320. const res = []
  321. do {
  322. let mod = quotient % radix;
  323. quotient = (quotient - mod) / radix;
  324. res.push(charArr[mod])
  325. } while (quotient);
  326. return res.join('')
  327. },
  328. dynamicText(value, options) {
  329. if (!value) return ''
  330. if (Array.isArray(value)) {
  331. if (!options || !Array.isArray(options)) return value.join()
  332. let textList = []
  333. for (let i = 0; i < value.length; i++) {
  334. let item = options.filter(o => o.id == value[i])[0]
  335. if (!item || !item.fullName) {
  336. textList.push(value[i])
  337. } else {
  338. textList.push(item.fullName)
  339. }
  340. }
  341. return textList.join()
  342. }
  343. if (!options || !Array.isArray(options)) return value
  344. let item = options.filter(o => o.id == value)[0]
  345. if (!item || !item.fullName) return value
  346. return item.fullName
  347. },
  348. treeToArray(treeData, type = '') {
  349. let list = []
  350. const loop = (treeData) => {
  351. for (let i = 0; i < treeData.length; i++) {
  352. const item = treeData[i]
  353. if (!type || item.type === type) list.push(item)
  354. if (item.children && Array.isArray(item.children)) loop(item.children)
  355. }
  356. }
  357. loop(treeData)
  358. return list
  359. },
  360. dynamicTreeText(value, options) {
  361. if (!value) return ''
  362. const transfer = (data, partition) => {
  363. let textList = []
  364. const loop = (data, id) => {
  365. for (let i = 0; i < data.length; i++) {
  366. if (data[i].id === id) {
  367. textList.push(data[i].fullName)
  368. break
  369. }
  370. if (data[i].children) loop(data[i].children, id)
  371. }
  372. }
  373. for (let i = 0; i < data.length; i++) {
  374. if (Array.isArray(data[i])) {
  375. textList.push(transfer(data[i], "/"))
  376. } else {
  377. loop(options, data[i])
  378. }
  379. }
  380. return textList.join(partition)
  381. }
  382. if (!options || !Array.isArray(options)) return Array.isArray(value) ? value.join() : value
  383. if (Array.isArray(value)) return transfer(value)
  384. return transfer(value.split())
  385. },
  386. onlineUtils: {
  387. // 获取用户信息
  388. getUserInfo() {
  389. const userInfo = uni.getStorageSync('userInfo') || {};
  390. userInfo.token = uni.getStorageSync('token') || '';
  391. return userInfo;
  392. },
  393. // 获取设备信息
  394. getDeviceInfo() {
  395. const deviceInfo = {
  396. vueVersion: '3',
  397. origin: 'app'
  398. };
  399. return deviceInfo;
  400. },
  401. // 请求
  402. request(url, method, data, header) {
  403. return request({
  404. url: url,
  405. method: method || 'GET',
  406. data: data || {},
  407. header: header || {},
  408. options: {
  409. load: false
  410. }
  411. })
  412. },
  413. // 路由跳转
  414. route(url, type = 'navigateTo') {
  415. if (!url) return;
  416. uni.$u.route({
  417. url,
  418. type
  419. })
  420. },
  421. // 消息提示
  422. toast(message, _type = 'info', duration = 3000) {
  423. uni.$u.toast(message, duration)
  424. },
  425. },
  426. aesEncryption: {
  427. decrypt(str, cipherKey = '') {
  428. if (!cipherKey) cipherKey = md5Libs.md5(define.cipherKey)
  429. const hexStr = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(str))
  430. const decryptedData = CryptoJS.AES.decrypt(hexStr, CryptoJS.enc.Utf8.parse(cipherKey), {
  431. mode: CryptoJS.mode.ECB,
  432. padding: CryptoJS.pad.Pkcs7
  433. }).toString(CryptoJS.enc.Utf8);
  434. return decryptedData
  435. },
  436. encrypt(str, cipherKey = '') {
  437. if (!cipherKey) cipherKey = md5Libs.md5(define.cipherKey)
  438. const encryptedData = CryptoJS.AES.encrypt(str, CryptoJS.enc.Utf8.parse(cipherKey), {
  439. mode: CryptoJS.mode.ECB,
  440. padding: CryptoJS.pad.Pkcs7
  441. }).toString();
  442. const result = CryptoJS.enc.Hex.stringify(CryptoJS.enc.Base64.parse(encryptedData))
  443. return result
  444. }
  445. },
  446. getDistance(lat1, lon1, lat2, lon2) {
  447. const toRadians = (degrees) => {
  448. return degrees * (Math.PI / 180);
  449. }
  450. const R = 6371;
  451. const dLat = toRadians(lat2 - lat1);
  452. const dLon = toRadians(lon2 - lon1);
  453. const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
  454. Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) *
  455. Math.sin(dLon / 2) * Math.sin(dLon / 2);
  456. const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  457. const distance = R * c;
  458. return distance * 1000;
  459. },
  460. getParamList(templateJson, data, rowKey = 'id') {
  461. if (!templateJson || !templateJson.length) return [];
  462. for (let i = 0; i < templateJson.length; i++) {
  463. const e = templateJson[i];
  464. if (e.sourceType == 1 && data) {
  465. e.defaultValue = data[e.relationField] || data[e.relationField] == 0 ||
  466. data[e.relationField] == false ? data[e.relationField] : '';
  467. }
  468. if (e.sourceType == 4 && e.relationField == '@formId') e.defaultValue = data[rowKey] || '';
  469. }
  470. return templateJson;
  471. },
  472. getBatchParamList(templateJson, data) {
  473. if (!templateJson?.length) return [];
  474. for (let i = 0; i < templateJson.length; i++) {
  475. const e = templateJson[i];
  476. if (e.sourceType == 1 && data.items?.length) {
  477. e.defaultValue = data.items.map(o => (data.webType == '4' ? o[e.relationField] : o[e
  478. .relationField + '_jnpfId']));
  479. }
  480. if (e.sourceType == 4 && e.relationField == '@formId') e.defaultValue = data.items.map(o => o.id);
  481. }
  482. return templateJson;
  483. },
  484. getLaunchFlowParamList(transferList, data, rowKey = 'id') {
  485. transferList = JSON.parse(JSON.stringify(transferList))
  486. if (!transferList?.length) return [];
  487. for (let i = 0; i < transferList.length; i++) {
  488. const e = transferList[i];
  489. if (e.sourceType == 1) {
  490. if (e.sourceValue == '@formId') {
  491. e.defaultValue = data[rowKey] || '';
  492. } else {
  493. if (e.sourceValue.includes('-')) {
  494. const tableVModel = e.sourceValue.split('-')[0];
  495. const childVModel = e.sourceValue.split('-')[1];
  496. e.defaultValue = (data[tableVModel] || []).map(o => o[childVModel + '_jnpfId']);
  497. } else {
  498. const key = e.sourceValue + '_jnpfId';
  499. e.defaultValue = data[key] || data[key] == 0 || data[key] == false ? data[key] : '';
  500. }
  501. }
  502. } else {
  503. e.defaultValue = e.sourceValue;
  504. }
  505. }
  506. return transferList;
  507. },
  508. getDateTimeUnit(format) {
  509. if (format == 'YYYY' || format == 'yyyy') return 'year';
  510. if (format == 'YYYY-MM' || format == 'yyyy-MM') return 'month';
  511. if (format == 'YYYY-MM-DD' || format == 'yyyy-MM-dd') return 'day';
  512. if (format == 'YYYY-MM-DD HH:mm' || format == 'yyyy-MM-dd HH:mm') return 'minute';
  513. if (format == 'YYYY-MM-DD HH:mm:ss' || format == 'yyyy-MM-dd HH:mm:ss') return 'second';
  514. return 'day';
  515. },
  516. // 在线开发搜索设置默认值
  517. setSearchDefaultValue(item, now) {
  518. if (!['datePicker', 'organizeSelect', 'posSelect', 'userSelect'].includes(item.jnpfKey) ||
  519. item.sourceType != 4) return;
  520. const val = item.value;
  521. item.value = this.getSearchRealValue(val, item.format, now, item.__config__.isFromParam,
  522. item.searchMultiple);
  523. },
  524. // 代码生成默认值使用
  525. getSearchRealValue(key, format, now, isFromParam = false, multiple = false) {
  526. const userInfo = uni.getStorageSync('userInfo') || {}
  527. // 当前组织
  528. if (key === '@currOrganize') {
  529. if (!userInfo.organizeIds?.length) return !!multiple ? [] : '';
  530. return !!multiple ? userInfo.organizeIds : userInfo.organizeId;
  531. }
  532. // 当前岗位
  533. if (key === '@currPosition') {
  534. if (!userInfo.positionIds?.length) return !!multiple ? [] : '';
  535. return !!multiple ? userInfo.positionIds : userInfo.positionId;
  536. }
  537. // 当前用户
  538. if (key === '@currUser') {
  539. return !!multiple ? [userInfo.userId] : userInfo.userId;
  540. }
  541. now = dayjs(now)
  542. const unit = this.getDateTimeUnit(format || 'YYYY-MM-DD HH:mm:ss');
  543. const lastTimeStamp = now.startOf(unit).valueOf();
  544. if (isFromParam) return lastTimeStamp;
  545. let firstDate = now;
  546. // 前三天
  547. if (key === '@pastThreeDays') {
  548. firstDate = now.subtract(3, 'day');
  549. }
  550. // 前一周
  551. if (key === '@pastWeek') {
  552. firstDate = now.subtract(1, 'week');
  553. }
  554. // 前一个月
  555. if (key === '@pastMonth') {
  556. firstDate = now.subtract(1, 'month');
  557. }
  558. // 前三个月
  559. if (key === '@pastThreeMonths') {
  560. firstDate = now.subtract(3, 'month');
  561. }
  562. // 前半年
  563. if (key === '@pastSixMonths') {
  564. firstDate = now.subtract(6, 'month');
  565. }
  566. // 前一年
  567. if (key === '@pastYear') {
  568. firstDate = now.subtract(1, 'year');
  569. }
  570. const firstTimeStamp = firstDate.startOf(unit).valueOf();
  571. return [firstTimeStamp, lastTimeStamp];
  572. },
  573. getAuthImgUrl(url, isRedirect = true) {
  574. // #ifndef H5
  575. isRedirect = false
  576. // #endif
  577. if (!url) return '';
  578. const base64WithPrefixRegex =
  579. /^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+);base64,([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/;
  580. if (base64WithPrefixRegex.test(url)) return url;
  581. const userInfo = uni.getStorageSync('userInfo') || {}
  582. const securityKey = userInfo?.securityKey || '';
  583. if (!securityKey) return define.baseURL + url;
  584. const realUrl = define.baseURL + url + (url.includes('?') ? '&' : '?') + 's=' + securityKey +
  585. (isRedirect ? '' : '&t=t');
  586. return realUrl;
  587. }
  588. }
  589. export default jnpf