123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <template>
- <popup v-if="show">
- <div
- class="ui-message ui-message-confirm message-material"
- style="width: 500px"
- >
- <div class="ui-message-header header-material">
- <span>{{ share }}</span>
- <span @click="$emit('close')">
- <i class="iconfont icon-close"></i>
- </span>
- </div>
- <div class="ui-message-main">
- <ul>
- <li>
- <span>{{ work_link }}</span>
- <input
- :title="item.share + `&vr=${defaultscenesCode}&lang=${$lang}`"
- class="ui-input"
- disabled
- type="text"
- maxlength="15"
- v-model="item.share"
- />
- </li>
- <li>
- <span>{{ work_qrCode }} </span>
- <img :src="item.qrCode + `?${Math.random()}` || $thumb" alt="" />
- </li>
- </ul>
- </div>
- <div class="ui-message-footer footer-material">
- <button @click="downloadImg(item)" class="ui-button">
- {{ download_qrCode }}
- </button>
- <button
- @click="copy(item.share + `&vr=${defaultscenesCode}&lang=${$lang}`)"
- class="ui-button submit"
- >
- {{ copy_link }}
- </button>
- </div>
- </div>
- </popup>
- </template>
- <script>
- import Popup from "@/components/shared/popup";
- import { i18n } from "@/lang";
- let dataUrlToBold = function (url) {
- let arr = url.split(","),
- mime = arr[0].match(/:(.*?);/)[1],
- bStr = atob(arr[1]),
- n = bStr.length,
- u8arr = new Uint8Array(n);
- while (n--) {
- u8arr[n] = bStr.charCodeAt(n);
- }
- return new Blob([u8arr], { type: mime });
- };
- export default {
- props: ["show", "item"],
- components: {
- Popup,
- },
- data() {
- return {
- work_link: i18n.t("material.works.work_link"),
- work_qrCode: i18n.t("material.works.work_qrCode"),
- share: i18n.t("material.works.share"),
- download_qrCode: i18n.t("material.works.download_qrCode"),
- copy_link: i18n.t("material.works.copy_link"),
- key: "",
- };
- },
- computed: {
- defaultscenesCode: function () {
- if (this.item.firstScene) {
- return this.item.firstScene.sceneCode || "";
- } else {
- return Array.from(this.item.scenes).length > 0
- ? Array.from(this.item.scenes)[0].sceneCode
- : "";
- }
- },
- },
- mounted() {},
- methods: {
- downloadImg(workItem) {
- let val = workItem.qrCode;
- // var a = document.createElement("a");
- // a.download = 'qrcode';
- // a.href = 'https://4dkk.4dage.com/720yun_fd_manage/620/qrCode.jpg';
- // a.target
- // console.log(workItem,11222);
- // val 为传入的图片地址
- let _type_index = val.lastIndexOf(".");
- let _type = val.substr(_type_index + 1); //原始图片类型
- let image = new Image();
- image.setAttribute("crossOrigin", "anonymous"); //消除跨域
- image.src = val;
- image.onload = function () {
- //借助canvas实现 消除 图片地址会先直接窗口打开图片地址
- let canvas = document.createElement("canvas");
- canvas.width = image.width;
- canvas.height = image.height;
- let context = canvas.getContext("2d");
- context.drawImage(image, 0, 0, image.width, image.height);
- let url = canvas.toDataURL("image/" + _type);
- let blob = dataUrlToBold(url);
- let obj_url = URL.createObjectURL(blob); // 消除Chrome下文件太大 导致下载失败(网络失败)的问题
- let a = document.createElement("a");
- let event = new MouseEvent("click");
- a.download = workItem.name || "qrcode";
- a.href = obj_url;
- a.dispatchEvent(event);
- };
- },
- copy(text) {
- var textArea = document.createElement("textarea");
- textArea.style.position = "fixed";
- textArea.style.top = 0;
- textArea.style.left = 0;
- textArea.style.width = "2em";
- textArea.style.height = "2em";
- textArea.style.padding = 0;
- textArea.style.border = "none";
- textArea.style.outline = "none";
- textArea.style.boxShadow = "none";
- textArea.style.background = "transparent";
- textArea.value = text;
- document.body.appendChild(textArea);
- textArea.select();
- try {
- document.execCommand("copy")
- ? this.$msg.success(this.$i18n.t("gather.scene_link_copy_tips"))
- : this.$msg.error(this.$i18n.t("gather.scene_link_copy_failed"));
- } catch (err) {
- this.$msg.error(this.$i18n.t("gather.scene_link_copy_failed"));
- }
- document.body.removeChild(textArea);
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .ui-message-confirm {
- border-radius: 0;
- .icon-close {
- color: #909090;
- }
- .ui-message-main {
- margin: 20px auto;
- padding-bottom: 20px;
- background: #fff;
- > ul {
- color: #646566;
- > li {
- display: flex;
- align-items: flex-start;
- margin-bottom: 20px;
- > span {
- font-size: 14px;
- display: inline-block;
- width: 70px;
- margin-top: 4px;
- text-align: right;
- margin-right: 16px;
- }
- > img {
- width: 120px;
- border: 1px solid #ebedf0;
- border-radius: 4px;
- }
- .ui-input {
- width: 362px;
- height: 36px;
- background: #f7f7f7;
- border-radius: 4px;
- border: 1px solid #ebedf0;
- }
- .ui-button {
- min-width: 104px;
- margin-left: 10px;
- }
- }
- }
- }
- .ui-message-footer {
- width: 100%;
- }
- .footer-material {
- margin-top: 0 !important;
- }
- }
- </style>
- <style lang="less" scoped>
- @import "../style.less";
- </style>
|