common.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import config from '@/config'
  2. const baseUrlimg=config.baseUrl
  3. /**
  4. * 显示消息提示框
  5. * @param content 提示的标题
  6. */
  7. export function toast(content) {
  8. uni.showToast({
  9. icon: 'none',
  10. title: content
  11. })
  12. }
  13. /**
  14. * 显示模态弹窗
  15. * @param content 提示的标题
  16. */
  17. export function showConfirm(content) {
  18. return new Promise((resolve, reject) => {
  19. uni.showModal({
  20. title: '提示',
  21. content: content,
  22. cancelText: '取消',
  23. confirmText: '确定',
  24. success: function(res) {
  25. resolve(res)
  26. }
  27. })
  28. })
  29. }
  30. //解析富文本方法
  31. export function formatRichText(html) {
  32. let newContent = html.replace(/\/dev-api/g, '');
  33. newContent = newContent.replace(/\<img src="/gi,
  34. '<img style="max-width:100%;height:auto;" src="' +baseUrlimg);
  35. return newContent;
  36. }
  37. /**
  38. * 参数处理
  39. * @param params 参数
  40. */
  41. export function tansParams(params) {
  42. let result = ''
  43. for (const propName of Object.keys(params)) {
  44. const value = params[propName]
  45. var part = encodeURIComponent(propName) + "="
  46. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  47. if (typeof value === 'object') {
  48. for (const key of Object.keys(value)) {
  49. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  50. let params = propName + '[' + key + ']'
  51. var subPart = encodeURIComponent(params) + "="
  52. result += subPart + encodeURIComponent(value[key]) + "&"
  53. }
  54. }
  55. } else {
  56. result += part + encodeURIComponent(value) + "&"
  57. }
  58. }
  59. }
  60. return result
  61. }