common.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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,showCancel) {
  16. return new Promise((resolve, reject) => {
  17. uni.showModal({
  18. title: '提示',
  19. content: content,
  20. cancelText: '取消',
  21. confirmText: '确定',
  22. showCancel:true||showCancel,
  23. success: function(res) {
  24. resolve(res)
  25. }
  26. })
  27. })
  28. }
  29. /**
  30. * 参数处理
  31. * @param params 参数
  32. */
  33. export function tansParams(params) {
  34. let result = ''
  35. for (const propName of Object.keys(params)) {
  36. const value = params[propName]
  37. var part = encodeURIComponent(propName) + "="
  38. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  39. if (typeof value === 'object') {
  40. for (const key of Object.keys(value)) {
  41. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  42. let params = propName + '[' + key + ']'
  43. var subPart = encodeURIComponent(params) + "="
  44. result += subPart + encodeURIComponent(value[key]) + "&"
  45. }
  46. }
  47. } else {
  48. result += part + encodeURIComponent(value) + "&"
  49. }
  50. }
  51. }
  52. return result
  53. }