Files
soul-yongping/miniprogram/pages/link-preview/link-preview.js

44 lines
941 B
JavaScript
Raw Normal View History

const app = getApp()
Page({
data: {
url: '',
title: '链接预览',
statusBarHeight: 44,
navBarHeight: 88,
},
onLoad(options) {
const url = decodeURIComponent(options.url || '')
const title = options.title ? decodeURIComponent(options.title) : '链接预览'
this.setData({
url,
title,
statusBarHeight: app.globalData.statusBarHeight || 44,
navBarHeight: app.globalData.navBarHeight || 88,
})
},
goBack() {
const pages = getCurrentPages()
if (pages.length > 1) {
wx.navigateBack()
} else {
wx.switchTab({ url: '/pages/index/index' })
}
},
copyLink() {
const url = (this.data.url || '').trim()
if (!url) {
wx.showToast({ title: '暂无可复制链接', icon: 'none' })
return
}
wx.setClipboardData({
data: url,
success: () => wx.showToast({ title: '链接已复制', icon: 'none' }),
})
},
})