follow.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. {{ $t(`关注`) }}
  16. <!-- #ifdef MP -->
  17. <official-account class="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">{{ $t(`关注公众号`) }}</view>
  26. <view class="tips">{{ $t(`活动福利,第一时间了解`) }}</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">{{ $t(`保存图片`) }}</view>
  32. <!-- #endif -->
  33. <!-- #ifdef H5 -->
  34. <view class="btn" v-show="isWeixin" @tap="savePic">{{ $t(`长按保存图片`) }}</view>
  35. <view class="btn" v-show="!isWeixin" @tap="savePic">{{ $t(`保存图片`) }}</view>
  36. <!-- #endif -->
  37. <view class="close acea-row row-center-wrapper" @click="closeFollowCode">
  38. <text class="iconfont icon-ic_close1"></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 = `${this.dataConfig.fillet.val * 2}rpx`;
  87. if (this.dataConfig.fillet.type) {
  88. borderRadius = `${this.dataConfig.fillet.valList[0].val * 2}rpx ${this.dataConfig.fillet.valList[1].val * 2}rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx ${this.dataConfig.fillet.valList[2].val * 2}rpx`;
  89. }
  90. return {
  91. 'border-radius': borderRadius,
  92. 'background': `linear-gradient(90deg, ${this.dataConfig.bgColor.color[0].item} 0%, ${this.dataConfig.bgColor.color[1].item} 100%)`,
  93. 'color': this.dataConfig.themeColor.color[0].item,
  94. };
  95. },
  96. followWrapStyle() {
  97. return {
  98. 'padding': `0 ${this.dataConfig.prConfig.val * 2}rpx`,
  99. 'margin-top': `${this.dataConfig.mbConfig.val * 2}rpx`,
  100. };
  101. },
  102. },
  103. created() {},
  104. mounted() {
  105. getSubscribe().then(res => {
  106. this.subscribe = res.data.subscribe || false;
  107. }).catch(() => {})
  108. },
  109. methods: {
  110. savePic(){
  111. // #ifdef H5
  112. var a = document.createElement('a'); // 生成一个a元素
  113. a.download = 'wechat'; // 设置图片名称
  114. a.style.display = "none";
  115. a.href = this.dataConfig.codeConfig.url; // 将生成的URL设置为a.href属性
  116. document.body.appendChild(a); // 将a标签追加到文档对象中
  117. a.click(); // 触发a的单击事件
  118. a.remove(); // 一次性的,用完就删除a标签
  119. // #endif
  120. // #ifdef MP
  121. let that = this;
  122. uni.downloadFile({
  123. url: that.dataConfig.codeConfig.url, //图片地址
  124. success: function(response){
  125. uni.getSetting({
  126. success(res) {
  127. if (!res.authSetting['scope.writePhotosAlbum']) {
  128. uni.authorize({
  129. scope: 'scope.writePhotosAlbum',
  130. success() {
  131. uni.saveImageToPhotosAlbum({
  132. filePath: response.tempFilePath,
  133. success: function(res) {
  134. that.closeFollowCode();
  135. that.$util.Tips({
  136. title: '保存成功',
  137. icon: 'success'
  138. });
  139. },
  140. fail: function(res) {
  141. that.$util.Tips({
  142. title: '保存失败'
  143. });
  144. }
  145. });
  146. }
  147. });
  148. } else {
  149. uni.saveImageToPhotosAlbum({
  150. filePath: response.tempFilePath,
  151. success: function(res) {
  152. that.closeFollowCode();
  153. that.$util.Tips({
  154. title: '保存成功',
  155. icon: 'success'
  156. });
  157. },
  158. fail: function(res) {
  159. that.$util.Tips({
  160. title: '保存失败'
  161. });
  162. }
  163. });
  164. }
  165. }
  166. });
  167. }
  168. })
  169. // #endif
  170. //#ifdef APP-PLUS
  171. let that = this
  172. uni.downloadFile({
  173. url: that.dataConfig.codeConfig.url, //图片地址
  174. success: function(response){
  175. uni.saveImageToPhotosAlbum({
  176. filePath: response.tempFilePath,
  177. success: function(res) {
  178. that.posterImageClose();
  179. that.$util.Tips({
  180. title: '保存成功',
  181. icon: 'success'
  182. });
  183. },
  184. fail: function(res) {
  185. that.$util.Tips({
  186. title: '保存失败'
  187. });
  188. }
  189. });
  190. }
  191. })
  192. // #endif
  193. },
  194. followTap() {
  195. // #ifndef MP-WEIXIN
  196. this.followCode = true;
  197. // #endif
  198. },
  199. closeFollowCode() {
  200. this.followCode = false
  201. },
  202. }
  203. }
  204. </script>
  205. <style lang="scss">
  206. .follow {
  207. padding: 14rpx 32rpx 14rpx 30rpx;
  208. background: #FFFFFF;
  209. .picTxt {
  210. flex: 1;
  211. min-width: 0;
  212. .name {
  213. flex: 1;
  214. font-size: 30rpx;
  215. color: #333333;
  216. margin-left: 20rpx;
  217. }
  218. }
  219. .notes {
  220. position: relative;
  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. overflow: hidden;
  229. }
  230. .iconfont {
  231. margin-left: 16rpx;
  232. font-size: 32rpx;
  233. color: #333333;
  234. }
  235. }
  236. .followCode {
  237. .pictrue {
  238. width: 548rpx;
  239. height: 758rpx;
  240. border-radius: 48rpx;
  241. background: #FFFFFF;
  242. left: 50%;
  243. top: 50%;
  244. position: fixed;
  245. z-index: 10000;
  246. transform: translate(-50%, -50%);
  247. .title {
  248. padding: 48rpx 0 46rpx;
  249. border-top-left-radius: 48rpx;
  250. border-top-right-radius: 48rpx;
  251. border-bottom-right-radius: 274rpx 40rpx;
  252. border-bottom-left-radius: 274rpx 40rpx;
  253. background: linear-gradient(90deg, #FF7931 0%, var(--view-theme) 100%);
  254. text-align: center;
  255. font-weight: 500;
  256. font-size: 40rpx;
  257. line-height: 56rpx;
  258. color: #FFFFFF;
  259. }
  260. .tips {
  261. margin-top: 48rpx;
  262. text-align: center;
  263. font-size: 28rpx;
  264. line-height: 40rpx;
  265. color: #3D3D3D;
  266. }
  267. .code-bg {
  268. width: 312rpx;
  269. height: 312rpx;
  270. margin: 24rpx auto 0;
  271. }
  272. .imgs {
  273. width: 100%;
  274. height: 100%;
  275. }
  276. .btn {
  277. width: 420rpx;
  278. height: 80rpx;
  279. border-radius: 40rpx;
  280. margin: 40rpx auto 60rpx;
  281. background: linear-gradient(90deg, #FF7931 0%, var(--view-theme) 100%);
  282. text-align: center;
  283. font-weight: 500;
  284. font-size: 28rpx;
  285. line-height: 80rpx;
  286. color: #FFFFFF;
  287. }
  288. .close {
  289. position: absolute;
  290. bottom: -108rpx;
  291. left: 50%;
  292. width: 60rpx;
  293. height: 60rpx;
  294. border: 2rpx solid #CCCCCC;
  295. border-radius: 50%;
  296. transform: translateX(-50%);
  297. .iconfont {
  298. font-size: 40rpx;
  299. color: #CCCCCC;
  300. }
  301. }
  302. }
  303. .mask {
  304. z-index: 9999;
  305. }
  306. }
  307. .official-account{
  308. position: absolute;
  309. z-index: 99999;
  310. top: 0;
  311. right: 0;
  312. bottom: 0;
  313. left: 0;
  314. opacity: 0;
  315. }
  316. </style>