common.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * 显示消息提示框
  3. * @param content 提示的标题
  4. */
  5. export function toast(content) {
  6. uni.showToast({
  7. icon: 'none',
  8. title: content
  9. })
  10. }
  11. /**
  12. * 显示模态弹窗
  13. * @param content 提示的标题
  14. */
  15. export function showConfirm(content) {
  16. return new Promise((resolve, reject) => {
  17. uni.showModal({
  18. title: '提示',
  19. content: content,
  20. cancelText: '取消',
  21. confirmText: '确定',
  22. success: function(res) {
  23. resolve(res)
  24. }
  25. })
  26. })
  27. }
  28. /**
  29. * 参数处理
  30. * @param params 参数
  31. */
  32. export function tansParams(params) {
  33. let result = ''
  34. for (const propName of Object.keys(params)) {
  35. const value = params[propName]
  36. var part = encodeURIComponent(propName) + "="
  37. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  38. if (typeof value === 'object') {
  39. for (const key of Object.keys(value)) {
  40. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  41. let params = propName + '[' + key + ']'
  42. var subPart = encodeURIComponent(params) + "="
  43. result += subPart + encodeURIComponent(value[key]) + "&"
  44. }
  45. }
  46. } else {
  47. result += part + encodeURIComponent(value) + "&"
  48. }
  49. }
  50. }
  51. return result
  52. }