utils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Created by Vbe on 16/11/18.
  3. */
  4. /**
  5. * @param {string} path
  6. * @returns {Boolean}
  7. */
  8. export function isExternal(path) {
  9. return /^(https?:|mailto:|tel:)/.test(path)
  10. }
  11. /**
  12. * @param {string} str
  13. * @returns {Boolean}
  14. */
  15. export function validUsername(str) {
  16. const valid_map = ['admin', 'editor']
  17. return valid_map.indexOf(str.trim()) >= 0
  18. }
  19. /**
  20. * @param {string} str
  21. * @returns {Boolean}
  22. */
  23. export function isString(str) {
  24. if (typeof str === 'string' || str instanceof String) {
  25. return true
  26. }
  27. return false
  28. }
  29. /**
  30. * @param {Array} arg
  31. * @returns {Boolean}
  32. */
  33. export function isArray(arg) {
  34. if (typeof Array.isArray === 'undefined') {
  35. return Object.prototype.toString.call(arg) === '[object Array]'
  36. }
  37. return Array.isArray(arg)
  38. }
  39. export function formatNumber(number) {
  40. number += '';
  41. let x = number.split('.');
  42. let x1 = x[0];
  43. let x2 = x.length > 1 ? '.' + x[1] : '';
  44. var rgx = /(\d+)(\d{3})/;
  45. while (rgx.test(x1)) {
  46. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  47. }
  48. return x1 + x2;
  49. }
  50. export function viewUrl(url) {
  51. // #ifdef APP-PLUS
  52. plus.share.sendWithSystem({
  53. //type: 'text',
  54. href: url,
  55. //content: 'https://www.trecs.ai'
  56. }, success => {
  57. }, error => {
  58. })
  59. // #endif
  60. // #ifdef H5
  61. window.open(url)
  62. // #endif
  63. }
  64. export function openUrl(url) {
  65. // #ifdef APP-PLUS
  66. plus.runtime.openURL(url)
  67. // #endif
  68. // #ifdef H5
  69. //window.open(url)
  70. location.href = url;
  71. // #endif
  72. }