video.vue 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037
  1. <template>
  2. <view class="content">
  3. <view class="header-nav" :style="{height: `calc(88rpx + ${statusBarHeight}px)`,paddingTop: statusBarHeight + 'px'}">
  4. <view class="header-title" :style="{width:menuButtonLeft + 'px',height:menuButtonH+'px',lineHeight:menuButtonH+'px'}">{{courseInfo.title}}</view>
  5. </view>
  6. <view class="video-box">
  7. <image v-if="!isLogin || isAddKf!=1" class="video-poster" :src="courseInfo.imgUrl" mode="aspectFill">
  8. </image>
  9. <video
  10. @timeupdate="onTimeUpdate"
  11. @progress="progressChange"
  12. @error="videoErrorCallback"
  13. @play="getPlay"
  14. @pause="getPause"
  15. @ended="getEnded"
  16. @fullscreenchange="fullscreenchange"
  17. @controlstoggle="controlstoggle"
  18. :title="courseInfo.title"
  19. style="width: 100%;height: 420rpx;"
  20. :poster="poster"
  21. id="video-content-box"
  22. controls
  23. :show-fullscreen-btn="true"
  24. :auto-pause-if-open-native="true"
  25. :auto-pause-if-navigate="true"
  26. :enable-progress-gesture="false"
  27. :show-progress="true"
  28. :picture-in-picture-mode="[]"
  29. :show-background-playback-button="false"
  30. :src="videoUrl"
  31. :danmu-list="danmuList"
  32. enable-danmu
  33. danmu-btn>
  34. <cover-view class="video-danmu-btnbox" :style="{display: isfull&&crtShow&&isLogin&&isAddKf==1 ? 'block':'none'}">
  35. <cover-image class="video-danmu-image"
  36. src="https://cos.his.cdwjyyh.com/fs/20250418/beaf9df1a6204b8babc3e28d9b563c62.png"
  37. @click="openDanmu(1)"></cover-image>
  38. </cover-view>
  39. </video>
  40. </view>
  41. <view class="title-content" id="title-content">
  42. <!-- 答题时展示小节课程名,其他展示课程名 -->
  43. <!-- 小节课程名 -->
  44. <view class="subtitlebox" v-if="isLogin&&isAddKf==1">
  45. {{courseInfo.title}}
  46. </view>
  47. <!-- 课程名字 -->
  48. <view class="miantitlebox" v-else>
  49. {{courseInfo.courseName}}
  50. </view>
  51. </view>
  52. <scroll-view class="scroll-view" :style="{height: height}" :scroll-top="scrollTop" scroll-y="true">
  53. <!-- 介绍 -->
  54. <view class="descbox">
  55. <template v-if="!isLogin||isAddKf!=1">
  56. <view class="descbox-title">{{courseInfo.title}}</view>
  57. <view class="descbox-info">
  58. <!-- <view class="descbox-info-l">
  59. <view>{{courseInfo.views}}次播放</view>
  60. <view class="descbox-info-time">总时长:{{courseInfo.totalDuration}}</view>
  61. </view> -->
  62. <view class="descbox-info-r expand" v-if="textHeight > 21">
  63. <text @click="handleExpand">{{isExpand ? '收起简介' : '展开简介'}}</text>
  64. <image :src="baseUrl+'/images/course_arrow_up_icon.png'" v-show="isExpand"></image>
  65. <image :src="baseUrl+'/images/course_arrow_down_icon.png'" v-show="!isExpand"></image>
  66. </view>
  67. </view>
  68. </template>
  69. <view class="descbox-desc" id="descbox-desc" :style="{height: isExpand ? 'auto': '42rpx'}">
  70. <text>{{courseInfo.description}}</text>
  71. <view :class="isExpand ? 'expand': 'expand expand-ab'" v-if="isLogin&&isAddKf==1&&textHeight > 21">
  72. <text @click="handleExpand">{{isExpand ? '收起简介' : '展开简介'}}</text>
  73. <image :src="baseUrl+'/images/course_arrow_up_icon.png'" v-show="isExpand"></image>
  74. <image :src="baseUrl+'/images/course_arrow_down_icon.png'" v-show="!isExpand"></image>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 问题 -->
  79. <view class="ques-content" v-if="isLogin&&isAddKf==1">
  80. <view class="ques-content-tit">问答题</view>
  81. <view v-for="(item,index) in quesList" :key="index">
  82. <view class="ques-title">
  83. <text>{{index + 1}}.</text>
  84. <view class="ques-type" v-show="item.type == 1 || item.type == 2">
  85. {{item.type == 1 ? '单选' : item.type == 2 ? '多选' : ''}}
  86. </view>
  87. <text>{{item.title}}</text>
  88. </view>
  89. <view
  90. :class="isAnswer(item,option.name) ?'ques-option ques-option-active':'ques-option'"
  91. v-for="(option,idx) in item.questionOption"
  92. :key="idx"
  93. @click="handleAnswer(item,option)">
  94. <view>
  95. {{numberToLetter(idx)}}.
  96. </view>
  97. <view>{{option.name}}</view>
  98. </view>
  99. </view>
  100. </view>
  101. </scroll-view>
  102. <!-- 线路 -->
  103. <view class="video-line" @click="openPop" v-if="isLogin&&isAddKf==1">
  104. <image :src="baseUrl+'/images/changePlayer-icon.png'"></image>
  105. <text>线路{{lineIndex + 1 | numberToChinese}}</text>
  106. </view>
  107. <!-- 线路弹窗 -->
  108. <uni-popup ref="popup" type="bottom" class="full-width-popup">
  109. <view class="popupbox">
  110. <view class="popupbox-head">
  111. <text>线路选择</text>
  112. <image class="close-icon" :src="baseUrl+'/images/tc_close_icon.png'" mode="aspectFill" @click="close">
  113. </image>
  114. </view>
  115. <view class="popupbox-content">
  116. <view :class="lineIndex == index ? 'line-item line-active': 'line-item'"
  117. v-for="(it,index) in lineList" :key="index" @click="handleLine(index)">
  118. 线路{{index + 1 | numberToChinese}}</view>
  119. </view>
  120. </view>
  121. </uni-popup>
  122. <!-- 发送弹幕 -->
  123. <view class="video-line danmu-line" @click="openDanmu(0)" v-if="isLogin&&isAddKf==1">
  124. <image class="set_image" src="https://cos.his.cdwjyyh.com/fs/20250418/5e508642737a44169061382566043ac9.png" mode="aspectFill"></image>
  125. <text>发弹幕</text>
  126. </view>
  127. <!-- 发送弹幕弹窗 -->
  128. <uni-popup ref="danmuPopup" type="bottom" style="z-index: 999;" @change="changeShowPopup">
  129. <view class="danmuPopup" :style="{marginLeft:isfull ? statusBarHeight+'px': 0,marginBottom: danmuboxHeight+'px'}">
  130. <view class="danmuPopup-head border-line">
  131. <u-input
  132. class="danmuPopup-input"
  133. placeholder="发个弹幕吧~"
  134. border="surround"
  135. shape="circle"
  136. :focus="focus"
  137. :adjustPosition="false"
  138. :autoBlur="true"
  139. maxlength="140"
  140. clearable
  141. v-model="danmuIput"></u-input>
  142. <button class="danmuPopup-send" :disabled="danmubtnLoading" @click="sendDanmu">发送</button>
  143. </view>
  144. </view>
  145. </uni-popup>
  146. <!-- 答题弹窗 -->
  147. <uni-popup ref="answerPopup" type="center" :show="answerPopup">
  148. <view :class="errTitle == '恭喜你,回答正确' ? 'answerPopup-box bg':'answerPopup-box'">
  149. <!-- 正确 -->
  150. <image class="tipimg" v-if="errTitle == '恭喜你,回答正确'" :src="baseUrl+'/images/course_answer_img.png'"
  151. mode="aspectFill"></image>
  152. <!-- 错误 -->
  153. <image class="tipimg" v-else :src="baseUrl+'/images/course_answer_incorrectly_img.png'" mode="aspectFill">
  154. </image>
  155. <view class="answerPopup-title">{{errTitle}}</view>
  156. <view class="answerPopup-desc" v-html="errDesc"></view>
  157. <!-- 选择奖励 -->
  158. <view class="reward-list" v-if="errTitle == '恭喜你,回答正确'">
  159. <radio-group class="reward-list-group" @change="rewardChange">
  160. <label class="reward-list-option" v-for="(item, index) in rewardType" :key="item.value">
  161. <radio :value="item.value+ ''" :checked="item.value == currentReward"
  162. activeBorderColor="#FF5C03" activeBackgroundColor="#FF5C03"
  163. style="transform:scale(0.7)" />
  164. <view :style="{color: item.value == currentReward ? '#FF5C03':''}">{{item.name}}</view>
  165. </label>
  166. </radio-group>
  167. </view>
  168. <!-- 错误题目 -->
  169. <view class="errQuesbox" v-if="errQues&&errQues.length>0">
  170. <view class="errQuesbox-item textOne" v-for="(it,index) in errQues" :key="index">{{it.title}}</view>
  171. </view>
  172. <view class="answerPopup-btn" v-if="errTitle == '恭喜你,回答正确'" @click="closeAnswerPopup">确认</view>
  173. <view class="tipsPopup-btn-box" v-else
  174. :style="{marginTop: errQues&&errQues.length>0 ? '40rpx':'54rpx'}">
  175. <view class="tipsPopup-btn" @click="closeAnswerPopup">{{remain > 0 ? '重新答题': '确认'}}</view>
  176. </view>
  177. </view>
  178. </uni-popup>
  179. <!-- 客服二维码弹窗 -->
  180. <uni-popup ref="kfPopup" type="center" :mask-click="false">
  181. <view class="kfqrcode-box">
  182. <image class="kfqrcode" :src="qrcode" show-menu-by-longpress="true"></image>
  183. <view v-show="qrcodeMsg" style="margin-top: 30rpx;" v-html="qrcodeMsg"></view>
  184. <image class="kfqrcode-close" :src="baseUrl+'/images/course_close_white_icon.png'" mode="aspectFill"
  185. @click="closeKFPop"></image>
  186. </view>
  187. </uni-popup>
  188. <!-- footer -->
  189. <view class="footer" v-if="videoId">
  190. <view :class="isLogin&&isAddKf==1 ? 'footer-btn footer-btn-border':'footer-btn'" @click="submit">
  191. <image class="footer-btn-img" v-show="isLogin&&isAddKf==1" :src="baseUrl+'/images/red_envelope_btnimg.png'"
  192. mode="aspectFill"></image>
  193. <text>{{isLogin&&isAddKf==1 ? '提交答案领取奖励' : '立即学习'}}</text>
  194. </view>
  195. <!-- <view @click="checked=!checked" class="agreement" v-if="!isLogin">
  196. <radio value="r1" :checked="checked" color="#ff5c03" activeBorderColor="#ff5c03"
  197. style="transform:scale(0.6);" />
  198. <view>阅读并同意<text style="color: #ff5c03;" @click.stop="goWeb(0)">《用户协议》</text>和<text
  199. style="color: #ff5c03;" @click.stop="goWeb(1)">《隐私协议》</text></view>
  200. </view> -->
  201. <view class="footer-tips">重庆云联融智提供技术支持</view>
  202. </view>
  203. </view>
  204. </template>
  205. <script>
  206. import { generateRandomString } from "@/utils/common.js"
  207. import dayjs from 'dayjs';
  208. import {
  209. getErrMsg,
  210. getH5CourseByVideoId,
  211. getH5CourseVideoDetails,
  212. courseAnswer,
  213. getFinishCourseVideo,
  214. getIsAddKf,
  215. getInternetTraffic,
  216. getIntegralByH5Video,
  217. sendReward,
  218. loginByMp,
  219. getRealLink,
  220. getDanmuList
  221. } from "@/api/course.js"
  222. export default {
  223. data() {
  224. return {
  225. baseUrl:uni.getStorageSync('requestPath'),
  226. // 1 红包 2 积分
  227. rewardType: [{
  228. name: '红包奖励',
  229. value: 1
  230. }, {
  231. name: '积分奖励',
  232. value: 2
  233. }],
  234. currentReward: 1,
  235. player: null,
  236. loading: true,
  237. progress: 0,
  238. code: null,
  239. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  240. scrollTop: 0,
  241. height: '0px',
  242. isLogin: true,
  243. videoUrl: "",
  244. videoId: "",
  245. //现在的时长
  246. playTime: 0,
  247. //总时长
  248. duration: 0,
  249. playDuration: 0,
  250. // 用于续播
  251. playDurationSeek: 0,
  252. // 温馨提醒时间节点,
  253. tipsTime: 0,
  254. tipsOpen: false,
  255. config: {},
  256. courseInfo: {},
  257. quesList: [],
  258. lineList: [],
  259. // 错题
  260. errQues: [],
  261. // 答题机会
  262. remain: 0,
  263. errTitle: "",
  264. errDesc: "",
  265. showPlay: true,
  266. showControls: false,
  267. playStatus: "",
  268. isfull: false,
  269. isAddKf: 0,
  270. lineIndex: 0,
  271. // 是否展开
  272. isExpand: false,
  273. textHeight: 0, //文本高度
  274. qwUserId: "",
  275. qrcode: "",
  276. corpId: "",
  277. qrcodeMsg: "",
  278. urlOption: {},
  279. bufferRate: 0, // 缓冲时间
  280. uuId: "",
  281. isEnded: false,
  282. // 是否允许拖动进度条
  283. linkType: 0,
  284. ip: null,
  285. checked: true,
  286. isFinish: 0, // 是否完课
  287. interval: null,
  288. intervalIntegral: null, // 积分定时
  289. options: {
  290. sources: [{
  291. src: ""
  292. }],
  293. poster: "",
  294. live: false /* 是否直播 */ ,
  295. controls: true,
  296. autoplay: false,
  297. licenseUrl: 'https://license.vod2.myqcloud.com/license/v2/1323137866_1/v_cube.license', // license 地址,参考准备工作部分,在视立方控制台申请 license 后可获得 licenseUrl,
  298. LicenseKey: 'bcc5bd9a14b798b48c52ff005a21d926',
  299. controlBar: {
  300. volumePanel: false,
  301. playbackRateMenuButton: false,
  302. QualitySwitcherMenuButton: false,
  303. // progressControl: false
  304. },
  305. plugins: {
  306. // ProgressMarker: false,
  307. ContextMenu: {
  308. statistic: false
  309. }
  310. },
  311. },
  312. // 错误请求次数
  313. errorCount: 0,
  314. answerPopup: false,
  315. sortLink:"",
  316. // 课程是否过期
  317. isExpire: true,
  318. menuButtonLeft: 281,
  319. menuButtonH: 45,
  320. timer: null,
  321. flag: false,
  322. danmuList: [],
  323. danmuIput: '',
  324. focus: false,
  325. danmubtnLoading: false,
  326. openDanmuType: 0,
  327. socket:null,
  328. isSocketOpen: false,
  329. isSend:true,
  330. reOpenSocket: false,
  331. pingpangTimes:null,
  332. danmuboxHeight: 0,
  333. user: {},
  334. crtShow: true,
  335. isCheckRealUrl: false
  336. }
  337. },
  338. filters: {
  339. numberToChinese(number) {
  340. if (number) {
  341. const chineseNumber = ['一', '二', '三', '四', '五', '六', '七', '八', '九'];
  342. return chineseNumber[number - 1];
  343. } else {
  344. return ''
  345. }
  346. },
  347. },
  348. computed: {
  349. isAnswer() {
  350. return (item, name) => {
  351. if (item.type == 1) {
  352. return item.answer == name
  353. } else if (item.type == 2) {
  354. const array = item.answer.split(',')
  355. return array.some(i => i == name)
  356. } else {
  357. return false
  358. }
  359. }
  360. }
  361. },
  362. onLoad(option) {
  363. this.code = option.code
  364. this.urlOption = option.course ? JSON.parse(option.course) : {}
  365. this.videoId = this.urlOption.videoId
  366. this.qwUserId = this.urlOption.qwUserId || ''
  367. this.corpId = this.urlOption.corpId || ''
  368. this.linkType = this.urlOption.linkType || 0
  369. // if (this.code) {
  370. // this.loginByMp()
  371. // }
  372. var that=this;
  373. // this.videoId=769;
  374. // this.qwUserId=2110;
  375. // this.corpId='ww5a88c4f879f204c5';
  376. // this.linkType=0;
  377. // this.urlOption.videoId=769;
  378. // this.urlOption.courseId=79;
  379. // this.urlOption.companyId=170;
  380. // this.urlOption.companyUserId=3972;
  381. // this.urlOption.qwUserId=1;
  382. // this.urlOption.corpId='ww5a88c4f879f204c5';
  383. // this.urlOption.qwExternalId=6213064;
  384. // this.urlOption.qwUserId=2110;
  385. // this.urlOption.linkType=0;
  386. this.sortLink = this.urlOption.link || ''
  387. this.getMenuButton()
  388. // #ifndef H5
  389. uni.onKeyboardHeightChange(this.keyboardHeightChange);
  390. // #endif
  391. if(this.socket!=null){
  392. this.socket.close()
  393. clearInterval(this.pingpangTimes)
  394. this.socket = null
  395. }
  396. },
  397. onShow() {
  398. this.tipsOpen = false
  399. this.isExpand = true
  400. // this.isLogin = this.$isLoginCourse()
  401. this.uuId = generateRandomString(16)
  402. if(uni.getStorageSync('userInfo') && JSON.stringify(uni.getStorageSync('userInfo'))!='{}') {
  403. this.user = JSON.parse(uni.getStorageSync('userInfo'))
  404. } else {
  405. this.user = {}
  406. }
  407. if (this.videoId) {
  408. this.getH5CourseByVideo()
  409. }
  410. if(this.sortLink){
  411. this.getLink()
  412. } else {
  413. uni.showToast({
  414. title: 'sortLink is not found',
  415. icon: 'none'
  416. });
  417. }
  418. },
  419. mounted() {
  420. this.getIP()
  421. this.getHeight()
  422. },
  423. onHide() {
  424. // this.player = uni.createVideoContext('video-content-box');
  425. if (this.player) {
  426. this.player.pause()
  427. }
  428. // if (this.interval != null) {
  429. // clearInterval(this.interval)
  430. // this.interval = null
  431. // }
  432. },
  433. onUnload() {
  434. if (this.interval != null) {
  435. clearInterval(this.interval)
  436. this.interval = null
  437. }
  438. if(this.socket!=null){
  439. this.socket.close()
  440. clearInterval(this.pingpangTimes)
  441. this.socket = null
  442. }
  443. // #ifndef H5
  444. uni.offKeyboardHeightChange(this.keyboardHeightChange);
  445. // #endif
  446. this.clearIntegral()
  447. },
  448. beforeDestroy() {
  449. this.player = uni.createVideoContext('video-content-box');
  450. if (this.player) {
  451. this.player.stop()
  452. this.player = null
  453. }
  454. if (this.interval != null) {
  455. clearInterval(this.interval)
  456. this.interval = null
  457. }
  458. if(this.socket!=null){
  459. this.socket.close()
  460. clearInterval(this.pingpangTimes)
  461. this.socket = null
  462. }
  463. // #ifndef H5
  464. uni.offKeyboardHeightChange(this.keyboardHeightChange);
  465. // #endif
  466. this.clearIntegral()
  467. },
  468. methods: {
  469. keyboardHeightChange(res) {
  470. // #ifndef H5
  471. console.log("this.danmuboxHeight",this.danmuboxHeight)
  472. this.danmuboxHeight = res.height
  473. // #endif
  474. },
  475. getMenuButton(){
  476. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  477. this.menuButtonLeft = menuButtonInfo.left
  478. this.menuButtonH = menuButtonInfo.height
  479. },
  480. //播放时间更新事件方法
  481. onTimeUpdate(e){
  482. let currentTime = Math.round(e.detail.currentTime)
  483. if (this.playDurationSeek > 0) {
  484. this.playTime = this.playDurationSeek
  485. this.throttle(() => this.changeTime(this), 1000, false)
  486. } else {
  487. if (this.linkType != 1 && (currentTime - this.playTime > 3 || currentTime - this.playTime < -3)&&this.isFinish!=1) {
  488. uni.showToast({
  489. title: '不能快进哦',
  490. icon: 'none',
  491. });
  492. currentTime = this.playTime
  493. this.player.seek(this.playTime);
  494. }
  495. this.playTime = currentTime
  496. }
  497. },
  498. changeTime(that,e) {
  499. that.playDurationSeek = 0
  500. },
  501. videoErrorCallback(e) {
  502. this.clearIntegral()
  503. this.errorCount++
  504. if (this.errorCount > 3) return
  505. console.log(e)
  506. this.getErrMsg(e.target.errMsg)
  507. this.getH5CourseVideoDetails('error')
  508. },
  509. // 当开始/继续播放时触发play事件
  510. getPlay() {
  511. this.errorCount = 0
  512. this.judgeDuration()
  513. },
  514. getPause() {
  515. this.clearIntegral()
  516. },
  517. getEnded() {
  518. this.clearIntegral()
  519. this.isEnded = true
  520. this.getFinishCourseVideo()
  521. },
  522. fullscreenchange(event) {
  523. this.isfull = event.detail.fullScreen
  524. },
  525. controlstoggle(event) {
  526. this.crtShow = event.detail.show
  527. },
  528. getIP() {
  529. uni.request({
  530. url: 'https://ipinfo.io/json', //仅为示例,并非真实接口地址。
  531. method: 'GET',
  532. success: (res) => {
  533. this.ip = res.data.ip
  534. }
  535. });
  536. },
  537. getHeight() {
  538. this.$nextTick(() => {
  539. const query = uni.createSelectorQuery().in(this);
  540. query
  541. .select("#title-content")
  542. .boundingClientRect((data) => {
  543. this.height =
  544. `calc(100vh - ${data.height}px - 420rpx - ${this.statusBarHeight}px - 164rpx - 88rpx)`
  545. })
  546. .exec();
  547. })
  548. },
  549. getDescHeight() {
  550. this.$nextTick(() => {
  551. const query = uni.createSelectorQuery().in(this);
  552. query
  553. .select("#descbox-desc")
  554. .boundingClientRect((data) => {
  555. this.textHeight = data.height
  556. })
  557. .exec();
  558. })
  559. },
  560. numberToLetter(num) {
  561. // 将数字转换为字母的 ASCII 码
  562. let letterCode = num + 65;
  563. // 将 ASCII 码转换为大写字母
  564. let letter = String.fromCharCode(letterCode);
  565. return letter;
  566. },
  567. updateTime() {
  568. var that = this;
  569. if (this.interval != null) {
  570. clearInterval(this.interval)
  571. }
  572. this.interval = setInterval(function() {
  573. that.getFinishCourseVideo()
  574. that.getInternetTraffic()
  575. }, 60000);
  576. },
  577. judgeDuration() {
  578. var that = this;
  579. if (this.intervalIntegral != null) {
  580. clearInterval(this.intervalIntegral)
  581. this.intervalIntegral = null
  582. }
  583. // 观看10分钟获得积分
  584. this.intervalIntegral = setInterval(function() {
  585. that.getIntegralByH5Video()
  586. }, 600000);
  587. },
  588. clearIntegral() {
  589. if (this.intervalIntegral != null) {
  590. clearInterval(this.intervalIntegral)
  591. this.intervalIntegral = null
  592. }
  593. },
  594. // 展开简介
  595. handleExpand() {
  596. this.isExpand = !this.isExpand
  597. },
  598. getH5CourseByVideo() {
  599. this.loading = true
  600. getH5CourseByVideoId({
  601. videoId: this.videoId
  602. }).then(res => {
  603. this.loading = false
  604. if (res.code == 200) {
  605. this.courseInfo = res.data
  606. uni.setNavigationBarTitle({
  607. title: this.courseInfo && this.courseInfo.title ? this.courseInfo.title : ''
  608. });
  609. }
  610. this.getHeight()
  611. this.getDescHeight()
  612. },
  613. rej => {
  614. this.loading = false
  615. }
  616. ).catch(() => {
  617. this.loading = false
  618. })
  619. },
  620. getH5CourseVideoDetails(type) {
  621. getH5CourseVideoDetails(this.urlOption).then(res => {
  622. if (res.code == 200) {
  623. this.config = res.config || {}
  624. this.isFinish = res.isFinish || 0
  625. this.duration = res.course && res.course.duration ? res.course.duration : 0
  626. this.playDuration = res.playDuration || 0
  627. this.playDurationSeek = res.playDuration || 0
  628. this.tipsTime = res.tipsTime || 0
  629. let lineList = []
  630. if (res.course && res.course.lineOne) {
  631. lineList.push(res.course.lineOne)
  632. }
  633. if (res.course && res.course.lineTwo) {
  634. lineList.push(res.course.lineTwo)
  635. }
  636. if (res.course && res.course.lineThree) {
  637. lineList.push(res.course.lineThree)
  638. }
  639. this.lineList = lineList
  640. if (!this.player || type == 'error') {
  641. this.lineIndex = this.config.defaultLine
  642. this.videoUrl = lineList[this.lineIndex]
  643. this.poster= res.course && res.course.imgUrl ? res.course.imgUrl : ''
  644. // this.options.sources = [{
  645. // src: this.videoUrl
  646. // }]
  647. // this.options.poster = res.course && res.course.imgUrl ? res.course.imgUrl : ''
  648. // this.initVideo()
  649. this.playTime = this.playDuration >= this.duration ? 0 : this.playDuration
  650. setTimeout(()=>{
  651. this.player = uni.createVideoContext('video-content-box');
  652. this.player.seek(this.playTime)
  653. this.player.play();
  654. },500);
  655. this.getDanmuList()
  656. if (this.socket) {
  657. this.socket.close({
  658. success:()=>{
  659. this.reOpenSocket = true
  660. clearInterval(this.pingpangTimes)
  661. }
  662. })
  663. } else {
  664. this.initSocket()
  665. }
  666. } else {
  667. // let div = document.querySelector(".vjs-progress-control");
  668. // if(div) {
  669. // if (this.isFinish == 1 || this.isEnded || this.linkType == 1) {
  670. // div.style.pointerEvents = "auto";
  671. // } else {
  672. // div.style.pointerEvents = "none"; //禁止所有事件
  673. // }
  674. // }
  675. this.playTime = this.playTime > this.playDuration ? this.playTime : this.playDuration >= this.duration ? 0 : this.playDuration
  676. this.player.seek(this.playTime)
  677. this.player.play();
  678. }
  679. this.updateTime();
  680. this.quesList = res.questions && res.questions.length > 0 ? res.questions : [],
  681. this.quesList = this.quesList.map(item => ({
  682. ...item,
  683. questionOption: JSON.parse(item.question),
  684. answer: ''
  685. }))
  686. }
  687. this.getHeight()
  688. this.getDescHeight()
  689. },
  690. rej => {}
  691. )
  692. },
  693. handleAnswer(item, option, idx) {
  694. let time = this.playTime
  695. if(this.isEnded) {
  696. time = this.duration
  697. } else {
  698. if(time < this.playDuration&&this.isFinish!=1) {
  699. // 没完课且小于续播的时间
  700. time = this.playDuration
  701. }
  702. }
  703. if(Number(this.duration || 0) == 0 || time < this.duration - 60) {
  704. uni.showToast({
  705. title: "请先观看完整课程再答题哦~",
  706. icon: "none"
  707. })
  708. return
  709. }
  710. if (item.type == 1) {
  711. // 单选option
  712. item.answer = option.name
  713. } else if (item.type == 2) {
  714. // 多选
  715. let answer = item.answer ? item.answer.split(',') : []
  716. if (answer.indexOf(option.name) === -1) {
  717. answer.push(option.name)
  718. item.answer = answer.join(',')
  719. } else {
  720. answer.splice(answer.indexOf(option.name), 1)
  721. item.answer = answer.join(',')
  722. }
  723. }
  724. },
  725. submit() {
  726. if(this.isExpire){
  727. uni.showToast({
  728. title: '课程已过期或链接无效',
  729. icon: 'none'
  730. });
  731. return
  732. }
  733. // 登录
  734. this.$isLoginCourse().then(
  735. res => {
  736. if(res){
  737. if (this.isAddKf == 1&&this.isCheckRealUrl) {
  738. // 答题
  739. // 您已提交过答案,请领取红包
  740. this.courseAnswer()
  741. } else {
  742. // 添加客服
  743. if (this.videoId && this.qwUserId) {
  744. this.getIsAddKf()
  745. } else {
  746. uni.showToast({
  747. title: '请添加客服',
  748. icon: 'none'
  749. })
  750. }
  751. }
  752. } else{
  753. this.goLogin()
  754. }
  755. },
  756. rej => {}
  757. );
  758. },
  759. // 答题
  760. courseAnswer() {
  761. let time = this.playTime
  762. if (this.isEnded) {
  763. time = this.duration
  764. } else {
  765. if (time < this.playDuration && this.isFinish != 1) {
  766. // 没完课且小于续播的时间
  767. time = this.playDuration
  768. }
  769. }
  770. if (Number(this.duration || 0) == 0 || time < this.duration - 60) {
  771. uni.showToast({
  772. title: "请先观看完整课程再答题哦~",
  773. icon: "none"
  774. })
  775. return
  776. }
  777. if (this.quesList.some(item => !item.answer)) {
  778. uni.showToast({
  779. title: "请确认是否答完所有题目",
  780. icon: "none"
  781. })
  782. return
  783. }
  784. const questions = this.quesList.map(obj => {
  785. const {
  786. questionOption,
  787. ...rest
  788. } = obj;
  789. return rest;
  790. });
  791. if(!this.isCheckRealUrl) return;
  792. const param = {
  793. ...this.urlOption,
  794. questions: questions,
  795. videoId: this.videoId,
  796. duration: this.playTime,
  797. }
  798. this.errTitle = ""
  799. this.errDesc = ""
  800. this.errQues = []
  801. courseAnswer(param).then(res => {
  802. if (res.code == 200) {
  803. if (res.incorrectQuestions) {
  804. // 答题失败
  805. if (res.incorrectQuestions.length > 0) {
  806. this.errQues = res.incorrectQuestions
  807. }
  808. this.remain = res.remain || 0
  809. if (res.remain > 0) {
  810. this.errTitle = "很遗憾答错了"
  811. this.errDesc = `<span style="color:#FF5C03">还有${res.remain}次机会,继续加油</span>`
  812. this.$refs.answerPopup.open("center")
  813. }
  814. } else {
  815. // 答题成功
  816. this.errTitle = "恭喜你,回答正确"
  817. this.errDesc = `请选择奖励`
  818. this.$refs.answerPopup.open("center")
  819. }
  820. } else {
  821. if (res.msg == "该课题到达答错次数限制") {
  822. this.errTitle = "答题次数超过限制"
  823. this.errDesc = "以后的课程要认真学习哦"
  824. this.$refs.answerPopup.open("center")
  825. } else {
  826. uni.showToast({
  827. title: res.msg,
  828. icon: "none"
  829. })
  830. }
  831. }
  832. },
  833. rej => {}
  834. )
  835. },
  836. // 选择
  837. rewardChange(e) {
  838. this.currentReward = e.detail.value
  839. },
  840. closeAnswerPopup() {
  841. this.$refs.answerPopup.close()
  842. if(!this.isCheckRealUrl) return;
  843. if (this.errTitle == '恭喜你,回答正确') {
  844. const param = {
  845. ...this.urlOption,
  846. rewardType: Number(this.currentReward),
  847. source: 2
  848. }
  849. sendReward(param).then(res => {
  850. uni.showToast({
  851. title: res.msg,
  852. icon: 'none'
  853. })
  854. // if(res.code == 200) {
  855. // //重构 发红包,后台通过OPENID发零钱到 账
  856. // //this.initWXConfig(res.package)
  857. // }else {
  858. // uni.showToast({
  859. // title: res.msg,
  860. // icon: 'none'
  861. // })
  862. // }
  863. })
  864. }
  865. },
  866. // 线路
  867. openPop() {
  868. this.$refs.popup.open('bottom')
  869. },
  870. close() {
  871. this.$refs.popup.close()
  872. },
  873. handleLine(index) {
  874. var that=this;
  875. if (this.lineIndex == index && this.videoUrl == this.lineList[index]) {
  876. this.close()
  877. return
  878. } else {
  879. // let div = document.querySelector(".vjs-progress-control");
  880. // if(div) {
  881. // if (this.isFinish == 1 || this.isEnded || this.linkType == 1) {
  882. // div.style.pointerEvents = "auto";
  883. // } else {
  884. // div.style.pointerEvents = "none"; //禁止所有事件
  885. // }
  886. // }
  887. this.lineIndex = index
  888. this.videoUrl = this.lineList[index]
  889. this.tipsOpen = false
  890. this.playDurationSeek = this.playTime || 0
  891. this.player = uni.createVideoContext('video-content-box');
  892. setTimeout(function(){
  893. that.player.seek(that.playDurationSeek)
  894. that.player.play();
  895. },500);
  896. // this.player.src(this.lineList[index])
  897. // this.player.one('loadedmetadata', () => {
  898. // this.player.currentTime(this.playDurationSeek);
  899. // this.player.play();
  900. // });
  901. this.close()
  902. }
  903. },
  904. // 客服
  905. getIsAddKf() {
  906. this.qrcode = ''
  907. this.qrcodeMsg = ''
  908. this.isAddKf = 0
  909. // {videoId: this.videoId,qwUserId: this.qwUserId,corpId: this.corpId}
  910. getIsAddKf(this.urlOption).then(res => {
  911. if (res.code == 200) {
  912. this.isAddKf = 1
  913. this.isCheckRealUrl = true
  914. this.getH5CourseVideoDetails()
  915. } else if (res.code == 400) {
  916. this.isAddKf = 0
  917. this.isCheckRealUrl = false
  918. this.qrcode = res.qrcode
  919. this.qrcodeMsg = res.msg
  920. this.$refs.kfPopup.open()
  921. } else if (res.code == 504) {
  922. // 登录
  923. this.isCheckRealUrl = false
  924. this.goLogin()
  925. } else if (res.code == 566) {
  926. this.isAddKf = 1
  927. this.isCheckRealUrl = true
  928. // 官方群发通用链接
  929. const url = res.courseLink.realLink.split('?course=')[1]
  930. this.urlOption = JSON.parse(url)
  931. this.getH5CourseVideoDetails()
  932. } else {
  933. this.isCheckRealUrl = false
  934. this.isAddKf = 0
  935. uni.showToast({
  936. title: res.msg,
  937. icon: 'none'
  938. });
  939. }
  940. },
  941. err => {}
  942. );
  943. },
  944. closeKFPop() {
  945. this.$refs.kfPopup.close()
  946. },
  947. getFinishCourseVideo() {
  948. if (!this.playTime || !this.isCheckRealUrl) return
  949. // {videoId: this.videoId,duration:this.playTime}
  950. const param = {
  951. duration: this.playTime,
  952. ...this.urlOption
  953. }
  954. getFinishCourseVideo(param)
  955. },
  956. // 每十分钟获得积分
  957. getIntegralByH5Video() {
  958. if(!this.isCheckRealUrl) return
  959. const param = {
  960. duration: this.playTime,
  961. ...this.urlOption
  962. }
  963. getIntegralByH5Video(param).then(res => {
  964. if (res.code == 200) {
  965. uni.showToast({
  966. title: "积分+10",
  967. icon: "none"
  968. })
  969. }
  970. })
  971. },
  972. progressChange(e) {
  973. this.bufferRate = Math.ceil(e.detail.buffered)
  974. },
  975. // 缓冲
  976. getInternetTraffic() {
  977. if(!this.isCheckRealUrl) return
  978. const playVideoTime = Math.ceil(this.playTime / this.duration * 100) // 播放百分比
  979. if(this.bufferRate == 0 || this.bufferRate < playVideoTime) {
  980. this.bufferRate = playVideoTime
  981. }
  982. if(this.bufferRate == 0 || Number(this.bufferRate.toFixed(2)) == 0) return
  983. const param = {
  984. uuId: dayjs().format('YYYYMMDD') + this.uuId,
  985. duration: this.playTime,
  986. bufferRate: Number(this.bufferRate.toFixed(2)),
  987. ...this.urlOption
  988. }
  989. getInternetTraffic(param)
  990. },
  991. getErrMsg(err) {
  992. let msgerr = {
  993. videoUrl: this.videoUrl,
  994. lineIndex: this.lineIndex,
  995. errTime: new Date(),
  996. ip: this.ip,
  997. errMsg: err
  998. }
  999. getErrMsg({
  1000. msg: JSON.stringify(msgerr)
  1001. })
  1002. },
  1003. goLogin() {
  1004. this.$getProvider().then(provider=>{
  1005. console.log('当前的环境商',provider)
  1006. if (!provider) {
  1007. reject()
  1008. }
  1009. uni.login({
  1010. provider: provider,
  1011. success: async loginRes => {
  1012. console.log(loginRes)
  1013. uni.getUserInfo({
  1014. provider: provider,
  1015. success: (infoRes)=> {
  1016. uni.showToast({
  1017. title: '处理中...',
  1018. icon: 'loading'
  1019. });
  1020. loginByMp({code: loginRes.code,encryptedData:infoRes.encryptedData,iv:infoRes.iv}).then(res=>{
  1021. uni.hideLoading();
  1022. if (res.code == 200) {
  1023. uni.setStorageSync('AppTokenmini_RTCourse', res.token);
  1024. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  1025. this.user = res.user
  1026. this.isLogin = true
  1027. this.getIsAddKf()
  1028. } else {
  1029. uni.showToast({
  1030. title: res.msg,
  1031. icon: 'none'
  1032. });
  1033. }
  1034. }).catch(err=>{
  1035. uni.hideLoading();
  1036. uni.showToast({
  1037. icon:'none',
  1038. title: "登录失败,请重新登录",
  1039. });
  1040. });
  1041. }
  1042. });
  1043. }
  1044. })
  1045. }).catch(err => {})
  1046. },
  1047. getLink() {
  1048. let that = this;
  1049. getRealLink({sortLink:this.sortLink}).then(res=>{
  1050. if(res.code == 200) {
  1051. this.isExpire = false
  1052. // 如果响应中包含真实链接,则跳转到真实链接
  1053. // window.location.href = res.realLink +"&sortLink="+this.sortLink+"&code="+this.code+"&time="+new Date().getTime()
  1054. if (this.isLogin && this.isAddKf == 1&&this.isCheckRealUrl) {
  1055. this.getH5CourseVideoDetails()
  1056. }
  1057. if (this.videoId &&(this.isAddKf != 1 || !this.isCheckRealUrl)) {
  1058. this.$isLoginCourse().then(
  1059. isLogin => {
  1060. this.isLogin = isLogin
  1061. if(isLogin){
  1062. this.getIsAddKf()
  1063. } else {
  1064. this.goLogin()
  1065. }
  1066. },
  1067. rej => {}
  1068. );
  1069. }
  1070. } else {
  1071. this.isExpire = true
  1072. uni.showToast({
  1073. title: '课程已过期或链接无效',
  1074. icon: 'none'
  1075. });
  1076. }
  1077. }).catch(err=>{
  1078. this.isExpire = true
  1079. uni.showToast({
  1080. title: '发生错误,请稍后再试',
  1081. icon: 'none'
  1082. });
  1083. })
  1084. },
  1085. /**
  1086. * 节流原理:在一定时间内,只能触发一次
  1087. *
  1088. * @param {Function} func 要执行的回调函数
  1089. * @param {Number} wait 延时的时间
  1090. * @param {Boolean} immediate 是否立即执行
  1091. * @return null
  1092. */
  1093. throttle(func, wait = 500, immediate = true) {
  1094. if (immediate) {
  1095. if (!this.flag) {
  1096. this.flag = true
  1097. // 如果是立即执行,则在wait毫秒内开始时执行
  1098. typeof func === 'function' && func()
  1099. this.timer = setTimeout(() => {
  1100. this.flag = false
  1101. }, wait)
  1102. }
  1103. } else if (!this.flag) {
  1104. this.flag = true
  1105. // 如果是非立即执行,则在wait毫秒内的结束处执行
  1106. this.timer = setTimeout(() => {
  1107. this.flag = false
  1108. typeof func === 'function' && func()
  1109. }, wait)
  1110. }
  1111. },
  1112. // 弹幕
  1113. openDanmu(type) {
  1114. this.openDanmuType = type
  1115. this.danmuIput= ''
  1116. if(type == 1) {
  1117. this.player.exitFullScreen()
  1118. }
  1119. this.$refs.danmuPopup.open()
  1120. },
  1121. changeShowPopup(val) {
  1122. this.focus = val.show
  1123. },
  1124. // 发送弹幕
  1125. sendDanmu() {
  1126. if(this.danmuIput==''||this.danmuIput.trim()=='') {
  1127. uni.showToast({
  1128. title: '弹幕不能为空',
  1129. icon: 'none'
  1130. })
  1131. return;
  1132. }
  1133. this.sendMsg()
  1134. },
  1135. // 弹幕列表
  1136. getDanmuList(){
  1137. getDanmuList(this.videoId).then(res=>{
  1138. if(res.code == 200&&res.data&&res.data.length>0) {
  1139. this.danmuList = res.data.map(item=>({
  1140. id: item.id,
  1141. text: item.content,
  1142. time: item.timePoint ? Number(item.timePoint) : this.playTime,
  1143. color: "#FFFFFF",
  1144. }))
  1145. } else {
  1146. this.danmuList = []
  1147. }
  1148. })
  1149. },
  1150. //创建一个socket连接
  1151. initSocket() {
  1152. let userId = this.user.userId;
  1153. let that = this;
  1154. this.socket = uni.connectSocket({
  1155. url: getApp().globalData.danmuWSUrl + "/ws/barrage/" + this.videoId,
  1156. multiple: true,
  1157. header: {
  1158. 'token': uni.getStorageSync('AppTokenmini_RTCourse')
  1159. },
  1160. success: res => {
  1161. console.log('WebSocket连接已打开1!');
  1162. that.isSocketOpen = true
  1163. that.reOpenSocket = false
  1164. // 保持心跳
  1165. if(that.pingpangTimes) {
  1166. clearInterval(that.pingpangTimes)
  1167. that.pingpangTimes= null
  1168. }
  1169. that.pingpangTimes=setInterval(()=>{
  1170. let data={cmd:"heartbeat",userId: userId};
  1171. that.socket.send({
  1172. data: JSON.stringify(data),
  1173. success: () => {
  1174. // console.log('WebSocket发送心条数据!');
  1175. },
  1176. fail: () => {
  1177. that.isSocketOpen=false
  1178. }
  1179. });
  1180. },15000)
  1181. },
  1182. error: res => {
  1183. console.log(res)
  1184. },
  1185. })
  1186. this.socket.onMessage((res) => {
  1187. console.log("收到消息parse",JSON.parse(res.data))
  1188. const redata = JSON.parse(res.data);
  1189. if(redata.cmd=="heartbeat"){
  1190. //心跳
  1191. // console.log("heartbeat")
  1192. }else if(redata.cmd=="danmu"){
  1193. that.isSend=true;
  1194. that.addMsg(1,redata);
  1195. }
  1196. })
  1197. //监听socket打开
  1198. this.socket.onOpen(() => {
  1199. console.log('WebSocket连接已打开2!');
  1200. that.isSocketOpen = true
  1201. that.reOpenSocket = false
  1202. that.isSend = true;
  1203. })
  1204. //监听socket关闭
  1205. this.socket.onClose(() => {
  1206. that.isSocketOpen = false
  1207. that.socket = null
  1208. console.log('WebSocket连接已关闭!',that.reOpenSocket);
  1209. if(that.pingpangTimes) {
  1210. clearInterval(that.pingpangTimes)
  1211. that.pingpangTimes= null
  1212. }
  1213. if(that.reOpenSocket) {
  1214. //重启
  1215. that.initSocket()
  1216. }
  1217. // that.msgEnd = true
  1218. })
  1219. //监听socket错误
  1220. this.socket.onError((err) => {
  1221. console.log("socket err:",err)
  1222. that.isSocketOpen = false
  1223. that.reOpenSocket = false
  1224. that.socket = null
  1225. if(that.pingpangTimes) {
  1226. clearInterval(that.pingpangTimes)
  1227. that.pingpangTimes= null
  1228. }
  1229. })
  1230. },
  1231. sendMsg() {
  1232. if (!this.isSend) {
  1233. return;
  1234. }
  1235. if (this.isSocketOpen) {
  1236. var data = {
  1237. cmd: 'danmu',
  1238. userId: this.user.userId,
  1239. videoId: this.videoId,
  1240. content: this.danmuIput,
  1241. timePoint: this.playTime, // 弹幕对应视频时间节点()秒
  1242. platform: 'uniapp', //发送平台,app传值“app”,小程序传值“uniapp”
  1243. fontSize: '14px',
  1244. mode: "scroll",
  1245. color: "#fff",
  1246. };
  1247. this.socket.send({
  1248. data: JSON.stringify(data),
  1249. success: () => {
  1250. console.log("发送成功")
  1251. this.$refs.danmuPopup.close()
  1252. this.isSend = false;
  1253. },
  1254. fail: () => {
  1255. console.log("发送失败")
  1256. uni.showToast({
  1257. title: '发送失败',
  1258. icon: 'none'
  1259. })
  1260. }
  1261. });
  1262. }
  1263. },
  1264. // 收到消息
  1265. addMsg(type, content) {
  1266. if (!this.player) {
  1267. this.player = uni.createVideoContext('video-content-box');
  1268. }
  1269. this.player.sendDanmu({
  1270. text: content.content,
  1271. color: "#FF0000",
  1272. time: this.playTime + 1
  1273. })
  1274. // setTimeout(()=>{
  1275. // this.player.sendDanmu({
  1276. // text: content.content,
  1277. // color: "#FF0000",
  1278. // time: this.playTime
  1279. // })
  1280. // },100)
  1281. }
  1282. }
  1283. }
  1284. </script>
  1285. <style scoped>
  1286. .full-width-popup {
  1287. width: 100%;
  1288. }
  1289. </style>
  1290. <style lang="scss" scoped>
  1291. @mixin u-flex($flexD, $alignI, $justifyC) {
  1292. display: flex;
  1293. flex-direction: $flexD;
  1294. align-items: $alignI;
  1295. justify-content: $justifyC;
  1296. }
  1297. .footer-tips {
  1298. margin-top: 14rpx;
  1299. text-align: center;
  1300. font-family: PingFang SC,PingFang SC;
  1301. font-weight: 500;
  1302. font-size: 12px;
  1303. color: #bbb;
  1304. }
  1305. .textOne {
  1306. overflow: hidden;
  1307. white-space: nowrap;
  1308. text-overflow: ellipsis;
  1309. }
  1310. .textTwo {
  1311. overflow: hidden;
  1312. text-overflow: ellipsis;
  1313. display: -webkit-box;
  1314. -webkit-line-clamp: 2;
  1315. -webkit-box-orient: vertical;
  1316. }
  1317. .header-nav {
  1318. height: 88rpx;
  1319. @include u-flex(row, center, flex-start);
  1320. overflow: hidden;
  1321. background-color: #fff;
  1322. box-sizing: border-box;
  1323. .header-title {
  1324. text-align: center;
  1325. overflow: hidden;
  1326. white-space: nowrap;
  1327. text-overflow: ellipsis;
  1328. padding: 0 10rpx 0 100rpx;
  1329. font-family: PingFang SC,PingFang SC;
  1330. font-weight: 500;
  1331. font-size: 15px;
  1332. color: #000;
  1333. box-sizing: border-box;
  1334. }
  1335. }
  1336. .reward-list {
  1337. width: 100%;
  1338. margin-top: 20rpx;
  1339. margin-bottom: -40rpx;
  1340. &-group {
  1341. font-family: PingFang SC, PingFang SC;
  1342. font-weight: 400;
  1343. font-size: 14px;
  1344. color: #222222;
  1345. @include u-flex(row, center, center);
  1346. }
  1347. &-option {
  1348. @include u-flex(row, center, flex-start);
  1349. &:first-child {
  1350. margin-right: 40rpx;
  1351. }
  1352. }
  1353. }
  1354. .err {
  1355. color: #f56c6c !important;
  1356. }
  1357. .kfqrcode-box {
  1358. background-color: #fff;
  1359. border-radius: 16rpx;
  1360. max-width: 560rpx;
  1361. padding: 60rpx 40rpx;
  1362. margin-top: -100rpx;
  1363. box-sizing: border-box;
  1364. @include u-flex(column, center, flex-start);
  1365. font-family: PingFang SC, PingFang SC;
  1366. font-weight: 400;
  1367. font-size: 34rpx;
  1368. color: #222;
  1369. position: relative;
  1370. text-align: center;
  1371. .kfqrcode {
  1372. height: 460rpx;
  1373. width: 460rpx;
  1374. }
  1375. }
  1376. .kfqrcode-close {
  1377. width: 64rpx;
  1378. height: 64rpx;
  1379. position: absolute;
  1380. bottom: -100rpx;
  1381. left: 50%;
  1382. transform: translateX(-50%);
  1383. }
  1384. .tipsPopup-mask {
  1385. position: relative;
  1386. width: 560rpx;
  1387. background-color: transparent;
  1388. .red_envelope_top {
  1389. width: 480rpx;
  1390. height: 360rpx;
  1391. margin: 0 auto;
  1392. display: inherit;
  1393. }
  1394. }
  1395. .tipsPopup-btn-box {
  1396. width: 456rpx;
  1397. height: 104rpx;
  1398. padding: 4rpx;
  1399. box-sizing: border-box;
  1400. background: linear-gradient(180deg, rgba(252, 209, 94, 1), rgba(254, 253, 251, 1));
  1401. border-radius: 52rpx;
  1402. }
  1403. .tipsPopup-btn {
  1404. width: 100%;
  1405. height: 100%;
  1406. background: linear-gradient(180deg, #FF9F22 0%, #FA1E05 100%);
  1407. border-radius: 52rpx 52rpx 52rpx 52rpx;
  1408. font-family: PingFang SC, PingFang SC;
  1409. font-weight: 500;
  1410. font-size: 36rpx;
  1411. color: #FFFFFF;
  1412. line-height: 96rpx;
  1413. text-align: center;
  1414. }
  1415. .tipsPopup {
  1416. width: 560rpx;
  1417. padding: 12rpx;
  1418. margin-top: -72rpx;
  1419. box-sizing: border-box;
  1420. background: linear-gradient(180deg, #FFFBEF 0%, #FFFFF5 43%, #F5EAC2 100%);
  1421. border-radius: 32rpx 32rpx 32rpx 32rpx;
  1422. position: relative;
  1423. &-close {
  1424. width: 64rpx;
  1425. height: 64rpx;
  1426. position: absolute;
  1427. right: 0;
  1428. top: -188rpx;
  1429. }
  1430. &-line {
  1431. padding: 3rpx;
  1432. box-sizing: border-box;
  1433. background: linear-gradient(180deg, rgba(247, 245, 220, 1), rgba(250, 220, 157, 1));
  1434. border-radius: 24rpx;
  1435. }
  1436. &-box {
  1437. padding: 0 40rpx 40rpx 40rpx;
  1438. box-sizing: border-box;
  1439. background: linear-gradient(180deg, #FFFBEF 0%, #FFFFF5 43%, #F5EAC2 100%);
  1440. border-radius: 24rpx;
  1441. @include u-flex(column, center, flex-start);
  1442. }
  1443. &-head {
  1444. @include u-flex(row, center, center);
  1445. &-title {
  1446. width: 364rpx;
  1447. height: auto;
  1448. margin-top: -22rpx;
  1449. }
  1450. }
  1451. &-content {
  1452. margin: 48rpx 0;
  1453. font-family: PingFang SC, PingFang SC;
  1454. font-weight: 500;
  1455. font-size: 32rpx;
  1456. color: #222222;
  1457. text-align: center;
  1458. &-title {
  1459. margin-bottom: 26rpx;
  1460. font-weight: 600;
  1461. font-size: 40rpx;
  1462. color: #FF5C03;
  1463. }
  1464. }
  1465. }
  1466. .video-controls-box {
  1467. width: 100%;
  1468. height: 420rpx;
  1469. overflow: hidden;
  1470. position: absolute;
  1471. bottom: 0;
  1472. left: 0;
  1473. z-index: 2;
  1474. background: rgba(0, 0, 0, 0.2);
  1475. .video-play {
  1476. height: 72rpx;
  1477. width: 72rpx;
  1478. position: absolute;
  1479. top: 50%;
  1480. left: 50%;
  1481. transform: translate(-50%, -50%);
  1482. }
  1483. }
  1484. .video-controls {
  1485. width: 100%;
  1486. height: 80rpx;
  1487. padding: 0 28rpx;
  1488. box-sizing: border-box;
  1489. position: absolute;
  1490. bottom: 0;
  1491. left: 0;
  1492. display: flex;
  1493. align-items: center;
  1494. justify-content: space-between;
  1495. background: linear-gradient(to top, #222 0%, transparent 80%);
  1496. .video-icon {
  1497. height: 44rpx;
  1498. width: 44rpx;
  1499. }
  1500. }
  1501. .errQuesbox {
  1502. width: 100%;
  1503. max-height: 260rpx;
  1504. overflow-y: auto;
  1505. margin-top: 24rpx;
  1506. font-family: PingFang SC, PingFang SC;
  1507. font-weight: 500;
  1508. font-size: 30rpx;
  1509. color: #222222;
  1510. &-item {
  1511. width: 100%;
  1512. height: 128rpx;
  1513. line-height: 128rpx;
  1514. margin-bottom: 24rpx;
  1515. padding: 0 30rpx;
  1516. box-sizing: border-box;
  1517. overflow: hidden;
  1518. background: #fff;
  1519. border-radius: 16rpx 16rpx 16rpx 16rpx;
  1520. position: relative;
  1521. &::after {
  1522. content: "题目";
  1523. min-width: 64rpx;
  1524. height: 36rpx;
  1525. padding: 0 12rpx;
  1526. line-height: 36rpx;
  1527. background: #FF5C03;
  1528. box-sizing: border-box;
  1529. border-radius: 0rpx 0rpx 16rpx 0rpx;
  1530. text-align: center;
  1531. font-family: PingFang SC, PingFang SC;
  1532. font-weight: 500;
  1533. font-size: 20rpx;
  1534. color: #fff;
  1535. position: absolute;
  1536. left: 0;
  1537. top: 0;
  1538. }
  1539. }
  1540. }
  1541. .bg {
  1542. background: #fff !important;
  1543. }
  1544. .answerPopup {
  1545. &-box {
  1546. width: 560rpx;
  1547. background: linear-gradient(180deg, #FFFAF6 0%, #FEECD8 100%);
  1548. border-radius: 32rpx 32rpx 32rpx 32rpx;
  1549. background-color: #fff;
  1550. font-weight: 400;
  1551. padding: 32rpx;
  1552. box-sizing: border-box;
  1553. position: relative;
  1554. @include u-flex(column, center, flex-start);
  1555. font-family: PingFang SC, PingFang SC;
  1556. font-weight: 400;
  1557. .tipimg {
  1558. width: 206rpx;
  1559. height: 206rpx;
  1560. margin-bottom: 16rpx;
  1561. }
  1562. }
  1563. &-title {
  1564. font-weight: 600;
  1565. font-size: 36rpx;
  1566. color: #222222;
  1567. }
  1568. &-desc {
  1569. margin-top: 10rpx;
  1570. font-size: 28rpx;
  1571. color: #757575;
  1572. }
  1573. &-btn {
  1574. width: 464rpx;
  1575. height: 84rpx;
  1576. margin-top: 54rpx;
  1577. margin-bottom: 16rpx;
  1578. background: #FF5C03;
  1579. border-radius: 42rpx;
  1580. font-weight: 500;
  1581. font-size: 32rpx;
  1582. color: #FFFFFF;
  1583. text-align: center;
  1584. line-height: 84rpx;
  1585. }
  1586. }
  1587. .popupbox {
  1588. width: 100%;
  1589. background-color: #fff;
  1590. border-radius: 16rpx 16rpx 0 0;
  1591. padding: 24rpx 32rpx;
  1592. position: relative;
  1593. &-head {
  1594. height: 60rpx;
  1595. margin-bottom: 30rpx;
  1596. text-align: center;
  1597. overflow-y: auto;
  1598. color: #414858;
  1599. font-size: 32rpx;
  1600. font-weight: bold;
  1601. position: relative;
  1602. .close-icon {
  1603. position: absolute;
  1604. right: 0;
  1605. top: 0;
  1606. height: 40rpx;
  1607. width: 40rpx;
  1608. }
  1609. }
  1610. &-content {
  1611. height: 20vh;
  1612. overflow-y: auto;
  1613. display: flex;
  1614. align-items: flex-start;
  1615. flex-wrap: wrap;
  1616. gap: 32rpx;
  1617. .line-item {
  1618. display: inline-block;
  1619. min-width: 200rpx;
  1620. min-height: 60rpx;
  1621. padding: 0 20rpx;
  1622. box-sizing: border-box;
  1623. border-radius: 50rpx;
  1624. overflow: hidden;
  1625. background-color: #f7f7f7;
  1626. text-align: center;
  1627. color: #414858;
  1628. font-size: 28rpx;
  1629. line-height: 60rpx;
  1630. }
  1631. .line-active {
  1632. color: #f56c6c !important;
  1633. background-color: #fef0f0 !important;
  1634. }
  1635. }
  1636. }
  1637. .content {
  1638. padding-bottom: calc(var(--window-bottom) + 164rpx);
  1639. .video-box {
  1640. width: 100%;
  1641. height: 420rpx;
  1642. overflow: hidden;
  1643. position: relative;
  1644. #myVideo {
  1645. width: 100%;
  1646. height: 100%;
  1647. }
  1648. }
  1649. .video-poster {
  1650. width: 100%;
  1651. height: 420rpx;
  1652. }
  1653. .miantitlebox {
  1654. padding: 30rpx 0;
  1655. border-bottom: 2rpx solid #F5F7FA;
  1656. font-family: PingFang SC, PingFang SC;
  1657. font-weight: 500;
  1658. font-size: 36rpx;
  1659. color: #222222;
  1660. }
  1661. .subtitlebox {
  1662. padding: 30rpx 0;
  1663. border-bottom: 2rpx solid #F5F7FA;
  1664. font-family: PingFang SC, PingFang SC;
  1665. font-weight: 500;
  1666. font-size: 36rpx;
  1667. color: #222222;
  1668. }
  1669. .title-content {
  1670. padding: 0 32rpx;
  1671. background-color: #fff;
  1672. font-size: 28rpx;
  1673. line-height: 1.6;
  1674. .title {
  1675. font-size: 36rpx;
  1676. font-weight: 500;
  1677. color: #414858;
  1678. }
  1679. .time-or-subtitle {
  1680. margin-top: 12rpx;
  1681. color: #666666;
  1682. }
  1683. }
  1684. .descbox {
  1685. padding: 36rpx 32rpx;
  1686. margin-bottom: 20rpx;
  1687. background-color: #fff;
  1688. font-family: PingFang SC, PingFang SC;
  1689. font-weight: 400;
  1690. font-size: 28rpx;
  1691. color: #222222;
  1692. line-height: 42rpx;
  1693. word-break: break-word;
  1694. &-title {
  1695. margin-bottom: 24rpx;
  1696. font-weight: 500;
  1697. font-size: 32rpx;
  1698. }
  1699. &-info {
  1700. margin-bottom: 24rpx;
  1701. @include u-flex(row, center, space-between);
  1702. font-size: 26rpx;
  1703. color: #757575;
  1704. &-l {
  1705. flex: 1;
  1706. @include u-flex(row, center, flex-start);
  1707. }
  1708. &-time {
  1709. margin-left: 18rpx;
  1710. padding-left: 18rpx;
  1711. position: relative;
  1712. &::after {
  1713. content: "";
  1714. width: 4rpx;
  1715. height: 4rpx;
  1716. background: #999999;
  1717. border-radius: 50%;
  1718. position: absolute;
  1719. left: 0;
  1720. top: 50%;
  1721. transform: translateY(-50%);
  1722. }
  1723. }
  1724. &-r {
  1725. background: transparent;
  1726. }
  1727. }
  1728. &-desc {
  1729. overflow: hidden;
  1730. position: relative;
  1731. }
  1732. }
  1733. .expand {
  1734. flex-shrink: 0;
  1735. @include u-flex(row, center, flex-end);
  1736. color: #FF5C03;
  1737. font-weight: 400;
  1738. font-size: 24rpx;
  1739. image {
  1740. width: 32rpx;
  1741. height: 32rpx;
  1742. }
  1743. }
  1744. .expand-ab {
  1745. position: absolute;
  1746. top: 0;
  1747. right: 0;
  1748. box-shadow: -50rpx 0 20rpx 8rpx #FFFFFF;
  1749. background-color: #fff;
  1750. }
  1751. .ques-content {
  1752. background-color: #fff;
  1753. padding: 40rpx 32rpx;
  1754. box-sizing: border-box;
  1755. font-family: PingFang SC, PingFang SC;
  1756. font-weight: 400;
  1757. font-size: 28rpx;
  1758. color: #222222;
  1759. }
  1760. .ques-content-tit {
  1761. font-family: PingFang SC, PingFang SC;
  1762. font-weight: 600;
  1763. font-size: 36rpx;
  1764. color: #222222;
  1765. }
  1766. .ques-title {
  1767. margin: 48rpx 0 34rpx 0;
  1768. font-weight: 500;
  1769. font-size: 32rpx;
  1770. white-space: normal;
  1771. }
  1772. .ques-type {
  1773. flex-shrink: 0;
  1774. min-width: 72rpx;
  1775. min-height: 40rpx;
  1776. padding: 0 12rpx;
  1777. margin: 0 12rpx;
  1778. box-sizing: border-box;
  1779. background: #FF5C03;
  1780. border-radius: 8rpx 8rpx 8rpx 8rpx;
  1781. line-height: 40rpx;
  1782. text-align: center;
  1783. font-family: PingFang SC, PingFang SC;
  1784. font-weight: 400;
  1785. font-size: 24rpx;
  1786. color: #FFFFFF;
  1787. display: inline-block;
  1788. }
  1789. .ques-option {
  1790. min-height: 88rpx;
  1791. padding: 24rpx 32rpx;
  1792. box-sizing: border-box;
  1793. margin-bottom: 24rpx;
  1794. background: #F5F7FA;
  1795. border-radius: 16rpx 16rpx 16rpx 16rpx;
  1796. display: flex;
  1797. align-items: center;
  1798. &-active {
  1799. color: #FF5C03 !important;
  1800. background: #FCF0E7 !important;
  1801. }
  1802. }
  1803. .video-line {
  1804. min-width: 140rpx;
  1805. max-width: 200rpx;
  1806. height: 60rpx;
  1807. padding: 0 20rpx;
  1808. box-sizing: border-box;
  1809. border-radius: 50rpx 0 0 50rpx;
  1810. overflow: hidden;
  1811. background-color: #fff;
  1812. text-align: center;
  1813. color: #888;
  1814. font-size: 28rpx;
  1815. line-height: 60rpx;
  1816. display: inline-flex;
  1817. align-items: center;
  1818. justify-content: center;
  1819. position: fixed;
  1820. right: 0;
  1821. z-index: 9;
  1822. bottom: calc(var(--window-bottom) + 280rpx);
  1823. box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, .12);
  1824. image {
  1825. flex-shrink: 0;
  1826. height: 34rpx;
  1827. width: 34rpx;
  1828. margin-right: 6rpx;
  1829. }
  1830. }
  1831. .danmu-line {
  1832. bottom: calc(var(--window-bottom) + 370rpx);
  1833. word-break: keep-all;
  1834. .set_image {
  1835. height: 40rpx;
  1836. width: 40rpx;
  1837. }
  1838. }
  1839. .footer {
  1840. border-top: 1rpx solid #ededef;
  1841. background: #fff;
  1842. width: 100%;
  1843. position: fixed;
  1844. bottom: 0;
  1845. padding: 32rpx;
  1846. padding-bottom: calc(var(--window-bottom) + 14rpx);
  1847. box-sizing: border-box;
  1848. z-index: 9;
  1849. &-btn {
  1850. width: 100%;
  1851. height: 98rpx;
  1852. background: #FF5C03;
  1853. border-radius: 49rpx 49rpx 49rpx 49rpx;
  1854. line-height: 98rpx;
  1855. text-align: center;
  1856. font-family: PingFang SC, PingFang SC;
  1857. font-weight: 600;
  1858. font-size: 32rpx;
  1859. color: #FFFFFF;
  1860. @include u-flex(row, center, center);
  1861. &-img {
  1862. flex-shrink: 0;
  1863. width: 144rpx;
  1864. height: 144rpx;
  1865. margin-right: 8rpx;
  1866. margin-top: -24rpx;
  1867. }
  1868. }
  1869. &-btn-border {
  1870. position: relative;
  1871. &::after {
  1872. content: "";
  1873. background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
  1874. position: absolute;
  1875. top: -2rpx;
  1876. left: 0;
  1877. height: 103rpx;
  1878. width: 100%;
  1879. z-index: -1;
  1880. border-radius: 49rpx 49rpx 49rpx 49rpx;
  1881. box-shadow: 0rpx 8rpx 11rpx 0rpx rgba(255, 92, 3, 0.3);
  1882. overflow: hidden;
  1883. }
  1884. }
  1885. }
  1886. }
  1887. .agreement {
  1888. display: inline-flex;
  1889. margin-top: 16rpx;
  1890. font-size: 24rpx;
  1891. color: #525252;
  1892. align-items: center;
  1893. justify-content: center;
  1894. }
  1895. .video-danmu-btnbox {
  1896. width: 50px;
  1897. height: 50px;
  1898. border-radius: 50%;
  1899. overflow: hidden;
  1900. position: absolute;
  1901. right: 10px;
  1902. bottom: calc(50% - 50px);
  1903. transform: translateY(-50%);
  1904. padding: 8px;
  1905. box-sizing: border-box;
  1906. }
  1907. .video-danmu-image {
  1908. width: 100%;
  1909. height: 100%;
  1910. }
  1911. .danmuPopup {
  1912. background-color: #fff;
  1913. padding-bottom: var(--window-bottom);
  1914. &-head {
  1915. width: 100%;
  1916. padding: 10px;
  1917. box-sizing: border-box;
  1918. overflow: hidden;
  1919. @include u-flex(row,center,flex-start);
  1920. .danmu-icon {
  1921. height: 24px;
  1922. width: 24px;
  1923. margin-right: 12px;
  1924. }
  1925. }
  1926. &-input {
  1927. flex: 1;
  1928. height: 35px;
  1929. }
  1930. &-send {
  1931. flex-shrink: 0;
  1932. height: 35px;
  1933. display: flex;
  1934. align-items: center;
  1935. justify-content: center;
  1936. padding: 5px 15px;
  1937. box-sizing: border-box;
  1938. background: #FF5C03 !important;
  1939. border-radius: 22px;
  1940. font-family: PingFang SC, PingFang SC;
  1941. font-weight: 500;
  1942. font-size: 15px;
  1943. color: #fff !important;
  1944. margin-left: 12px;
  1945. &::after {
  1946. border: none;
  1947. }
  1948. }
  1949. &-con {
  1950. background-color: #F5F7FA;
  1951. padding: 24px 12px 48px 12px;
  1952. font-family: PingFang SC, PingFang SC;
  1953. font-weight: 400;
  1954. font-size: 14px;
  1955. color: #757575;
  1956. }
  1957. }
  1958. </style>