common.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 selectValueKey(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. export function selectValue(datas, value) {
  56. var actions = [];
  57. var idx=0;
  58. Object.keys(datas).some((key) => {
  59. if (datas[key].value == ('' + value)) {
  60. actions.push(datas[key].label);
  61. return true;
  62. }
  63. })
  64. return actions.join('')
  65. }
  66. export function selectValuetext(datas, value) {
  67. var actions = [];
  68. var idx=0;
  69. Object.keys(datas).some((key) => {
  70. if (datas[key].value == ('' + value)) {
  71. actions.push(datas[key].text);
  72. return true;
  73. }
  74. })
  75. return actions.join('')
  76. }
  77. /**
  78. * 参数处理
  79. * @param params 参数
  80. */
  81. export function tansParams(params) {
  82. let result = ''
  83. for (const propName of Object.keys(params)) {
  84. const value = params[propName]
  85. var part = encodeURIComponent(propName) + "="
  86. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  87. if (typeof value === 'object') {
  88. for (const key of Object.keys(value)) {
  89. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  90. let params = propName + '[' + key + ']'
  91. var subPart = encodeURIComponent(params) + "="
  92. result += subPart + encodeURIComponent(value[key]) + "&"
  93. }
  94. }
  95. } else {
  96. result += part + encodeURIComponent(value) + "&"
  97. }
  98. }
  99. }
  100. return result
  101. }