common.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. if (res.confirm) {
  24. resolve(res.confirm)
  25. } else {
  26. resolve(false)
  27. }
  28. },
  29. fail: function(error){
  30. reject(error)
  31. }
  32. })
  33. })
  34. }
  35. /**
  36. * 参数处理
  37. * @param params 参数
  38. */
  39. export function tansParams(params) {
  40. let result = ''
  41. for (const propName of Object.keys(params)) {
  42. const value = params[propName]
  43. var part = encodeURIComponent(propName) + "="
  44. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  45. if (typeof value === 'object') {
  46. for (const key of Object.keys(value)) {
  47. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  48. let params = propName + '[' + key + ']'
  49. var subPart = encodeURIComponent(params) + "="
  50. result += subPart + encodeURIComponent(value[key]) + "&"
  51. }
  52. }
  53. } else {
  54. result += part + encodeURIComponent(value) + "&"
  55. }
  56. }
  57. }
  58. return result
  59. }