common.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. export function selectDictValue(datas, value) {
  30. var actions = [];
  31. Object.keys(datas).some((key) => {
  32. if (datas[key].dictValue == ('' + value)) {
  33. actions.push(datas[key].dictLabel);
  34. return true;
  35. }
  36. })
  37. return actions.join('');
  38. }
  39. /**
  40. * 参数处理
  41. * @param params 参数
  42. */
  43. export function tansParams(params) {
  44. let result = ''
  45. for (const propName of Object.keys(params)) {
  46. const value = params[propName]
  47. var part = encodeURIComponent(propName) + "="
  48. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  49. if (typeof value === 'object') {
  50. for (const key of Object.keys(value)) {
  51. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  52. let params = propName + '[' + key + ']'
  53. var subPart = encodeURIComponent(params) + "="
  54. result += subPart + encodeURIComponent(value[key]) + "&"
  55. }
  56. }
  57. } else {
  58. result += part + encodeURIComponent(value) + "&"
  59. }
  60. }
  61. }
  62. return result
  63. }