showlist.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <template>
  2. <view class="prayers-list" @click="handleclick">
  3. <u-navbar
  4. title="南华云灯会"
  5. leftIconColor="#fff"
  6. :titleStyle="{ color: '#fff' }"
  7. bgColor="transparent"
  8. :autoBack="true"
  9. >
  10. </u-navbar>
  11. <!-- <u-navbar title="剑未配妥,出门已是江湖" @click-left="onClickBack" @click-right="onClickRight"></u-navbar> -->
  12. <view class="allList">
  13. <view class="list">
  14. <scroll-view
  15. scroll-x="true"
  16. class="content-scroll swiper"
  17. scroll-with-animation
  18. :scroll-left="scrollLeft"
  19. >
  20. <view
  21. v-for="(item, index) in list"
  22. :key="index"
  23. class="scroll-item list"
  24. :class="
  25. current == index
  26. ? `active index${index} ${curIndex == index ? 'fang' : ''}`
  27. : `index${index}`
  28. "
  29. @click="changeTitle(index)"
  30. >
  31. <view class="activeItem" v-if="curIndex == index">
  32. <view class="activetext" v-for="(items, a) in item.list" :key="a">
  33. {{ items }}
  34. </view>
  35. </view>
  36. <view class="item-text item" v-else>{{ item.name }}</view>
  37. <view class="source">
  38. <text style="color: #9c9590">来源</text>
  39. <text>小阿飞</text>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. <view class="tips">
  45. 请选择祈愿类型
  46. <view v-if="curIndex" class="downButtom flex justify-center">
  47. <view class="downButtomItem">返回我的祈愿</view>
  48. </view>
  49. <view v-else class="downButtom flex justify-center">
  50. <view class="downButtomItem">祈愿地图</view>
  51. <view class="downButtomItem" @click="handleShare">分享</view>
  52. </view>
  53. </view>
  54. <view class="img_signal" v-if="!show"></view>
  55. <u-popup
  56. :show="shareShow"
  57. mode="center"
  58. bgColor="transparent"
  59. round="10"
  60. @close="close"
  61. >
  62. <view class="mySharepopup planel" ref="addImage" id="capture">
  63. <!-- <view class="close" @click="close">
  64. <u--image
  65. width="42px"
  66. height="42px"
  67. src="/static/img/icon_cancel@2x.png"
  68. ></u--image>
  69. </view> -->
  70. <view class="shareItem answer_draw_canvas">
  71. <view class="activeItem answer_draw_canvas">
  72. <view
  73. class="activetext answer_draw_canvas"
  74. v-for="(items, a) in shareData.list"
  75. :key="a"
  76. >
  77. {{ items }}
  78. </view>
  79. </view>
  80. <!-- <view class="share-page-box" id="box" v-if="shareShow"
  81. :style="{ width: '180px', height: '600px' }">
  82. <wxml-to-canvas class="widget" :width="canvasWidth" :height="canvasHeight"></wxml-to-canvas>
  83. </view> -->
  84. <view class="shareRight answer_draw_canvas">
  85. <view class="close" @click="close">
  86. <u--image
  87. width="42px"
  88. height="42px"
  89. src="/static/img/icon_cancel@2x.png"
  90. ></u--image>
  91. </view>
  92. <view class="downBut" @click="handleDown">
  93. <view class="img">
  94. <view>
  95. <u--image
  96. width="36px"
  97. height="36px"
  98. src="https://4dscene.4dage.com/new4dkk/deng/static/img/icon_download@2x.png"
  99. ></u--image>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="downText" @click="handleDown">下载图片</view>
  104. </view>
  105. <view class="codeImg1 answer_draw_canvas">
  106. <QiyanQrcode
  107. :size="72"
  108. background="#fff"
  109. @click="title1 = '1.现在时间戳:' + Date.now()"
  110. :text="title1"
  111. ></QiyanQrcode>
  112. </view>
  113. <view class="codeImg2 answer_draw_canvas">
  114. <QiyanQrcode
  115. :size="72"
  116. background="#fff"
  117. @click="title1 = '1.现在时间戳:' + Date.now()"
  118. :text="title1"
  119. ></QiyanQrcode>
  120. </view>
  121. </view>
  122. </view>
  123. </u-popup>
  124. <canvas
  125. canvas-id="answerCanvas"
  126. class="answerCanvas"
  127. :style="'width:' + canvasWidth + 'px;height:' + canvasHeight + 'px;'"
  128. ></canvas>
  129. </view>
  130. </view>
  131. </template>
  132. <script>
  133. // import uNavbar from "uview-ui/components/u-navbar/u-navbar.vue";
  134. import { wxml, style } from './DomData';
  135. import QiyanQrcode from "@/components/qiyan-qrcode/qiyan-qrcode.vue";
  136. import Wxml2Canvas from "wxml2canvas";
  137. import html2canvas from "html2canvas";
  138. export default {
  139. components: {
  140. // uNavbar
  141. QiyanQrcode,
  142. },
  143. data() {
  144. return {
  145. active: "婚姻祈愿1",
  146. title1: "1.现在时间戳:" + Date.now(),
  147. show: false,
  148. shareShow: false,
  149. scrollLeft: 0, // 横向滚动条位置
  150. current: 2,
  151. curIndex: null,
  152. province: "请选择",
  153. provinceShow: false,
  154. shareData: {},
  155. list: [
  156. {
  157. name: "学业祈愿1",
  158. list: ["知识的殿堂中闪耀属于你的光芒。", "愿你学业精进,成绩辉煌,"],
  159. },
  160. {
  161. name: "学业祈愿2",
  162. list: ["知识的殿堂中闪耀属于你的光芒。", "愿你学业精进,成绩辉煌,"],
  163. },
  164. {
  165. name: "学业祈愿3",
  166. list: ["知识的殿堂中闪耀属于你的光芒。", "愿你学业精进,成绩辉煌,"],
  167. },
  168. {
  169. name: "学业祈愿4",
  170. list: ["知识的殿堂中闪耀属于你的光芒。", "愿你学业精进,成绩辉煌,"],
  171. },
  172. {
  173. name: "学业祈愿5",
  174. list: ["知识的殿堂中闪耀属于你的光芒。", "愿你学业精进,成绩辉煌,"],
  175. },
  176. {
  177. name: "学业祈愿6",
  178. list: ["知识的殿堂中闪耀属于你的光芒。", "愿你学业精进,成绩辉煌,"],
  179. },
  180. ],
  181. canvasWidth: 180, // 默认canvas宽高
  182. canvasHeight: 700,
  183. screenWidth: null, // 设备宽度
  184. screenHeight: null, // 设备高度
  185. // name: '',
  186. // pic: '',
  187. // chapter1: '',
  188. // chapter2: '',
  189. widget: null,
  190. msg: '加载中,请稍等...', // 提示语
  191. };
  192. },
  193. mounted() {
  194. // 获取标题区域宽度,和每个子元素节点的宽度
  195. this.getScrollW();
  196. },
  197. onLoad() {
  198. },
  199. methods: {
  200. renderInit(){
  201. // 获取设备信息
  202. wx.getSystemInfo({
  203. success: (res) => {
  204. console.log("屏幕", res);
  205. this.screenWidth = 180;
  206. this.canvasWidth = this.screenWidth;
  207. this.canvasHeight = 600;
  208. console.log("海报高度:", this.canvasHeight);
  209. this.show = true;
  210. // 数字容器宽度 动态设置
  211. setTimeout(() => {
  212. wx.showLoading({ title: "海报加载中..." });
  213. this.widget = this.selectComponent(".widget");
  214. this.renderToCanvas();
  215. }, 1000);
  216. },
  217. });
  218. },
  219. // 获取标题区域宽度,和每个子元素节点的宽度以及元素距离左边栏的距离
  220. getScrollW() {
  221. const query = uni.createSelectorQuery().in(this);
  222. query
  223. .select(".content-scroll")
  224. .boundingClientRect((data) => {
  225. // 拿到 scroll-view 组件宽度
  226. this.contentScrollW = data.width;
  227. })
  228. .exec();
  229. query
  230. .selectAll(".scroll-item")
  231. .boundingClientRect((data) => {
  232. let dataLen = data.length;
  233. for (let i = 0; i < dataLen; i++) {
  234. // scroll-view 子元素组件距离左边栏的距离
  235. this.list[i].left = data[i].left;
  236. // scroll-view 子元素组件宽度
  237. this.list[i].width = data[i].width;
  238. }
  239. })
  240. .exec();
  241. },
  242. // 选择标题
  243. changeTitle(index) {
  244. if (index == this.current && this.curIndex != index) {
  245. this.curIndex = index;
  246. } else {
  247. this.curIndex = null;
  248. }
  249. this.current = index;
  250. console.log("changeTitle", index);
  251. this.scrollLeft = (index - 1) * 118;
  252. },
  253. handleHome() {
  254. console.log("开启云上观灯", uni);
  255. uni.$u.route("/pages/home/home");
  256. },
  257. handleclick() {
  258. this.show = true;
  259. },
  260. handleShare() {
  261. console.log("handleShare");
  262. this.shareShow = true;
  263. this.shareData = this.list[this.current];
  264. setTimeout(()=>{
  265. // this.renderInit();
  266. },500)
  267. },
  268. close() {
  269. this.shareShow = false;
  270. console.log("handleShare", this.shareShow);
  271. },
  272. changeswiper(e) {
  273. // 得加上这个方法!!!
  274. this.currentswiper = e.detail.current;
  275. },
  276. confirm(val) {
  277. console.log("confirm", val);
  278. this.province = val.value[0];
  279. this.provinceShow = false;
  280. },
  281. handleDown() {
  282. // this.renderInit();
  283. // this.extraImage()
  284. this.draw();
  285. },
  286. // wxml 转 canvas
  287. renderToCanvas() {
  288. console.log('canvasStyle.widget', this.shareData)
  289. const _wxml = wxml(this.shareData);
  290. console.log('this.widget', this.widget)
  291. const _style = style(this.screenWidth, this.canvasWidth, this.canvasHeight) //this.canvasHeight
  292. const p1 = this.widget.renderToCanvas({ wxml: _wxml, style: _style })
  293. console.log('renderToCanvas', p1)
  294. p1.then((res) => {
  295. console.log('海报生成成功', res);
  296. wx.hideLoading()
  297. }).catch((err) => {
  298. console.log('生成失败', err)
  299. })
  300. },
  301. // 保存到朋友圈
  302. extraImage() {
  303. if (!this.show) {
  304. wx.showToast({ title: '海报生成失败,无法分享到朋友圈', icon: 'none' })
  305. return
  306. }
  307. wx.showLoading({ title: '海报生成中...' })
  308. const p2 = this.widget.canvasToTempFilePath({ fileType:'jpg', quality :0.5})
  309. let that = this;
  310. p2.then(result => {
  311. let path = result.tempFilePath
  312. wx.getSetting({
  313. success: res => {
  314. wx.hideLoading()
  315. // 非初始化且未授权的情况,需要再次弹窗提示授权
  316. if (res.authSetting['scope.writePhotosAlbum'] != undefined && res.authSetting['scope.writePhotosAlbum'] != true) {
  317. wx.showModal({
  318. title: '是否授权相册权限',
  319. content: '需要获取相册权限,请确认授权,否则无法使用相关功能',
  320. success: res => {
  321. if (res.confirm) {
  322. wx.openSetting({
  323. success: dataAu => {
  324. if (dataAu.authSetting["scope.writePhotosAlbum"] == true) {
  325. wx.showToast({
  326. title: '授权成功',
  327. icon: 'none',
  328. duration: 1000
  329. });
  330. that.saveIMg(path);
  331. } else {
  332. wx.showToast({
  333. title: '授权失败',
  334. icon: 'success',
  335. duration: 1000
  336. });
  337. }
  338. }
  339. });
  340. }
  341. }
  342. });
  343. } else {
  344. // 初始化且未授权,系统默认会弹窗提示授权
  345. // 非初始化且已授权,也会进入这里
  346. that.saveIMg(path);
  347. }
  348. }
  349. });
  350. })
  351. },
  352. draw() {
  353. let that = this;
  354. //创建wxml2canvas对象
  355. let drawImage = new Wxml2Canvas(
  356. {
  357. element: "answerCanvas", // canvas节点的id,
  358. obj: that, // 在组件中使用时,需要传入当前组件的this
  359. width: 180, // 宽 自定义
  360. height: 700, // 高 自定义
  361. background: "#fff", // 默认背景色 设置背景色
  362. progress(percent) {
  363. // 绘制进度
  364. console.log(percent);
  365. },
  366. finish(url) {
  367. uni.saveImageToPhotosAlbum({
  368. filePath: url,
  369. success() {
  370. uni.hideLoading();
  371. },
  372. fail() {
  373. uni.hideLoading();
  374. },
  375. });
  376. },
  377. error(res) {
  378. console.log(res);
  379. // uni.hideLoading()
  380. // 画失败的原因
  381. },
  382. },
  383. this
  384. );
  385. //传入数据,画制canvas图片
  386. let data = {
  387. //直接获取wxml数据
  388. list: [
  389. {
  390. type: "wxml",
  391. class: ".planel .answer_draw_canvas", // answer_canvas这边为要绘制的wxml元素跟元素类名, answer_draw_canvas要绘制的元素的类名(所有要绘制的元素都要添加该类名)
  392. limit: ".mySharepopup", // 这边为要绘制的wxml元素跟元素类名,最外面的元素
  393. x: 0,
  394. y: 0,
  395. },
  396. ],
  397. };
  398. drawImage.draw(data, that);
  399. },
  400. // 保存到相册
  401. async saveIMg(tempFilePath) {
  402. wx.saveImageToPhotosAlbum({
  403. filePath: tempFilePath,
  404. success: async (res) => {
  405. wx.showModal({
  406. content: '图片已保存,分享给好友吧!',
  407. showCancel: false,
  408. confirmText: '好的',
  409. confirmColor: '#333',
  410. success: function (res) {
  411. wx.navigateBack({
  412. //返回
  413. delta: 1
  414. });
  415. },
  416. fail: function (res) {
  417. console.log('res', res);
  418. }
  419. });
  420. },
  421. fail: function (res) {
  422. wx.showToast({
  423. title: '您取消了授权',
  424. icon: 'none',
  425. duration: 2000
  426. })
  427. }
  428. });
  429. },
  430. },
  431. };
  432. </script>
  433. // <script lang="renderjs" module="canvasImage">
  434. // import html2canvas from 'html2canvas'
  435. // export default {
  436. // methods: {
  437. // // 生成图片需要调用的方法
  438. // handleDown(){
  439. // // const query = uni.createSelectorQuery().in(this);
  440. // const dom = this.$refs.addImage;//query.select('#capture'); // 需要生成图片内容的 dom 节点
  441. // html2canvas(dom).then(canvas => {
  442. // this.imgs= canvas.toDataURL() //base64字符串 放到图片标签上
  443. // });
  444. // }
  445. // }
  446. // }
  447. // </script>
  448. <style lang="scss" scoped>
  449. .prayers-list {
  450. background: rgba(32, 21, 10, 0.7);
  451. border-radius: 0px 0px 0px 0px;
  452. height: 100vh;
  453. padding-top: 100px;
  454. .img_signal {
  455. width: 76px;
  456. height: 106px;
  457. background: url(https://4dscene.4dage.com/new4dkk/deng/static/img/img_signal@2x.png)
  458. 100% 100% no-repeat;
  459. background-size: cover;
  460. position: absolute;
  461. right: 50px;
  462. bottom: 30px;
  463. animation: handleAni 1s linear infinite;
  464. transition: all 1s;
  465. }
  466. .mySharepopup {
  467. // width: 330px;
  468. // height: 537px;
  469. padding: 19px 17px 0px 17px;
  470. .close {
  471. position: absolute;
  472. right: -24px;
  473. top: -20px;
  474. width: 42px;
  475. height: 42px;
  476. }
  477. .shareItem {
  478. width: 150px;
  479. height: calc(100% - 512px);
  480. padding: 160px 0px;
  481. display: inline-block;
  482. background-size: 100% 100%;
  483. font-size: 12px;
  484. color: #303030;
  485. line-height: 18px;
  486. display: flex;
  487. writing-mode: vertical-lr;
  488. text-align: left;
  489. justify-content: center;
  490. flex-direction: column;
  491. background: url(https://4dscene.4dage.com/new4dkk/deng/static/img/img_label@2x.png)
  492. 100% 100% no-repeat;
  493. background-size: contain;
  494. position: relative;
  495. top: 44px;
  496. font-weight: 400;
  497. font-size: 16px;
  498. color: #303030;
  499. line-height: 24px;
  500. .activetext {
  501. margin: 0 9px;
  502. }
  503. }
  504. .shareRight {
  505. position: absolute;
  506. right: -50px;
  507. .img {
  508. }
  509. }
  510. .downBut {
  511. position: absolute;
  512. right: -20px;
  513. bottom: -70px;
  514. }
  515. .downText {
  516. position: absolute;
  517. right: -34px;
  518. bottom: -90px;
  519. font-weight: 400;
  520. font-size: 16px;
  521. color: #ffffff;
  522. line-height: 19px;
  523. width: 64px;
  524. writing-mode: rl;
  525. }
  526. .codeImg1 {
  527. position: absolute;
  528. right: -90px;
  529. bottom: 50px;
  530. padding: 3px;
  531. background: #fff;
  532. }
  533. .codeImg2 {
  534. position: absolute;
  535. right: -90px;
  536. bottom: 150px;
  537. padding: 3px;
  538. background: #fff;
  539. }
  540. .qrcode {
  541. position: absolute;
  542. right: -50px;
  543. .codeImg {
  544. width: 100%;
  545. }
  546. }
  547. }
  548. .tips {
  549. width: 100%;
  550. text-align: center;
  551. margin-top: 27px;
  552. color: #fff;
  553. font-size: 14px;
  554. line-height: 21px;
  555. .downButtom {
  556. padding-top: 20px;
  557. .downButtomItem {
  558. width: 140px;
  559. height: 42px;
  560. background: url(https://4dscene.4dage.com/new4dkk/deng/static/img/btn01@2x.png)
  561. 100% 100% no-repeat;
  562. background-size: cover;
  563. font-weight: 400;
  564. font-size: 16px;
  565. color: #ffffff;
  566. line-height: 19px;
  567. font-style: normal;
  568. margin: 0 5px;
  569. line-height: 42px;
  570. text-align: center;
  571. }
  572. }
  573. }
  574. .list {
  575. height: 555px;
  576. width: 100%;
  577. // margin-top: 50rpx;
  578. box-sizing: border-box;
  579. .content-scroll {
  580. height: 500px;
  581. white-space: nowrap;
  582. display: flex;
  583. text-align: center;
  584. justify-content: center;
  585. flex-direction: column;
  586. .scroll-item {
  587. height: 500px;
  588. width: 118px;
  589. padding: 0 20rpx;
  590. display: inline-block;
  591. text-align: center;
  592. position: relative;
  593. transition: all 0.3s;
  594. .source {
  595. display: none;
  596. font-weight: 400;
  597. font-size: 12px;
  598. color: #fff9b1;
  599. line-height: 18px;
  600. writing-mode: vertical-lr;
  601. position: absolute;
  602. bottom: 23%;
  603. right: -10px;
  604. }
  605. .item-text {
  606. // transform: rotateY(180deg);
  607. font-size: 30rpx;
  608. line-height: 100rpx;
  609. position: absolute;
  610. top: calc(50% - 133px);
  611. left: calc(50% - 34px);
  612. &.active {
  613. color: #1468ff;
  614. }
  615. }
  616. .activeItem {
  617. }
  618. }
  619. .fang {
  620. transform: rotateY(180deg);
  621. transition: all 0.5s;
  622. .item-text {
  623. transform: rotateY(0deg);
  624. }
  625. .source {
  626. display: block;
  627. transform: rotateY(180deg);
  628. }
  629. }
  630. .active {
  631. .item-text {
  632. top: calc(50% - 226px);
  633. left: calc(50% - 50px);
  634. }
  635. .item {
  636. width: 50px;
  637. height: 453px;
  638. background-size: 100% 100%;
  639. font-size: 27px;
  640. color: #8c4042;
  641. line-height: 41px;
  642. }
  643. .activeItem {
  644. transform: rotateY(180deg);
  645. width: 100px;
  646. height: 263px;
  647. padding: 95px 0px;
  648. display: inline-block;
  649. background-size: 100% 100%;
  650. font-size: 12px;
  651. color: #303030;
  652. line-height: 18px;
  653. display: flex;
  654. writing-mode: vertical-lr;
  655. text-align: left;
  656. justify-content: center;
  657. flex-direction: column;
  658. background: url(https://4dscene.4dage.com/new4dkk/deng/static/img/img_label@2x.png)
  659. 100% 100% no-repeat;
  660. background-size: 100% 100%;
  661. position: relative;
  662. top: 44px;
  663. }
  664. }
  665. }
  666. .swiper {
  667. padding: 0 10px;
  668. // .listitem {
  669. // text-align: center;
  670. // padding: 0 20px;
  671. .item {
  672. margin: 20px auto;
  673. width: 18px;
  674. height: 267px;
  675. background: url(https://4dscene.4dage.com/new4dkk/deng/static/img/label@2x.png)
  676. 100% 100% no-repeat;
  677. background-size: cover;
  678. writing-mode: tb-rl;
  679. text-align: center;
  680. padding: 0 25px;
  681. position: relative;
  682. display: flex;
  683. writing-mode: vertical-lr;
  684. text-align: center;
  685. justify-content: center;
  686. flex-direction: column;
  687. }
  688. // .active {
  689. // &:after {
  690. // content: "";
  691. // box-shadow: 0px 2px 18px 11px #fff86c,
  692. // inset 0px 1px 1px 0px rgba(177, 156, 125, 0.7);
  693. // position: absolute;
  694. // height: 71%;
  695. // width: 80%;
  696. // top: 32px;
  697. // left: 8px;
  698. // border-radius: 25px;
  699. // z-index: -1;
  700. // }
  701. // }
  702. // }
  703. }
  704. }
  705. }
  706. @keyframes handleAni {
  707. from {
  708. right: 50px;
  709. }
  710. to {
  711. right: 30px;
  712. }
  713. }
  714. </style>