follow.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <!-- 关注公众号 -->
  3. <view>
  4. <view :style="[followWrapStyle]">
  5. <view :style="[followStyle]" class="follow acea-row row-between-wrapper">
  6. <view class="picTxt acea-row row-middle">
  7. <view class="pictrue">
  8. <easy-loadimage mode="widthFix" :image-src="dataConfig.imgConfig.url" width="92rpx" height="92rpx" borderRadius="46rpx"></easy-loadimage>
  9. </view>
  10. <view class="name line1">
  11. {{ dataConfig.titleConfig.value }}
  12. </view>
  13. </view>
  14. <view :style="[buttonStyle]" class="notes acea-row row-center-wrapper" @click="followTap">
  15. 关注
  16. <!-- #ifdef MP -->
  17. <official-account></official-account>
  18. <!-- #endif -->
  19. </view>
  20. <view class="iconfont icon-ic_close"></view>
  21. </view>
  22. </view>
  23. <view class="followCode" v-if="followCode">
  24. <view class="pictrue">
  25. <view class="title">关注公众号</view>
  26. <view class="tips">活动福利,第一时间了解</view>
  27. <view class="code-bg">
  28. <image class="imgs" :src="dataConfig.codeConfig.url" mode=""></image>
  29. </view>
  30. <!-- #ifdef MP || APP-PLUS -->
  31. <view class="btn" @tap="savePic">保存图片</view>
  32. <!-- #endif -->
  33. <!-- #ifdef H5 -->
  34. <view class="btn" v-show="isWeixin" @tap="savePic">长按保存图片</view>
  35. <view class="btn" v-show="!isWeixin" @tap="savePic">保存图片</view>
  36. <!-- #endif -->
  37. <view class="close acea-row row-center-wrapper" @click="closeFollowCode">
  38. <text class="iconfont icon-ic_close"></text>
  39. </view>
  40. </view>
  41. <view class="mask"></view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import {follow} from '@/api/api.js';
  47. import {getSubscribe} from '@/api/public';
  48. // #ifdef H5
  49. import Auth from '@/libs/wechat';
  50. // #endif
  51. export default {
  52. name: 'follow',
  53. props: {
  54. dataConfig: {
  55. type: Object,
  56. default: () => {}
  57. },
  58. isSortType: {
  59. type: String | Number,
  60. default: 0
  61. }
  62. },
  63. data() {
  64. return {
  65. followCode: false,
  66. followUrl: '',
  67. bgColor: '',
  68. imgConfig: '',
  69. mbConfig: 0,
  70. themeColor: '',
  71. titleConfig: 0,
  72. subscribe: false,
  73. // #ifdef H5
  74. isWeixin: Auth.isWeixin(),
  75. //#endif
  76. };
  77. },
  78. computed: {
  79. buttonStyle() {
  80. return {
  81. 'border-color': this.dataConfig.themeColor.color[0].item,
  82. 'color': this.dataConfig.themeColor.color[0].item,
  83. };
  84. },
  85. followStyle() {
  86. let borderRadius = [];
  87. if (this.dataConfig.fillet.type) {
  88. for (let i = 0; i < this.dataConfig.fillet.valList.length; i++) {
  89. borderRadius.push(`${this.dataConfig.fillet.valList[i].val * 2}rpx`);
  90. }
  91. } else {
  92. borderRadius = [`${this.dataConfig.fillet.val * 2}rpx`];
  93. }
  94. return {
  95. 'border-radius': borderRadius.join(' '),
  96. 'background': `linear-gradient(90deg, ${this.dataConfig.bgColor.color[0].item} 0%, ${this.dataConfig.bgColor.color[1].item} 100%)`,
  97. 'color': this.dataConfig.themeColor.color[0].item,
  98. };
  99. },
  100. followWrapStyle() {
  101. return {
  102. 'padding': `0 ${this.dataConfig.prConfig.val * 2}rpx`,
  103. 'margin-top': `${this.dataConfig.mbConfig.val * 2}rpx`,
  104. };
  105. },
  106. },
  107. created() {},
  108. mounted() {
  109. getSubscribe().then(res => {
  110. this.subscribe = res.data.subscribe || false;
  111. }).catch(() => {})
  112. },
  113. methods: {
  114. savePic(){
  115. // #ifdef H5
  116. var a = document.createElement('a'); // 生成一个a元素
  117. a.download = 'wechat'; // 设置图片名称
  118. a.style.display = "none";
  119. a.href = this.dataConfig.codeConfig.url; // 将生成的URL设置为a.href属性
  120. document.body.appendChild(a); // 将a标签追加到文档对象中
  121. a.click(); // 触发a的单击事件
  122. a.remove(); // 一次性的,用完就删除a标签
  123. // #endif
  124. // #ifdef MP
  125. let that = this;
  126. uni.downloadFile({
  127. url: that.dataConfig.codeConfig.url, //图片地址
  128. success: function(response){
  129. uni.getSetting({
  130. success(res) {
  131. if (!res.authSetting['scope.writePhotosAlbum']) {
  132. uni.authorize({
  133. scope: 'scope.writePhotosAlbum',
  134. success() {
  135. uni.saveImageToPhotosAlbum({
  136. filePath: response.tempFilePath,
  137. success: function(res) {
  138. that.closeFollowCode();
  139. that.$util.Tips({
  140. title: '保存成功',
  141. icon: 'success'
  142. });
  143. },
  144. fail: function(res) {
  145. that.$util.Tips({
  146. title: '保存失败'
  147. });
  148. }
  149. });
  150. }
  151. });
  152. } else {
  153. uni.saveImageToPhotosAlbum({
  154. filePath: response.tempFilePath,
  155. success: function(res) {
  156. that.closeFollowCode();
  157. that.$util.Tips({
  158. title: '保存成功',
  159. icon: 'success'
  160. });
  161. },
  162. fail: function(res) {
  163. that.$util.Tips({
  164. title: '保存失败'
  165. });
  166. }
  167. });
  168. }
  169. }
  170. });
  171. }
  172. })
  173. // #endif
  174. //#ifdef APP-PLUS
  175. let that = this
  176. uni.downloadFile({
  177. url: that.dataConfig.codeConfig.url, //图片地址
  178. success: function(response){
  179. uni.saveImageToPhotosAlbum({
  180. filePath: response.tempFilePath,
  181. success: function(res) {
  182. that.posterImageClose();
  183. that.$util.Tips({
  184. title: '保存成功',
  185. icon: 'success'
  186. });
  187. },
  188. fail: function(res) {
  189. that.$util.Tips({
  190. title: '保存失败'
  191. });
  192. }
  193. });
  194. }
  195. })
  196. // #endif
  197. },
  198. followTap() {
  199. this.followCode = true;
  200. },
  201. closeFollowCode() {
  202. this.followCode = false
  203. },
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. .follow {
  209. padding: 14rpx 32rpx 14rpx 30rpx;
  210. background: #FFFFFF;
  211. .picTxt {
  212. flex: 1;
  213. .name {
  214. flex: 1;
  215. font-size: 30rpx;
  216. color: #333333;
  217. margin-left: 20rpx;
  218. }
  219. }
  220. .notes {
  221. font-weight: 500;
  222. font-size: 24rpx;
  223. color: var(--view-theme);
  224. width: 112rpx;
  225. height: 56rpx;
  226. border: 1px solid var(--view-theme);
  227. border-radius: 28rpx;
  228. }
  229. .iconfont {
  230. margin-left: 16rpx;
  231. font-size: 32rpx;
  232. color: #333333;
  233. }
  234. }
  235. .followCode {
  236. .pictrue {
  237. width: 548rpx;
  238. height: 758rpx;
  239. border-radius: 48rpx;
  240. background: #FFFFFF;
  241. left: 50%;
  242. top: 50%;
  243. position: fixed;
  244. z-index: 10000;
  245. transform: translate(-50%, -50%);
  246. .title {
  247. padding: 48rpx 0 46rpx;
  248. border-top-left-radius: 48rpx;
  249. border-top-right-radius: 48rpx;
  250. border-bottom-right-radius: 274rpx 40rpx;
  251. border-bottom-left-radius: 274rpx 40rpx;
  252. background: linear-gradient(90deg, #FF7931 0%, var(--view-theme) 100%);
  253. text-align: center;
  254. font-weight: 500;
  255. font-size: 40rpx;
  256. line-height: 56rpx;
  257. color: #FFFFFF;
  258. }
  259. .tips {
  260. margin-top: 48rpx;
  261. text-align: center;
  262. font-size: 28rpx;
  263. line-height: 40rpx;
  264. color: #3D3D3D;
  265. }
  266. .code-bg {
  267. width: 312rpx;
  268. height: 312rpx;
  269. margin: 24rpx auto 0;
  270. }
  271. .imgs {
  272. width: 100%;
  273. height: 100%;
  274. }
  275. .btn {
  276. width: 420rpx;
  277. height: 80rpx;
  278. border-radius: 40rpx;
  279. margin: 40rpx auto 60rpx;
  280. background: linear-gradient(90deg, #FF7931 0%, var(--view-theme) 100%);
  281. text-align: center;
  282. font-weight: 500;
  283. font-size: 28rpx;
  284. line-height: 80rpx;
  285. color: #FFFFFF;
  286. }
  287. .close {
  288. position: absolute;
  289. bottom: -108rpx;
  290. left: 50%;
  291. width: 60rpx;
  292. height: 60rpx;
  293. border: 2rpx solid #CCCCCC;
  294. border-radius: 50%;
  295. transform: translateX(-50%);
  296. .iconfont {
  297. font-size: 40rpx;
  298. color: #CCCCCC;
  299. }
  300. }
  301. }
  302. .mask {
  303. z-index: 9999;
  304. }
  305. }
  306. </style>