演示项目-图书馆
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.

112 lines
3.3 KiB

2 years ago
  1. export const Urlencode = str => {
  2. str = (str + '').toString();
  3. return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
  4. replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
  5. }
  6. export const isIPhoneX = () => {
  7. let u = navigator.userAgent;
  8. let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
  9. if (isIOS) {
  10. if (screen.height == 812 && screen.width == 375) {
  11. return true;
  12. }
  13. else {
  14. return false;
  15. }
  16. }
  17. }
  18. //获取url 参数值,并解码
  19. export const getUnescapeUrlParam = (name) => {
  20. let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  21. let localUrl = window.location.href.split("?")[1]
  22. let r = localUrl.match(reg);
  23. if (r != null) {
  24. return unescape(r[2]);
  25. }
  26. return null;
  27. }
  28. // 截取时间
  29. export const cutTime = (val) => {
  30. if (val == null) {
  31. return val
  32. } else {
  33. return val.slice(0, val.indexOf("T"))
  34. }
  35. }
  36. // 判断是否登录才可操作
  37. export const isLogin = (proxy,$dialog) => {
  38. let userData = localStorage.getItem('userData') || "";
  39. // clientType主要是鉴别当前用户的类型
  40. // ClientType = 1 普通用户
  41. // ClientType = 0 白名单用户
  42. if (JSON.parse(userData).clientType === 0) {
  43. proxy.$dialog.confirm({
  44. title: '',
  45. message: '该功能需要登录账号!',
  46. })
  47. .then(() => {
  48. proxy.$router.push('/Login');
  49. })
  50. .catch(() => {
  51. console.log('用户点击取消');
  52. });
  53. return false;
  54. }
  55. }
  56. // 时间格式化1 val时间戳数字
  57. export const formatDateDay = (val) => {
  58. let date = new Date(val);
  59. let YY = date.getFullYear() + '-';
  60. let MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  61. let DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  62. return YY + MM + + DD
  63. }
  64. // 时间格式化2 val时间戳数字
  65. export const formatDateMin = (val) => {
  66. let date = new Date(val);
  67. let YY = date.getFullYear() + '-';
  68. let MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  69. let DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  70. let hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  71. let mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  72. let ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  73. return YY + MM + DD +" "+ hh + mm + ss;
  74. }
  75. // 判断是否微信浏览器
  76. export const isWeiXin = () => {
  77. let ua = window.navigator.userAgent.toLowerCase();
  78. if(ua.match(/MicroMessenger/i) == 'micromessenger'){
  79. return true;
  80. }else{
  81. return false;
  82. }
  83. }
  84. //获取url 参数值 (原封不动获取url 参数, 不解码)
  85. const getUrlParam = (name) => {
  86. let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
  87. let localUrl = window.location.href.split("?")[1]
  88. let r = localUrl.match(reg);
  89. if (r != null) {
  90. return r[2];
  91. }
  92. return null;
  93. }
  94. //检测是否是移动端
  95. const isMobile = () => {
  96. if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
  97. return true;
  98. } else {
  99. return false;
  100. }
  101. }