common.js 1.8 KB

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