index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * FeHelper,截图后的保存界面
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. capturedImage: '',
  8. imageHTML: '',
  9. originPageInfo: '',
  10. defaultFilename: Date.now() + '.png',
  11. expand: false,
  12. btnInfoText: '点击展开'
  13. },
  14. mounted: function () {
  15. let bpInstance = chrome.extension.getBackgroundPage().BgPageInstance;
  16. let capturedData = bpInstance.getCapturedData();
  17. if (capturedData && capturedData.imageURI && capturedData.imageURI.length) {
  18. this.capturedImage = capturedData.imageURI[0];
  19. this.imageHTML = `<img class="img-result" src="${this.capturedImage}" />`;
  20. this.originPageInfo = JSON.stringify(capturedData.pageInfo, null, 4);
  21. this.defaultFilename = capturedData.filename;
  22. }
  23. },
  24. methods: {
  25. expandInfo: function () {
  26. this.expand = !this.expand;
  27. this.btnInfoText = this.expand ? '点击收起' : '点击展开';
  28. },
  29. save: function () {
  30. // 请求权限
  31. chrome.permissions.request({
  32. permissions: ['downloads']
  33. }, (granted) => {
  34. if (granted) {
  35. chrome.downloads.download({
  36. url: this.capturedImage,
  37. saveAs: true,
  38. conflictAction: 'overwrite',
  39. filename: this.defaultFilename
  40. });
  41. } else {
  42. alert('必须接受授权,才能正常下载!');
  43. }
  44. });
  45. }
  46. }
  47. });