tool.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const getRandomNum = (len, radix) => {
  2. // getRandomNum(24, 16)
  3.   const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
  4.   const uuid = []
  5.   radix = radix || chars.length
  6.   if (len) {
  7.     // Compact form
  8.     for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix ]
  9.   } else {
  10.     // rfc4122, version 4 form
  11.     let r
  12.     // rfc4122 requires these characters
  13.     uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
  14.     uuid[14] = '4'
  15.     // Fill in random data.  At i==19 set the high bits of clock sequence as
  16.     // per rfc4122, sec. 4.1.5
  17.     for (let i = 0; i < 36; i++) {
  18.       if (!uuid[i]) {
  19.         r = 0 | Math.random() * 16
  20.         uuid[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r]
  21.       }
  22.     }
  23.   }
  24.   return uuid.join('') + new Date().getTime()
  25. }
  26. const msgBase = (msgText, bc) => {
  27. uni.showToast({
  28. title: msgText,
  29. icon: 'none',
  30. duration: 2000
  31. }).then(() => {
  32. if (bc) bc()
  33. })
  34. }
  35. const confirmMsgFn = (msgText, successBc, errorBc, title = '提示') => {
  36. uni.showModal({
  37. title,
  38. content: msgText,
  39. success: function (res) {
  40. if (res.confirm) {
  41. if (successBc) successBc()
  42. } else if (res.cancel) {
  43. if (errorBc) errorBc()
  44. }
  45. }
  46. })
  47. }
  48. export {
  49. msgBase,
  50. confirmMsgFn,
  51. getRandomNum,
  52. }