VideoPlayer.vue 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. <template>
  2. <section class="space-y-6">
  3. <!-- 返回按钮 -->
  4. <div class="flex items-center justify-between">
  5. <div class="flex items-center gap-2 sm:gap-3">
  6. <button
  7. @click="goBack"
  8. class="flex items-center gap-1 sm:gap-2 text-white/80 hover:text-white transition whitespace-nowrap"
  9. >
  10. <svg
  11. class="w-4 h-4 sm:w-5 sm:h-5 flex-shrink-0"
  12. fill="none"
  13. stroke="currentColor"
  14. viewBox="0 0 24 24"
  15. >
  16. <path
  17. stroke-linecap="round"
  18. stroke-linejoin="round"
  19. stroke-width="2"
  20. d="M15 19l-7-7 7-7"
  21. />
  22. </svg>
  23. <span class="text-xs sm:text-sm">返回</span>
  24. </button>
  25. </div>
  26. <!-- 购买按钮区域 -->
  27. <div
  28. v-if="!isSinglePurchased && !isVip"
  29. class="flex items-center gap-1 sm:gap-1.5"
  30. >
  31. <!-- 游客和免费用户显示试看时间信息 -->
  32. <div
  33. v-if="isGuestOrFree"
  34. class="text-2xs sm:text-xs text-white/60 px-1 sm:px-2 py-0.5 sm:py-1"
  35. >
  36. 试看{{ trialDuration }}秒
  37. </div>
  38. <!-- 只有非游客用户才显示购买会员按钮 -->
  39. <button
  40. v-if="!isGuest"
  41. @click="handleMembershipClick"
  42. class="px-1.5 sm:px-2 py-0.5 sm:py-1 rounded-md bg-brand text-slate-900 text-2xs sm:text-xs font-medium hover:bg-brand/90 transition whitespace-nowrap min-w-fit"
  43. >
  44. 开通会员
  45. </button>
  46. <button
  47. @click="handleSinglePurchaseClick"
  48. class="px-2 sm:px-3 py-1 sm:py-2 rounded-lg bg-blue-500 text-white text-2xs sm:text-sm font-semibold hover:bg-blue-600 transition shadow-lg hover:shadow-xl flash-animation glow-animation hover:animate-none whitespace-nowrap min-w-fit"
  49. >
  50. 单片购买
  51. </button>
  52. </div>
  53. </div>
  54. <!-- 视频播放器区域 -->
  55. <div class="relative rounded-2xl overflow-hidden bg-black">
  56. <div class="aspect-video video-container">
  57. <VideoProcessor
  58. ref="videoProcessorRef"
  59. :cover-url="videoInfo.cover"
  60. :m3u8-url="videoInfo.m3u8"
  61. :alt="videoInfo.name"
  62. :auto-play="false"
  63. :hide-error="false"
  64. :enable-retry="true"
  65. cover-class="w-full h-full object-cover"
  66. video-class="w-full h-full object-contain"
  67. @cover-loaded="onCoverLoaded"
  68. @video-loaded="onVideoLoaded"
  69. @error="onVideoProcessorError"
  70. @retry="onVideoProcessorRetry"
  71. @play="onVideoPlay"
  72. @timeupdate="onVideoTimeUpdate"
  73. @seeking="onVideoSeeking"
  74. />
  75. <!-- 试看提示 -->
  76. <div
  77. v-if="isTrialMode"
  78. class="absolute top-4 right-4 text-white px-3 py-1.5 text-sm font-medium"
  79. >
  80. 试看中
  81. </div>
  82. <!-- 试看结束遮罩 -->
  83. <div
  84. v-if="showTrialEndModal && !isSinglePurchased && !isVip"
  85. class="absolute inset-0 bg-black/80 flex items-center justify-center z-50"
  86. >
  87. <div
  88. class="bg-white/10 backdrop-blur-sm rounded-2xl p-6 max-w-sm mx-4 text-center"
  89. >
  90. <div class="text-white text-lg font-semibold mb-4">
  91. 试看时间已结束
  92. </div>
  93. <div class="text-white/70 text-sm mb-6">
  94. <span v-if="!isGuest">购买会员或单独购买本片继续观看</span>
  95. <span v-else>单独购买本片继续观看</span>
  96. </div>
  97. <div class="space-y-3">
  98. <!-- 只有非游客用户才显示购买会员按钮 -->
  99. <button
  100. v-if="!isGuest"
  101. @click="purchaseMembership"
  102. class="w-full bg-brand hover:bg-brand/90 text-slate-900 py-3 px-4 rounded-lg font-medium transition whitespace-nowrap"
  103. >
  104. 开通会员
  105. </button>
  106. <button
  107. @click="purchaseVideo"
  108. class="w-full bg-blue-500 hover:bg-blue-600 text-white py-3 px-4 rounded-lg font-semibold transition shadow-lg hover:shadow-xl flash-animation glow-animation hover:animate-none whitespace-nowrap"
  109. >
  110. 单独购买本片
  111. </button>
  112. <button
  113. @click="showTrialEndModal = false"
  114. class="w-full text-white/60 hover:text-white/80 py-2 text-sm transition"
  115. >
  116. 取消
  117. </button>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <!-- 单片购买确认弹窗 -->
  124. <div
  125. v-if="showSinglePurchaseModal"
  126. class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
  127. @click.self="showSinglePurchaseModal = false"
  128. >
  129. <div
  130. class="bg-surface border border-white/10 rounded-2xl p-6 w-full max-w-sm mx-4 text-center"
  131. >
  132. <h3 class="text-lg font-semibold text-white/90 mb-2">确认购买</h3>
  133. <p class="text-sm text-white/70 mb-4">
  134. 确定要购买当前视频吗?<br />
  135. 购买后即可观看完整内容
  136. </p>
  137. <div class="text-lg font-semibold text-brand mb-6">
  138. ¥{{ priceStore.getSinglePrice() }}
  139. </div>
  140. <div class="space-y-3">
  141. <button
  142. @click="purchaseVideo"
  143. class="w-full bg-blue-500 hover:bg-blue-600 text-white py-3 px-4 rounded-lg font-semibold transition shadow-lg hover:shadow-xl flash-animation glow-animation hover:animate-none whitespace-nowrap"
  144. >
  145. 确认购买
  146. </button>
  147. <button
  148. @click="showSinglePurchaseModal = false"
  149. class="w-full text-white/60 hover:text-white/80 py-2 text-sm transition"
  150. >
  151. 取消
  152. </button>
  153. </div>
  154. </div>
  155. </div>
  156. <!-- 会员购买弹窗 -->
  157. <div
  158. v-if="showMembershipPurchaseModal"
  159. class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
  160. @click.self="showMembershipPurchaseModal = false"
  161. >
  162. <div
  163. class="bg-surface border border-white/10 rounded-2xl p-4 w-full max-w-sm mx-4"
  164. >
  165. <h3 class="text-lg font-semibold text-white/90 mb-4 text-center">
  166. 开通会员
  167. </h3>
  168. <!-- 会员套餐选择 -->
  169. <div class="space-y-2 mb-3">
  170. <h4 class="text-sm font-medium text-white/70 mb-2">选择套餐</h4>
  171. <div class="space-y-2">
  172. <label
  173. v-for="plan in membershipPlans"
  174. :key="plan.key"
  175. class="relative cursor-pointer"
  176. >
  177. <input
  178. v-model="selectedPlan"
  179. :value="plan.key"
  180. type="radio"
  181. name="membership-plan"
  182. class="sr-only"
  183. />
  184. <div
  185. class="border-2 rounded-lg p-2 transition-all"
  186. :class="
  187. selectedPlan === plan.key
  188. ? 'border-brand bg-brand/10'
  189. : 'border-white/20 hover:border-white/30'
  190. "
  191. >
  192. <div class="flex justify-between items-center">
  193. <div
  194. class="font-medium text-white/90 text-sm whitespace-nowrap"
  195. >
  196. {{ plan.label }} - {{ plan.duration }}
  197. </div>
  198. <div class="font-semibold text-white/90 text-sm">
  199. {{ plan.price }}
  200. </div>
  201. </div>
  202. </div>
  203. </label>
  204. </div>
  205. </div>
  206. <!-- 支付方式选择 -->
  207. <div class="mb-3">
  208. <h4 class="text-sm font-medium text-white/70 mb-2">支付方式</h4>
  209. <label
  210. class="flex items-center p-2 border border-white/20 rounded-lg cursor-pointer hover:bg-white/5"
  211. >
  212. <input
  213. v-model="selectedPayment"
  214. value="alipay"
  215. type="radio"
  216. name="payment-method"
  217. class="sr-only"
  218. />
  219. <div class="flex items-center">
  220. <div
  221. class="w-6 h-6 bg-blue-500 rounded flex items-center justify-center mr-3"
  222. >
  223. <span class="text-white text-sm font-bold">支</span>
  224. </div>
  225. <span class="text-white/90 text-sm">支付宝</span>
  226. </div>
  227. </label>
  228. </div>
  229. <!-- 操作按钮 -->
  230. <div class="flex gap-2 pt-3 border-t border-white/10">
  231. <button
  232. type="button"
  233. @click="showMembershipPurchaseModal = false"
  234. class="flex-1 px-3 py-2 border border-white/20 text-white/70 rounded-lg hover:bg-white/5 transition text-sm"
  235. >
  236. 取消
  237. </button>
  238. <button
  239. @click="handleMembershipPurchase"
  240. :disabled="!selectedPlan || isPaymentLoading"
  241. class="flex-1 px-3 py-2 bg-brand text-slate-900 rounded-lg hover:bg-brand/90 transition disabled:opacity-50 disabled:cursor-not-allowed text-sm"
  242. >
  243. {{ isPaymentLoading ? "处理中..." : "立即购买" }}
  244. </button>
  245. </div>
  246. </div>
  247. </div>
  248. <!-- 支付等待弹窗 -->
  249. <div
  250. v-if="showPaymentWaitingDialog"
  251. class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
  252. >
  253. <div
  254. class="bg-surface border border-white/10 rounded-2xl p-8 w-full max-w-sm mx-4 text-center"
  255. >
  256. <!-- 加载动画 -->
  257. <div class="mb-6">
  258. <div
  259. class="w-16 h-16 mx-auto border-4 border-white/20 border-t-brand rounded-full animate-spin"
  260. ></div>
  261. </div>
  262. <!-- 等待文字 -->
  263. <h3 class="text-lg font-semibold text-white/90 mb-2">
  264. 正在拉起支付页面,等待支付...
  265. </h3>
  266. <p class="text-sm text-white/60 mb-6">
  267. 请在支付页面完成支付<br />
  268. 支付完成后点击已完成支付
  269. </p>
  270. <!-- 操作按钮 -->
  271. <div class="flex gap-3">
  272. <button
  273. @click="showPaymentWaitingDialog = false"
  274. class="flex-1 px-4 py-2 border border-white/20 text-white/70 rounded-lg hover:bg-white/5 transition"
  275. >
  276. 取消支付
  277. </button>
  278. <button
  279. @click="handleQueryOrder"
  280. class="flex-1 px-4 py-2 bg-brand text-slate-900 rounded-lg hover:bg-brand/90 transition"
  281. >
  282. 已完成支付
  283. </button>
  284. </div>
  285. </div>
  286. </div>
  287. <!-- 单片购买支付等待弹窗 -->
  288. <div
  289. v-if="showSinglePaymentWaitingDialog"
  290. class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
  291. >
  292. <div
  293. class="bg-surface border border-white/10 rounded-2xl p-8 w-full max-w-sm mx-4 text-center"
  294. >
  295. <!-- 加载动画 -->
  296. <div class="mb-6">
  297. <div
  298. class="w-16 h-16 mx-auto border-4 border-white/20 border-t-brand rounded-full animate-spin"
  299. ></div>
  300. </div>
  301. <!-- 等待文字 -->
  302. <h3 class="text-lg font-semibold text-white/90 mb-2">
  303. 正在拉起支付页面,等待支付...
  304. </h3>
  305. <p class="text-sm text-white/60 mb-6">
  306. 请在支付页面完成支付<br />
  307. 支付完成后点击已完成支付
  308. </p>
  309. <!-- 操作按钮 -->
  310. <div class="flex gap-3">
  311. <button
  312. @click="showSinglePaymentWaitingDialog = false"
  313. class="flex-1 px-4 py-2 border border-white/20 text-white/70 rounded-lg hover:bg-white/5 transition"
  314. >
  315. 取消支付
  316. </button>
  317. <button
  318. @click="handleSingleQueryOrder"
  319. class="flex-1 px-4 py-2 bg-brand text-slate-900 rounded-lg hover:bg-brand/90 transition"
  320. >
  321. 已完成支付
  322. </button>
  323. </div>
  324. </div>
  325. </div>
  326. <!-- 错误提示弹窗 -->
  327. <div
  328. v-if="showErrorDialog"
  329. class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
  330. @click.self="showErrorDialog = false"
  331. >
  332. <div
  333. class="bg-surface border border-white/10 rounded-2xl p-6 w-full max-w-sm mx-4 text-center"
  334. >
  335. <!-- 错误图标 -->
  336. <div class="mb-4">
  337. <div
  338. class="w-12 h-12 mx-auto bg-red-500/20 rounded-full flex items-center justify-center"
  339. >
  340. <svg
  341. class="w-6 h-6 text-red-400"
  342. fill="none"
  343. stroke="currentColor"
  344. viewBox="0 0 24 24"
  345. >
  346. <path
  347. stroke-linecap="round"
  348. stroke-linejoin="round"
  349. stroke-width="2"
  350. d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L3.732 16.5c-.77.833.192 2.5 1.732 2.5z"
  351. />
  352. </svg>
  353. </div>
  354. </div>
  355. <!-- 错误信息 -->
  356. <h3 class="text-lg font-semibold text-white/90 mb-2">操作失败</h3>
  357. <p class="text-sm text-white/70 mb-6">
  358. {{ errorMessage }}
  359. </p>
  360. <!-- 确认按钮 -->
  361. <button
  362. @click="showErrorDialog = false"
  363. class="w-full px-4 py-2 bg-brand text-slate-900 rounded-lg hover:bg-brand/90 transition"
  364. >
  365. 确定
  366. </button>
  367. </div>
  368. </div>
  369. <!-- 成功提示弹窗 -->
  370. <div
  371. v-if="showSuccessDialog"
  372. class="fixed inset-0 bg-black/50 flex items-center justify-center z-50"
  373. @click.self="showSuccessDialog = false"
  374. >
  375. <div
  376. class="bg-surface border border-white/10 rounded-2xl p-6 w-full max-w-sm mx-4 text-center"
  377. >
  378. <!-- 成功图标 -->
  379. <div class="mb-4">
  380. <div
  381. class="w-12 h-12 mx-auto bg-green-500/20 rounded-full flex items-center justify-center"
  382. >
  383. <svg
  384. class="w-6 h-6 text-green-400"
  385. fill="none"
  386. stroke="currentColor"
  387. viewBox="0 0 24 24"
  388. >
  389. <path
  390. stroke-linecap="round"
  391. stroke-linejoin="round"
  392. stroke-width="2"
  393. d="M5 13l4 4L19 7"
  394. />
  395. </svg>
  396. </div>
  397. </div>
  398. <!-- 成功信息 -->
  399. <h3 class="text-lg font-semibold text-white/90 mb-2">操作成功</h3>
  400. <p class="text-sm text-white/70 mb-6">
  401. {{ successMessage }}
  402. </p>
  403. <!-- 确认按钮 -->
  404. <button
  405. @click="showSuccessDialog = false"
  406. class="w-full px-4 py-2 bg-brand text-slate-900 rounded-lg hover:bg-brand/90 transition"
  407. >
  408. 确定
  409. </button>
  410. </div>
  411. </div>
  412. <!-- 视频信息区域 -->
  413. <div class="space-y-6">
  414. <!-- 视频标题和基本信息 -->
  415. <div class="space-y-3">
  416. <h1 class="text-xl font-semibold text-white leading-tight">
  417. {{ videoInfo.name || "视频标题" }}
  418. </h1>
  419. <div class="flex items-center gap-4 text-sm text-white/60">
  420. <div class="flex items-center gap-1">
  421. <svg
  422. class="w-4 h-4"
  423. fill="none"
  424. stroke="currentColor"
  425. viewBox="0 0 24 24"
  426. >
  427. <path
  428. stroke-linecap="round"
  429. stroke-linejoin="round"
  430. stroke-width="2"
  431. d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
  432. />
  433. </svg>
  434. <span>{{ formatDuration(videoInfo.duration) }}</span>
  435. </div>
  436. <div class="flex items-center gap-1">
  437. <svg
  438. class="w-4 h-4"
  439. fill="none"
  440. stroke="currentColor"
  441. viewBox="0 0 24 24"
  442. >
  443. <path
  444. stroke-linecap="round"
  445. stroke-linejoin="round"
  446. stroke-width="2"
  447. d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
  448. />
  449. <path
  450. stroke-linecap="round"
  451. stroke-linejoin="round"
  452. stroke-width="2"
  453. d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
  454. />
  455. </svg>
  456. <span>{{ formatNumber(videoInfo.view) }} 次观看</span>
  457. </div>
  458. <div class="flex items-center gap-1">
  459. <svg
  460. class="w-4 h-4"
  461. fill="none"
  462. stroke="currentColor"
  463. viewBox="0 0 24 24"
  464. >
  465. <path
  466. stroke-linecap="round"
  467. stroke-linejoin="round"
  468. stroke-width="2"
  469. d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
  470. />
  471. </svg>
  472. <span>{{ formatNumber(videoInfo.like) }} 点赞</span>
  473. </div>
  474. </div>
  475. </div>
  476. <!-- 标签信息 -->
  477. <!-- <div
  478. v-if="videoInfo.taginfo && videoInfo.taginfo.length > 0"
  479. class="space-y-3"
  480. >
  481. <h3 class="text-sm font-medium text-white/80">标签</h3>
  482. <div class="flex flex-wrap gap-2">
  483. <span
  484. v-for="tag in videoInfo.taginfo"
  485. :key="tag.hash"
  486. class="px-3 py-1.5 rounded-full bg-white/5 border border-white/10 text-xs text-white/70 hover:bg-white/10 hover:text-white transition"
  487. >
  488. {{ tag.name }}
  489. </span>
  490. </div>
  491. </div> -->
  492. <!-- 相关推荐 -->
  493. <div v-if="relatedVideos.length > 0" class="space-y-4">
  494. <h3 class="text-sm font-medium text-white/80">相关推荐</h3>
  495. <div class="grid grid-cols-2 gap-3">
  496. <article
  497. v-for="video in relatedVideos.slice(0, 12)"
  498. :key="video.id"
  499. @click="playVideo(video)"
  500. class="group rounded-xl overflow-hidden bg-white/5 border border-white/10 cursor-pointer hover:bg-white/10 transition"
  501. >
  502. <!-- 横屏封面 -->
  503. <div class="aspect-[16/9] relative">
  504. <VideoProcessor
  505. :cover-url="video.cover"
  506. :alt="video.name"
  507. cover-class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
  508. />
  509. <div
  510. class="absolute bottom-2 right-2 bg-black/70 text-white text-xs px-2 py-1 rounded"
  511. >
  512. {{ formatDuration(video.duration) }}
  513. </div>
  514. </div>
  515. <!-- 视频信息 -->
  516. <div class="p-3">
  517. <h4 class="text-sm font-medium text-white/90 line-clamp-2 mb-1">
  518. {{ video.name }}
  519. </h4>
  520. <p class="text-xs text-white/50 truncate">
  521. {{ formatNumber(video.view) }} 次观看 ·
  522. {{ formatNumber(video.like) }} 点赞
  523. </p>
  524. <!-- 标签信息(移动端隐藏) -->
  525. <div
  526. v-if="video.taginfo && video.taginfo.length > 0"
  527. class="hidden sm:flex flex-wrap gap-1 mt-2"
  528. >
  529. <span
  530. v-for="tag in video.taginfo.slice(0, 2)"
  531. :key="tag.hash"
  532. class="px-2 py-0.5 rounded-full bg-white/5 border border-white/10 text-xs text-white/70"
  533. >
  534. {{ tag.name }}
  535. </span>
  536. <span
  537. v-if="video.taginfo.length > 2"
  538. class="px-2 py-0.5 rounded-full bg-white/5 border border-white/10 text-xs text-white/50"
  539. >
  540. +{{ video.taginfo.length - 2 }}
  541. </span>
  542. </div>
  543. </div>
  544. </article>
  545. </div>
  546. </div>
  547. </div>
  548. </section>
  549. </template>
  550. <script setup lang="ts">
  551. import { ref, onMounted, onUnmounted, computed, watch } from "vue";
  552. import { useRoute, useRouter } from "vue-router";
  553. import {
  554. searchVideoByTags,
  555. getVideoDetail,
  556. purchaseSingle,
  557. purchaseMember,
  558. userQueryOrder,
  559. checkSinglePurchase,
  560. } from "@/services/api";
  561. import VideoProcessor from "@/components/VideoProcessor.vue";
  562. import { useUserStore } from "@/store/user";
  563. import { usePriceStore } from "@/store/price";
  564. import { VipLevel, canWatchFullVideo, getTrialDuration } from "@/types/vip";
  565. // 路由相关
  566. const route = useRoute();
  567. const router = useRouter();
  568. // 用户状态
  569. const userStore = useUserStore();
  570. const priceStore = usePriceStore();
  571. // 视频播放器引用(现在由 VideoProcessor 组件管理)
  572. const videoPlayer = ref<HTMLVideoElement>();
  573. const videoProcessorRef = ref<any>();
  574. // 视频信息
  575. const videoInfo = ref<any>({
  576. id: "",
  577. name: "",
  578. cover: "",
  579. m3u8: "",
  580. duration: 0,
  581. view: 0,
  582. like: 0,
  583. time: 0,
  584. taginfo: [],
  585. });
  586. // 相关视频
  587. const relatedVideos = ref<any[]>([]);
  588. // 状态管理
  589. const showTrialEndModal = ref(false);
  590. const showMembershipPurchaseModal = ref(false);
  591. const showSinglePurchaseModal = ref(false);
  592. const isTrialMode = ref(false);
  593. // 单片购买状态
  594. const isSinglePurchased = ref(false);
  595. // 使用动态价格配置
  596. const membershipPlans = computed(() => priceStore.getMembershipPlans);
  597. const selectedPlan = ref("");
  598. const selectedPayment = ref("alipay");
  599. const isPaymentLoading = ref(false);
  600. // 支付等待相关
  601. const showPaymentWaitingDialog = ref(false);
  602. const currentOrderNo = ref("");
  603. // 提示弹窗相关
  604. const showSuccessDialog = ref(false);
  605. const showErrorDialog = ref(false);
  606. const successMessage = ref("");
  607. const errorMessage = ref("");
  608. // 单片购买支付等待相关
  609. const showSinglePaymentWaitingDialog = ref(false);
  610. const singleCurrentOrderNo = ref("");
  611. // 检测是否为夸克浏览器
  612. const isQuarkBrowser = () => {
  613. const ua = navigator.userAgent.toLowerCase();
  614. return ua.includes("quark");
  615. };
  616. // 显示成功/错误提示的函数
  617. const showSuccess = (message: string) => {
  618. successMessage.value = message;
  619. showSuccessDialog.value = true;
  620. // 夸克浏览器自动滚动到底部
  621. if (isQuarkBrowser()) {
  622. setTimeout(() => {
  623. window.scrollTo({
  624. top: document.documentElement.scrollHeight,
  625. behavior: "smooth",
  626. });
  627. }, 100);
  628. }
  629. };
  630. const showError = (message: string) => {
  631. errorMessage.value = message;
  632. showErrorDialog.value = true;
  633. // 夸克浏览器自动滚动到底部
  634. if (isQuarkBrowser()) {
  635. setTimeout(() => {
  636. window.scrollTo({
  637. top: document.documentElement.scrollHeight,
  638. behavior: "smooth",
  639. });
  640. }, 100);
  641. }
  642. };
  643. // 生成设备标识
  644. const generateMacAddress = (): string => {
  645. const hex = "0123456789ABCDEF";
  646. let mac = "";
  647. for (let i = 0; i < 6; i++) {
  648. if (i > 0) mac += ":";
  649. mac += hex[Math.floor(Math.random() * 16)];
  650. mac += hex[Math.floor(Math.random() * 16)];
  651. }
  652. return mac;
  653. };
  654. const device = generateMacAddress();
  655. // Safari兼容性处理:打开支付页面
  656. const openPaymentPage = (url: string) => {
  657. // 检测是否为Safari浏览器
  658. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  659. if (isSafari) {
  660. // Safari浏览器
  661. setTimeout(() => window.open(url, "_blank"));
  662. // window.location.href = url;
  663. } else {
  664. // 其他浏览器:正常使用window.open
  665. window.open(url, "_blank");
  666. }
  667. };
  668. // 计算属性
  669. const currentVipLevel = computed(() => userStore.getVipLevel());
  670. const isGuestOrFree = computed(() => !canWatchFullVideo(currentVipLevel.value));
  671. const trialDuration = computed(() => getTrialDuration(priceStore));
  672. // 参考Account.vue的用户类型判断
  673. const isGuest = computed(() => {
  674. return userStore.userInfo?.vipLevel === "guest";
  675. });
  676. const isVip = computed(() => {
  677. const level = userStore.userInfo?.vipLevel;
  678. return level && level !== VipLevel.GUEST && level !== VipLevel.FREE;
  679. });
  680. // VideoProcessor 事件处理
  681. const onCoverLoaded = (url: string) => {
  682. // 封面加载完成
  683. };
  684. const onVideoLoaded = (url: string) => {
  685. // 视频加载完成
  686. };
  687. const onVideoProcessorError = (error: string) => {
  688. console.error("VideoProcessor 错误:", error);
  689. };
  690. const onVideoProcessorRetry = () => {
  691. // VideoProcessor 重试
  692. };
  693. const onVideoPlay = () => {
  694. // 如果是guest或free用户且还没有开始试看,且未购买当前视频,则开始试看
  695. if (isGuestOrFree.value && !isTrialMode.value && !isSinglePurchased.value) {
  696. startTrial();
  697. }
  698. };
  699. // 监听视频播放进度
  700. const onVideoTimeUpdate = () => {
  701. if (isGuestOrFree.value && isTrialMode.value) {
  702. const video = document.querySelector("video");
  703. if (video && video.currentTime > trialDuration.value) {
  704. // 超过试看时间,停止播放并显示购买弹窗
  705. video.pause();
  706. // 将视频时间重置到试看结束时间
  707. video.currentTime = trialDuration.value;
  708. // 停止HLS加载
  709. if (videoProcessorRef.value) {
  710. videoProcessorRef.value.stopHlsLoading();
  711. }
  712. showTrialEndModal.value = true;
  713. }
  714. }
  715. };
  716. // 监听视频时间变化(包括拖拽进度条)
  717. const onVideoSeeking = () => {
  718. if (isGuestOrFree.value && isTrialMode.value) {
  719. const video = document.querySelector("video");
  720. if (video && video.currentTime > trialDuration.value) {
  721. // 如果拖拽到超过试看时间,强制回到试看结束时间
  722. video.currentTime = trialDuration.value;
  723. }
  724. }
  725. };
  726. // 格式化时长
  727. const formatDuration = (duration: string | number): string => {
  728. const seconds = parseInt(String(duration));
  729. const minutes = Math.floor(seconds / 60);
  730. const remainingSeconds = seconds % 60;
  731. return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`;
  732. };
  733. // 格式化数字
  734. const formatNumber = (num: string | number): string => {
  735. const n = parseInt(String(num));
  736. if (n >= 10000) {
  737. return `${(n / 10000).toFixed(1)}万`;
  738. }
  739. return n.toString();
  740. };
  741. // 返回上一页
  742. const goBack = () => {
  743. // 使用router.back()返回上一页,而不是直接导航到主页
  744. // 这样可以确保按照浏览历史顺序返回
  745. router.back();
  746. };
  747. // 播放视频
  748. const playVideo = (video: any) => {
  749. const vipLevel = userStore.getVipLevel();
  750. if (vipLevel === VipLevel.GUEST || vipLevel === VipLevel.FREE) {
  751. // guest和free用户通过URL参数传递cover和m3u8,同时包含视频ID
  752. router.push({
  753. name: "VideoPlayer",
  754. params: { id: video.id },
  755. query: {
  756. cover: video.cover,
  757. m3u8: video.m3u8,
  758. name: video.name,
  759. duration: video.duration,
  760. view: video.view,
  761. like: video.like,
  762. },
  763. });
  764. } else {
  765. // 其他VIP用户正常调用详情接口
  766. router.push({
  767. name: "VideoPlayer",
  768. params: { id: video.id },
  769. });
  770. }
  771. // 滚动到页面顶端
  772. window.scrollTo({
  773. top: 0,
  774. behavior: "smooth",
  775. });
  776. };
  777. // 开始试看
  778. const startTrial = () => {
  779. isTrialMode.value = true;
  780. };
  781. // 处理顶部会员购买按钮点击
  782. const handleMembershipClick = () => {
  783. showMembershipPurchaseModal.value = true;
  784. // 夸克浏览器自动滚动到底部
  785. if (isQuarkBrowser()) {
  786. setTimeout(() => {
  787. window.scrollTo({
  788. top: document.documentElement.scrollHeight,
  789. behavior: "smooth",
  790. });
  791. }, 100);
  792. }
  793. };
  794. // 处理顶部单片购买按钮点击
  795. const handleSinglePurchaseClick = () => {
  796. showSinglePurchaseModal.value = true;
  797. // 夸克浏览器自动滚动到底部
  798. if (isQuarkBrowser()) {
  799. setTimeout(() => {
  800. window.scrollTo({
  801. top: document.documentElement.scrollHeight,
  802. behavior: "smooth",
  803. });
  804. }, 100);
  805. }
  806. };
  807. // 购买会员
  808. const purchaseMembership = () => {
  809. // 关闭试看结束弹窗
  810. showTrialEndModal.value = false;
  811. // 打开会员购买弹窗
  812. showMembershipPurchaseModal.value = true;
  813. // 夸克浏览器自动滚动到底部
  814. if (isQuarkBrowser()) {
  815. setTimeout(() => {
  816. window.scrollTo({
  817. top: document.documentElement.scrollHeight,
  818. behavior: "smooth",
  819. });
  820. }, 100);
  821. }
  822. };
  823. // 处理会员购买
  824. const handleMembershipPurchase = async () => {
  825. if (!selectedPlan.value) {
  826. showError("请选择会员套餐");
  827. return;
  828. }
  829. isPaymentLoading.value = true;
  830. try {
  831. const response = await purchaseMember(
  832. userStore.userInfo.id,
  833. selectedPlan.value
  834. );
  835. if (response.code === 1) {
  836. // 保存订单号
  837. currentOrderNo.value = response.out_trade_no;
  838. // 关闭购买弹窗
  839. showMembershipPurchaseModal.value = false;
  840. // Safari兼容性处理:使用多种方式打开支付页面
  841. // openPaymentPage(response.code_url);
  842. setTimeout(() => window.open(response.code_url, "_blank"));
  843. // 显示支付等待弹窗
  844. showPaymentWaitingDialog.value = true;
  845. // 重置选择
  846. selectedPlan.value = "";
  847. } else {
  848. showError(`支付失败: ${response.msg || "未知错误"}`);
  849. }
  850. } catch (error) {
  851. console.error("购买会员失败", error);
  852. showError("购买失败,请重试");
  853. } finally {
  854. isPaymentLoading.value = false;
  855. }
  856. };
  857. // 查询订单状态
  858. const handleQueryOrder = async () => {
  859. if (!currentOrderNo.value) {
  860. showError("没有找到订单信息");
  861. return;
  862. }
  863. try {
  864. const response = await userQueryOrder(currentOrderNo.value);
  865. if (response.status === 1) {
  866. // 支付成功
  867. await userStore.sync();
  868. showPaymentWaitingDialog.value = false;
  869. showSuccess("会员购买成功!");
  870. currentOrderNo.value = "";
  871. } else {
  872. showError(response.msg || "会员购买失败");
  873. }
  874. } catch (error) {
  875. console.error("查询订单状态失败:", error);
  876. showError("会员购买失败,请重试");
  877. }
  878. };
  879. // 查询单片购买订单状态
  880. const handleSingleQueryOrder = async () => {
  881. if (!singleCurrentOrderNo.value) {
  882. showError("没有找到订单信息");
  883. return;
  884. }
  885. try {
  886. // 使用视频信息的真实ID查询订单
  887. const response = await userQueryOrder(
  888. singleCurrentOrderNo.value,
  889. videoInfo.value.id
  890. );
  891. if (response.status === 1) {
  892. // 支付成功
  893. await userStore.sync();
  894. showSinglePaymentWaitingDialog.value = false;
  895. showSuccess("视频购买成功!");
  896. singleCurrentOrderNo.value = "";
  897. // 重新检查购买状态(已完成支付时的检查)
  898. await checkVideoPurchaseStatus();
  899. } else {
  900. showError(response.msg || "视频购买失败");
  901. }
  902. } catch (error) {
  903. console.error("查询单片购买订单状态失败:", error);
  904. showError("视频购买失败,请重试");
  905. }
  906. };
  907. // 单独购买本片
  908. const purchaseVideo = async () => {
  909. // 夸克浏览器自动滚动到底部
  910. if (isQuarkBrowser()) {
  911. setTimeout(() => {
  912. window.scrollTo({
  913. top: document.documentElement.scrollHeight,
  914. behavior: "smooth",
  915. });
  916. }, 100);
  917. }
  918. try {
  919. // 使用视频信息的真实ID
  920. if (!videoInfo.value.id || videoInfo.value.id === "unknown") {
  921. showError("未找到视频资源ID");
  922. return;
  923. }
  924. const response = await purchaseSingle(
  925. userStore.userInfo.id,
  926. videoInfo.value.id
  927. );
  928. if (response.code === 1) {
  929. // 保存订单号
  930. singleCurrentOrderNo.value = response.out_trade_no;
  931. // 关闭弹窗
  932. showTrialEndModal.value = false;
  933. showSinglePurchaseModal.value = false;
  934. // Safari兼容性处理:使用多种方式打开支付页面
  935. // openPaymentPage(response.code_url);
  936. setTimeout(() => window.open(response.code_url, "_blank"));
  937. // 显示支付等待弹窗
  938. showSinglePaymentWaitingDialog.value = true;
  939. console.log("单片购买订单创建成功:", response.out_trade_no);
  940. } else {
  941. console.error("单片购买失败:", response.msg);
  942. showError(`购买失败: ${response.msg || "未知错误"}`);
  943. }
  944. } catch (error) {
  945. console.error("单片购买异常:", error);
  946. showError("购买失败,请重试");
  947. }
  948. };
  949. // 检查用户是否已购买当前视频
  950. const checkVideoPurchaseStatus = async () => {
  951. if (!videoInfo.value.id || videoInfo.value.id === "unknown") {
  952. return;
  953. }
  954. try {
  955. const response = await checkSinglePurchase(videoInfo.value.id);
  956. isSinglePurchased.value = response === true;
  957. } catch (error) {
  958. console.error("检查视频购买状态失败:", error);
  959. isSinglePurchased.value = false;
  960. }
  961. };
  962. // 加载视频信息
  963. const loadVideoInfo = async () => {
  964. const vipLevel = userStore.getVipLevel();
  965. // 获取视频ID(无论什么用户类型都使用相同的获取方式)
  966. const videoId = route.params.id || route.query.id;
  967. // 如果是guest或free用户,从query参数获取视频信息
  968. if (vipLevel === VipLevel.GUEST || vipLevel === VipLevel.FREE) {
  969. const { cover, m3u8, name, duration, view, like } = route.query;
  970. if (cover && m3u8) {
  971. videoInfo.value = {
  972. id: videoId || "unknown",
  973. name: name || "试看视频",
  974. cover: cover as string,
  975. m3u8: m3u8 as string,
  976. duration: parseInt(duration as string) || 0,
  977. view: parseInt(view as string) || 0,
  978. like: parseInt(like as string) || 0,
  979. time: 0,
  980. taginfo: [],
  981. };
  982. // 设置页面标题
  983. document.title = `${videoInfo.value.name} - 试看`;
  984. return;
  985. }
  986. }
  987. // 其他情况,通过API获取视频详情
  988. if (videoId) {
  989. try {
  990. // 通过API获取视频详情
  991. const response = await getVideoDetail(device, String(videoId));
  992. if (response.status === 0 && response.data) {
  993. const data = response.data;
  994. videoInfo.value = {
  995. id: data.id || videoId,
  996. name: data.name || `视频 ${videoId}`,
  997. cover: data.cover || "",
  998. m3u8: data.m3u8 || "",
  999. duration: data.duration || 0,
  1000. view: data.view || 0,
  1001. like: data.like || 0,
  1002. time: data.time || 0,
  1003. taginfo: data.tags
  1004. ? data.tags
  1005. .split(",")
  1006. .map((tag: string) => ({ name: tag.trim(), hash: tag.trim() }))
  1007. : [],
  1008. };
  1009. // 设置页面标题
  1010. document.title = `${videoInfo.value.name} - 视频播放`;
  1011. } else {
  1012. console.error("获取视频详情失败-1:", response.msg);
  1013. // 设置默认值
  1014. videoInfo.value = {
  1015. id: videoId,
  1016. name: `视频 ${videoId}`,
  1017. cover: "",
  1018. m3u8: "",
  1019. duration: 0,
  1020. view: 0,
  1021. like: 0,
  1022. time: 0,
  1023. taginfo: [],
  1024. };
  1025. }
  1026. } catch (error) {
  1027. console.error("获取视频详情失败-2:", error);
  1028. // 设置默认值
  1029. videoInfo.value = {
  1030. id: videoId,
  1031. name: `视频 ${videoId}`,
  1032. cover: "",
  1033. m3u8: "",
  1034. duration: 0,
  1035. view: 0,
  1036. like: 0,
  1037. time: 0,
  1038. taginfo: [],
  1039. };
  1040. }
  1041. } else {
  1042. console.error("未找到视频ID");
  1043. }
  1044. };
  1045. // 加载相关视频
  1046. const loadRelatedVideos = async () => {
  1047. try {
  1048. // 获取当前视频的标签
  1049. const currentVideoTags = videoInfo.value.taginfo || [];
  1050. if (currentVideoTags.length > 0) {
  1051. // 随机选择一个标签
  1052. const randomTag =
  1053. currentVideoTags[Math.floor(Math.random() * currentVideoTags.length)];
  1054. // 生成1-10之间的随机页码
  1055. const randomPage = Math.floor(Math.random() * 10) + 1;
  1056. // 获取12个该标签下的最热视频
  1057. const response = await searchVideoByTags(
  1058. device,
  1059. randomPage,
  1060. 12,
  1061. randomTag.hash,
  1062. "long",
  1063. "view"
  1064. );
  1065. if (response.status === 0 && response.data?.list) {
  1066. // 过滤掉当前视频
  1067. relatedVideos.value = response.data.list
  1068. .filter((video: any) => video.id !== videoInfo.value.id)
  1069. .slice(0, 12);
  1070. }
  1071. } else {
  1072. // 如果没有标签,则获取全局最热视频
  1073. const randomPage = Math.floor(Math.random() * 10) + 1;
  1074. const response = await searchVideoByTags(
  1075. device,
  1076. randomPage,
  1077. 12,
  1078. undefined,
  1079. "long",
  1080. "view"
  1081. );
  1082. if (response.status === 0 && response.data?.list) {
  1083. relatedVideos.value = response.data.list
  1084. .filter((video: any) => video.id !== videoInfo.value.id)
  1085. .slice(0, 12);
  1086. }
  1087. }
  1088. } catch (error) {
  1089. console.error("加载相关视频失败:", error);
  1090. }
  1091. };
  1092. // 监听路由参数变化
  1093. watch(
  1094. () => route.params.id,
  1095. async (newId, oldId) => {
  1096. if (newId && newId !== oldId) {
  1097. // 停止当前视频播放
  1098. if (videoProcessorRef.value) {
  1099. videoProcessorRef.value.stopVideo();
  1100. }
  1101. // 重置购买状态
  1102. isSinglePurchased.value = false;
  1103. await loadVideoInfo();
  1104. await loadRelatedVideos();
  1105. // 检查购买状态(首页点击进入视频时的检查)
  1106. const vipLevel = userStore.getVipLevel();
  1107. if (
  1108. vipLevel !== VipLevel.GUEST &&
  1109. videoInfo.value.id &&
  1110. videoInfo.value.id !== "unknown"
  1111. ) {
  1112. await checkVideoPurchaseStatus();
  1113. }
  1114. } else if (oldId === undefined && newId) {
  1115. await loadVideoInfo();
  1116. await loadRelatedVideos();
  1117. const vipLevel = userStore.getVipLevel();
  1118. if (
  1119. vipLevel !== VipLevel.GUEST &&
  1120. videoInfo.value.id &&
  1121. videoInfo.value.id !== "unknown"
  1122. ) {
  1123. await checkVideoPurchaseStatus();
  1124. }
  1125. }
  1126. },
  1127. { immediate: true }
  1128. );
  1129. onMounted(async () => {
  1130. // 加载价格配置
  1131. if (!priceStore.isPriceConfigLoaded) {
  1132. await priceStore.fetchPriceConfig();
  1133. }
  1134. });
  1135. onUnmounted(() => {
  1136. // 组件卸载时的清理工作
  1137. });
  1138. </script>
  1139. <style scoped>
  1140. /* 视频容器样式 */
  1141. .video-container {
  1142. position: relative;
  1143. }
  1144. /* 自定义闪烁动画 */
  1145. @keyframes flash {
  1146. 0%,
  1147. 50%,
  1148. 100% {
  1149. opacity: 1;
  1150. transform: scale(1);
  1151. }
  1152. 25%,
  1153. 75% {
  1154. opacity: 0.8;
  1155. transform: scale(1.05);
  1156. }
  1157. }
  1158. @keyframes glow {
  1159. 0%,
  1160. 100% {
  1161. box-shadow: 0 0 5px rgba(59, 130, 246, 0.5),
  1162. 0 0 10px rgba(59, 130, 246, 0.3);
  1163. }
  1164. 50% {
  1165. box-shadow: 0 0 20px rgba(59, 130, 246, 0.8),
  1166. 0 0 30px rgba(59, 130, 246, 0.6);
  1167. }
  1168. }
  1169. .flash-animation {
  1170. animation: flash 2s ease-in-out infinite;
  1171. }
  1172. .glow-animation {
  1173. animation: glow 2s ease-in-out infinite;
  1174. }
  1175. /* 移动端全屏样式 */
  1176. @media screen and (max-width: 768px) {
  1177. video {
  1178. /* 强制横屏全屏 */
  1179. object-fit: contain;
  1180. }
  1181. /* 全屏时的样式 */
  1182. video:fullscreen {
  1183. width: 100vw;
  1184. height: 100vh;
  1185. object-fit: contain;
  1186. background: black;
  1187. }
  1188. /* WebKit全屏样式 */
  1189. video:-webkit-full-screen {
  1190. width: 100vw;
  1191. height: 100vh;
  1192. object-fit: contain;
  1193. background: black;
  1194. }
  1195. /* Mozilla全屏样式 */
  1196. video:-moz-full-screen {
  1197. width: 100vw;
  1198. height: 100vh;
  1199. object-fit: contain;
  1200. background: black;
  1201. }
  1202. /* MS全屏样式 */
  1203. video:-ms-fullscreen {
  1204. width: 100vw;
  1205. height: 100vh;
  1206. object-fit: contain;
  1207. background: black;
  1208. }
  1209. }
  1210. </style>