智慧申请系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

396 lines
9.4 KiB

  1. const formatTime = date => {
  2. const year = date.getFullYear()
  3. const month = date.getMonth() + 1
  4. const day = date.getDate()
  5. const hour = date.getHours()
  6. const minute = date.getMinutes()
  7. const second = date.getSeconds()
  8. return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  9. }
  10. const parseTime = (time, cFormat) => {
  11. if (arguments.length === 0 || !time) {
  12. return null
  13. }
  14. const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  15. let date
  16. if (typeof time === 'object') {
  17. date = time
  18. } else {
  19. if (typeof time === 'string') {
  20. if (/^[0-9]+$/.test(time)) {
  21. // support "1548221490638"
  22. time = parseInt(time)
  23. } else {
  24. // support safari
  25. time = time.replace(new RegExp(/-/gm), '/')
  26. }
  27. }
  28. if (typeof time === 'number' && time.toString().length === 10) {
  29. time = time * 1000
  30. }
  31. date = new Date(time)
  32. }
  33. const formatObj = {
  34. y: date.getFullYear(),
  35. m: date.getMonth() + 1,
  36. d: date.getDate(),
  37. h: date.getHours(),
  38. i: date.getMinutes(),
  39. s: date.getSeconds(),
  40. a: date.getDay()
  41. }
  42. return format.replace(/{([ymdhisa])+}/g, (result, key) => {
  43. const value = formatObj[key]
  44. if (key === 'a') {
  45. return ['日', '一', '二', '三', '四', '五', '六'][value]
  46. }
  47. return value.toString().padStart(2, '0')
  48. })
  49. }
  50. const formatNumber = n => {
  51. n = n.toString()
  52. return n[1] ? n : '0' + n
  53. }
  54. // 验证手机号码
  55. const verifyPhoneNum = value => /^1[3|4|5|6|7|8|9]\d{9}$/.test(value)
  56. // 验证身份证号码
  57. const verifyCardID = value => /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value)
  58. const getBirthday = (idCard) => {
  59. var birthday = "";
  60. if (idCard != null && idCard != "") {
  61. if (idCard.length == 15) {
  62. birthday = "19" + idCard.substr(6, 6);
  63. } else if (idCard.length == 18) {
  64. birthday = idCard.substr(6, 8);
  65. }
  66. birthday = birthday.replace(/(.{4})(.{2})/, "$1-$2-");
  67. }
  68. return birthday;
  69. }
  70. // 下划线转换驼峰
  71. const toHump = (name) => {
  72. return name.replace(/\_(\w)/g, function(all, letter) {
  73. return letter.toUpperCase();
  74. });
  75. }
  76. // 驼峰转换下划线
  77. const toLine = (name) => {
  78. return name.replace(/([A-Z])/g, "_$1").toLowerCase();
  79. }
  80. // 节流
  81. const throttle = (fn, wait) => {
  82. var timer = null;
  83. return function() {
  84. var context = this;
  85. var args = arguments;
  86. if (!timer) {
  87. timer = setTimeout(function() {
  88. fn.apply(context, args);
  89. timer = null;
  90. }, wait)
  91. }
  92. }
  93. }
  94. const CryptoJS = CryptoJS || function(h, i) {
  95. var e = {},
  96. f = e.lib = {},
  97. l = f.Base = function() {
  98. function a() {}
  99. return {
  100. extend: function(j) {
  101. a.prototype = this;
  102. var d = new a;
  103. j && d.mixIn(j);
  104. d.$super = this;
  105. return d
  106. },
  107. create: function() {
  108. var a = this.extend();
  109. a.init.apply(a, arguments);
  110. return a
  111. },
  112. init: function() {},
  113. mixIn: function(a) {
  114. for (var d in a) a.hasOwnProperty(d) && (this[d] = a[d]);
  115. a.hasOwnProperty("toString") && (this.toString = a.toString)
  116. },
  117. clone: function() {
  118. return this.$super.extend(this)
  119. }
  120. }
  121. }(),
  122. k = f.WordArray = l.extend({
  123. init: function(a, j) {
  124. a =
  125. this.words = a || [];
  126. this.sigBytes = j != i ? j : 4 * a.length
  127. },
  128. toString: function(a) {
  129. return (a || m).stringify(this)
  130. },
  131. concat: function(a) {
  132. var j = this.words,
  133. d = a.words,
  134. c = this.sigBytes,
  135. a = a.sigBytes;
  136. this.clamp();
  137. if (c % 4)
  138. for (var b = 0; b < a; b++) j[c + b >>> 2] |= (d[b >>> 2] >>> 24 - 8 * (b % 4) & 255) << 24 - 8 * ((c + b) % 4);
  139. else if (65535 < d.length)
  140. for (b = 0; b < a; b += 4) j[c + b >>> 2] = d[b >>> 2];
  141. else j.push.apply(j, d);
  142. this.sigBytes += a;
  143. return this
  144. },
  145. clamp: function() {
  146. var a = this.words,
  147. b = this.sigBytes;
  148. a[b >>> 2] &= 4294967295 << 32 - 8 * (b % 4);
  149. a.length = h.ceil(b / 4)
  150. },
  151. clone: function() {
  152. var a =
  153. l.clone.call(this);
  154. a.words = this.words.slice(0);
  155. return a
  156. },
  157. random: function(a) {
  158. for (var b = [], d = 0; d < a; d += 4) b.push(4294967296 * h.random() | 0);
  159. return k.create(b, a)
  160. }
  161. }),
  162. o = e.enc = {},
  163. m = o.Hex = {
  164. stringify: function(a) {
  165. for (var b = a.words, a = a.sigBytes, d = [], c = 0; c < a; c++) {
  166. var e = b[c >>> 2] >>> 24 - 8 * (c % 4) & 255;
  167. d.push((e >>> 4).toString(16));
  168. d.push((e & 15).toString(16))
  169. }
  170. return d.join("")
  171. },
  172. parse: function(a) {
  173. for (var b = a.length, d = [], c = 0; c < b; c += 2) d[c >>> 3] |= parseInt(a.substr(c, 2), 16) << 24 - 4 * (c %
  174. 8);
  175. return k.create(d, b / 2)
  176. }
  177. },
  178. q = o.Latin1 = {
  179. stringify: function(a) {
  180. for (var b =
  181. a.words, a = a.sigBytes, d = [], c = 0; c < a; c++) d.push(String.fromCharCode(b[c >>> 2] >>> 24 - 8 * (c % 4) &
  182. 255));
  183. return d.join("")
  184. },
  185. parse: function(a) {
  186. for (var b = a.length, d = [], c = 0; c < b; c++) d[c >>> 2] |= (a.charCodeAt(c) & 255) << 24 - 8 * (c % 4);
  187. return k.create(d, b)
  188. }
  189. },
  190. r = o.Utf8 = {
  191. stringify: function(a) {
  192. try {
  193. return decodeURIComponent(escape(q.stringify(a)))
  194. } catch (b) {
  195. throw Error("Malformed UTF-8 data");
  196. }
  197. },
  198. parse: function(a) {
  199. return q.parse(unescape(encodeURIComponent(a)))
  200. }
  201. },
  202. b = f.BufferedBlockAlgorithm = l.extend({
  203. reset: function() {
  204. this._data = k.create();
  205. this._nDataBytes = 0
  206. },
  207. _append: function(a) {
  208. "string" == typeof a && (a = r.parse(a));
  209. this._data.concat(a);
  210. this._nDataBytes += a.sigBytes
  211. },
  212. _process: function(a) {
  213. var b = this._data,
  214. d = b.words,
  215. c = b.sigBytes,
  216. e = this.blockSize,
  217. g = c / (4 * e),
  218. g = a ? h.ceil(g) : h.max((g | 0) - this._minBufferSize, 0),
  219. a = g * e,
  220. c = h.min(4 * a, c);
  221. if (a) {
  222. for (var f = 0; f < a; f += e) this._doProcessBlock(d, f);
  223. f = d.splice(0, a);
  224. b.sigBytes -= c
  225. }
  226. return k.create(f, c)
  227. },
  228. clone: function() {
  229. var a = l.clone.call(this);
  230. a._data = this._data.clone();
  231. return a
  232. },
  233. _minBufferSize: 0
  234. });
  235. f.Hasher = b.extend({
  236. init: function() {
  237. this.reset()
  238. },
  239. reset: function() {
  240. b.reset.call(this);
  241. this._doReset()
  242. },
  243. update: function(a) {
  244. this._append(a);
  245. this._process();
  246. return this
  247. },
  248. finalize: function(a) {
  249. a && this._append(a);
  250. this._doFinalize();
  251. return this._hash
  252. },
  253. clone: function() {
  254. var a = b.clone.call(this);
  255. a._hash = this._hash.clone();
  256. return a
  257. },
  258. blockSize: 16,
  259. _createHelper: function(a) {
  260. return function(b, d) {
  261. return a.create(d).finalize(b)
  262. }
  263. },
  264. _createHmacHelper: function(a) {
  265. return function(b, d) {
  266. return g.HMAC.create(a, d).finalize(b)
  267. }
  268. }
  269. });
  270. var g = e.algo = {};
  271. return e
  272. }(Math);
  273. (function(h) {
  274. var i = CryptoJS,
  275. e = i.lib,
  276. f = e.WordArray,
  277. e = e.Hasher,
  278. l = i.algo,
  279. k = [],
  280. o = [];
  281. (function() {
  282. function e(a) {
  283. for (var b = h.sqrt(a), d = 2; d <= b; d++)
  284. if (!(a % d)) return !1;
  285. return !0
  286. }
  287. function f(a) {
  288. return 4294967296 * (a - (a | 0)) | 0
  289. }
  290. for (var b = 2, g = 0; 64 > g;) e(b) && (8 > g && (k[g] = f(h.pow(b, 0.5))), o[g] = f(h.pow(b, 1 / 3)), g++), b++
  291. })();
  292. var m = [],
  293. l = l.SHA256 = e.extend({
  294. _doReset: function() {
  295. this._hash = f.create(k.slice(0))
  296. },
  297. _doProcessBlock: function(e, f) {
  298. for (var b = this._hash.words, g = b[0], a = b[1], j = b[2], d = b[3], c = b[4], h = b[5], l = b[6], k = b[7], n =
  299. 0; 64 >
  300. n; n++) {
  301. if (16 > n) m[n] = e[f + n] | 0;
  302. else {
  303. var i = m[n - 15],
  304. p = m[n - 2];
  305. m[n] = ((i << 25 | i >>> 7) ^ (i << 14 | i >>> 18) ^ i >>> 3) + m[n - 7] + ((p << 15 | p >>> 17) ^ (p << 13 |
  306. p >>> 19) ^ p >>> 10) + m[n - 16]
  307. }
  308. i = k + ((c << 26 | c >>> 6) ^ (c << 21 | c >>> 11) ^ (c << 7 | c >>> 25)) + (c & h ^ ~c & l) + o[n] + m[n];
  309. p = ((g << 30 | g >>> 2) ^ (g << 19 | g >>> 13) ^ (g << 10 | g >>> 22)) + (g & a ^ g & j ^ a & j);
  310. k = l;
  311. l = h;
  312. h = c;
  313. c = d + i | 0;
  314. d = j;
  315. j = a;
  316. a = g;
  317. g = i + p | 0
  318. }
  319. b[0] = b[0] + g | 0;
  320. b[1] = b[1] + a | 0;
  321. b[2] = b[2] + j | 0;
  322. b[3] = b[3] + d | 0;
  323. b[4] = b[4] + c | 0;
  324. b[5] = b[5] + h | 0;
  325. b[6] = b[6] + l | 0;
  326. b[7] = b[7] + k | 0
  327. },
  328. _doFinalize: function() {
  329. var e = this._data,
  330. f = e.words,
  331. b = 8 * this._nDataBytes,
  332. g = 8 * e.sigBytes;
  333. f[g >>> 5] |= 128 << 24 - g % 32;
  334. f[(g + 64 >>> 9 << 4) + 15] = b;
  335. e.sigBytes = 4 * f.length;
  336. this._process()
  337. }
  338. });
  339. i.SHA256 = e._createHelper(l);
  340. i.HmacSHA256 = e._createHmacHelper(l)
  341. })(Math);
  342. (function() {
  343. var h = CryptoJS,
  344. i = h.enc.Utf8;
  345. h.algo.HMAC = h.lib.Base.extend({
  346. init: function(e, f) {
  347. e = this._hasher = e.create();
  348. "string" == typeof f && (f = i.parse(f));
  349. var h = e.blockSize,
  350. k = 4 * h;
  351. f.sigBytes > k && (f = e.finalize(f));
  352. for (var o = this._oKey = f.clone(), m = this._iKey = f.clone(), q = o.words, r = m.words, b = 0; b < h; b++) q[
  353. b] ^= 1549556828, r[b] ^= 909522486;
  354. o.sigBytes = m.sigBytes = k;
  355. this.reset()
  356. },
  357. reset: function() {
  358. var e = this._hasher;
  359. e.reset();
  360. e.update(this._iKey)
  361. },
  362. update: function(e) {
  363. this._hasher.update(e);
  364. return this
  365. },
  366. finalize: function(e) {
  367. var f =
  368. this._hasher,
  369. e = f.finalize(e);
  370. f.reset();
  371. return f.finalize(this._oKey.clone().concat(e))
  372. }
  373. })
  374. })();
  375. module.exports = CryptoJS
  376. module.exports = {
  377. formatTime,
  378. verifyPhoneNum,
  379. toHump,
  380. toLine,
  381. verifyCardID,
  382. getBirthday,
  383. throttle,
  384. parseTime,
  385. CryptoJS
  386. }