123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- <template>
- <div class="wrap">
- <view class="save-btn" @click="createCanvas"> 点击保存 </view>
-
- <div class="swiper">
- <swiper
- duration="100"
- :current="current"
- :indicator-dots="false"
- :autoplay="false"
- :interval="3000"
- :duration="1000"
- @change="swiperChange"
- >
-
- <swiper-item
- v-for="(item, index) in list"
- :key="index"
- :style="{
- padding: `calc((100vh - ${swiper_height}px - 60px) / 2) 0`,
- display: 'flex',
- justifyContent: 'center',
- }"
- >
- <view class="swiper-item" :id="'swiper-item' + index">
- <view
- class="title-box"
- :style="
- meun_info.jt_bg1
- ? { background: `url(${BASE_URL + meun_info.jt_bg1})` }
- : ''
- "
- >
- <limeQrcodeVue
- v-if="item.id"
- size="112rpx"
- ref="qrcodeRef"
- :value="
- BASE_URL1 +
- `/h5/#/pages/deal/product_info?id=${item.id}&rand_num=${item.rand_num}`
- "
- ></limeQrcodeVue>
- <view class="title">
- <p>{{ item.title1 }}</p>
- <p>{{ item.title2 }}</p>
- <p class="warn">{{ item.title3 }}</p>
- </view>
- </view>
- <view
- class="content"
- v-if="item.detail"
- :style="
- meun_info.jt_bg2
- ? { background: 'url(' + BASE_URL + meun_info.jt_bg2 + ')' }
- : ''
- "
- >
- <u-parse :content="item.detail"></u-parse>
- <view
- class="watermark"
- v-if="
- item.watermark_info &&
- (item.watermark_info.type == 1 ||
- item.watermark_info.type == 3)
- "
- >
- <image
- v-if="
- item.watermark_info.image && item.watermark_info.type == 1
- "
- v-for="i in 100"
- :style="item.style"
- :src="BASE_URL + item.watermark_info.image"
- ></image>
- <text
- v-if="
- item.watermark_info.water_text &&
- item.watermark_info.type == 3
- "
- v-for="i in 100"
- :style="item.style"
- >{{ item.watermark_info.water_text }}</text
- >
- </view>
- <view
- class="watermark-position"
- v-if="
- item.watermark_info &&
- (item.watermark_info.type == 2 ||
- item.watermark_info.type == 4)
- "
- :style="item.style_position"
- >
- <image
- v-if="
- item.watermark_info.image && item.watermark_info.type == 2
- "
- :style="item.style"
- :src="BASE_URL + item.watermark_info.image"
- ></image>
- <text
- v-if="
- item.watermark_info.water_text &&
- item.watermark_info.type == 4
- "
- :style="item.style"
- >{{ item.watermark_info.water_text }}
- </text>
- </view>
- </view>
- </view>
- </swiper-item>
- </swiper>
- </div>
-
- <u-overlay :show="popup_diagram" @click="popup_diagram = false">
- <view class="window">
- <view class="diagram" @tap.stop>
- <image :src="diagram_url" mode="widthFix"></image>
-
- <p @click="popup_diagram = false">长按保存到本地</p>
- </view>
- </view>
- </u-overlay>
-
- <u-overlay :show="popup_tips" @click="popup_tips = false">
- <view class="window">
- <view class="tips">
- <image src="@/static/swiper1.png" mode=""></image>
- <p style="color: #fff">{{ tips_value }}</p>
- </view>
- </view>
- </u-overlay>
-
- <u-overlay :show="popup_collect" @click="popup_collect = false">
- <view class="window">
- <view class="collect" @tap.stop>
- <image src="@/static/warn.png" mode=""></image>
- <p>{{ collect_value }}</p>
- <u-button
- color="#A5CF49"
- type="success"
- shape="circle"
- text="确认收藏"
- @click="addFavorite"
- ></u-button>
- </view>
- </view>
- </u-overlay>
- </div>
- </template>
- <script setup>
- import { ref } from "vue";
- import { onLoad, onShow, onPullDownRefresh, onReady } from "@dcloudio/uni-app";
- import { BASE_URL, BASE_URL1 } from "@/utils/http.js";
- import {
- getsimpleimages,
- getplatformeditor,
- getplatformmeun,
- } from "@/utils/api.js";
- import limeQrcodeVue from "@/uni_modules/lime-qrcode/components/l-qrcode/l-qrcode.vue";
- import domtoimage from "@/components/dom-to-image.js";
- const current = ref(0),
- form = ref({ page: 1, page_num: 12 }),
- list = ref([]),
- meun_info = ref({}),
- popup_diagram = ref(false),
- popup_tips = ref(false),
- tips_value = ref(""),
- popup_collect = ref(false),
- collect_value = ref(""),
- swiper_height = ref(67),
- loop = ref(() => {}),
- diagram_url = ref("");
- function swiperChange(index) {
- const current_index = index.detail.current;
- current_index == list.value.length - 3 ? getData("getsimpleimages") : "";
- current.value = current_index;
- setTimeout(() => {
- computeSwiperHeight();
- });
- }
- function computeSwiperHeight() {
- let dom = document.getElementById("swiper-item" + current.value);
- if (dom && dom.children[1]) {
- swiper_height.value = 67 + dom.children[1].clientHeight;
- } else {
- swiper_height.value = 67;
- }
- }
- function createCanvas() {
- let dom = document.getElementById("swiper-item" + current.value),
- item = list.value[current.value];
- if (item.diagram_url) {
- diagram_url.value = item.diagram_url;
- popup_diagram.value = true;
- return;
- }
- const width = dom.clientWidth;
- domtoimage
- .toPng(dom, {
- bgcolor: "#fff",
- cacheBust: true,
- width: width,
- height: swiper_height.value,
- scale: 4,
- filter: (el) => {
- if (el.contains(dom) || dom.contains(el)) {
- return true;
- }
- return false;
- },
- })
- .then(function (dataUrl) {
- diagram_url.value = dataUrl.replace("image/png", "image/octet-stream");
- item.diagram_url = diagram_url.value;
- popup_diagram.value = true;
- });
- }
- function touchstart() {
- clearTimeout(loop.value);
- setTimeout(() => {
- saveImage();
- }, 600);
- }
- function touchend() {
- clearTimeout(loop.value);
- }
- function saveImage() {
- let blob = new Blob([""], { type: "application/octet-stream" });
- let url = URL.createObjectURL(blob);
- let a = document.createElement("a");
- a.href = diagram_url.value;
-
-
-
- a.download = "斑马简图.png";
- let e = document.createEvent("MouseEvents");
- e.initMouseEvent("click", true);
- a.dispatchEvent(e);
- URL.revokeObjectURL(url);
- }
- let addFavorite = () => {
- var url = window.location;
- var title = "斑马交易平台";
- var ua = navigator.userAgent.toLowerCase();
- if (ua.indexOf("360se") > -1) {
- alert("您的浏览器不支持自动加入收藏,请手动设置!");
- } else if (ua.indexOf("msie 8") > -1) {
- window.external.AddToFavoritesBar(url, title);
- } else if (document.all) {
-
- try {
- window.external.addFavorite(url, title);
- } catch (e) {
- alert("您的浏览器不支持自动加入收藏,请手动设置!");
- }
- } else if (window.sidebar) {
-
- window.sidebar.addPanel(title, url, "");
- } else {
- alert("您的浏览器不支持自动加入收藏,请手动设置!");
- }
- popup_collect.value = false;
- };
- function getData(url) {
- switch (url) {
- case "getplatformeditor":
- getplatformeditor().then(({ data }) => {
- collect_value.value = data.alert1;
- tips_value.value = data.alert2;
- });
- break;
- case "getplatformmeun":
- getplatformmeun().then(({ data }) => {
- uni.setNavigationBarTitle({
- title: data.name,
- });
- meun_info.value = data;
- });
- break;
- case "getsimpleimages":
- getsimpleimages(form.value).then(({ data }) => {
- data.forEach((item) => {
- let { watermark_info } = item,
- family_arr = [
- "fangsong",
- "Helvetica",
- "Arial",
- "Tahoma",
- "Microsoft YaHei",
- "SimSun",
- ];
- item.style = {
- opacity: (100 - watermark_info.opacity * 1) * 0.01,
- color: watermark_info.color,
- fontSize: watermark_info.text_font + "px",
- fontWeight: watermark_info.bold == 1 ? "bold" : "",
-
- fontFamily: family_arr[watermark_info.typeface - 1],
- transform: `rotate(${watermark_info.angle}deg)`,
- };
- item.style_position = {
- top: watermark_info.yy + "px",
- left: watermark_info.xx + "px",
- };
- if (watermark_info.type == "4") {
- item.style_position.height = item.style.lineHeight =
- item.style.fontSize;
- }
- });
- if (form.value.page == 1) {
- list.value = data;
- popup_tips.value = true;
- setTimeout(() => {
- popup_tips.value = false;
- }, 5000);
- } else {
- list.value = [...list.value, ...data];
- }
- form.value.page++;
- setTimeout(() => {
- computeSwiperHeight();
- });
- });
- break;
- }
- }
- onLoad(() => {
- getData("getplatformeditor");
- getData("getplatformmeun");
- getData("getsimpleimages");
- });
- onReady(() => {
- let flag = uni.getStorageSync("collect");
- if (!flag) {
- popup_collect.value = true;
- uni.setStorageSync("collect", true);
- }
- });
- </script>
- <style lang="scss" scoped>
- .wrap {
- .save-btn {
- font-size: 35rpx;
- color: #fff;
- text-align: center;
- line-height: 90rpx;
- float: right;
- width: 200rpx;
- height: 90rpx;
- background: #a5cf49;
- border-radius: 0rpx 0rpx 0rpx 32rpx;
- position: fixed;
- right: 0;
- top: 0;
- z-index: 1000;
- }
- .swiper {
- // width: 694rpx;
- // position: fixed;
- // top: 50%;
- // left: 50%;
- // transform: translate(-50%, -50%);
- > :first-child {
- height: 100vh;
- // width: 100vw;
- display: flex;
- align-items: center;
- }
- .swiper-item {
- max-width: 60vh;
- .title-box {
- font-size: 28rpx;
- color: #666666;
- padding: 6rpx;
- // background: #fff5e5;
- display: flex;
- align-items: flex-end;
- image {
- margin-right: 4rpx;
- width: 112rpx;
- height: 112rpx;
- }
- .warn {
- font-size: 32rpx;
- color: #ff2828;
- }
- .title {
- margin-left: 4rpx;
- }
- }
- .content {
- padding-left: 10rpx;
- padding-right: 10rpx;
- overflow: hidden;
- position: relative;
- word-break: break-all;
- word-wrap: break-word;
- overflow: hidden;
- position: relative;
- .watermark {
- position: absolute;
- display: flex;
- flex-wrap: wrap;
- top: 0;
- left: 0;
- right: 0;
- image {
- width: 100rpx;
- height: 100rpx;
- }
- }
- .watermark-position {
- position: absolute;
- display: flex;
- image {
- width: 100rpx;
- height: 100rpx;
- }
- }
- text {
- white-space: nowrap;
- }
- }
- }
- }
- .window {
- padding: 0 28rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- height: 100%;
- .diagram {
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 694px;
- height: auto;
- image {
- width: 100%;
- }
- p {
- font-size: 48rpx;
- color: #fff;
- margin-top: 12rpx;
- width: 100%;
- text-align: center;
- }
- }
- .tips {
- display: flex;
- flex-direction: column;
- align-items: center;
- image {
- width: 374rpx;
- height: 361rpx;
- }
- @keyframes example1 {
- 0% {
- transform: translate(0);
- }
- 50% {
- transform: translate(-40px);
- }
- 100% {
- transform: translate(-80px);
- }
- 0% {
- transform: translate(0);
- }
- }
- transform: translate(0);
- animation: example1 1s linear 0s backwards;
- animation-iteration-count: infinite;
- }
- .collect {
- padding: 60rpx 60rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- width: 558rpx;
- // height: 438rpx;
- background: #ffffff;
- border-radius: 20rpx;
- image {
- max-width: 96rpx;
- max-height: 96rpx;
- }
- p {
- font-size: 30rpx;
- margin: 62rpx 0 40rpx;
- }
- // background-color: #fff;
- }
- }
- }
- </style>
|