share.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <popup v-if="show">
  3. <div
  4. class="ui-message ui-message-confirm message-material"
  5. style="width: 500px"
  6. >
  7. <div class="ui-message-header header-material">
  8. <span>{{ share }}</span>
  9. <span @click="$emit('close')">
  10. <i class="iconfont icon-close"></i>
  11. </span>
  12. </div>
  13. <div class="ui-message-main">
  14. <ul>
  15. <li>
  16. <span>{{ work_link }}</span>
  17. <input
  18. :title="item.share + `&vr=${defaultscenesCode}&lang=${$lang}`"
  19. class="ui-input"
  20. disabled
  21. type="text"
  22. maxlength="15"
  23. v-model="item.share"
  24. />
  25. </li>
  26. <li>
  27. <span>{{ work_qrCode }} </span>
  28. <img :src="item.qrCode + `?${Math.random()}` || $thumb" alt="" />
  29. </li>
  30. </ul>
  31. </div>
  32. <div class="ui-message-footer footer-material">
  33. <button @click="downloadImg(item)" class="ui-button">
  34. {{ download_qrCode }}
  35. </button>
  36. <button
  37. @click="copy(item.share + `&vr=${defaultscenesCode}&lang=${$lang}`)"
  38. class="ui-button submit"
  39. >
  40. {{ copy_link }}
  41. </button>
  42. </div>
  43. </div>
  44. </popup>
  45. </template>
  46. <script>
  47. import Popup from "@/components/shared/popup";
  48. import { i18n } from "@/lang";
  49. let dataUrlToBold = function (url) {
  50. let arr = url.split(","),
  51. mime = arr[0].match(/:(.*?);/)[1],
  52. bStr = atob(arr[1]),
  53. n = bStr.length,
  54. u8arr = new Uint8Array(n);
  55. while (n--) {
  56. u8arr[n] = bStr.charCodeAt(n);
  57. }
  58. return new Blob([u8arr], { type: mime });
  59. };
  60. export default {
  61. props: ["show", "item"],
  62. components: {
  63. Popup,
  64. },
  65. data() {
  66. return {
  67. work_link: i18n.t("material.works.work_link"),
  68. work_qrCode: i18n.t("material.works.work_qrCode"),
  69. share: i18n.t("material.works.share"),
  70. download_qrCode: i18n.t("material.works.download_qrCode"),
  71. copy_link: i18n.t("material.works.copy_link"),
  72. key: "",
  73. };
  74. },
  75. computed: {
  76. defaultscenesCode: function () {
  77. if (this.item.firstScene) {
  78. return this.item.firstScene.sceneCode || "";
  79. } else {
  80. return Array.from(this.item.scenes).length > 0
  81. ? Array.from(this.item.scenes)[0].sceneCode
  82. : "";
  83. }
  84. },
  85. },
  86. mounted() {},
  87. methods: {
  88. downloadImg(workItem) {
  89. let val = workItem.qrCode;
  90. // var a = document.createElement("a");
  91. // a.download = 'qrcode';
  92. // a.href = 'https://4dkk.4dage.com/720yun_fd_manage/620/qrCode.jpg';
  93. // a.target
  94. // console.log(workItem,11222);
  95. // val 为传入的图片地址
  96. let _type_index = val.lastIndexOf(".");
  97. let _type = val.substr(_type_index + 1); //原始图片类型
  98. let image = new Image();
  99. image.setAttribute("crossOrigin", "anonymous"); //消除跨域
  100. image.src = val;
  101. image.onload = function () {
  102. //借助canvas实现 消除 图片地址会先直接窗口打开图片地址
  103. let canvas = document.createElement("canvas");
  104. canvas.width = image.width;
  105. canvas.height = image.height;
  106. let context = canvas.getContext("2d");
  107. context.drawImage(image, 0, 0, image.width, image.height);
  108. let url = canvas.toDataURL("image/" + _type);
  109. let blob = dataUrlToBold(url);
  110. let obj_url = URL.createObjectURL(blob); // 消除Chrome下文件太大 导致下载失败(网络失败)的问题
  111. let a = document.createElement("a");
  112. let event = new MouseEvent("click");
  113. a.download = workItem.name || "qrcode";
  114. a.href = obj_url;
  115. a.dispatchEvent(event);
  116. };
  117. },
  118. copy(text) {
  119. var textArea = document.createElement("textarea");
  120. textArea.style.position = "fixed";
  121. textArea.style.top = 0;
  122. textArea.style.left = 0;
  123. textArea.style.width = "2em";
  124. textArea.style.height = "2em";
  125. textArea.style.padding = 0;
  126. textArea.style.border = "none";
  127. textArea.style.outline = "none";
  128. textArea.style.boxShadow = "none";
  129. textArea.style.background = "transparent";
  130. textArea.value = text;
  131. document.body.appendChild(textArea);
  132. textArea.select();
  133. try {
  134. document.execCommand("copy")
  135. ? this.$msg.success(this.$i18n.t("gather.scene_link_copy_tips"))
  136. : this.$msg.error(this.$i18n.t("gather.scene_link_copy_failed"));
  137. } catch (err) {
  138. this.$msg.error(this.$i18n.t("gather.scene_link_copy_failed"));
  139. }
  140. document.body.removeChild(textArea);
  141. },
  142. },
  143. };
  144. </script>
  145. <style lang="less" scoped>
  146. .ui-message-confirm {
  147. border-radius: 0;
  148. .icon-close {
  149. color: #909090;
  150. }
  151. .ui-message-main {
  152. margin: 20px auto;
  153. padding-bottom: 20px;
  154. background: #fff;
  155. > ul {
  156. color: #646566;
  157. > li {
  158. display: flex;
  159. align-items: flex-start;
  160. margin-bottom: 20px;
  161. > span {
  162. font-size: 14px;
  163. display: inline-block;
  164. width: 70px;
  165. margin-top: 4px;
  166. text-align: right;
  167. margin-right: 16px;
  168. }
  169. > img {
  170. width: 120px;
  171. border: 1px solid #ebedf0;
  172. border-radius: 4px;
  173. }
  174. .ui-input {
  175. width: 362px;
  176. height: 36px;
  177. background: #f7f7f7;
  178. border-radius: 4px;
  179. border: 1px solid #ebedf0;
  180. }
  181. .ui-button {
  182. min-width: 104px;
  183. margin-left: 10px;
  184. }
  185. }
  186. }
  187. }
  188. .ui-message-footer {
  189. width: 100%;
  190. }
  191. .footer-material {
  192. margin-top: 0 !important;
  193. }
  194. }
  195. </style>
  196. <style lang="less" scoped>
  197. @import "../style.less";
  198. </style>