sharePdf.vue 7.8 KB

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