clipboard-data.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: '剪切板',
  5. path: 'packageAPI/pages/device/clipboard-data/clipboard-data'
  6. }
  7. },
  8. onShareTimeline() {
  9. return {
  10. title: '剪切板'
  11. }
  12. },
  13. data: {
  14. theme: 'light',
  15. value: 'edit and copy me',
  16. pasted: '',
  17. },
  18. valueChanged(e) {
  19. this.setData({
  20. value: e.detail.value
  21. })
  22. },
  23. copy() {
  24. wx.setClipboardData({
  25. data: this.data.value,
  26. success() {
  27. wx.showToast({
  28. title: '复制成功',
  29. icon: 'success',
  30. duration: 1000
  31. })
  32. }
  33. })
  34. },
  35. paste() {
  36. const self = this
  37. wx.getClipboardData({
  38. success(res) {
  39. self.setData({
  40. pasted: res.data
  41. })
  42. wx.showToast({
  43. title: '粘贴成功',
  44. icon: 'success',
  45. duration: 1000
  46. })
  47. }
  48. })
  49. },
  50. onLoad() {
  51. this.setData({
  52. theme: wx.getSystemInfoSync().theme || 'light'
  53. })
  54. if (wx.onThemeChange) {
  55. wx.onThemeChange(({theme}) => {
  56. this.setData({theme})
  57. })
  58. }
  59. }
  60. })