index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_home = require("../../api/home.js");
  4. const common_assets = require("../../common/assets.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. // 是否长按
  18. timeout: null,
  19. // 计时器
  20. liveId: 2
  21. };
  22. },
  23. onLoad(option) {
  24. },
  25. onShow() {
  26. if (common_vendor.index.getStorageSync("AppToken")) {
  27. this.getliving();
  28. }
  29. },
  30. methods: {
  31. open() {
  32. },
  33. close() {
  34. this.iskefu = !this.iskefu;
  35. },
  36. longPress() {
  37. this.timeout = setTimeout(() => {
  38. this.isLongPress = true;
  39. common_vendor.index.saveImageToPhotosAlbum({
  40. filePath: this.livedata.qwQrCode,
  41. // 图片的本地路径或网络路径
  42. success: () => {
  43. common_vendor.index.showToast({
  44. title: "保存成功"
  45. });
  46. },
  47. fail: () => {
  48. common_vendor.index.showToast({
  49. title: "保存失败",
  50. icon: "none"
  51. });
  52. }
  53. });
  54. }, 500);
  55. },
  56. cancelLongPress() {
  57. clearTimeout(this.timeout);
  58. this.isLongPress = false;
  59. },
  60. getliving() {
  61. const param = {
  62. id: this.liveId
  63. };
  64. api_home.getlive(param).then((res) => {
  65. if (res.code == 200) {
  66. this.livedata = res.data;
  67. } else {
  68. common_vendor.index.showToast({
  69. title: res.msg,
  70. icon: "none",
  71. duration: 2e3
  72. });
  73. }
  74. });
  75. },
  76. getWechatCode() {
  77. if (isWechat) {
  78. let appid = "wx93ce67750e3cfba3";
  79. let code = this.getUrlCode().code;
  80. let local = window.location.href.split("#")[0];
  81. if (code == null || code === "") {
  82. 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";
  83. } else {
  84. this.code = code;
  85. this.loginByMp();
  86. }
  87. }
  88. },
  89. loginByMp() {
  90. if (this.code == null) {
  91. return;
  92. }
  93. common_vendor.index.showLoading({
  94. title: "处理中..."
  95. });
  96. var data = {
  97. code: this.code
  98. };
  99. api_home.loginByMp(data).then(
  100. (res) => {
  101. common_vendor.index.hideLoading();
  102. if (res.code == 200) {
  103. console.log(res);
  104. common_vendor.index.setStorageSync("AppToken", res.token);
  105. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  106. let beforLoginUrl = common_vendor.index.getStorageSync("beforLoginPage");
  107. common_vendor.index.reLaunch({
  108. url: beforLoginUrl
  109. });
  110. common_vendor.index.showToast({
  111. title: "登录成功",
  112. icon: "none"
  113. });
  114. this.getliving();
  115. } else {
  116. common_vendor.index.showToast({
  117. title: res.msg,
  118. icon: "none"
  119. });
  120. }
  121. },
  122. (err) => {
  123. }
  124. );
  125. },
  126. getUrlCode() {
  127. var url = location.search;
  128. var theRequest = new Object();
  129. if (url.indexOf("?") != -1) {
  130. var str = url.substr(1);
  131. var strs = str.split("&");
  132. for (var i = 0; i < strs.length; i++) {
  133. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  134. }
  135. }
  136. return theRequest;
  137. },
  138. comelive() {
  139. common_vendor.index.setStorageSync("AppToken", null);
  140. if (common_vendor.index.getStorageSync("AppToken")) {
  141. common_vendor.index.navigateTo({
  142. url: "/pages/home/living"
  143. });
  144. } else {
  145. common_vendor.index.showToast({
  146. title: "请登录授权!",
  147. icon: "none"
  148. });
  149. common_vendor.index.navigateTo({
  150. url: "/pages/auth/login"
  151. });
  152. }
  153. }
  154. }
  155. };
  156. if (!Array) {
  157. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  158. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  159. (_easycom_u_icon2 + _easycom_u_popup2)();
  160. }
  161. const _easycom_u_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  162. const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
  163. if (!Math) {
  164. (_easycom_u_icon + _easycom_u_popup)();
  165. }
  166. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  167. return {
  168. a: common_assets._imports_0,
  169. b: $data.livedata.liveImgUrl,
  170. c: common_vendor.t($data.livedata.liveName),
  171. d: common_vendor.t($data.livedata.startTime),
  172. e: common_vendor.t($data.livedata.finishTime),
  173. f: $data.livedata.liveDesc,
  174. g: common_vendor.o((...args) => $options.comelive && $options.comelive(...args)),
  175. h: common_vendor.o(($event) => _ctx.showadd = !_ctx.showadd),
  176. i: common_vendor.p({
  177. name: "close",
  178. size: "18"
  179. }),
  180. j: _ctx.codeimg,
  181. k: common_vendor.o((...args) => $options.longPress && $options.longPress(...args)),
  182. l: common_vendor.o((...args) => $options.cancelLongPress && $options.cancelLongPress(...args)),
  183. m: common_vendor.o($options.close),
  184. n: common_vendor.o($options.open),
  185. o: common_vendor.p({
  186. show: $data.iskefu,
  187. round: "20rpx",
  188. bgColor: "#fffee1"
  189. })
  190. };
  191. }
  192. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-4978fed5"]]);
  193. wx.createPage(MiniProgramPage);