소스 검색

直播间分享

skyblued 2 년 전
부모
커밋
db3883edbb

+ 8 - 0
src/router/routes-common.ts

@@ -282,5 +282,13 @@ export const rootRouter = [
     meta: {
       title: '联系我们'
     }
+  },
+  {
+    path: '/shareLiveRoom',
+    name: 'shareLiveRoom',
+    component: () => import('@/teacher/share-page/share-live-room'),
+    meta: {
+      title: '直播间分享'
+    }
   }
 ]

BIN
src/teacher/share-page/share-live-room/images/icon-bg.png


BIN
src/teacher/share-page/share-live-room/images/icon-live.png


+ 137 - 0
src/teacher/share-page/share-live-room/index.module.less

@@ -0,0 +1,137 @@
+.container {
+  min-height: 100vh;
+  box-sizing: border-box;
+  background: linear-gradient(180deg, #b8c7ff 0%, #f8f9ff 100%);
+}
+.wrap {
+  background-image: url('./images/icon-bg.png');
+  background-repeat: no-repeat;
+  background-size: 100% auto;
+  min-height: 100vh;
+  box-sizing: border-box;
+}
+
+.userWrap {
+  padding: 36px 0 0 48px;
+  display: flex;
+  .user {
+    position: relative;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    .avator {
+      width: 80px;
+      height: 80px;
+      border-radius: 50%;
+      overflow: hidden;
+      background-color: #fff;
+      padding: 2px;
+    }
+    .avator > img {
+      display: flex;
+      width: 100%;
+      height: 100%;
+      object-fit: cover;
+      border-radius: 50%;
+    }
+    .tips {
+      display: flex;
+      justify-content: space-around;
+      align-items: center;
+      height: 24px;
+      padding: 0 10px;
+      background: linear-gradient(180deg, #ff598e 0%, #fd2d55 100%);
+      border-radius: 22px;
+      color: #fff;
+      font-size: 12px;
+      font-weight: bold;
+      margin-top: -10px;
+      img {
+        width: 10px;
+        height: 10px;
+        margin-right: 7px;
+      }
+    }
+  }
+}
+
+.titleWrap {
+  padding: 26px;
+  color: #ffffff;
+  line-height: 33px;
+  text-shadow: 0px 0px 4px rgba(23, 78, 255, 0.5);
+  font-weight: 600;
+  font-size: 24px;
+  .liveUser {
+    font-size: 18px;
+  }
+}
+
+.content {
+  background: rgba(255, 255, 255, 0.8);
+  border-radius: 14px;
+  margin: 0 16px;
+  padding: 14px 18px;
+  font-size: 16px;
+  line-height: 22px;
+  color: #333;
+  .top {
+    position: relative;
+    padding-left: 14px;
+    font-size: 16px;
+    font-weight: 600;
+    margin-bottom: 12px;
+    &::before {
+      content: '';
+      position: absolute;
+      left: 0;
+      top: 12%;
+      height: 70%;
+      width: 4px;
+      background-color: var(--van-primary-color);
+      border-radius: 4px;
+    }
+  }
+  .comentWrap {
+    margin-top: 16px;
+    background: linear-gradient(270deg, #baffe7 0%, #c0dcff 100%);
+    border-radius: 10px;
+    padding: 14px;
+    display: flex;
+    align-items: center;
+    .contentAvator{
+      width: 38px;
+      height: 38px;
+      padding: 1px;
+      background-color: #fff;
+      border-radius: 50%;
+      margin-right: 10px;
+      img{
+        width: 100%;
+        height: 100%;
+        display: block;
+        border-radius: 50%;
+      }
+    }
+    .comentTitle{
+      font-size: 16Px;
+      font-weight: bold;
+    }
+    .comentDes{
+      font-size: 12Px;
+    }
+  }
+}
+.wxpopup {
+  width: 100%;
+  height: 100vh;
+  position: fixed;
+  top: 0;
+  left: 0;
+  background: rgba(0, 0, 0, 0.5);
+  z-index: 9999;
+  img {
+    width: 88%;
+    margin: 0 6%;
+  }
+}

+ 171 - 0
src/teacher/share-page/share-live-room/index.tsx

@@ -0,0 +1,171 @@
+import ColSticky from '@/components/col-sticky'
+import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
+import request from '@/helpers/request'
+import { browser } from '@/helpers/utils'
+import { state } from '@/state'
+import { Button, Dialog, Toast } from 'vant'
+import { defineComponent } from 'vue'
+import styles from './index.module.less'
+import iconDefault from '@/common/images/icon_teacher.png'
+export const getAssetsHomeFile = (fileName: string) => {
+  const path = `./images/${fileName}`
+  const modules = import.meta.globEager('./images/*')
+  return modules[path].default
+}
+export default defineComponent({
+  name: 'shareLiveRoom',
+  data() {
+    return {
+      query: {
+        ...this.$route.query,
+        // id: 'COOLESHOW-TEMP-416-1663833046284',
+        // userId: 416
+      },
+      liveRoom: {} as any, //直播间信息
+      teacher: {} as any,
+      student: {} as any, // 分享人信息
+      wxStatus: false
+    }
+  },
+  async mounted() {
+    this.getData()
+    this.openApp()
+  },
+  methods: {
+    // 获取直播信息和分享人信息
+    async getData() {
+      try {
+        const { data } = await request.get(
+          `/api-student/open/liveRoom/detail/${this.query.id}`,
+          {
+            params: {
+              userId: this.query.userId
+            }
+          }
+        )
+        this.liveRoom = data
+        this.teacher = data.teacher || {}
+        this.student = data.student || {}
+      } catch {}
+    },
+
+    // 分享进入
+    openApp() {
+      if (browser().weixin) {
+        // 微信浏览器
+        this.wxStatus = true
+        return
+      }
+
+      if (!browser().isApp) {
+        // 不是APP
+        this.onWakeApp()
+        return
+      }
+
+      if (browser().isApp) {
+        if (state.platformType === 'STUDENT') {
+          this.onJoinLiveRoom()
+        } else if (state.platformType === 'TEACHER') {
+          Dialog.alert({
+            title: '提示',
+            message: '请使用酷乐秀学生端扫码打开',
+            confirmButtonColor: '#2dc7aa'
+          }).then(() => {
+            postMessage({ api: 'back' })
+          })
+        }
+      }
+    },
+
+    //进入直播间
+    onJoinLiveRoom() {
+      postMessage({
+        api: 'joinLiveRoom',
+        content: {
+          roomId: this.liveRoom.roomUid,
+          teacherId: this.liveRoom.userId
+        }
+      })
+    },
+
+    // 唤醒APP
+    onWakeApp() {
+      const query = {
+        action: 'app', // app, h5
+        pageTag: 'liveRoom', // 页面标识
+        params: JSON.stringify({ liveRoomId: this.query.id })
+      }
+      const iosStr = encodeURIComponent(JSON.stringify(query))
+      if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
+        // ColexiuStudent 唤起学生端
+        // ColexiuTeacher 唤起老师端
+        window.location.href = `ColexiuStudent://linkUrl=${iosStr}`
+      } else if (/(Android)/i.test(navigator.userAgent)) {
+        window.location.href = `colexiustudent://html:8888/SplashActivity?url=${iosStr}`
+      } else {
+        Toast('请用手机或移动设备打开')
+      }
+    }
+  },
+  render() {
+    return (
+      <div class={styles.container}>
+        <div class={styles.wrap}>
+          <div class={styles.userWrap}>
+            <div class={styles.user}>
+              <div class={styles.avator}>
+                <img src={this.teacher.avatar || iconDefault} />
+              </div>
+              <div class={styles.tips}>
+                <img src={getAssetsHomeFile('icon-live.png')} />
+                <span>直播中</span>
+              </div>
+            </div>
+          </div>
+          <div class={styles.titleWrap}>
+            <div class={styles.title}>{this.liveRoom.roomTitle}</div>
+            <div class={styles.liveUser}>主讲人:{this.teacher.realName || this.teacher.username}</div>
+          </div>
+
+          <div class={styles.content}>
+            <div class={styles.top}>直播内容</div>
+            <div>
+              {this.liveRoom.liveRemark}
+            </div>
+            <div class={styles.comentWrap}>
+              <div class={styles.contentAvator}>
+                <img src={this.student.avatar || iconDefault} />
+              </div>
+              <div>
+                <div class={styles.comentTitle}>
+                  快进入达人的直播间一起围观~
+                </div>
+                <div class={styles.comentDes}>{this.teacher.realName || this.student.username} 为您推荐</div>
+              </div>
+            </div>
+          </div>
+        </div>
+
+        <ColSticky position="bottom">
+          <div class={['btnGroup']} style={{ paddingTop: '12px' }}>
+            <Button color='linear-gradient(180deg, #59E5D5 0%, #2DC7AA 100%)' block round type="primary" onClick={this.openApp}>
+              开启酷乐秀进入直播间!
+            </Button>
+          </div>
+        </ColSticky>
+
+        {this.wxStatus && (
+          <div
+            class={styles.wxpopup}
+            onClick={() => {
+              this.wxStatus = false
+            }}
+          >
+            <img src={getAssetsHomeFile('wx_bg.png')} alt="" />
+          </div>
+        )}
+      </div>
+    )
+  }
+})