common.js 2.2 KB

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