猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.3 KiB

3 months ago
3 months ago
3 months ago
  1. <template>
  2. <view class="share w100 h100">
  3. <view class="flex-colc content w100">
  4. <image :src="url" mode=""></image>
  5. <view class="btn color-fff size-30 flex-rowc" @tap="getImageInfo">
  6. 保存海报
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. url: "",
  16. }
  17. },
  18. onLoad(options) {
  19. this.url = options.url
  20. },
  21. methods: {
  22. getImageInfo() {
  23. // uni.getImageInfo({
  24. // src: this.url,
  25. // success: res => {
  26. // this.savePosterPath(res.path)
  27. // }
  28. // })
  29. uni.downloadFile({
  30. url: this.url,
  31. success: res => {
  32. this.savePosterPath(res.tempFilePath)
  33. }
  34. })
  35. },
  36. savePosterPath(path) {
  37. uni.getSetting({
  38. success: res => {
  39. console.log(res)
  40. if (res.authSetting['scope.writePhotosAlbum']) {
  41. uni.authorize({
  42. scope: 'scope.writePhotosAlbum',
  43. success: () => {
  44. uni.saveImageToPhotosAlbum({
  45. filePath: path,
  46. success: () => {
  47. uni.showToast({
  48. title: "保存成功"
  49. })
  50. },
  51. fail: () => {
  52. uni.showToast({
  53. title: "保存失败",
  54. icon: "none"
  55. })
  56. }
  57. })
  58. }
  59. })
  60. } else {
  61. uni.showModal({
  62. title: "权限提醒",
  63. content: "是否开启保存相册功能?",
  64. success: res1 => {
  65. if (res1.confirm) {
  66. uni.openSetting({
  67. success: result => {
  68. uni.showToast({
  69. title: "保存成功"
  70. })
  71. },
  72. fail: () => {
  73. uni.showToast({
  74. title: "保存失败",
  75. icon: "none"
  76. })
  77. }
  78. })
  79. }
  80. },
  81. fail: () => {
  82. uni.showToast({
  83. title: "保存失败",
  84. icon: "none"
  85. })
  86. }
  87. })
  88. }
  89. }
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style scoped lang="scss">
  96. .share {
  97. background-color: #FFEFD8;
  98. width: 100vw;
  99. height: 100vh;
  100. .content {
  101. position: fixed;
  102. bottom: 30rpx;
  103. }
  104. image {
  105. width: 250rpx;
  106. height: 237rpx;
  107. background-color: #fff;
  108. margin-bottom: 186rpx;
  109. }
  110. .btn {
  111. width: 594rpx;
  112. height: 94rpx;
  113. border-radius: 94rpx;
  114. background-color: #FFBF60;
  115. }
  116. }
  117. </style>