index.js 5.9 KB

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