Преглед изворни кода

1、手动发送直播链接

yys пре 20 часа
родитељ
комит
72f035c09c
2 измењених фајлова са 63 додато и 1 уклоњено
  1. 9 0
      src/api/live/live.js
  2. 54 1
      src/views/live/live/index.vue

+ 9 - 0
src/api/live/live.js

@@ -139,3 +139,12 @@ export function generateCode(data) {
     params: data
   })
 }
+
+// 创建App跳转通用链接
+export function createAppLink(data) {
+  return request({
+    url: '/live/live/createAppLink',
+    method: 'get',
+    params: data
+  })
+}

+ 54 - 1
src/views/live/live/index.vue

@@ -245,6 +245,12 @@
               >
                 <i class="el-icon-service"></i> 查看小程序链接
               </el-dropdown-item>
+              <el-dropdown-item
+                @click.native="handleCreateAppLink(scope.row)"
+                v-hasPermi="['live:live:createAppLink']"
+              >
+                <i class="el-icon-link"></i> 复制通用链接
+              </el-dropdown-item>
               <el-dropdown-item
                 v-if="scope.row.liveCodeUrl == null"
                 @click.native="handleGenerateCode(scope.row)"
@@ -410,6 +416,7 @@
     <el-button type="primary" @click="rtmpUrlVisible = false">确 定</el-button>
   </span>
     </el-dialog>
+
   </div>
 </template>
 
@@ -425,7 +432,7 @@ import {
   handleShelfOrUn,
   handleDeleteSelected,
   finishLive,
-  startLive, copyLive,generateCode
+  startLive, copyLive, generateCode, createAppLink
 } from "@/api/live/live";
 import Editor from '@/components/Editor/wang';
 import user from '@/store/modules/user';
@@ -575,6 +582,52 @@ export default {
   },
   methods: {
 
+    handleCreateAppLink(row) {
+      if (!row.liveId) {
+        this.$message.error('获取直播间id失败');
+        return;
+      }
+      this.loading = true;
+      createAppLink({ liveId: row.liveId }).then(response => {
+        if (response.code === 200 && response.realLink) {
+          this.copyLink(response.realLink);
+        } else {
+          this.$message.error(response.msg || '生成通用链接失败');
+        }
+      }).finally(() => {
+        this.loading = false;
+      });
+    },
+    copyLink(link) {
+      if (navigator.clipboard && window.isSecureContext) {
+        navigator.clipboard.writeText(link).then(() => {
+          this.$message.success('通用链接已复制到剪贴板');
+        }).catch(() => {
+          this.$message.error('复制失败,请手动复制');
+        });
+      } else {
+        const input = document.createElement('input');
+        input.style.position = 'fixed';
+        input.style.top = '-10000px';
+        input.style.zIndex = '-999';
+        document.body.appendChild(input);
+        input.value = link;
+        input.focus();
+        input.select();
+        try {
+          const result = document.execCommand('copy');
+          document.body.removeChild(input);
+          if (!result || result === 'unsuccessful') {
+            this.$message.error('复制失败,请手动复制');
+          } else {
+            this.$message.success('通用链接已复制到剪贴板');
+          }
+        } catch (e) {
+          document.body.removeChild(input);
+          this.$message.error('当前浏览器不支持复制功能,请手动复制');
+        }
+      }
+    },
     handleLink(row){
       if (!row.liveId) {
         this.$message.error('获取直播间id失败');