shareDetail.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div>
  3. <el-form :model="form" ref="form" class="form">
  4. <el-form-item label="分享对象" v-if="row.os !== 'mobile'">
  5. <el-radio-group v-model="form.shareTarget" @change="changeShareTarget">
  6. <el-radio v-model="form.shareTarget" label="1">主讲人</el-radio>
  7. <el-radio v-model="form.shareTarget" label="2">学员</el-radio>
  8. </el-radio-group>
  9. </el-form-item>
  10. <el-form-item label="分享方式" v-if="form.shareTarget == 2">
  11. <el-radio v-model="form.shareType" label="1">链接分享</el-radio>
  12. <el-radio v-model="form.shareType" label="2">二维码分享</el-radio>
  13. <el-radio
  14. v-model="form.shareType"
  15. label="3"
  16. v-if="row.viewMode != 'VISITOR'"
  17. >群聊分享</el-radio
  18. >
  19. </el-form-item>
  20. </el-form>
  21. <div>
  22. <div class="linkWrap" v-if="form.shareType == 1">
  23. <div class="shareWrap">
  24. <h2>乐团老师邀请您参与直播课!</h2>
  25. <h4>{{ row.roomTitle }}</h4>
  26. <p v-if="form.shareTarget != 1">主讲人:{{ row.speakerName }}</p>
  27. <p>开播时间:{{ row.liveStartTime }}</p>
  28. <p>直播内容:{{ row.liveRemark }}</p>
  29. <!-- 为1是主讲人的 -->
  30. <template v-if="this.row.os == 'client'">
  31. <p v-if="form.shareTarget == 1">
  32. 下载地址:https://www.dayaedu.com
  33. </p>
  34. <p v-else>直播地址:{{ url }}</p>
  35. <p v-if="form.shareTarget == 1">
  36. 请在电脑浏览器中打开以上链接进行下载
  37. </p>
  38. </template>
  39. <template v-else>
  40. <p v-if="form.shareTarget == 1">直播地址:{{ Teacherurl }}</p>
  41. <p v-else>直播地址:{{ url }}</p>
  42. <p v-if="form.shareTarget == 1">
  43. 请在电脑浏览器中打开以上链接进行直播
  44. </p>
  45. </template>
  46. </div>
  47. <div
  48. class="shareBtn shareText"
  49. :class="row.liveState == 2 ? 'disabled' : ''"
  50. data-clipboard-action="copy"
  51. data-clipboard-target=".shareBtn"
  52. @click="copyText"
  53. >
  54. 复制分享内容
  55. </div>
  56. </div>
  57. <div class="codeWrap" v-if="form.shareType == 2">
  58. <div class="shareWrap">
  59. <preview :form="row" id="preview" :url="url" />
  60. </div>
  61. <div
  62. class="shareBtn"
  63. :class="row.liveState == 2 ? 'disabled' : ''"
  64. @click="shareImage"
  65. >
  66. 下载图片
  67. </div>
  68. </div>
  69. <div class="groupWrap" v-if="form.shareType == 3">
  70. <!-- im分享 -->
  71. <groupChat ref="groupChat" />
  72. <div
  73. class="shareBtn"
  74. :class="row.liveState == 2 ? 'disabled' : ''"
  75. @click="shareChat"
  76. >
  77. 发送分享信息
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import { toPng } from "html-to-image";
  85. // import copy from "copy-to-clipboard";
  86. import Clipboard from "clipboard";
  87. import preview from "./preview";
  88. import groupChat from "./groupChat";
  89. import { shareGroup } from "../api";
  90. import { vaildUrl } from "@/utils/validate";
  91. export default {
  92. props: ["row"],
  93. components: { preview, groupChat },
  94. data() {
  95. return {
  96. form: {
  97. shareTarget: "1",
  98. shareType: "1"
  99. },
  100. content: "",
  101. url: "",
  102. Teacherurl: "",
  103. clipboard: null
  104. };
  105. },
  106. mounted() {
  107. // 直播分享地址分为 登录或者不登陆的
  108. console.log(this.row);
  109. if (this.row.viewMode == "VISITOR") {
  110. this.url =
  111. vaildUrl() +
  112. `/mlive/?roomUid=${this.row.roomUid}&speakerId=${
  113. this.row.speakerId
  114. }&isLogin=false#/live`;
  115. } else {
  116. this.url =
  117. vaildUrl() +
  118. `/mlive/?roomUid=${this.row.roomUid}&speakerId=${
  119. this.row.speakerId
  120. }&isLogin=true#/login`;
  121. // this.url = vaildUrl() + `/#/liveClassTransfer?roomUid=${this.row.roomUid}`;
  122. }
  123. let domain = window.location.origin;
  124. this.Teacherurl = domain
  125. ? domain + `/live/?roomUid=${this.row.roomUid}`
  126. : "https://test.dayaedu.com" + `/live/?roomUid=${this.row.roomUid}`;
  127. // this.copyText()
  128. // 判断一下
  129. if (this.row.os == "mobile") {
  130. console.log("设置学员观看");
  131. this.form.shareTarget = "2";
  132. } else {
  133. this.form.shareTarget = "1";
  134. }
  135. },
  136. methods: {
  137. copyText(e) {
  138. if (this.row.liveState == 2) {
  139. return;
  140. }
  141. let text = "";
  142. if (this.form.shareTarget == 1) {
  143. if (this.row.os == "client") {
  144. text = `乐团老师邀请您参与直播课!\n${this.row.roomTitle ||
  145. ""}\n开播时间:${this.row.liveStartTime || ""}\n直播内容:${this.row
  146. .liveRemark ||
  147. ""}\n下载地址:https://www.dayaedu.com\n请在电脑浏览器中打开以上链接进行下载`;
  148. } else {
  149. text = `乐团老师邀请您参与直播课!\n${this.row.roomTitle ||
  150. ""}\n开播时间:${this.row.liveStartTime || ""}\n直播内容:${this.row
  151. .liveRemark || ""}\n直播地址:${
  152. this.Teacherurl
  153. }\n请在电脑浏览器中打开以上链接进行直播`;
  154. }
  155. } else {
  156. text = `乐团老师邀请您参与直播课!\n${this.row.roomTitle ||
  157. ""}\n主讲人:${this.row.speakerName}\n开播时间:${this.row
  158. .liveStartTime || ""}\n直播内容:${this.row.liveRemark ||
  159. ""}\n直播地址:${this.url}\n`;
  160. }
  161. var clipboard = new Clipboard(".shareText", {
  162. text: function(trigger) {
  163. // console.log(trigger,text)
  164. return text;
  165. }
  166. });
  167. clipboard.on("success", e => {
  168. this.$message.success("复制成功");
  169. this.$emit("close");
  170. // 释放内存
  171. clipboard.destroy();
  172. });
  173. clipboard.on("error", e => {
  174. // 不支持复制
  175. console.log("该浏览器不支持自动复制");
  176. // 释放内存
  177. clipboard.destroy();
  178. });
  179. // if (text) {
  180. // console.log(clipboard)
  181. // clipboard.on("success", function (e) {
  182. // console.info("Action:", e.action);
  183. // console.info("Text:", e.text);
  184. // console.info("Trigger:", e.trigger);
  185. // this.$message.success("复制成功");
  186. // this.$emit("close");
  187. // e.clearSelection();
  188. // });
  189. // }
  190. // return text
  191. },
  192. shareImage() {
  193. if (this.row.liveState == 2) {
  194. return;
  195. }
  196. var node = document.getElementById("preview");
  197. toPng(node)
  198. .then(dataUrl => {
  199. var img = new Image();
  200. img.src = dataUrl;
  201. // 在这里下载
  202. let link = document.createElement("a");
  203. let fname = this.row.roomTitle || "分享图片文件.png"; //下载文件的名字
  204. link.href = dataUrl;
  205. link.setAttribute("download", fname);
  206. document.body.appendChild(link);
  207. link.click();
  208. this.$emit("close");
  209. })
  210. .catch(function(error) {
  211. console.error("oops, something went wrong!", error);
  212. });
  213. },
  214. async shareChat() {
  215. if (this.row.liveState == 2) {
  216. return;
  217. }
  218. let checkList = this.$refs.groupChat.checkList;
  219. if (!(checkList.length > 0)) {
  220. this.$message.error("请至少选择一个群聊");
  221. return;
  222. }
  223. try {
  224. let obj = {
  225. groupIds: checkList.join(","),
  226. roomUid: this.row.roomUid
  227. };
  228. const res = await shareGroup(obj);
  229. this.$message.success("分享成功");
  230. this.$emit("close");
  231. } catch (e) {
  232. console.log(e);
  233. }
  234. },
  235. changeShareTarget(val) {
  236. if (val == 2) {
  237. this.form.shareType = "1";
  238. }
  239. if (val == 1) {
  240. this.form.shareType = "1";
  241. }
  242. }
  243. }
  244. };
  245. </script>
  246. <style lang="scss" scoped>
  247. .shareWrap {
  248. background: #f9f9f9;
  249. padding: 16px;
  250. h2 {
  251. font-size: 18px;
  252. font-family: PingFangSC-Semibold, PingFang SC;
  253. font-weight: 600;
  254. color: #333333;
  255. line-height: 25px;
  256. margin-bottom: 18px;
  257. }
  258. h4 {
  259. font-size: 16px;
  260. font-family: PingFangSC-Medium, PingFang SC;
  261. font-weight: 500;
  262. color: #333333;
  263. line-height: 28px;
  264. }
  265. p {
  266. font-size: 16px;
  267. font-family: PingFangSC-Medium, PingFang SC;
  268. font-weight: 500;
  269. color: #333333;
  270. line-height: 30px;
  271. }
  272. }
  273. .shareBtn {
  274. height: 48px;
  275. background: var(--color-primary);
  276. border-radius: 32px;
  277. width: 192px;
  278. color: #fff;
  279. margin: 24px auto 0;
  280. text-align: center;
  281. line-height: 48px;
  282. font-size: 20px;
  283. cursor: pointer;
  284. &.disabled {
  285. background: #80d3ce;
  286. border-color: #80d3ce;
  287. color: #fff;
  288. cursor: not-allowed;
  289. }
  290. }
  291. </style>