kefu.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="kefu">
  3. <view class="kf">
  4. <!-- #ifdef H5 -->
  5. <image :src="kefu_img" class="kfimg"></image>
  6. <!-- #endif -->
  7. <!-- #ifdef MP -->
  8. <image :src="kefu_img" @longpress="savePosterPath(kefu_img)" class="kfimg"></image>
  9. <!-- #endif -->
  10. <view class="kftext">
  11. {{kefu_text}}
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. getArticleDetails
  19. } from '@/api/api.js'
  20. export default {
  21. data() {
  22. return {
  23. kefu_img: '',
  24. kefu_text: '',
  25. }
  26. },
  27. onLoad() {
  28. this.getKefuInfo()
  29. },
  30. methods: {
  31. getKefuInfo() {
  32. getArticleDetails(151, {}).then(({
  33. data
  34. }) => {
  35. this.kefu_img = data.image_input
  36. this.kefu_text = data.synopsis
  37. uni.setNavigationBarTitle({
  38. title: data.title
  39. })
  40. })
  41. },
  42. // #ifdef MP
  43. // 小程序保存图片
  44. savePosterPath(url) {
  45. uni.downloadFile({
  46. url,
  47. success: (resFile) => {
  48. console.log(resFile, "resFile");
  49. if (resFile.statusCode === 200) {
  50. uni.getSetting({
  51. success: (res) => {
  52. if (!res.authSetting["scope.writePhotosAlbum"]) {
  53. uni.authorize({
  54. scope: "scope.writePhotosAlbum",
  55. success: () => {
  56. uni.saveImageToPhotosAlbum({
  57. filePath: resFile.tempFilePath,
  58. success: (res) => {
  59. return uni.showToast({
  60. title: "保存成功!",
  61. });
  62. },
  63. fail: (res) => {
  64. return uni.showToast({
  65. title: res.errMsg,
  66. });
  67. },
  68. complete: (res) => {},
  69. });
  70. },
  71. fail: () => {
  72. uni.showModal({
  73. title: "您已拒绝获取相册权限",
  74. content: "是否进入权限管理,调整授权?",
  75. success: (res) => {
  76. if (res.confirm) {
  77. uni.openSetting({
  78. success: (res) => {
  79. console.log(res.authSetting);
  80. },
  81. });
  82. } else if (res.cancel) {
  83. return uni.showToast({
  84. title: "已取消!",
  85. });
  86. }
  87. },
  88. });
  89. },
  90. });
  91. } else {
  92. uni.saveImageToPhotosAlbum({
  93. filePath: resFile.tempFilePath,
  94. success: (res) => {
  95. return uni.showToast({
  96. title: "保存成功!",
  97. });
  98. },
  99. fail: (res) => {
  100. return uni.showToast({
  101. title: res.errMsg,
  102. });
  103. },
  104. complete: (res) => {},
  105. });
  106. }
  107. },
  108. fail: (res) => {},
  109. });
  110. } else {
  111. return uni.showToast({
  112. title: resFile.errMsg,
  113. });
  114. }
  115. },
  116. fail: (res) => {
  117. return uni.showToast({
  118. title: res.errMsg,
  119. });
  120. },
  121. });
  122. },
  123. // #endif
  124. }
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. .kefu {
  129. position: fixed;
  130. background-color: #f5f5f5;
  131. height: 100%;
  132. width: 100%;
  133. .kf {
  134. height: 500rpx;
  135. width: 500rpx;
  136. position: absolute;
  137. // background-color: #bfa;
  138. top: 0;
  139. right: 0;
  140. left: 0;
  141. bottom: 0;
  142. margin: auto;
  143. .kfimg {
  144. display: block;
  145. margin: 0 auto;
  146. width: 400rpx;
  147. height: 400rpx;
  148. }
  149. .kftext {
  150. padding-top: 20rpx;
  151. font-size: 32rpx;
  152. text-align: center;
  153. }
  154. }
  155. // .kftext {
  156. // font-size: 32rpx;
  157. // height: 50rpx;
  158. // width: 750rpx;
  159. // position: absolute;
  160. // top: 0;
  161. // right: 0;
  162. // left: 0;
  163. // bottom: 0;
  164. // margin:50rpx auto 0;
  165. // }
  166. }
  167. </style>