common.uts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * 显示消息提示框
  3. * @param content 提示的标题
  4. */
  5. export function toast(content:string):void {
  6. uni.showToast({
  7. icon: 'none',
  8. title: content
  9. })
  10. }
  11. /**
  12. * 显示模态弹窗
  13. * @param content 提示的标题
  14. */
  15. export function showConfirm(content:string):Promise<ShowModalSuccess> {
  16. return new Promise((resolve, reject) => {
  17. uni.showModal({
  18. title: '提示',
  19. content: content,
  20. cancelText: '取消',
  21. confirmText: '确定',
  22. success: function(res:ShowModalSuccess) {
  23. resolve(res)
  24. }
  25. })
  26. })
  27. }
  28. /**
  29. * 参数处理
  30. * @param params 参数
  31. */
  32. export function tansParams(params:UTSJSONObject):string {
  33. let result:string = ''
  34. // #ifdef WEB
  35. let paramKeys=Object.keys(params)
  36. // #endif
  37. // #ifndef WEB
  38. let paramKeys=UTSJSONObject.keys(params)
  39. // #endif
  40. for (const propName in paramKeys) {
  41. let value:any|null= params[propName]
  42. var part:string = encodeURIComponent(propName) + "="
  43. if (value !== null && value !== "" && typeof (value) !== "undefined") {
  44. if (typeof value === 'object') {
  45. // #ifdef WEB
  46. let valueKeys=Object.keys(value)
  47. // #endif
  48. // #ifndef WEB
  49. let valueJson:UTSJSONObject|null=params.getJSON(propName)
  50. let valueKeys=valueJson===null?[]:UTSJSONObject.keys(valueJson)
  51. // #endif
  52. for (const key in valueKeys) {
  53. // #ifdef WEB
  54. let newValue=value[key]
  55. // #endif
  56. // #ifndef WEB
  57. let newValue=valueJson?.getString(key)
  58. // #endif
  59. if (newValue !== null && newValue !== "" && typeof (newValue) !== 'undefined') {
  60. let params:string = propName + '[' + key + ']'
  61. var subPart:string = encodeURIComponent(params) + "="
  62. result += subPart + encodeURIComponent(newValue) + "&"
  63. }
  64. }
  65. } else {
  66. // #ifdef APP-ANDROID
  67. value=value as string
  68. // #endif
  69. result += part + encodeURIComponent(value) + "&"
  70. }
  71. }
  72. }
  73. return result
  74. }