index_new.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <div class="wrap">
  3. <view class="save-btn" @click="createCanvas"> 点击保存 </view>
  4. <!-- 简图轮播 -->
  5. <div class="swiper">
  6. <swiper
  7. duration="100"
  8. :current="current"
  9. :indicator-dots="false"
  10. :autoplay="false"
  11. :interval="3000"
  12. :duration="1000"
  13. @change="swiperChange"
  14. >
  15. <!-- -->
  16. <swiper-item
  17. v-for="(item, index) in list"
  18. :key="index"
  19. :style="{
  20. padding: `calc((100vh - ${swiper_height}px - 60px) / 2) 0`,
  21. display: 'flex',
  22. justifyContent: 'center',
  23. }"
  24. >
  25. <view class="swiper-item" :id="'swiper-item' + index">
  26. <view
  27. class="title-box"
  28. :style="
  29. meun_info.jt_bg1
  30. ? { background: `url(${BASE_URL + meun_info.jt_bg1})` }
  31. : ''
  32. "
  33. >
  34. <limeQrcodeVue
  35. v-if="item.id"
  36. size="112rpx"
  37. ref="qrcodeRef"
  38. :value="
  39. BASE_URL1 +
  40. `/h5/#/pages/deal/product_info?id=${item.id}&rand_num=${item.rand_num}`
  41. "
  42. ></limeQrcodeVue>
  43. <view class="title">
  44. <p>{{ item.title1 }}</p>
  45. <p>{{ item.title2 }}</p>
  46. <p class="warn">{{ item.title3 }}</p>
  47. </view>
  48. </view>
  49. <view
  50. class="content"
  51. v-if="item.detail"
  52. :style="
  53. meun_info.jt_bg2
  54. ? { background: 'url(' + BASE_URL + meun_info.jt_bg2 + ')' }
  55. : ''
  56. "
  57. >
  58. <u-parse :content="item.detail"></u-parse>
  59. <view
  60. class="watermark"
  61. v-if="
  62. item.watermark_info &&
  63. (item.watermark_info.type == 1 ||
  64. item.watermark_info.type == 3)
  65. "
  66. >
  67. <image
  68. v-if="
  69. item.watermark_info.image && item.watermark_info.type == 1
  70. "
  71. v-for="i in 100"
  72. :style="item.style"
  73. :src="BASE_URL + item.watermark_info.image"
  74. ></image>
  75. <text
  76. v-if="
  77. item.watermark_info.water_text &&
  78. item.watermark_info.type == 3
  79. "
  80. v-for="i in 100"
  81. :style="item.style"
  82. >{{ item.watermark_info.water_text }}</text
  83. >
  84. </view>
  85. <view
  86. class="watermark-position"
  87. v-if="
  88. item.watermark_info &&
  89. (item.watermark_info.type == 2 ||
  90. item.watermark_info.type == 4)
  91. "
  92. :style="item.style_position"
  93. >
  94. <image
  95. v-if="
  96. item.watermark_info.image && item.watermark_info.type == 2
  97. "
  98. :style="item.style"
  99. :src="BASE_URL + item.watermark_info.image"
  100. ></image>
  101. <text
  102. v-if="
  103. item.watermark_info.water_text &&
  104. item.watermark_info.type == 4
  105. "
  106. :style="item.style"
  107. >{{ item.watermark_info.water_text }}
  108. </text>
  109. </view>
  110. </view>
  111. </view>
  112. </swiper-item>
  113. </swiper>
  114. </div>
  115. <!-- 简图 -->
  116. <u-overlay :show="popup_diagram" @click="popup_diagram = false">
  117. <view class="window">
  118. <view class="diagram" @tap.stop>
  119. <image :src="diagram_url" mode="widthFix"></image>
  120. <!-- <p @touchstart.prevent="touchstart" @touchend.prevent="touchend">
  121. 长按保存到本地
  122. </p> -->
  123. <p @click="popup_diagram = false">长按保存到本地</p>
  124. </view>
  125. </view>
  126. </u-overlay>
  127. <!-- 操作提示 -->
  128. <u-overlay :show="popup_tips" @click="popup_tips = false">
  129. <view class="window">
  130. <view class="tips">
  131. <image src="@/static/swiper1.png" mode=""></image>
  132. <p style="color: #fff">{{ tips_value }}</p>
  133. </view>
  134. </view>
  135. </u-overlay>
  136. <!-- 收藏 -->
  137. <u-overlay :show="popup_collect" @click="popup_collect = false">
  138. <view class="window">
  139. <view class="collect" @tap.stop>
  140. <image src="@/static/warn.png" mode=""></image>
  141. <p>{{ collect_value }}</p>
  142. <u-button
  143. color="#A5CF49"
  144. type="success"
  145. shape="circle"
  146. text="确认收藏"
  147. @click="addFavorite"
  148. ></u-button>
  149. </view>
  150. </view>
  151. </u-overlay>
  152. </div>
  153. </template>
  154. <script setup>
  155. import { ref } from "vue";
  156. import { onLoad, onShow, onPullDownRefresh, onReady } from "@dcloudio/uni-app";
  157. import { BASE_URL, BASE_URL1 } from "@/utils/http.js";
  158. import {
  159. getsimpleimages,
  160. getplatformeditor,
  161. getplatformmeun,
  162. } from "@/utils/api.js";
  163. import limeQrcodeVue from "@/uni_modules/lime-qrcode/components/l-qrcode/l-qrcode.vue";
  164. // import domtoimage from "dom-to-image";
  165. import domtoimage from "@/components/dom-to-image.js";
  166. const current = ref(0), // 当前选中项
  167. form = ref({ page: 1, page_num: 12 }), // 请求列表数据form
  168. list = ref([]), // 列表数据
  169. meun_info = ref({}), // tabbar等信息
  170. popup_diagram = ref(false), // 简图弹窗
  171. popup_tips = ref(false), // 操作提示弹窗
  172. tips_value = ref(""), // 操作提示弹窗内容
  173. popup_collect = ref(false), // 收藏弹窗
  174. collect_value = ref(""), // 收藏弹窗内容
  175. swiper_height = ref(67), // 轮播高度
  176. loop = ref(() => {}), // 长按延时事件
  177. diagram_url = ref(""); // 简图地址
  178. // 切换轮播图
  179. function swiperChange(index) {
  180. const current_index = index.detail.current;
  181. current_index == list.value.length - 3 ? getData("getsimpleimages") : "";
  182. current.value = current_index;
  183. setTimeout(() => {
  184. computeSwiperHeight();
  185. });
  186. }
  187. // 计算轮播高度
  188. function computeSwiperHeight() {
  189. let dom = document.getElementById("swiper-item" + current.value); // 获取dom元素
  190. if (dom && dom.children[1]) {
  191. swiper_height.value = 67 + dom.children[1].clientHeight;
  192. } else {
  193. swiper_height.value = 67;
  194. }
  195. }
  196. // 生成简图图片---domtoimage截图
  197. function createCanvas() {
  198. let dom = document.getElementById("swiper-item" + current.value),
  199. item = list.value[current.value]; // 获取dom元素
  200. if (item.diagram_url) {
  201. diagram_url.value = item.diagram_url;
  202. popup_diagram.value = true;
  203. return;
  204. }
  205. const width = dom.clientWidth;
  206. domtoimage
  207. .toPng(dom, {
  208. bgcolor: "#fff",
  209. cacheBust: true,
  210. width: width,
  211. height: swiper_height.value,
  212. scale: 4,
  213. filter: (el) => {
  214. if (el.contains(dom) || dom.contains(el)) {
  215. return true;
  216. }
  217. return false;
  218. },
  219. })
  220. .then(function (dataUrl) {
  221. diagram_url.value = dataUrl.replace("image/png", "image/octet-stream");
  222. item.diagram_url = diagram_url.value;
  223. popup_diagram.value = true;
  224. });
  225. }
  226. // 长按开始
  227. function touchstart() {
  228. clearTimeout(loop.value);
  229. setTimeout(() => {
  230. saveImage();
  231. }, 600);
  232. }
  233. // 长按结束
  234. function touchend() {
  235. clearTimeout(loop.value);
  236. }
  237. // 保存图片
  238. function saveImage() {
  239. let blob = new Blob([""], { type: "application/octet-stream" });
  240. let url = URL.createObjectURL(blob);
  241. let a = document.createElement("a");
  242. a.href = diagram_url.value;
  243. // a.download = diagram_url.value
  244. // .replace(/(.*\/)*([^.]+.*)/gi, "$2")
  245. // .split("?")[0];
  246. a.download = "斑马简图.png";
  247. let e = document.createEvent("MouseEvents");
  248. e.initMouseEvent("click", true);
  249. a.dispatchEvent(e);
  250. URL.revokeObjectURL(url);
  251. }
  252. // 收藏本站
  253. let addFavorite = () => {
  254. var url = window.location;
  255. var title = "斑马交易平台";
  256. var ua = navigator.userAgent.toLowerCase();
  257. if (ua.indexOf("360se") > -1) {
  258. alert("您的浏览器不支持自动加入收藏,请手动设置!");
  259. } else if (ua.indexOf("msie 8") > -1) {
  260. window.external.AddToFavoritesBar(url, title); //IE8
  261. } else if (document.all) {
  262. //IE类浏览器
  263. try {
  264. window.external.addFavorite(url, title);
  265. } catch (e) {
  266. alert("您的浏览器不支持自动加入收藏,请手动设置!");
  267. }
  268. } else if (window.sidebar) {
  269. //firfox等浏览器;
  270. window.sidebar.addPanel(title, url, "");
  271. } else {
  272. alert("您的浏览器不支持自动加入收藏,请手动设置!");
  273. }
  274. popup_collect.value = false;
  275. };
  276. // 获取数据
  277. function getData(url) {
  278. switch (url) {
  279. case "getplatformeditor": // 获取平台信息
  280. getplatformeditor().then(({ data }) => {
  281. collect_value.value = data.alert1;
  282. tips_value.value = data.alert2;
  283. });
  284. break;
  285. case "getplatformmeun": // 获取tabbar等信息
  286. getplatformmeun().then(({ data }) => {
  287. uni.setNavigationBarTitle({
  288. title: data.name,
  289. });
  290. meun_info.value = data;
  291. });
  292. break;
  293. case "getsimpleimages": // 获取列表数据
  294. getsimpleimages(form.value).then(({ data }) => {
  295. data.forEach((item) => {
  296. let { watermark_info } = item,
  297. family_arr = [
  298. "fangsong",
  299. "Helvetica",
  300. "Arial",
  301. "Tahoma",
  302. "Microsoft YaHei",
  303. "SimSun",
  304. ];
  305. item.style = {
  306. opacity: (100 - watermark_info.opacity * 1) * 0.01,
  307. color: watermark_info.color,
  308. fontSize: watermark_info.text_font + "px",
  309. fontWeight: watermark_info.bold == 1 ? "bold" : "",
  310. // fontFamily: `typeface${watermark_info.typeface}`,
  311. fontFamily: family_arr[watermark_info.typeface - 1],
  312. transform: `rotate(${watermark_info.angle}deg)`,
  313. };
  314. item.style_position = {
  315. top: watermark_info.yy + "px",
  316. left: watermark_info.xx + "px",
  317. };
  318. if (watermark_info.type == "4") {
  319. item.style_position.height = item.style.lineHeight =
  320. item.style.fontSize;
  321. }
  322. });
  323. if (form.value.page == 1) {
  324. list.value = data;
  325. popup_tips.value = true;
  326. setTimeout(() => {
  327. popup_tips.value = false;
  328. }, 5000);
  329. } else {
  330. list.value = [...list.value, ...data];
  331. }
  332. form.value.page++;
  333. setTimeout(() => {
  334. computeSwiperHeight();
  335. });
  336. });
  337. break;
  338. }
  339. }
  340. onLoad(() => {
  341. getData("getplatformeditor");
  342. getData("getplatformmeun");
  343. getData("getsimpleimages");
  344. });
  345. onReady(() => {
  346. let flag = uni.getStorageSync("collect");
  347. if (!flag) {
  348. popup_collect.value = true;
  349. uni.setStorageSync("collect", true);
  350. }
  351. });
  352. </script>
  353. <style lang="scss" scoped>
  354. .wrap {
  355. .save-btn {
  356. font-size: 35rpx;
  357. color: #fff;
  358. text-align: center;
  359. line-height: 90rpx;
  360. float: right;
  361. width: 200rpx;
  362. height: 90rpx;
  363. background: #a5cf49;
  364. border-radius: 0rpx 0rpx 0rpx 32rpx;
  365. position: fixed;
  366. right: 0;
  367. top: 0;
  368. z-index: 1000;
  369. }
  370. .swiper {
  371. // width: 694rpx;
  372. // position: fixed;
  373. // top: 50%;
  374. // left: 50%;
  375. // transform: translate(-50%, -50%);
  376. > :first-child {
  377. height: 100vh;
  378. // width: 100vw;
  379. display: flex;
  380. align-items: center;
  381. }
  382. .swiper-item {
  383. max-width: 60vh;
  384. .title-box {
  385. font-size: 28rpx;
  386. color: #666666;
  387. padding: 6rpx;
  388. // background: #fff5e5;
  389. display: flex;
  390. align-items: flex-end;
  391. image {
  392. margin-right: 4rpx;
  393. width: 112rpx;
  394. height: 112rpx;
  395. }
  396. .warn {
  397. font-size: 32rpx;
  398. color: #ff2828;
  399. }
  400. .title {
  401. margin-left: 4rpx;
  402. }
  403. }
  404. .content {
  405. padding-left: 10rpx;
  406. padding-right: 10rpx;
  407. overflow: hidden;
  408. position: relative;
  409. word-break: break-all;
  410. word-wrap: break-word;
  411. overflow: hidden;
  412. position: relative;
  413. .watermark {
  414. position: absolute;
  415. display: flex;
  416. flex-wrap: wrap;
  417. top: 0;
  418. left: 0;
  419. right: 0;
  420. image {
  421. width: 100rpx;
  422. height: 100rpx;
  423. }
  424. }
  425. .watermark-position {
  426. position: absolute;
  427. display: flex;
  428. image {
  429. width: 100rpx;
  430. height: 100rpx;
  431. }
  432. }
  433. text {
  434. white-space: nowrap;
  435. }
  436. }
  437. }
  438. }
  439. .window {
  440. padding: 0 28rpx;
  441. display: flex;
  442. align-items: center;
  443. justify-content: center;
  444. height: 100%;
  445. .diagram {
  446. display: flex;
  447. flex-direction: column;
  448. align-items: center;
  449. width: 694px;
  450. height: auto;
  451. image {
  452. width: 100%;
  453. }
  454. p {
  455. font-size: 48rpx;
  456. color: #fff;
  457. margin-top: 12rpx;
  458. width: 100%;
  459. text-align: center;
  460. }
  461. }
  462. .tips {
  463. display: flex;
  464. flex-direction: column;
  465. align-items: center;
  466. image {
  467. width: 374rpx;
  468. height: 361rpx;
  469. }
  470. @keyframes example1 {
  471. 0% {
  472. transform: translate(0);
  473. }
  474. 50% {
  475. transform: translate(-40px);
  476. }
  477. 100% {
  478. transform: translate(-80px);
  479. }
  480. 0% {
  481. transform: translate(0);
  482. }
  483. }
  484. transform: translate(0);
  485. animation: example1 1s linear 0s backwards;
  486. animation-iteration-count: infinite;
  487. }
  488. .collect {
  489. padding: 60rpx 60rpx;
  490. display: flex;
  491. flex-direction: column;
  492. align-items: center;
  493. width: 558rpx;
  494. // height: 438rpx;
  495. background: #ffffff;
  496. border-radius: 20rpx;
  497. image {
  498. max-width: 96rpx;
  499. max-height: 96rpx;
  500. }
  501. p {
  502. font-size: 30rpx;
  503. margin: 62rpx 0 40rpx;
  504. }
  505. // background-color: #fff;
  506. }
  507. }
  508. }
  509. </style>