common.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. export function selectValue(datas, value) {
  40. var actions = [];
  41. var idx=0;
  42. Object.keys(datas).some((key) => {
  43. if (datas[key].value == ('' + value)) {
  44. idx=key;
  45. actions.push(datas[key].label);
  46. return true;
  47. }
  48. })
  49. var newObj={
  50. actions:actions.join(''),
  51. key:idx
  52. }
  53. return newObj
  54. }
  55. /**
  56. * 参数处理
  57. * @param params 参数
  58. */
  59. export function tansParams(params) {
  60. let result = ''
  61. for (const propName of Object.keys(params)) {
  62. const value = params[propName]
  63. var part = encodeURIComponent(propName) + "="
  64. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  65. if (typeof value === 'object') {
  66. for (const key of Object.keys(value)) {
  67. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  68. let params = propName + '[' + key + ']'
  69. var subPart = encodeURIComponent(params) + "="
  70. result += subPart + encodeURIComponent(value[key]) + "&"
  71. }
  72. }
  73. } else {
  74. result += part + encodeURIComponent(value) + "&"
  75. }
  76. }
  77. }
  78. return result
  79. }