video.vue 51 KB

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