sharePdf.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <el-dialog
  3. :visible.sync="show"
  4. :append-to-body="true"
  5. width="560px"
  6. :before-close="handleClose"
  7. class="dialog_diy"
  8. >
  9. <div class="share_box">
  10. <div class="url_box">
  11. <div class="title">
  12. 分享链接
  13. </div>
  14. <div class="url">
  15. <el-input
  16. class="sc_fu_input"
  17. style="color: black"
  18. disabled
  19. v-model="origin"
  20. >
  21. <template slot="append"
  22. ><div class="sc_fu_copyBtn" @click.stop="copy()">
  23. 复制链接
  24. </div></template
  25. >
  26. </el-input>
  27. <!-- <el-tooltip :content="origin" placement="top" effect="dark">
  28. <span>{{ origin }}</span>
  29. </el-tooltip>
  30. <span @click="copy" :data-clipboard-text="copyText" class="tag-read"
  31. >复制链接</span
  32. > -->
  33. </div>
  34. </div>
  35. <div class="qrcode_box">
  36. <div class="title">
  37. 分享二维码
  38. </div>
  39. <div class="qrcode">
  40. <span class="qrcodeUrl" ref="qrCodeUrl"></span>
  41. <span @click="downQr">下载二维码</span>
  42. </div>
  43. </div>
  44. <div class="btn_box">
  45. <!-- <button
  46. class="c_pub_button_confirm tag-read2"
  47. @click="copy2"
  48. :data-clipboard-text="copyText2"
  49. >
  50. 复制信息
  51. </button> -->
  52. </div>
  53. </div>
  54. </el-dialog>
  55. </template>
  56. <script>
  57. import Clipboard from "clipboard";
  58. import QRCode from "qrcodejs2";
  59. export default {
  60. props: {
  61. tid: {
  62. type: String,
  63. default: ""
  64. }
  65. },
  66. data() {
  67. return {
  68. origin: "",
  69. copyText: "",
  70. copyText2: "",
  71. noCount: 0,
  72. pname: [],
  73. show: false
  74. };
  75. },
  76. methods: {
  77. handleClose(done) {
  78. this.close();
  79. done();
  80. },
  81. open() {
  82. this.show = true;
  83. this.setQr();
  84. },
  85. close() {
  86. // this.$emit("update:dialogVisibleShare", false);
  87. // this.$emit('shareBtn');
  88. this.show = false;
  89. },
  90. setQr() {
  91. this.$nextTick(() => {
  92. let url = `https://cloud.cocorobo.hk/aigpt/#/classroom_observation_board?tid=${this.tid}`;
  93. this.origin = url;
  94. this.$refs.qrCodeUrl.innerHTML = "";
  95. var qrcode = new QRCode(this.$refs.qrCodeUrl, {
  96. text: url, // 需要转换为二维码的内容
  97. width: 100,
  98. height: 100,
  99. colorDark: "#000000",
  100. colorLight: "#ffffff",
  101. correctLevel: QRCode.CorrectLevel.H
  102. });
  103. });
  104. },
  105. downQr() {
  106. // 创建一个虚拟链接,并将 canvas 转换为图片文件
  107. const link = document.createElement("a");
  108. link.href = this.$refs.qrCodeUrl.querySelector("img").src;
  109. link.download = "qrcode.png";
  110. // 模拟点击链接进行下载
  111. link.click();
  112. },
  113. copy() {
  114. const input = document.createElement("input");
  115. // 设置 display为none会导致无法复制
  116. // input.style.display = "none";
  117. // 所以只能用其他方法隐藏
  118. input.style.opacity = 0;
  119. // 为了不影响布局
  120. input.style.position = "fixed";
  121. input.style.left = "-100%";
  122. input.style.top = "-100%";
  123. input.value = this.origin;
  124. document.body.appendChild(input);
  125. input.select();
  126. const success = document.execCommand("copy");
  127. document.body.removeChild(input);
  128. if (!success) {
  129. return this.$message.error("复制失败");
  130. } else {
  131. return this.$message.success("复制成功");
  132. }
  133. // this.copyText = `https://cloud.cocorobo.hk/aigpt/#/classroom_observation_board?tid=${this.tid}`;
  134. // var clipboard = new Clipboard(".tag-read");
  135. // clipboard.on("success", e => {
  136. // this.$message.success("复制成功");
  137. // console.log("复制成功");
  138. // clipboard.destroy(); // 释放内存
  139. // });
  140. // clipboard.on("error", e => {
  141. // console.log("不支持复制,该浏览器不支持自动复制");
  142. // clipboard.destroy(); // 释放内存
  143. // });
  144. },
  145. copy2() {
  146. let url = "https://cloud.cocorobo.hk/#/classroomObservation";
  147. this.copyText2 = `链接提醒:${url}`;
  148. var clipboard = new Clipboard(".tag-read2");
  149. clipboard.on("success", e => {
  150. this.$message.success("复制成功");
  151. console.log("复制成功");
  152. clipboard.destroy(); // 释放内存
  153. });
  154. clipboard.on("error", e => {
  155. console.log("不支持复制,该浏览器不支持自动复制");
  156. clipboard.destroy(); // 释放内存
  157. });
  158. }
  159. // getData() {
  160. // // if(!this.testJson.juriP){
  161. // // return;
  162. // // }
  163. // let params = {
  164. // id: this.testJson.courseId
  165. // };
  166. // this.ajax
  167. // .get(this.$store.state.api + "getTestWorkShare", params)
  168. // .then(res => {
  169. // let parray = res.data[0];
  170. // let is = res.data[1];
  171. // this.noCount = parray.length - is.length;
  172. // let isA = [];
  173. // for (var i = 0; i < is.length; i++) {
  174. // isA.push(is[i].userid);
  175. // }
  176. // let pname = [];
  177. // for (var i = 0; i < parray.length; i++) {
  178. // if (isA.indexOf(parray[i].userid) == -1) {
  179. // pname.push(parray[i].username);
  180. // }
  181. // }
  182. // this.pname = pname;
  183. // })
  184. // .catch(err => {
  185. // console.error(err);
  186. // });
  187. // }
  188. },
  189. watch: {
  190. tid() {
  191. if (this.show) {
  192. this.setQr();
  193. }
  194. }
  195. },
  196. mounted() {
  197. // console.log("this.info", this.info);
  198. // console.log(top.origin);
  199. // this.origin = top.origin
  200. }
  201. };
  202. </script>
  203. <style scoped>
  204. .dialog_diy >>> .el-dialog {
  205. /* height: 100%; */
  206. /* margin: 0 auto !important; */
  207. }
  208. .dialog_diy >>> .el-dialog__header {
  209. background: #fff !important;
  210. padding: 15px 20px;
  211. }
  212. .dialog_diy >>> .el-dialog__body {
  213. height: calc(100% - 124px);
  214. box-sizing: border-box;
  215. padding: 0px;
  216. }
  217. .dialog_diy >>> .el-dialog__title {
  218. color: #000;
  219. }
  220. .dialog_diy >>> .el-dialog__headerbtn {
  221. top: 19px;
  222. }
  223. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close {
  224. color: #000;
  225. }
  226. .dialog_diy >>> .el-dialog__headerbtn .el-dialog__close:hover {
  227. color: #000;
  228. }
  229. .dialog_diy >>> .el-dialog__body,
  230. .dialog_diy >>> .el-dialog__footer {
  231. background: #fff;
  232. }
  233. .share_box {
  234. width: 100%;
  235. height: 100%;
  236. padding: 0 20px 15px;
  237. box-sizing: border-box;
  238. }
  239. .info_box {
  240. margin: 0 0 20px;
  241. }
  242. .info_box > .info {
  243. line-height: 18px;
  244. }
  245. .info_box > .info > span:nth-child(1) {
  246. color: #00000099;
  247. }
  248. .info_box > .info > span:nth-child(2) {
  249. color: #000000;
  250. }
  251. .info_box > .info + .info {
  252. margin-top: 10px;
  253. }
  254. .url_box {
  255. margin-bottom: 20px;
  256. }
  257. .qrcode_box {
  258. margin-bottom: 20px;
  259. }
  260. .url_box > .url {
  261. width: 100%;
  262. display: flex;
  263. align-items: center;
  264. /*border: 1px solid #e7e7e7;*/
  265. border-radius: 4px;
  266. height: 35px;
  267. padding: 0 7px;
  268. box-sizing: border-box;
  269. }
  270. .url_box > .url > span {
  271. font-size: 16px;
  272. color: #000000;
  273. }
  274. .url_box > .url > span:nth-child(1) {
  275. width: 100%;
  276. white-space: nowrap;
  277. overflow: hidden;
  278. text-overflow: ellipsis;
  279. }
  280. .url_box > .url > span:nth-child(2) {
  281. margin-left: auto;
  282. border-left: 1px solid #e7e7e7;
  283. padding-left: 7px;
  284. cursor: pointer;
  285. min-width: fit-content;
  286. }
  287. .url_box > .title,
  288. .qrcode_box > .title {
  289. font-size: 16px;
  290. font-weight: 700;
  291. margin-bottom: 10px;
  292. }
  293. .qrcode_box > .qrcode {
  294. padding: 7px;
  295. border: 1px solid #e7e7e7;
  296. width: fit-content;
  297. border-radius: 4px;
  298. display: flex;
  299. align-items: flex-end;
  300. }
  301. .qrcode_box > .qrcode > span:nth-child(1) {
  302. width: 100px;
  303. display: block;
  304. height: 100px;
  305. }
  306. .qrcode_box > .qrcode > span:nth-child(2) {
  307. background: #f0f2f5;
  308. padding: 7px 15px;
  309. font-size: 16px;
  310. border-radius: 4px;
  311. cursor: pointer;
  312. color: #000;
  313. margin-left: 7px;
  314. }
  315. .btn_box {
  316. display: flex;
  317. justify-content: flex-end;
  318. }
  319. .more {
  320. cursor: pointer;
  321. color: #0061ff;
  322. }
  323. .sc_fu_input /deep/.el-input__inner {
  324. color: black !important;
  325. cursor: text !important;
  326. }
  327. .sc_fu_input >>> .el-input__inner {
  328. color: black !important;
  329. cursor: text !important;
  330. }
  331. .sc_fu_copyBtn {
  332. color: black;
  333. cursor: pointer;
  334. }
  335. </style>