follow.vue 8.4 KB

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