common.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * 参数处理
  30. * @param params 参数
  31. */
  32. export function tansParams(params) {
  33. let result = ''
  34. for (const propName of Object.keys(params)) {
  35. const value = params[propName]
  36. var part = encodeURIComponent(propName) + "="
  37. if (value !== null && value !== "" && typeof(value) !== "undefined") {
  38. if (typeof value === 'object') {
  39. for (const key of Object.keys(value)) {
  40. if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
  41. let params = propName + '[' + key + ']'
  42. var subPart = encodeURIComponent(params) + "="
  43. result += subPart + encodeURIComponent(value[key]) + "&"
  44. }
  45. }
  46. } else {
  47. result += part + encodeURIComponent(value) + "&"
  48. }
  49. }
  50. }
  51. return result
  52. }
  53. // 返回上一页
  54. export function back() {
  55. uni.navigateBack({
  56. delta: 1
  57. })
  58. }
  59. // 页面跳转
  60. export function navigateTo(url) {
  61. uni.navigateTo({
  62. url: url
  63. })
  64. }
  65. // 回显数据字典
  66. export function selectDictLabel(datas, value) {
  67. if (value === undefined) {
  68. return "";
  69. }
  70. var actions = [];
  71. Object.keys(datas).some((key) => {
  72. if (datas[key].dictValue == ('' + value)) {
  73. actions.push(datas[key].dictLabel);
  74. return true;
  75. }
  76. })
  77. if (actions.length === 0) {
  78. actions.push(value);
  79. }
  80. return actions.join('');
  81. }
  82. // 递归遍历多维数组(未完成)
  83. export function traverseArray(arr, callback) {
  84. if (Array.isArray(arr)) {
  85. arr.forEach((element) => {
  86. traverseArray(element);
  87. });
  88. } else {
  89. callback(arr)
  90. }
  91. }