follow.vue 10 KB

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