index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <view :style="viewColor">
  3. <view class='distribution-posters'>
  4. <swiper :indicator-dots="indicatorDots" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  5. @change="bindchange" previous-margin="40px" next-margin="40px">
  6. <block v-for="(item,index) in spreadData" :key="index" class="img-list">
  7. <swiper-item class="aaa">
  8. <div class="box" ref="bill" :class="swiperIndex == index ? 'active' : 'quiet'">
  9. <view class="user-msg">
  10. <view class="user-code">
  11. <image class="canvas" :style="{height:hg+'px'}" :src="posterImage[index]"
  12. v-if="posterImage[index]"></image>
  13. <canvas class="canvas" :style="{height:hg+'px'}" :canvas-id="'myCanvas'+ index"
  14. v-else></canvas>
  15. </view>
  16. </view>
  17. </div>
  18. <!-- <image :src="item.wap_poster" class="slide-image" :class="swiperIndex == index ? 'active' : 'quiet'" mode='aspectFill' /> -->
  19. </swiper-item>
  20. </block>
  21. </swiper>
  22. <!-- #ifndef H5 -->
  23. <view class='keep b-color' @click='savePosterPath(posterImage[swiperIndex])'>保存海报</view>
  24. <!-- #endif -->
  25. <!-- #ifdef H5 -->
  26. <div class="preserve acea-row row-center-wrapper">
  27. <div class="line"></div>
  28. <div class="tip">长按保存图片</div>
  29. <div class="line"></div>
  30. </div>
  31. <!-- #endif -->
  32. </view>
  33. <home></home>
  34. <view class="qrimg">
  35. <zb-code ref="qrcode" :show="codeShow" :cid="cid" :val="val" :size="size" :unit="unit" :background="background"
  36. :foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconsize" :onval="onval" :loadMake="loadMake"
  37. @result="qrR" />
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. // +----------------------------------------------------------------------
  43. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  44. // +----------------------------------------------------------------------
  45. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  46. // +----------------------------------------------------------------------
  47. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  48. // +----------------------------------------------------------------------
  49. // | Author: CRMEB Team <admin@crmeb.com>
  50. // +----------------------------------------------------------------------
  51. import zbCode from '@/components/zb-code/zb-code.vue'
  52. import {
  53. getUserInfo,
  54. spreadBanner,
  55. spreadMsg,
  56. imgToBase
  57. } from '@/api/user.js';
  58. import { toLogin } from '@/libs/login.js';
  59. import { mapGetters } from "vuex";
  60. import home from '@/components/home';
  61. // #ifdef APP-PLUS
  62. import {HTTP_REQUEST_URL} from '@/config/app.js'
  63. // #endif
  64. export default {
  65. components: {
  66. home,
  67. zbCode
  68. },
  69. data() {
  70. return {
  71. imgUrls: [],
  72. indicatorDots: false,
  73. posterImageStatus: true,
  74. circular: false,
  75. autoplay: false,
  76. interval: 3000,
  77. duration: 500,
  78. swiperIndex: 0,
  79. spreadList: [],
  80. userInfo: {},
  81. poster: '',
  82. spreadData: [{}], //新海报数据
  83. nickName: "",
  84. siteName: "",
  85. mpUrl: "",
  86. canvasImageUrl: '',
  87. posterImage: [],
  88. //二维码参数
  89. codeShow: false,
  90. cid: '1',
  91. ifShow: true,
  92. val: "", // 要生成的二维码值
  93. size: 200, // 二维码大小
  94. unit: 'upx', // 单位
  95. background: '#FFF', // 背景色
  96. foreground: '#000', // 前景色
  97. pdground: '#32dbc6', // 角标色
  98. icon: '', // 二维码图标
  99. iconsize: 40, // 二维码图标大小
  100. lv: 3, // 二维码容错级别 , 一般不用设置,默认就行
  101. onval: true, // val值变化时自动重新生成二维码
  102. loadMake: true, // 组件加载完成后自动生成二维码
  103. src: '', // 二维码生成后的图片地址或base64
  104. codeSrc: "",
  105. wd: 225,
  106. hg: 500
  107. };
  108. },
  109. computed: mapGetters({
  110. 'isLogin': 'isLogin',
  111. 'userData': 'userInfo',
  112. 'viewColor': 'viewColor'
  113. }),
  114. watch: {
  115. isLogin: {
  116. handler: function(newV, oldV) {
  117. if (newV) {
  118. this.userSpreadBannerList();
  119. }
  120. },
  121. deep: true
  122. },
  123. userData: {
  124. handler: function(newV, oldV) {
  125. if (newV) {
  126. this.$set(this, 'userInfo', newV);
  127. }
  128. },
  129. deep: true
  130. }
  131. },
  132. async onReady() {
  133. if (this.isLogin) {
  134. // #ifdef H5
  135. let userData = await getUserInfo()
  136. this.val = window.location.host + '?spread=' + userData.data.uid
  137. // #endif
  138. await this.spreadMsgs()
  139. } else {
  140. toLogin();
  141. }
  142. },
  143. onShow() {
  144. this.$nextTick(() => {
  145. let selector = uni.createSelectorQuery().select('.aaa');
  146. selector.fields({
  147. size: true
  148. }, data => {
  149. console.log(data)
  150. this.wd = data.width
  151. this.hg = data.height
  152. }).exec();
  153. })
  154. },
  155. methods: {
  156. onLoadFun: function(e) {
  157. this.$set(this, 'userInfo', e);
  158. this.userSpreadBannerList();
  159. },
  160. qrR(res) {
  161. this.codeSrc = res
  162. },
  163. //获取图片
  164. async spreadMsgs() {
  165. let that = this
  166. let rqData = {
  167. // #ifdef MP
  168. type: 'routine',
  169. // #endif
  170. // #ifndef MP
  171. type: 'h5',
  172. // #endif
  173. }
  174. let res = await spreadMsg(rqData)
  175. that.spreadData = res.data.poster
  176. that.nickName = res.data.nickname
  177. let codeUrl = "?spread=" + that.userInfo.uid
  178. // #ifdef MP || APP-PLUS
  179. let mpUrl = await that.downloadFilestoreImage(res.data.qrcode)
  180. // #endif
  181. // #ifdef H5 || APP-PLUS
  182. let qrCode = await that.imgToBase(res.data.qrcode)
  183. // #endif
  184. uni.showLoading({
  185. title: '海报生成中',
  186. mask: true
  187. });
  188. for (let i = 0; i < res.data.poster.length; i++) {
  189. let arr2
  190. // #ifdef MP || APP-PLUS
  191. arr2 = [mpUrl, await that.downloadFilestoreImage(res.data.poster[i].pic)]
  192. // #endif
  193. // #ifdef H5
  194. let img = await that.imgToBase(res.data.poster[i].pic)
  195. arr2 = [qrCode, img]
  196. // #endif
  197. that.$util.userPosterCanvas(arr2, res.data.nickname, res.data.mark, i, that.wd, that.hg, (tempFilePath) => {
  198. that.$set(that.posterImage, i, tempFilePath);
  199. });
  200. uni.hideLoading();
  201. }
  202. },
  203. async imgToBase(url) {
  204. let res = await imgToBase({
  205. image: url
  206. })
  207. return res.data.image
  208. },
  209. // 二维码生成
  210. codeImg() {
  211. // http://当前域名+"?spread="+用户uid
  212. },
  213. bindchange(e) {
  214. let spreadList = this.spreadList;
  215. this.swiperIndex = e.detail.current;
  216. // this.$set(this, 'poster', spreadList[e.detail.current].poster);
  217. },
  218. savePosterPath(url) {
  219. let that = this;
  220. // #ifdef MP
  221. uni.getSetting({
  222. success(res) {
  223. if (!res.authSetting['scope.writePhotosAlbum']) {
  224. uni.authorize({
  225. scope: 'scope.writePhotosAlbum',
  226. success() {
  227. uni.saveImageToPhotosAlbum({
  228. filePath: url,
  229. success: function(res) {
  230. that.$util.Tips({
  231. title: '保存成功',
  232. icon: 'success'
  233. });
  234. },
  235. fail: function(res) {
  236. that.$util.Tips({
  237. title: '保存失败'
  238. });
  239. }
  240. });
  241. }
  242. });
  243. } else {
  244. uni.saveImageToPhotosAlbum({
  245. filePath: url,
  246. success: function(res) {
  247. that.$util.Tips({
  248. title: '保存成功',
  249. icon: 'success'
  250. });
  251. },
  252. fail: function(res) {
  253. that.$util.Tips({
  254. title: '保存失败'
  255. });
  256. }
  257. });
  258. }
  259. }
  260. });
  261. // #endif
  262. // #ifdef APP-PLUS
  263. uni.saveImageToPhotosAlbum({
  264. filePath: url,
  265. success: function(res) {
  266. that.$util.Tips({
  267. title: '保存成功',
  268. icon: 'success'
  269. });
  270. },
  271. fail: function(res) {
  272. that.$util.Tips({
  273. title: '保存失败'
  274. });
  275. }
  276. });
  277. // #endif
  278. },
  279. //图片转符合安全域名路径
  280. downloadFilestoreImage(url) {
  281. return new Promise((resolve, reject) => {
  282. let that = this;
  283. uni.downloadFile({
  284. url: url,
  285. success: function(res) {
  286. resolve(res.tempFilePath);
  287. },
  288. fail: function() {
  289. return that.$util.Tips({
  290. title: ''
  291. });
  292. }
  293. });
  294. })
  295. },
  296. setShareInfoStatus: function() {
  297. if (this.$wechat.isWeixin()) {
  298. if (this.isLogin) {
  299. getUserInfo().then(res => {
  300. let configAppMessage = {
  301. desc: '分销海报',
  302. title: res.data.nickname + '-分销海报',
  303. link: '/pages/index/index?spread=' + res.data.uid,
  304. imgUrl: this.spreadList[0]
  305. };
  306. this.$wechat.wechatEvevt(["updateAppMessageShareData", "updateTimelineShareData"], configAppMessage)
  307. });
  308. } else {
  309. toLogin();
  310. }
  311. }
  312. },
  313. userSpreadBannerList: function() {
  314. let that = this;
  315. uni.showLoading({
  316. title: '获取中',
  317. mask: true,
  318. })
  319. spreadBanner().then(res => {
  320. uni.hideLoading();
  321. that.$set(that, 'spreadList', res.data);
  322. that.$set(that, 'poster', res.data[0].poster);
  323. // #ifdef H5
  324. that.setShareInfoStatus();
  325. // #endif
  326. }).catch(err => {
  327. uni.hideLoading();
  328. });
  329. }
  330. }
  331. }
  332. </script>
  333. <style lang="scss">
  334. page {
  335. background-color: #a3a3a3 !important;
  336. }
  337. .canvas {
  338. width: 100%;
  339. position: absolute;
  340. top: 0;
  341. left: 0;
  342. }
  343. .box {
  344. width: 100%;
  345. height: 100%;
  346. position: relative;
  347. border-radius: 18rpx;
  348. overflow: hidden;
  349. .user-msg {
  350. position: absolute;
  351. width: 100%;
  352. height: 100%;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. .user-code {
  357. width: 100%;
  358. display: flex;
  359. align-items: center;
  360. justify-content: center;
  361. justify-content: space-between;
  362. image {
  363. width: 100%;
  364. }
  365. }
  366. }
  367. }
  368. .img-list {
  369. margin-right: 40px;
  370. }
  371. .distribution-posters swiper {
  372. width: 100%;
  373. height: 1000rpx;
  374. position: relative;
  375. margin-top: 40rpx;
  376. }
  377. .distribution-posters .slide-image {
  378. width: 100%;
  379. height: 100%;
  380. margin: 0 auto;
  381. border-radius: 15rpx;
  382. }
  383. .distribution-posters /deep/.active {
  384. transform: none;
  385. transition: all 0.2s ease-in 0s;
  386. }
  387. .distribution-posters /deep/ .quiet {
  388. transform: scale(0.8333333);
  389. transition: all 0.2s ease-in 0s;
  390. }
  391. .distribution-posters .keep {
  392. font-size: 30rpx;
  393. color: #fff;
  394. width: 600rpx;
  395. height: 80rpx;
  396. border-radius: 50rpx;
  397. text-align: center;
  398. line-height: 80rpx;
  399. margin: 38rpx auto;
  400. background-color: var(--view-theme);
  401. }
  402. .distribution-posters .preserve {
  403. color: #fff;
  404. text-align: center;
  405. margin-top: 38rpx;
  406. }
  407. .distribution-posters .preserve .line {
  408. width: 100rpx;
  409. height: 1px;
  410. background-color: #fff;
  411. }
  412. .distribution-posters .preserve .tip {
  413. margin: 0 30rpx;
  414. }
  415. </style>