index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. "use strict";
  2. var common_vendor = require("../../common/vendor.js");
  3. var api_home = require("../../api/home.js");
  4. require("../../common/request.js");
  5. const isWechat = () => {
  6. return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === "micromessenger";
  7. };
  8. const _sfc_main = {
  9. data() {
  10. return {
  11. isLogin: false,
  12. code: "",
  13. livedata: {},
  14. path: "http://live.ylrzcloud.com/prod-api",
  15. iskefu: false,
  16. isLongPress: false,
  17. timeout: null,
  18. liveId: 2
  19. };
  20. },
  21. onLoad(option) {
  22. },
  23. onShow() {
  24. if (common_vendor.index.getStorageSync("AppToken")) {
  25. this.getliving();
  26. }
  27. },
  28. methods: {
  29. open() {
  30. },
  31. close() {
  32. this.iskefu = !this.iskefu;
  33. },
  34. longPress() {
  35. this.timeout = setTimeout(() => {
  36. this.isLongPress = true;
  37. common_vendor.index.saveImageToPhotosAlbum({
  38. filePath: this.livedata.qwQrCode,
  39. success: () => {
  40. common_vendor.index.showToast({
  41. title: "\u4FDD\u5B58\u6210\u529F"
  42. });
  43. },
  44. fail: () => {
  45. common_vendor.index.showToast({
  46. title: "\u4FDD\u5B58\u5931\u8D25",
  47. icon: "none"
  48. });
  49. }
  50. });
  51. }, 500);
  52. },
  53. cancelLongPress() {
  54. clearTimeout(this.timeout);
  55. this.isLongPress = false;
  56. },
  57. getliving() {
  58. const param = {
  59. id: this.liveId
  60. };
  61. api_home.getlive(param).then((res) => {
  62. if (res.code == 200) {
  63. this.livedata = res.data;
  64. } else {
  65. common_vendor.index.showToast({
  66. title: res.msg,
  67. icon: "none",
  68. duration: 2e3
  69. });
  70. }
  71. });
  72. },
  73. getWechatCode() {
  74. if (isWechat) {
  75. let appid = "wx93ce67750e3cfba3";
  76. let code = this.getUrlCode().code;
  77. let local = window.location.href.split("#")[0];
  78. if (code == null || code === "") {
  79. window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid + "&redirect_uri=" + encodeURIComponent(local) + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
  80. } else {
  81. this.code = code;
  82. this.loginByMp();
  83. }
  84. }
  85. },
  86. loginByMp() {
  87. if (this.code == null) {
  88. return;
  89. }
  90. common_vendor.index.showLoading({
  91. title: "\u5904\u7406\u4E2D..."
  92. });
  93. var data = {
  94. code: this.code
  95. };
  96. api_home.loginByMp(data).then((res) => {
  97. common_vendor.index.hideLoading();
  98. if (res.code == 200) {
  99. console.log(res);
  100. common_vendor.index.setStorageSync("AppToken", res.token);
  101. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  102. let beforLoginUrl = common_vendor.index.getStorageSync("beforLoginPage");
  103. common_vendor.index.reLaunch({
  104. url: beforLoginUrl
  105. });
  106. common_vendor.index.showToast({
  107. title: "\u767B\u5F55\u6210\u529F",
  108. icon: "none"
  109. });
  110. this.getliving();
  111. } else {
  112. common_vendor.index.showToast({
  113. title: res.msg,
  114. icon: "none"
  115. });
  116. }
  117. }, (err) => {
  118. });
  119. },
  120. getUrlCode() {
  121. var url = location.search;
  122. var theRequest = new Object();
  123. if (url.indexOf("?") != -1) {
  124. var str = url.substr(1);
  125. var strs = str.split("&");
  126. for (var i = 0; i < strs.length; i++) {
  127. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  128. }
  129. }
  130. return theRequest;
  131. },
  132. comelive() {
  133. common_vendor.index.setStorageSync("AppToken", null);
  134. if (common_vendor.index.getStorageSync("AppToken")) {
  135. common_vendor.index.navigateTo({
  136. url: "/pages/home/living"
  137. });
  138. } else {
  139. common_vendor.index.showToast({
  140. title: "\u8BF7\u767B\u5F55\u6388\u6743\uFF01",
  141. icon: "none"
  142. });
  143. common_vendor.index.navigateTo({
  144. url: "/pages/auth/login"
  145. });
  146. }
  147. }
  148. }
  149. };
  150. if (!Array) {
  151. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  152. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  153. (_easycom_u_icon2 + _easycom_u_popup2)();
  154. }
  155. const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  156. const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
  157. if (!Math) {
  158. (_easycom_u_icon + _easycom_u_popup)();
  159. }
  160. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  161. return {
  162. a: $data.livedata.liveImgUrl,
  163. b: common_vendor.t($data.livedata.liveName),
  164. c: common_vendor.t($data.livedata.startTime),
  165. d: common_vendor.t($data.livedata.finishTime),
  166. e: $data.livedata.liveDesc,
  167. f: common_vendor.o((...args) => $options.comelive && $options.comelive(...args)),
  168. g: common_vendor.o(($event) => _ctx.showadd = !_ctx.showadd),
  169. h: common_vendor.p({
  170. name: "close",
  171. size: "18"
  172. }),
  173. i: _ctx.codeimg,
  174. j: common_vendor.o((...args) => $options.longPress && $options.longPress(...args)),
  175. k: common_vendor.o((...args) => $options.cancelLongPress && $options.cancelLongPress(...args)),
  176. l: common_vendor.o($options.close),
  177. m: common_vendor.o($options.open),
  178. n: common_vendor.p({
  179. show: $data.iskefu,
  180. round: "20rpx",
  181. bgColor: "#fffee1"
  182. })
  183. };
  184. }
  185. var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-71e217db"], ["__file", "C:/Users/Administrator/Desktop/\u9879\u76EE/\u76F4\u64AD/liveH5-v3/pages/home/index.vue"]]);
  186. wx.createPage(MiniProgramPage);