util.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. var common_vendor = require("../common/vendor.js");
  3. const urlEncode = (obj = {}) => {
  4. const result = [];
  5. for (const key in obj) {
  6. const item = obj[key];
  7. if (!item) {
  8. continue;
  9. }
  10. if (isArray(item)) {
  11. item.forEach((val) => {
  12. result.push(key + "=" + val);
  13. });
  14. } else {
  15. result.push(key + "=" + item);
  16. }
  17. }
  18. return result.join("&");
  19. };
  20. const inArray = (search, array) => {
  21. for (var i in array) {
  22. if (array[i] == search)
  23. return true;
  24. }
  25. return false;
  26. };
  27. const isEmptyObject = (object) => {
  28. return Object.keys(object).length === 0;
  29. };
  30. const isObject = (object) => {
  31. return Object.prototype.toString.call(object) === "[object Object]";
  32. };
  33. const isArray = (array) => {
  34. return Object.prototype.toString.call(array) === "[object Array]";
  35. };
  36. const isEmpty = (value) => {
  37. if (isArray(value)) {
  38. return value.length === 0;
  39. }
  40. if (isObject(value)) {
  41. return isEmptyObject(value);
  42. }
  43. return !value;
  44. };
  45. function isLogin() {
  46. let obj = common_vendor.index.getStorageSync("AppToken");
  47. return !!obj;
  48. }
  49. function navTo(url) {
  50. common_vendor.index.navigateTo({
  51. url
  52. });
  53. }
  54. function getRegistrationID(type) {
  55. }
  56. function parsePhone(mobile) {
  57. var str = mobile.substr(0, 3) + "****" + mobile.substr(7);
  58. return str;
  59. }
  60. exports.getRegistrationID = getRegistrationID;
  61. exports.inArray = inArray;
  62. exports.isEmpty = isEmpty;
  63. exports.isLogin = isLogin;
  64. exports.navTo = navTo;
  65. exports.parsePhone = parsePhone;
  66. exports.urlEncode = urlEncode;