common.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 timestampToTime(timestamp) {
  55. var date = new Date(timestamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  56. var Y = date.getFullYear() + '-';
  57. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  58. var D = date.getDate() + ' ';
  59. var h = date.getHours() + ':';
  60. var m = date.getMinutes() + ':';
  61. var s = date.getSeconds();
  62. return Y + M + D + h + m + s;
  63. }