login.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. "use strict";
  2. var common_vendor = require("../../common/vendor.js");
  3. var api_user = require("../../api/user.js");
  4. require("../../common/request.js");
  5. const wxAuth = () => "../components/wxAuth.js";
  6. const _sfc_main = {
  7. components: {
  8. wxAuth
  9. },
  10. data() {
  11. return {
  12. wxShow: false,
  13. isAgreement: false,
  14. code: null
  15. };
  16. },
  17. computed: {},
  18. onLoad(option) {
  19. common_vendor.index.$on("refreshLogin", () => {
  20. common_vendor.index.navigateBack({
  21. delta: 1
  22. });
  23. });
  24. this.getCode();
  25. },
  26. onUnload() {
  27. },
  28. mounted() {
  29. },
  30. methods: {
  31. updateUser() {
  32. this.wxShow = false;
  33. common_vendor.index.$emit("refreshLogin");
  34. common_vendor.index.$emit("refreshIM");
  35. },
  36. wxAuthOpen() {
  37. this.wxShow = true;
  38. var that = this;
  39. setTimeout(function() {
  40. that.$refs.wxauth.getUserInfo();
  41. });
  42. },
  43. wxAuthClose() {
  44. this.wxShow = false;
  45. },
  46. wxLogin(e) {
  47. var that = this;
  48. if (!this.isAgreement) {
  49. common_vendor.index.showToast({
  50. icon: "none",
  51. title: "\u8BF7\u5148\u540C\u610F\u534F\u8BAE\u540E\u518D\u767B\u5F55"
  52. });
  53. return false;
  54. }
  55. common_vendor.index.showLoading({
  56. title: "\u5904\u7406\u4E2D..."
  57. });
  58. that.$getProvider().then((provider) => {
  59. console.log("\u5F53\u524D\u7684\u73AF\u5883\u5546", provider);
  60. if (!provider) {
  61. reject();
  62. }
  63. common_vendor.index.login({
  64. provider,
  65. success: async (loginRes) => {
  66. console.log(111);
  67. console.log(e);
  68. console.log(loginRes);
  69. }
  70. });
  71. }).catch((err) => {
  72. common_vendor.index.showToast({
  73. icon: "none",
  74. title: err
  75. });
  76. });
  77. },
  78. handleAgree() {
  79. if (!this.isAgreement) {
  80. common_vendor.index.showToast({
  81. icon: "none",
  82. title: "\u8BF7\u5148\u540C\u610F\u534F\u8BAE\u540E\u518D\u767B\u5F55"
  83. });
  84. }
  85. },
  86. openContent(type) {
  87. console.log(type);
  88. common_vendor.index.navigateTo({
  89. url: "/pages_user/agreement?type=" + type
  90. });
  91. },
  92. handleAgreement() {
  93. this.isAgreement = !this.isAgreement;
  94. },
  95. getCode() {
  96. var that = this;
  97. that.$getProvider().then((provider) => {
  98. if (!provider) {
  99. reject();
  100. }
  101. common_vendor.index.login({
  102. provider,
  103. success: async (loginRes) => {
  104. that.code = loginRes.code;
  105. }
  106. });
  107. }).catch((err) => {
  108. });
  109. },
  110. phoneLogin(e) {
  111. var that = this;
  112. common_vendor.index.showLoading({
  113. title: "\u5904\u7406\u4E2D"
  114. });
  115. console.log(e);
  116. if (e.detail.errMsg == "getPhoneNumber:ok") {
  117. this.$getProvider().then((provider) => {
  118. console.log("\u5F53\u524D\u7684\u73AF\u5883\u5546", provider);
  119. if (!provider) {
  120. reject();
  121. }
  122. common_vendor.index.login({
  123. provider,
  124. success: async (loginRes) => {
  125. console.log(loginRes);
  126. let code = loginRes.code;
  127. var tuiUserId = common_vendor.index.getStorageSync("tuiUserId");
  128. api_user.wxLogin({
  129. encryptedData: e.detail.encryptedData,
  130. iv: e.detail.iv,
  131. code,
  132. tuiUserId
  133. }).then((res) => {
  134. common_vendor.index.hideLoading();
  135. if (res.code == 200) {
  136. common_vendor.index.showToast({
  137. icon: "none",
  138. title: "\u767B\u5F55\u6210\u529F"
  139. });
  140. common_vendor.index.setStorageSync("AppToken", res.token);
  141. common_vendor.index.setStorageSync("userId", res.user.userId);
  142. common_vendor.index.setStorageSync("avatar", res.user.avatar);
  143. common_vendor.index.setStorageSync("nickName", res.user.nickName);
  144. if (res.user.isWeixinAuth == 0) {
  145. that.wxAuthOpen();
  146. } else {
  147. common_vendor.index.$emit("refreshLogin");
  148. common_vendor.index.$emit("refreshIM");
  149. }
  150. } else {
  151. common_vendor.index.showToast({
  152. icon: "none",
  153. title: "\u6388\u6743\u767B\u5F55\u5931\u8D25,\u8BF7\u91CD\u65B0\u767B\u5F55"
  154. });
  155. }
  156. }).catch((error) => {
  157. console.log(error);
  158. common_vendor.index.hideLoading();
  159. common_vendor.index.showToast({
  160. icon: "none",
  161. title: "\u6388\u6743\u767B\u5F55\u5931\u8D25,\u8BF7\u91CD\u65B0\u767B\u5F55"
  162. });
  163. });
  164. }
  165. });
  166. }).catch((err) => {
  167. });
  168. } else {
  169. common_vendor.index.showToast({
  170. title: "\u5DF2\u62D2\u7EDD\u6388\u6743",
  171. icon: "none",
  172. duration: 2e3
  173. });
  174. }
  175. },
  176. back() {
  177. common_vendor.index.reLaunch({
  178. url: "/pages/index/index",
  179. animationType: "pop-in",
  180. animationDuration: 100
  181. });
  182. }
  183. }
  184. };
  185. if (!Array) {
  186. const _component_wx_auth = common_vendor.resolveComponent("wx-auth");
  187. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  188. (_component_wx_auth + _easycom_u_popup2)();
  189. }
  190. const _easycom_u_popup = () => "../../uni_modules/uview-plus/components/u-popup/u-popup.js";
  191. if (!Math) {
  192. _easycom_u_popup();
  193. }
  194. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  195. return common_vendor.e({
  196. a: common_vendor.o((...args) => $options.phoneLogin && $options.phoneLogin(...args)),
  197. b: $data.isAgreement == false
  198. }, $data.isAgreement == false ? {
  199. c: common_vendor.o(($event) => $options.handleAgree())
  200. } : {}, {
  201. d: common_vendor.o((...args) => $options.back && $options.back(...args)),
  202. e: $data.isAgreement,
  203. f: common_vendor.o(($event) => $options.handleAgreement()),
  204. g: common_vendor.o(($event) => $options.handleAgreement()),
  205. h: common_vendor.o(($event) => $options.openContent("userRegister")),
  206. i: common_vendor.o(($event) => $options.openContent("userPrivacy")),
  207. j: common_vendor.sr("wxauth", "1e427071-1,1e427071-0"),
  208. k: common_vendor.o(($event) => $options.updateUser()),
  209. l: common_vendor.o($options.wxAuthClose),
  210. m: common_vendor.o($options.wxAuthOpen),
  211. n: common_vendor.p({
  212. bgColor: "#f6f6f6",
  213. safeAreaInsetBottom: false,
  214. round: 15,
  215. mode: "bottom",
  216. show: $data.wxShow
  217. })
  218. });
  219. }
  220. var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "E:/Project/2023/\u95EE\u8BCA\u5E73\u53F0/his_user_miniapp/pages/auth/login.vue"]]);
  221. wx.createPage(MiniProgramPage);