index.vue 13 KB

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