paste.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const COUNT_MAX=10;
  4. const app = getApp();
  5. Page({
  6. data: {
  7. Words:"",
  8. },
  9. onLoad: function (options) {
  10. let that = this;
  11. let words=app.globalData.SelectedWords.join("\n");
  12. that.setData({
  13. Containnerheight: main.getWindowHeight(),
  14. Words:words,
  15. });
  16. that.handlePaste();
  17. },
  18. handlePaste: function(e) {
  19. let that = this;
  20. // 获取剪贴板内容
  21. wx.getClipboardData({
  22. success: function(res) {
  23. // res.data 包含剪贴板的内容
  24. let pasteData = res.data;
  25. // 这里可以处理粘贴的数据,比如按空格分割成单词
  26. let words = pasteData.split(/[\r\n]+/); // 按空格分割
  27. // 过滤掉空字符串和非单词内容
  28. words = common.filterWordsWithSpecialChars(words);
  29. //debugger;
  30. let str="";
  31. if (that.data.Words)
  32. str+=that.data.Words+"\n";
  33. str+=words.join("\n");
  34. that.setData({
  35. Words: str,
  36. });
  37. },
  38. fail: function(err) {
  39. console.error('获取剪贴板失败', err);
  40. }
  41. });
  42. },
  43. submit:function(){
  44. app.globalData.SelectedWords=this.data.Words.split("\n");
  45. wx.navigateBack({
  46. delta: 1
  47. });
  48. },
  49. onShareAppMessage: function () {
  50. return {
  51. title: app.globalData.ShareTitle,
  52. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  53. imageUrl: app.globalData.ShareImage,
  54. }
  55. },
  56. })