util.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /** 判断是否是OAuth2APP环境 */
  2. export function isOAuth2AppEnv() {
  3. // #ifdef H5
  4. return /wxwork|dingtalk/i.test(navigator.userAgent)
  5. // #endif
  6. return false;
  7. }
  8. // 获取url中的参数
  9. export const getUrlParams = (url) => {
  10. let result = {
  11. url: '',
  12. params: {}
  13. };
  14. let list = url.split('?');
  15. result.url = list[0];
  16. let params = list[1];
  17. if (params) {
  18. let list = params.split('&');
  19. list.forEach(ele => {
  20. let dic = ele.split('=');
  21. let label = dic[0];
  22. let value = dic[1];
  23. result.params[label] = value;
  24. });
  25. }
  26. return result;
  27. };
  28. // 格式化金额,添加千位分隔符
  29. export const formatAmount = (amount, type) => {
  30. if (type === 'quantity') {
  31. if (amount === null || amount === undefined) return '0';
  32. return String(amount).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  33. } else {
  34. if (amount === null || amount === undefined) return '0.00';
  35. return parseFloat(amount)
  36. .toFixed(2)
  37. .replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  38. }
  39. };