common.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // FIXME 拼接参数
  35. return result
  36. }
  37. export function getStaticUrl(url) {
  38. let result = '';
  39. // #ifdef H5
  40. result = `/mdist/${url}`
  41. // #endif
  42. // #ifdef APP-PLUS
  43. result = url
  44. // #endif
  45. return result;
  46. }
  47. /************* 将时间格式化成 年月+日 ***********/
  48. export function formatDateToYearMonthDay(dateStr) {
  49. let date = new Date(dateStr.replace(/-/g, '/'));
  50. let dataStr1 = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`
  51. const yearMonth = dataStr1.substring(0, 7); // "2025-06"
  52. const day = dataStr1.substring(8); // "01"
  53. return [yearMonth, day]
  54. }
  55. export function getStringByHtml3(html) {
  56. return html ? html.replace(/<img [^.]*">/g, '')
  57. .replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, '')
  58. .replace(/<[^>]+?>/g, '')
  59. .replace(/\s+/g, ' ')
  60. .replace(/ /g, ' ')
  61. .replace(/>/g, ' ')
  62. .replace(/<?img[^>]*>/g, '')
  63. .replace(/<video[^>]*>.*?<\/video>/gi, '') : '';
  64. }