common.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 selectDictLabel(datas, value) {
  40. var actions = [];
  41. Object.keys(datas).some((key) => {
  42. if (datas[key].dictLabel == ('' + value)) {
  43. actions.push(datas[key].dictValue);
  44. return true;
  45. }
  46. })
  47. return actions.join('');
  48. }
  49. export function selectValueKey(datas, value) {
  50. var actions = [];
  51. var idx=0;
  52. Object.keys(datas).some((key) => {
  53. if (datas[key].value == ('' + value)) {
  54. idx=key;
  55. actions.push(datas[key].label);
  56. return true;
  57. }
  58. })
  59. var newObj={
  60. actions:actions.join(''),
  61. key:idx
  62. }
  63. return newObj
  64. }
  65. export function selectValue(datas, value) {
  66. var actions = [];
  67. var idx=0;
  68. Object.keys(datas).some((key) => {
  69. if (datas[key].value == ('' + value)) {
  70. actions.push(datas[key].label);
  71. return true;
  72. }
  73. })
  74. return actions.join('')
  75. }
  76. export function selectValuetext(datas, value) {
  77. var actions = [];
  78. var idx=0;
  79. Object.keys(datas).some((key) => {
  80. if (datas[key].value == ('' + value)) {
  81. actions.push(datas[key].text);
  82. return true;
  83. }
  84. })
  85. return actions.join('')
  86. }
  87. /**
  88. * 参数处理
  89. * @param params 参数
  90. */
  91. export function tansParams(params) {
  92. let result = ''
  93. for (const propName of Object.keys(params)) {
  94. const value = params[propName]
  95. var part = encodeURIComponent(propName) + "="
  96. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  97. if (typeof value === 'object') {
  98. for (const key of Object.keys(value)) {
  99. if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
  100. let params = propName + '[' + key + ']'
  101. var subPart = encodeURIComponent(params) + "="
  102. result += subPart + encodeURIComponent(value[key]) + "&"
  103. }
  104. }
  105. } else {
  106. result += part + encodeURIComponent(value) + "&"
  107. }
  108. }
  109. }
  110. return result
  111. }