living.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_live = require("../../api/live.js");
  4. require("../../api/order.js");
  5. const api_home = require("../../api/home.js");
  6. const common_assets = require("../../common/assets.js");
  7. var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket";
  8. var pingpangTimes = null;
  9. var isSocketOpen = false;
  10. var socket = null;
  11. const _sfc_main = {
  12. data() {
  13. return {
  14. boxHeight: 300,
  15. //小黄车高度
  16. isFollow: true,
  17. liveViewData: {},
  18. liveViewers: [],
  19. //观众
  20. likeName: 0,
  21. hlsPlayer: null,
  22. // HLS播放器实例,
  23. livingUrl: "",
  24. products: {},
  25. store: {},
  26. orderUser: {},
  27. //正在购买
  28. userType: 0,
  29. timestamp: "",
  30. liveId: null,
  31. // userId: uni.getStorageSync("userInfo.userId"),
  32. livedata: {},
  33. codeimg: "",
  34. placeholderText: "说点什么...",
  35. isZoom: false,
  36. //点赞按钮控制是否放大
  37. userinfo: "",
  38. //用户信息
  39. // path: 'http://192.168.10.166/dev-api', //余红奇
  40. // path: 'http://v56c9b8e.natappfree.cc', //余红奇
  41. path: "live.test.ylrztop.com/prod-api",
  42. //余红奇
  43. // path: 'http://192.168.10.170/dev-api', //陈果
  44. value: "",
  45. talkdisabled: false,
  46. //输入框是否禁用
  47. autoplay: false,
  48. //视频自动播放
  49. showadd: false,
  50. talklist: [],
  51. scrollIntoView: "",
  52. bufferRate: 0,
  53. //视频缓冲时间
  54. playDuration: 0,
  55. //视频播放时间
  56. videoContext: "",
  57. thistime: common_vendor.index.$u.timeFormat(/* @__PURE__ */ new Date(), "yyyy-mm-dd hh:MM:ss"),
  58. upDown: true,
  59. //是否视频显示隐藏
  60. isLongPress: false,
  61. // 是否长按
  62. timeout: null,
  63. // 计时器
  64. showWelcomeMessage: false,
  65. isSubmit: false,
  66. messageContent: "",
  67. showziliao: false,
  68. isScreen: true,
  69. showAnswer: false,
  70. //展示答题
  71. Answerlistall: {},
  72. //所有题目
  73. answerlist: {},
  74. //当前题目
  75. answerfrist: 0,
  76. //当前选择
  77. checkboxValue: [],
  78. //多选数据
  79. checkboxFormValue: "",
  80. //多选数据
  81. allAnswerLists: [],
  82. // 新增:存储所有题目列表
  83. showAnswerred: false,
  84. //展示红包答题
  85. answerbtn: false,
  86. //答题按钮弹窗
  87. redallAnswerLists: [],
  88. //储存所有红包答题列表
  89. redanswerAll: [],
  90. //红包当前题目
  91. redanswerList: [],
  92. //红包答题列表
  93. redanswertips: [],
  94. //红包答题提示
  95. shopping: false,
  96. //小黄车弹窗
  97. scrollTop: 0,
  98. //弹幕
  99. old: {
  100. scrollTop: 0
  101. },
  102. liveData: {}
  103. //直播间点赞、关注、在线人数数据
  104. // shopList: [{
  105. // title: '史士昊老师四神汤健脾消食疗法',
  106. // details: '看它来喘口气,小小震撼,',
  107. // people: '45708 '
  108. // },{
  109. // title: '史士昊老师四神汤健脾消食疗法',
  110. // details: '看它来喘口气,小小震撼,',
  111. // people: '45708 '
  112. // }],
  113. // chatList: [{
  114. // lable: '达人',
  115. // name: '锅巴',
  116. // txt: '中医调节身体确实'
  117. // },
  118. // {
  119. // lable: '',
  120. // name: '从芯开始',
  121. // txt: '来了'
  122. // }
  123. // {
  124. // lable: '',
  125. // name: '北京的帅小伙:',
  126. // txt: '来了来了,上茶'
  127. // },
  128. // {
  129. // lable: '',
  130. // name: '萍萍',
  131. // txt: '来了'
  132. // }
  133. // ]
  134. };
  135. },
  136. onLoad(options) {
  137. if (options.liveId) {
  138. this.liveId = options.liveId;
  139. console.log("接收到的liveId:", this.liveId);
  140. }
  141. },
  142. computed: {
  143. filteredViewers() {
  144. return this.liveViewers.slice(0, 3);
  145. }
  146. },
  147. // computed: {
  148. // userId() {
  149. // return this.$store.state.user.userId
  150. // }
  151. // },
  152. mounted() {
  153. this.getliveViewData();
  154. this.intervalId = setInterval(() => {
  155. this.getliveViewData();
  156. }, 60 * 1e3);
  157. this.getliveOrder();
  158. this.getliveStore();
  159. this.getliveUser();
  160. this.initTime();
  161. this.initSocket();
  162. var that = this;
  163. common_vendor.index.$on("initSocket", () => {
  164. that.initSocket();
  165. });
  166. common_vendor.index.$on("sendMsg", (item) => {
  167. that.sendMsg(item);
  168. });
  169. common_vendor.index.$on("closeWebSocket", () => {
  170. that.closeWebSocket();
  171. });
  172. this.getEWechatSdk();
  173. this.getliving();
  174. this.gettalklist();
  175. this.userinfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  176. },
  177. onReady: function(res) {
  178. this.videoContext = common_vendor.index.createVideoContext("myVideo");
  179. },
  180. onUnload() {
  181. if (this.hlsPlayer) {
  182. this.hlsPlayer.destroy();
  183. this.hlsPlayer = null;
  184. }
  185. },
  186. methods: {
  187. goStore() {
  188. common_vendor.index.navigateTo({
  189. url: "/pages_shop/store?liveId=" + this.liveId
  190. });
  191. },
  192. // 去订单列表
  193. goOrderList() {
  194. common_vendor.index.navigateTo({
  195. url: "/pages_shop/order"
  196. });
  197. },
  198. // 初始化HLS播放器
  199. initHlsPlayer() {
  200. if (common_vendor.Hls.isSupported() && this.livingUrl) {
  201. const video = document.getElementById("myVideo");
  202. if (video) {
  203. this.hlsPlayer = new common_vendor.Hls();
  204. this.hlsPlayer.loadSource(this.livingUrl);
  205. this.hlsPlayer.attachMedia(video);
  206. this.hlsPlayer.on(common_vendor.Hls.Events.MANIFEST_PARSED, () => {
  207. video.play();
  208. });
  209. }
  210. }
  211. },
  212. // 视频错误处理
  213. videoError(e) {
  214. console.error("视频播放错误:", e.detail.errMsg);
  215. if (this.livingUrl) {
  216. setTimeout(() => {
  217. this.videoContext.play();
  218. }, 2e3);
  219. }
  220. },
  221. getliving() {
  222. const param = {
  223. id: this.liveId
  224. };
  225. api_home.getlive(param).then((res) => {
  226. if (res.code == 200) {
  227. this.livedata = res.data;
  228. this.livingUrl = res.data.livingUrl;
  229. if (this.livingUrl && this.livingUrl.indexOf(".m3u8") > -1) {
  230. this.$nextTick(() => {
  231. if (this.videoContext) {
  232. this.videoContext.play();
  233. }
  234. });
  235. } else {
  236. if (this.livedata.liveType == 1) {
  237. this.autoplay = true;
  238. this.livingUrl = res.videoUrl;
  239. this.videoContext.seek(this.livedata.nowDuration);
  240. } else if (this.livedata.liveType == 2) {
  241. this.autoplay = true;
  242. this.getLiveinformation();
  243. } else {
  244. this.autoplay = false;
  245. this.placeholderText = "直播开始才能发言讨论";
  246. this.talkdisabled = true;
  247. }
  248. }
  249. } else {
  250. common_vendor.index.showToast({
  251. title: res.msg,
  252. icon: "none",
  253. duration: 2e3
  254. });
  255. }
  256. });
  257. },
  258. maskString(str, maskChar = "*") {
  259. if (!str)
  260. return "";
  261. const strVal = String(str);
  262. return strVal.split("").map((char, index) => index === 0 ? char : maskChar).join("");
  263. },
  264. getPureDecimal(num, precision = 6) {
  265. const decimalPart = Math.abs(num).toFixed(precision).split(".")[1];
  266. return (decimalPart == null ? void 0 : decimalPart.replace(/0+$/, "")) || "";
  267. },
  268. // 返回上一个页面并关闭WebSocket
  269. goBack() {
  270. common_vendor.index.navigateBack();
  271. closeWebSocket();
  272. },
  273. // // 收藏商品
  274. // collectProducts(){
  275. // },
  276. //直播间点赞、关注、在线人数数据
  277. getliveViewData() {
  278. api_live.getLiveViewData(this.liveId).then(
  279. (res) => {
  280. if (res.code == 200) {
  281. this.liveViewData = res;
  282. } else {
  283. common_vendor.index.showToast({
  284. title: res.msg,
  285. icon: "none"
  286. });
  287. }
  288. },
  289. (rej) => {
  290. }
  291. );
  292. },
  293. //正在购买
  294. getliveOrder() {
  295. api_live.liveOrderUser(this.liveId).then(
  296. (res) => {
  297. if (res.code == 200) {
  298. console.log("正在购买>>>>", res);
  299. this.orderUser = res;
  300. } else {
  301. common_vendor.index.showToast({
  302. title: res.msg,
  303. icon: "none"
  304. });
  305. }
  306. },
  307. (rej) => {
  308. }
  309. );
  310. },
  311. //小黄车 店铺展示
  312. getliveStore() {
  313. let data = {
  314. pageSize: 10,
  315. page: 1
  316. };
  317. api_live.liveStore(this.liveId, data).then(
  318. (res) => {
  319. if (res.code == 200) {
  320. console.log("小黄车 店铺展示>>>>", res);
  321. this.products = res.data;
  322. } else {
  323. common_vendor.index.showToast({
  324. title: res.msg,
  325. icon: "none"
  326. });
  327. }
  328. },
  329. (rej) => {
  330. }
  331. );
  332. },
  333. // 获取直播间信息接口
  334. getLiveinformation() {
  335. api_live.getLiveInfo(this.liveId).then(
  336. (res) => {
  337. if (res.code == 200) {
  338. console.log("获取直播间信息接口>>>>", res);
  339. this.livingUrl = res.livingUrl;
  340. } else {
  341. common_vendor.index.showToast({
  342. title: res.msg,
  343. icon: "none"
  344. });
  345. }
  346. },
  347. (rej) => {
  348. }
  349. );
  350. },
  351. // 获取直播间用户
  352. getliveUser() {
  353. api_live.getRecentLiveViewers(this.liveId).then(
  354. (res) => {
  355. if (res.code == 200) {
  356. console.log("获取直播间用户>>>>", res);
  357. this.liveViewers = res.recentLiveViewers;
  358. } else {
  359. common_vendor.index.showToast({
  360. title: res.msg,
  361. icon: "none"
  362. });
  363. }
  364. },
  365. (rej) => {
  366. }
  367. );
  368. },
  369. // 点赞
  370. onLike() {
  371. api_live.liveDataLike(this.liveId).then(
  372. (res) => {
  373. if (res.code == 200) {
  374. if (typeof res.msg === "number" || typeof res.msg === "string" && /^\d+$/.test(res.msg.trim())) {
  375. this.liveData++;
  376. } else {
  377. common_vendor.index.showToast({
  378. title: res.msg,
  379. icon: "none"
  380. });
  381. }
  382. } else {
  383. common_vendor.index.showToast({
  384. title: res.msg,
  385. icon: "none"
  386. });
  387. }
  388. },
  389. (rej) => {
  390. }
  391. );
  392. },
  393. // 去购买,跳商品详情
  394. goShop(item) {
  395. console.log("去购买,跳商品详情", item);
  396. common_vendor.index.navigateTo({
  397. url: "/pages_shop/goods?productId=" + item + "&liveId=" + this.liveId
  398. });
  399. },
  400. // 收藏
  401. onCollect(item) {
  402. console.log("item>>>", item.productId);
  403. common_vendor.index.setStorageSync("storeId", storeId);
  404. let data = {
  405. liveId: this.liveId,
  406. productId: item.productId,
  407. storeId: this.store.storeId
  408. };
  409. api_live.collectStore(data).then(
  410. (res) => {
  411. if (res.code == 200) {
  412. console.log("收藏lcollectStore>>>>", res);
  413. } else {
  414. common_vendor.index.showToast({
  415. title: res.msg,
  416. icon: "none"
  417. });
  418. }
  419. },
  420. (rej) => {
  421. }
  422. );
  423. },
  424. // 关注
  425. onFollow() {
  426. api_live.follow(this.liveId).then(
  427. (res) => {
  428. this.isFollow = !this.isFollow;
  429. common_vendor.index.showToast({
  430. title: res.msg,
  431. icon: "none"
  432. });
  433. },
  434. (rej) => {
  435. }
  436. );
  437. },
  438. initTime() {
  439. const now = /* @__PURE__ */ new Date();
  440. this.timestamp = now.getTime();
  441. },
  442. // initWebSocket() {
  443. // const liveWS = new LiveWS('ws://your-server.com', 123, 456);
  444. // // 从 URL 中解析 timestamp
  445. // const urlParams = new URL(liveWS.url).searchParams;
  446. // this.timestamp = urlParams.get('timestamp');
  447. // // console.log('Timestamp:', timestamp);
  448. // },
  449. // 弹幕滚动
  450. lowerChat: function(e) {
  451. console.log(e);
  452. },
  453. scroll: function(e) {
  454. console.log(e);
  455. this.old.scrollTop = e.detail.scrollTop;
  456. },
  457. loadmore() {
  458. },
  459. // 弹幕
  460. scrollchat() {
  461. },
  462. noredanswer() {
  463. if (this.Answerlistall > 0) {
  464. this.showAnswer = !this.this.showAnswer;
  465. } else {
  466. common_vendor.index.showToast({
  467. title: "暂无题目",
  468. icon: "none"
  469. });
  470. }
  471. },
  472. redbagAnswer() {
  473. this.showAnswerred = !this.showAnswerred;
  474. this.answerbtn = !this.answerbtn;
  475. },
  476. submitAnswers() {
  477. if (this.isSubmit)
  478. return;
  479. this.isSubmit = true;
  480. const data = {
  481. questionId: this.answerlist.id,
  482. answer: this.checkboxFormValue
  483. };
  484. api_home.submitAnswer(data).then((res) => {
  485. if (res.code == 200) {
  486. common_vendor.index.showToast({
  487. title: res.msg,
  488. icon: "none"
  489. });
  490. }
  491. if (this.answerfrist < this.Answerlistall - 1) {
  492. this.answerfrist++;
  493. this.answerlist = this.allAnswerLists[this.answerfrist];
  494. this.answerlist.content = JSON.parse(this.answerlist.content);
  495. } else {
  496. common_vendor.index.showToast({
  497. title: "已是最后一题",
  498. icon: "none"
  499. });
  500. this.showAnswer = false;
  501. }
  502. this.checkboxValue = [];
  503. this.checkboxFormValue = "";
  504. common_vendor.index.showToast({
  505. title: res.msg,
  506. icon: "none"
  507. });
  508. }).finally((e) => {
  509. this.isSubmit = false;
  510. });
  511. },
  512. handleCheckboxSelect(value) {
  513. const index = this.checkboxValue.indexOf(value);
  514. console.log(value);
  515. if (this.answerlist.type == 1) {
  516. this.checkboxValue = [value];
  517. this.checkboxFormValue = this.checkboxValue.join(",");
  518. this.submitAnswers();
  519. console.log(this.checkboxValue);
  520. } else if (this.answerlist.type == 2) {
  521. if (index > -1) {
  522. this.checkboxValue.splice(index, 1);
  523. this.checkboxFormValue = this.checkboxValue.join(",");
  524. } else {
  525. this.checkboxValue.push(value);
  526. this.checkboxFormValue = this.checkboxValue.join(",");
  527. }
  528. console.log(this.checkboxFormValue);
  529. }
  530. },
  531. getAnswerlists() {
  532. console.log(123);
  533. const data = {
  534. liveId: this.liveId
  535. };
  536. api_home.getAnswerlist(data).then((res) => {
  537. if (res.code == 200) {
  538. if (res.data.length > 0) {
  539. this.allAnswerLists = res.data;
  540. this.Answerlistall = res.data.length;
  541. if (this.allAnswerLists.length > 0) {
  542. this.answerlist = this.allAnswerLists[0];
  543. this.answerlist.content = JSON.parse(this.allAnswerLists[0].content);
  544. }
  545. this.showAnswer = true;
  546. } else {
  547. this.showAnswer = false;
  548. }
  549. }
  550. });
  551. },
  552. gettalklist() {
  553. const param = {
  554. id: this.liveId
  555. };
  556. api_home.gettextlist(param).then((res) => {
  557. if (res.code == 200) {
  558. this.talklist = res.data;
  559. this.$nextTick(() => {
  560. this.scrollIntoView = `list_${this.talklist.length - 1}`;
  561. });
  562. }
  563. });
  564. },
  565. open() {
  566. },
  567. close() {
  568. this.showadd = !this.showadd;
  569. },
  570. closes() {
  571. this.showziliao = !this.showziliao;
  572. },
  573. closest() {
  574. this.showAnswer = !this.showAnswer;
  575. },
  576. closestred() {
  577. this.showAnswerred = !this.showAnswerred;
  578. },
  579. closeanswer() {
  580. this.answerbtn = !this.answerbtn;
  581. },
  582. // 关闭小黄车
  583. closeshop() {
  584. this.shopping = !this.shopping;
  585. },
  586. longPress() {
  587. this.timeout = setTimeout(() => {
  588. this.isLongPress = true;
  589. common_vendor.index.saveImageToPhotosAlbum({
  590. filePath: this.livedata.qwQrCode,
  591. // 图片的本地路径或网络路径
  592. success: () => {
  593. common_vendor.index.showToast({
  594. title: "保存成功"
  595. });
  596. },
  597. fail: () => {
  598. common_vendor.index.showToast({
  599. title: "",
  600. icon: "none"
  601. });
  602. }
  603. });
  604. }, 500);
  605. },
  606. cancelLongPress() {
  607. clearTimeout(this.timeout);
  608. this.isLongPress = false;
  609. },
  610. // 触摸开始
  611. handleTouchStart() {
  612. this.isZoom = true;
  613. },
  614. // 触摸结束
  615. handleTouchEnd() {
  616. this.isZoom = false;
  617. },
  618. // getliving() {
  619. // const param = {
  620. // id: this.liveId
  621. // }
  622. // getlive(param).then(res => {
  623. // if (res.code == 200) {
  624. // this.livedata = res.data
  625. // this.codeimg = res.data.qwQrCode
  626. // if (this.livedata.status == 1) {
  627. // this.autoplay = true
  628. // this.videoContext.seek(this.livedata.nowDuration)
  629. // // console.log(this.autoplay)
  630. // } else {
  631. // this.autoplay = false
  632. // this.placeholderText = "直播开始才能发言讨论"
  633. // this.talkdisabled = true
  634. // }
  635. // console.log(this.autoplay)
  636. // } else {
  637. // uni.showToast({
  638. // title: res.msg,
  639. // icon: 'none',
  640. // duration: 2000
  641. // });
  642. // }
  643. // })
  644. // },
  645. getEWechatSdk() {
  646. },
  647. closeWebSocket() {
  648. if (socket != null) {
  649. common_vendor.index.closeSocket();
  650. }
  651. clearInterval(pingpangTimes);
  652. },
  653. reConnect() {
  654. var that = this;
  655. try {
  656. common_vendor.index.closeSocket();
  657. } catch (e) {
  658. }
  659. setTimeout(function() {
  660. that.initSocket();
  661. }, 1e4);
  662. },
  663. initSocket() {
  664. this.userinfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  665. let signature = common_vendor.CryptoJS.HmacSHA256(
  666. common_vendor.CryptoJS.enc.Utf8.parse(this.liveId.toString() + this.userinfo.userId + this.userType + this.timestamp),
  667. common_vendor.CryptoJS.enc.Utf8.parse(this.timestamp)
  668. ).toString(common_vendor.CryptoJS.enc.Hex);
  669. var that = this;
  670. socket = common_vendor.index.connectSocket({
  671. // url: wsUrl+"?userId=40486&liveId=2",
  672. // url: wsUrl + "?userId=" + this.userid + "&liveId=" +
  673. // this.liveId+"&AppToken="+'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI0IiwiaWF0IjoxNzQwNzIxMDQ1LCJleHAiOjE3NDEzMjU4NDV9.PgS83JTMSJgVFD6vGAhUsEPbS6Az4yMyX8wVug61TZNTB3092CtvANo-AB9ZG4NdSBLgLrf4litM3vvTk-FK0g',
  674. //
  675. // url: wsUrl + "?userId=" + this.userId + "&liveId=" + this.liveId + "&AppToken=" + uni
  676. // .getStorageSync('AppToken'),
  677. url: wsUrl + "?userId=" + this.userinfo.userId + "&liveId=" + this.liveId + "&userType=" + this.userType + "&timestamp=" + this.timestamp + "&signature=" + signature,
  678. multiple: true,
  679. success: (res) => {
  680. clearInterval(pingpangTimes);
  681. common_vendor.index.onSocketMessage((res2) => {
  682. if (res2.data.code == 500) {
  683. common_vendor.index.showToast({
  684. title: res2.data.msg,
  685. icon: "none",
  686. duration: 2e3
  687. });
  688. }
  689. const redata = JSON.parse(res2.data);
  690. console.log("WebSocket拿到的东西", redata);
  691. this.talklist.push(redata.data);
  692. this.$nextTick(() => {
  693. this.scrollIntoView = `list_${this.talklist.length - 1}`;
  694. });
  695. if (redata.cmd == "deleteId") {
  696. common_vendor.index.$emit("deleteId");
  697. } else if (redata.cmd == "init") {
  698. common_vendor.index.$emit("init", redata.data);
  699. } else if (redata.cmd == "reload") {
  700. common_vendor.index.$emit("reload");
  701. } else if (redata.data.cmd == "sendRedPacketQuestion") {
  702. const list = JSON.parse(redata.data.data);
  703. this.redanswerAll = [...this.redanswerAll, ...list];
  704. if (this.redanswerAll[1].randomAmount !== null) {
  705. this.redanswertips = JSON.parse(this.redanswerAll[0].randomAmount);
  706. }
  707. console.log(this.redanswertips);
  708. console.log(this.redanswerAll);
  709. } else if (redata.data.cmd == "entry") {
  710. this.showWelcomeMessage = true;
  711. common_vendor.index.$emit("entry", redata.data);
  712. }
  713. });
  714. },
  715. error: (res) => {
  716. common_vendor.index.$emit("websocket", 0);
  717. console.log(res);
  718. }
  719. });
  720. common_vendor.index.onSocketOpen(() => {
  721. isSocketOpen = true;
  722. console.log("WebSocket连接已打开!!");
  723. common_vendor.index.showToast({
  724. title: "插件已打开",
  725. icon: "none"
  726. });
  727. });
  728. common_vendor.index.onSocketClose(() => {
  729. isSocketOpen = false;
  730. clearInterval(pingpangTimes);
  731. console.log("WebSocket连接已关闭!");
  732. common_vendor.index.showToast({
  733. title: "插件离线",
  734. icon: "none"
  735. });
  736. that.reConnect();
  737. });
  738. common_vendor.index.onSocketError(() => {
  739. isSocketOpen = false;
  740. clearInterval(pingpangTimes);
  741. console.log("WebSocket连接打开失败");
  742. common_vendor.index.showToast({
  743. title: "插件离线",
  744. icon: "none"
  745. });
  746. common_vendor.index.showModal({
  747. content: "聊天连接失败是否重新尝试连接",
  748. success() {
  749. that.reConnect();
  750. }
  751. });
  752. });
  753. },
  754. sendMsg() {
  755. if (isSocketOpen) {
  756. const data = {
  757. liveId: this.liveId,
  758. userId: this.userinfo.userId,
  759. userType: 0,
  760. cmd: "sendMsg",
  761. msg: this.value,
  762. nickName: this.userinfo.nickName,
  763. avatar: this.userinfo.avatar
  764. };
  765. if (this.value == "") {
  766. common_vendor.index.showToast({
  767. title: "不能发送空消息",
  768. icon: "none"
  769. });
  770. } else {
  771. socket.send({
  772. data: JSON.stringify(data),
  773. success: () => {
  774. console.log("发送成功");
  775. this.value = "";
  776. },
  777. fail: () => {
  778. console.log("发送失败");
  779. }
  780. });
  781. }
  782. }
  783. }
  784. }
  785. };
  786. if (!Array) {
  787. const _easycom_u_avatar2 = common_vendor.resolveComponent("u-avatar");
  788. const _easycom_u_input2 = common_vendor.resolveComponent("u-input");
  789. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  790. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  791. (_easycom_u_avatar2 + _easycom_u_input2 + _easycom_u_icon2 + _easycom_u_popup2)();
  792. }
  793. const _easycom_u_avatar = () => "../../uni_modules/uview-plus/components/u-avatar/u-avatar.js";
  794. const _easycom_u_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js";
  795. const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  796. const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
  797. if (!Math) {
  798. (_easycom_u_avatar + _easycom_u_input + _easycom_u_icon + _easycom_u_popup)();
  799. }
  800. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  801. return common_vendor.e({
  802. a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  803. b: common_assets._imports_0$2,
  804. c: common_vendor.p({
  805. src: $data.livedata.liveImgUrl,
  806. size: "32"
  807. }),
  808. d: common_vendor.t($data.livedata.liveName ? $data.livedata.liveName : "芳华未来"),
  809. e: common_vendor.t($data.liveViewData.follow || $data.liveViewData.follow === 0 ? $data.liveViewData.follow : 0),
  810. f: $data.isFollow
  811. }, $data.isFollow ? {
  812. g: common_vendor.o((...args) => $options.onFollow && $options.onFollow(...args))
  813. } : {
  814. h: common_vendor.o((...args) => $options.onFollow && $options.onFollow(...args))
  815. }, {
  816. i: common_vendor.f($options.filteredViewers, (item, index, i0) => {
  817. return {
  818. a: index,
  819. b: item.avatar
  820. };
  821. }),
  822. j: common_vendor.t($data.liveViewData.online),
  823. k: common_vendor.o(($event) => $options.onLike()),
  824. l: common_assets._imports_1,
  825. m: common_vendor.t($data.liveViewData.like),
  826. n: common_assets._imports_2,
  827. o: common_vendor.o(($event) => $options.goStore()),
  828. p: common_assets._imports_3,
  829. q: common_assets._imports_4,
  830. r: common_vendor.t($data.orderUser.userName ? $options.maskString($data.orderUser.userName) : ""),
  831. s: common_vendor.t($data.orderUser.count || 0),
  832. t: $data.livingUrl,
  833. v: $data.autoplay,
  834. w: common_vendor.o((...args) => $options.videoError && $options.videoError(...args)),
  835. x: $data.isScreen ? "100vh" : "",
  836. y: common_vendor.f($data.talklist, (item, index, i0) => {
  837. return {
  838. a: common_vendor.t(item.msg),
  839. b: item.index,
  840. c: `list_${index}`,
  841. d: item.cmd == "announcement"
  842. };
  843. }),
  844. z: common_vendor.t($data.messageContent),
  845. A: common_vendor.f($data.talklist, (item, index, i0) => {
  846. return {
  847. a: common_vendor.t(item.nickName),
  848. b: common_vendor.t(item.msg),
  849. c: item.index,
  850. d: `list_${index}`,
  851. e: item.cmd == "sendMsg"
  852. };
  853. }),
  854. B: $data.showWelcomeMessage
  855. }, $data.showWelcomeMessage ? {
  856. C: common_vendor.f($data.talklist, (item, index, i0) => {
  857. return {
  858. a: common_vendor.t(item.nickName),
  859. b: common_vendor.t(item.msg),
  860. c: item.index,
  861. d: `list_${index}`,
  862. e: item.cmd == "entry" || item.cmd == "out"
  863. };
  864. }),
  865. D: common_vendor.t($data.messageContent)
  866. } : {}, {
  867. E: $data.scrollIntoView,
  868. F: common_vendor.o($options.sendMsg),
  869. G: common_vendor.o($options.sendMsg),
  870. H: common_vendor.o(($event) => $data.value = $event),
  871. I: common_vendor.p({
  872. placeholder: $data.placeholderText,
  873. border: "none",
  874. customStyle: "font-size:24rpx;",
  875. shape: "circle",
  876. color: "#fff",
  877. placeholderStyle: "color:#e7e7e7",
  878. modelValue: $data.value
  879. }),
  880. J: common_assets._imports_5,
  881. K: common_vendor.o(($event) => $data.shopping = !$data.shopping),
  882. L: common_assets._imports_6,
  883. M: common_vendor.o(($event) => $data.showziliao = !$data.showziliao),
  884. N: common_vendor.o(($event) => $data.showziliao = !$data.showziliao),
  885. O: common_vendor.p({
  886. name: "close",
  887. size: "18"
  888. }),
  889. P: $data.livedata.liveDesc,
  890. Q: common_vendor.o($options.closes),
  891. R: common_vendor.p({
  892. show: $data.showziliao,
  893. round: "20",
  894. bgColor: "#fffee1"
  895. }),
  896. S: common_vendor.p({
  897. src: $data.livedata.liveImgUrl,
  898. size: "36"
  899. }),
  900. T: common_assets._imports_0$1,
  901. U: common_assets._imports_10,
  902. V: common_vendor.o((...args) => $options.onCollect && $options.onCollect(...args)),
  903. W: common_assets._imports_9,
  904. X: common_vendor.o((...args) => $options.goOrderList && $options.goOrderList(...args)),
  905. Y: common_vendor.f($data.products, (item, index, i0) => {
  906. return common_vendor.e({
  907. a: item.imgUrl,
  908. b: common_vendor.t(index + 1),
  909. c: common_vendor.t(item.productName),
  910. d: common_vendor.t(item.productIntroduce),
  911. e: common_vendor.t(item.sales),
  912. f: common_vendor.t(Math.trunc(item.price)),
  913. g: common_vendor.t($options.getPureDecimal(item.price) ? $options.getPureDecimal(item.price) : "00"),
  914. h: common_vendor.o(($event) => $options.onCollect(item), index),
  915. i: item.status == 1
  916. }, item.status == 1 ? {
  917. j: common_vendor.o(($event) => $options.goShop(item.productId), index)
  918. } : item.status == 0 ? {
  919. l: common_vendor.o(($event) => $options.goShop(item.productId), index)
  920. } : {}, {
  921. k: item.status == 0,
  922. m: index
  923. });
  924. }),
  925. Z: common_assets._imports_10,
  926. aa: $data.boxHeight + "px",
  927. ab: common_vendor.o($options.closeshop),
  928. ac: common_vendor.o($options.open),
  929. ad: common_vendor.p({
  930. show: $data.shopping,
  931. round: "20rpx",
  932. bgColor: "#f3f5f9"
  933. })
  934. });
  935. }
  936. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-471975a0"]]);
  937. wx.createPage(MiniProgramPage);