瑶都万能墙
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.

141 lines
2.8 KiB

4 months ago
  1. <template>
  2. <!-- 实名认证 -->
  3. <uv-popup ref="popup" :round="30">
  4. <view class="page">
  5. <view class="info-tips">
  6. {{ title }}
  7. </view>
  8. <view class="image">
  9. <image :src="image" mode="widthFix"></image>
  10. </view>
  11. <view class="uni-color-btn" @click="save">
  12. 保存客服微信
  13. </view>
  14. </view>
  15. </uv-popup>
  16. </template>
  17. <script>
  18. export default {
  19. props: ['title', 'image'],
  20. data() {
  21. return {}
  22. },
  23. methods: {
  24. open() {
  25. this.$refs.popup.open()
  26. },
  27. preservationImg(img) {
  28. let that = this
  29. uni.authorize({
  30. /* scope.writePhotosAlbum 类型是保存到相册 */
  31. scope: 'scope.writePhotosAlbum',
  32. success() {
  33. /* 已授权进入 */
  34. /* 保存图片到相册方法方法 */
  35. that.imgApi(img);
  36. },
  37. complete(res) {
  38. /* 判断如果没有授权就打开设置选项让用户重新授权 */
  39. uni.getSetting({
  40. success(res) {
  41. if (!res.authSetting['scope.writePhotosAlbum']) {
  42. /* 打开设置的方法 */
  43. that.openInstall();
  44. }
  45. }
  46. });
  47. }
  48. });
  49. },
  50. imgApi(image) {
  51. /* 获取图片的信息 */
  52. uni.getImageInfo({
  53. src: image,
  54. success: function(image) {
  55. /* 保存图片到手机相册 */
  56. uni.saveImageToPhotosAlbum({
  57. filePath: image.path,
  58. success: function() {
  59. uni.showModal({
  60. title: '保存成功',
  61. content: '图片已成功保存到相册',
  62. showCancel: false
  63. });
  64. },
  65. complete(res) {
  66. console.log(res);
  67. }
  68. });
  69. }
  70. });
  71. },
  72. opensit() {
  73. uni.showModal({
  74. content: '没有授权保存图片到相册,点击确定去允许授权',
  75. success: function(res) {
  76. if (res.confirm) {
  77. /* 打开设置的API*/
  78. uni.openSetting({
  79. success(res) {
  80. console.log(res.authSetting);
  81. }
  82. });
  83. } else if (res.cancel) {
  84. uni.showModal({
  85. cancelText: '取消',
  86. confirmText: '重新授权',
  87. content: '你点击了取消,将无法进行保存操作',
  88. success: function(res) {
  89. if (res.confirm) {
  90. uni.openSetting({
  91. success(res) {
  92. /* 授权成功 */
  93. console.log(res.authSetting);
  94. }
  95. });
  96. } else if (res.cancel) {
  97. console.log('用户不授权');
  98. }
  99. }
  100. });
  101. }
  102. }
  103. });
  104. },
  105. save() {
  106. this.preservationImg(this.image)
  107. },
  108. }
  109. }
  110. </script>
  111. <style scoped lang="scss">
  112. .page {
  113. width: 650rpx;
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. flex-direction: column;
  118. .info-tips {
  119. width: 100%;
  120. padding: 30rpx 0;
  121. // background-color: #f3f3f3;
  122. text-align: center;
  123. text {
  124. color: $uni-color;
  125. }
  126. }
  127. .image {
  128. image {
  129. width: 300rpx;
  130. height: 300rpx;
  131. }
  132. }
  133. }
  134. </style>