common.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {
  2. buildPageUrl,
  3. formatDate
  4. } from '../common/util.js'
  5. export default {
  6. data() {
  7. const pages = getCurrentPages()
  8. console.log(pages);
  9. const PageTitle = '闽南魂';
  10. if (pages.length > 0) {
  11. const currentPage = pages[pages.length - 1]
  12. const currentPageUrl = buildPageUrl(currentPage.route, currentPage.options)
  13. return {
  14. PageTitle,
  15. currentPage,
  16. currentPageUrl
  17. }
  18. } else {
  19. return {
  20. PageTitle
  21. }
  22. }
  23. },
  24. onLoad(options) {
  25. console.log('page onLoad', this.currentPageUrl);
  26. },
  27. methods: {
  28. onCopy(text) {
  29. uni.setClipboardData({
  30. data: text + ''
  31. }).then(([err, res]) => {
  32. console.log('uni.setClipboardData', err, res);
  33. if (!err) {
  34. uni.showToast({
  35. title: '复制成功',
  36. icon: 'none',
  37. });
  38. }
  39. });
  40. }
  41. },
  42. computed: {
  43. costTime() {
  44. return (seconds, type) => {
  45. let second = parseInt(seconds)
  46. if (second <= 0) {
  47. if (type === 'countdown') {
  48. return '已结束'
  49. }
  50. return '0秒'
  51. }
  52. let minute = 0 // 初始化分
  53. let hour = 0 // 初始化小时
  54. if (second >= 60) { // 如果秒数大于等于60,将秒数转换成分钟
  55. minute = parseInt(second / 60) // 获取分钟
  56. second = parseInt(second % 60) // 获取秒数
  57. if (minute >= 60) { // 如果分钟大于等于60,将分钟转换成小时
  58. hour = parseInt(minute / 60) // 获取小时
  59. minute = parseInt(minute % 60) // 获取小时后取余的分
  60. }
  61. }
  62. if (type === 'countdown') {
  63. return `${hour.toString().padStart(2,'0')}:${minute.toString().padStart(2,'0')}:${second.toString().padStart(2,'0')}`
  64. }
  65. let desc = ''
  66. if (hour > 0) {
  67. desc = hour + '小时'
  68. }
  69. if (minute > 0 || hour > 0) {
  70. desc += minute + '分'
  71. }
  72. desc += second + '秒'
  73. return desc
  74. }
  75. },
  76. timeFormat() {
  77. return (timestamp) => {
  78. if (!timestamp) {
  79. return ''
  80. }
  81. return formatDate(timestamp, 'yyyy-MM-dd hh:mm:ss')
  82. }
  83. },
  84. },
  85. }