login.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. "use strict";
  2. var common_vendor = require("../../common/vendor.js");
  3. var api_login = require("../../api/login.js");
  4. require("../../common/request.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. userName: "",
  9. password: "",
  10. registrationID: "",
  11. unionid: "",
  12. userPhone: "",
  13. loginType: 0,
  14. isApp: false,
  15. agree: false,
  16. isAgreePrivacy: false,
  17. isIos: false,
  18. from: "",
  19. source: "",
  20. appleKey: ""
  21. };
  22. },
  23. onLoad(option) {
  24. this.from = option.from || "";
  25. let that = this;
  26. common_vendor.index.$on("getRegistrationID", function(data) {
  27. that.registrationID = data;
  28. });
  29. },
  30. onShow() {
  31. if (this.$isLogin()) {
  32. this.goPage();
  33. }
  34. },
  35. onUnload() {
  36. common_vendor.index.$off("getRegistrationID");
  37. },
  38. mounted() {
  39. },
  40. methods: {
  41. initUniverify() {
  42. const callback = (res) => {
  43. univerifyManager.getCheckBoxState({
  44. success(res2) {
  45. console.log("getCheckBoxState res: ", res2);
  46. if (res2.state) {
  47. univerifyManager.close();
  48. }
  49. }
  50. });
  51. };
  52. univerifyManager.onButtonsClick(callback);
  53. univerifyManager.offButtonsClick(callback);
  54. },
  55. login() {
  56. if (this.$isEmpty(this.userName)) {
  57. common_vendor.index.showToast({
  58. title: "\u8BF7\u8F93\u5165\u5E10\u53F7",
  59. icon: "none"
  60. });
  61. return;
  62. }
  63. if (this.$isEmpty(this.password)) {
  64. common_vendor.index.showToast({
  65. title: "\u8BF7\u8F93\u5165\u5BC6\u7801",
  66. icon: "none"
  67. });
  68. return;
  69. }
  70. if (!this.agree) {
  71. common_vendor.index.showToast({
  72. title: "\u8BF7\u540C\u610F\u76F8\u5173\u534F\u8BAE",
  73. icon: "none"
  74. });
  75. return;
  76. }
  77. var data = {
  78. phone: this.userName,
  79. password: this.password,
  80. loginType: 1
  81. };
  82. var that = this;
  83. common_vendor.index.showLoading({
  84. title: "\u5904\u7406\u4E2D..."
  85. });
  86. api_login.loginByApp(data).then((res) => {
  87. common_vendor.index.hideLoading();
  88. console.log("qxj res:" + JSON.stringify(res));
  89. if (res.code == 200) {
  90. common_vendor.index.setStorageSync("AppToken", res.token);
  91. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  92. common_vendor.index.$emit("refreshIM");
  93. common_vendor.index.$emit("showHealthButler");
  94. that.goPage();
  95. } else {
  96. common_vendor.index.showToast({
  97. title: res.msg,
  98. icon: "none"
  99. });
  100. }
  101. }, (rej) => {
  102. console.log("qxj rej:" + JSON.stringify(rej));
  103. });
  104. },
  105. quickAppleLogin() {
  106. let that = this;
  107. if (!this.agree) {
  108. common_vendor.index.showToast({
  109. title: "\u8BF7\u540C\u610F\u76F8\u5173\u534F\u8BAE",
  110. icon: "none"
  111. });
  112. return;
  113. }
  114. common_vendor.index.getProvider({
  115. service: "oauth",
  116. success: function(res) {
  117. if (res.provider.indexOf("apple")) {
  118. common_vendor.index.login({
  119. provider: "apple",
  120. success: function(loginRes) {
  121. that.appleKey = loginRes.authResult.openid;
  122. that.loginByAppleAct(loginRes.authResult);
  123. },
  124. fail: function(err) {
  125. console.log(err);
  126. }
  127. });
  128. }
  129. }
  130. });
  131. },
  132. async loginByAppleAct(authResult) {
  133. let loginDevice = "";
  134. if (plus.runtime.isAgreePrivacy()) {
  135. const info = await common_vendor.index.getPushClientId();
  136. common_vendor.index.setStorageSync("registrationID", info.cid);
  137. this.registrationID = info.cid;
  138. let devinfo = await common_vendor.index.getDeviceInfo();
  139. if (devinfo != null) {
  140. loginDevice += devinfo.deviceBrand ? devinfo.deviceBrand : "";
  141. loginDevice += devinfo.deviceModel ? " " + devinfo.deviceModel : "";
  142. loginDevice += devinfo.system ? " " + devinfo.system : "";
  143. }
  144. }
  145. const params = {
  146. loginDevice,
  147. jpushId: this.registrationID,
  148. source: this.source,
  149. appleKey: authResult.openid
  150. };
  151. common_vendor.index.showLoading({
  152. title: "\u767B\u9646\u4E2D"
  153. });
  154. loginByApple(params).then((res) => {
  155. common_vendor.index.hideLoading();
  156. if (res.user != null) {
  157. common_vendor.index.hideLoading();
  158. common_vendor.index.setStorageSync("AppToken", res.token);
  159. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  160. common_vendor.index.closeAuthView();
  161. common_vendor.index.$emit("refreshIM");
  162. common_vendor.index.$emit("showHealthButler");
  163. common_vendor.index.$emit("refreshUserInfo", {});
  164. this.goPage();
  165. } else {
  166. if (res.isNew) {
  167. this.bindMobile("apple");
  168. }
  169. }
  170. }).catch(() => {
  171. common_vendor.index.hideLoading();
  172. });
  173. },
  174. loginWeixin() {
  175. if (!this.agree) {
  176. common_vendor.index.showToast({
  177. title: "\u8BF7\u540C\u610F\u76F8\u5173\u534F\u8BAE",
  178. icon: "none"
  179. });
  180. return;
  181. }
  182. common_vendor.index.login({
  183. provider: "weixin",
  184. onlyAuthorize: true,
  185. success: async (res) => {
  186. common_vendor.index.showLoading({
  187. title: "\u5904\u7406\u4E2D..."
  188. });
  189. const params = {
  190. code: res.code,
  191. jpushId: this.registrationID,
  192. source: this.source
  193. };
  194. this.loginByWeChatAct(params);
  195. },
  196. fail: (err) => {
  197. console.log("qxj loginWeixin fail:", JSON.stringify(err));
  198. if (err.code == 1e3) {
  199. common_vendor.index.showModal({
  200. title: "\u767B\u5F55\u5931\u8D25",
  201. content: `${err.errMsg}
  202. \uFF0C\u9519\u8BEF\u7801\uFF1A${err.code}`,
  203. confirmText: "\u5F00\u901A\u6307\u5357",
  204. cancelText: "\u786E\u5B9A",
  205. success: (res) => {
  206. if (res.confirm) {
  207. setTimeout(() => {
  208. plus.runtime.openWeb("https://ask.dcloud.net.cn/article/37965");
  209. }, 500);
  210. }
  211. }
  212. });
  213. return;
  214. }
  215. if (err.code == "30005") {
  216. common_vendor.index.showModal({
  217. showCancel: false,
  218. title: "\u9884\u767B\u5F55\u5931\u8D25",
  219. content: err.errMsg
  220. });
  221. return;
  222. }
  223. if (err.code != "30003") {
  224. common_vendor.index.showModal({
  225. showCancel: false,
  226. title: "\u767B\u5F55\u5931\u8D25",
  227. content: JSON.stringify(err)
  228. });
  229. }
  230. },
  231. complete: () => {
  232. }
  233. });
  234. },
  235. goToRegister() {
  236. this.$navTo("./register");
  237. },
  238. goToFindPass() {
  239. this.$navTo("./findpass");
  240. },
  241. doUniverify(authResult) {
  242. common_vendor.pn.callFunction({
  243. name: "loginByMobile",
  244. data: {
  245. access_token: authResult.access_token,
  246. openid: authResult.openid
  247. }
  248. }).then((res) => {
  249. common_vendor.index.closeAuthView();
  250. if (res.result.errCode == 0) {
  251. this.userName = res.result.phoneNumber;
  252. } else {
  253. common_vendor.index.showToast({
  254. title: res.result.message,
  255. icon: "none"
  256. });
  257. }
  258. }).catch((err) => {
  259. console.error("\u8C03\u7528\u4E91\u51FD\u6570\u5931\u8D25:", err);
  260. console.error("\u9519\u8BEF\u4FE1\u606F:", err.errMsg);
  261. });
  262. },
  263. loginByWeChatAct(params) {
  264. api_login.loginByWeChat(params).then((res) => {
  265. if (res.code == 200) {
  266. if (res.user != null) {
  267. common_vendor.index.hideLoading();
  268. common_vendor.index.setStorageSync("AppToken", res.token);
  269. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  270. common_vendor.index.closeAuthView();
  271. common_vendor.index.$emit("refreshIM");
  272. common_vendor.index.$emit("showHealthButler");
  273. common_vendor.index.$emit("refreshUserInfo", {});
  274. this.goPage();
  275. } else {
  276. this.unionid = res.unionid;
  277. if (res.isNew) {
  278. this.bindMobile();
  279. }
  280. }
  281. } else {
  282. common_vendor.index.hideLoading();
  283. common_vendor.index.showToast({
  284. title: res.msg,
  285. icon: "none"
  286. });
  287. }
  288. }, (rej) => {
  289. });
  290. },
  291. bindMobile(type) {
  292. },
  293. loginByUniverify(authResult, type) {
  294. common_vendor.pn.callFunction({
  295. name: "loginByMobile",
  296. data: {
  297. access_token: authResult.access_token,
  298. openid: authResult.openid
  299. }
  300. }).then((res) => {
  301. console.log("qxj doUniverify:", JSON.stringify(res));
  302. if (res.result.errCode == 0) {
  303. userPhone = res.result.phoneNumber;
  304. if (type == 3) {
  305. this.setPhoneAct(3, userPhone, this.unionid);
  306. } else {
  307. this.setPhoneAct(1, userPhone, this.unionid);
  308. }
  309. } else {
  310. common_vendor.index.showToast({
  311. title: res.result.message,
  312. icon: "none"
  313. });
  314. }
  315. }).catch((err) => {
  316. console.error("\u8C03\u7528\u4E91\u51FD\u6570\u5931\u8D25:", err);
  317. console.error("\u9519\u8BEF\u4FE1\u606F:", err.errMsg);
  318. });
  319. },
  320. setPhoneAct(type, phone, unionId) {
  321. let params = {
  322. phone,
  323. unionId
  324. };
  325. if (type == 3) {
  326. params = {
  327. phone,
  328. unionId,
  329. appleKey: this.appleKey
  330. };
  331. }
  332. setPhone(params).then((res) => {
  333. common_vendor.index.hideLoading();
  334. if (res.code == 200) {
  335. common_vendor.index.setStorageSync("AppToken", res.token);
  336. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  337. common_vendor.index.closeAuthView();
  338. common_vendor.index.$emit("refreshIM");
  339. this.goPage();
  340. } else {
  341. common_vendor.index.showToast({
  342. title: res.msg,
  343. icon: "none"
  344. });
  345. common_vendor.index.closeAuthView();
  346. }
  347. }, (rej) => {
  348. });
  349. },
  350. getRegistrationID() {
  351. this.registrationID = common_vendor.index.getStorageSync("registrationID");
  352. if (this.registrationID == null || this.registrationID == "") {
  353. common_vendor.index.getPushClientId({
  354. success: (res) => {
  355. common_vendor.index.setStorageSync("registrationID", res.cid);
  356. this.registrationID = res.cid;
  357. }
  358. });
  359. }
  360. },
  361. goBack() {
  362. console.log("qxj goBack");
  363. common_vendor.index.$emit("showHealthButler");
  364. common_vendor.index.redirectTo({
  365. url: "/pages/auth/loginIndex"
  366. });
  367. },
  368. handleAgree() {
  369. this.agree = !this.agree;
  370. if (this.isIos) {
  371. if (this.agree) {
  372. plus.runtime.agreePrivacy();
  373. this.getRegistrationID();
  374. } else {
  375. plus.runtime.disagreePrivacy();
  376. }
  377. }
  378. },
  379. goToWeb(index) {
  380. common_vendor.index.setStorageSync("url", index == 0 ? "https://userapp.his.cdwjyyh.com/web/userAgreement" : "https://userapp.his.cdwjyyh.com/web/privacyPolicy");
  381. common_vendor.index.navigateTo({
  382. url: "/pages/index/h5"
  383. });
  384. },
  385. goPage() {
  386. let pages = getCurrentPages();
  387. pages[pages.length - 1];
  388. let openUrl = common_vendor.index.getStorageSync("openUrl");
  389. if (openUrl) {
  390. common_vendor.index.navigateTo({
  391. url: openUrl,
  392. success: function(res) {
  393. common_vendor.index.removeStorageSync("openUrl");
  394. }
  395. });
  396. } else {
  397. common_vendor.index.reLaunch({
  398. url: "/pages/list/index",
  399. animationType: "none",
  400. animationDuration: 2e3
  401. });
  402. return;
  403. }
  404. this.$updateMsgDot();
  405. this.$setSource();
  406. }
  407. }
  408. };
  409. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  410. return common_vendor.e({
  411. a: common_vendor.o(($event) => $options.goBack()),
  412. b: $data.userName,
  413. c: common_vendor.o(($event) => $data.userName = $event.detail.value),
  414. d: $data.password,
  415. e: common_vendor.o(($event) => $data.password = $event.detail.value),
  416. f: common_vendor.o((...args) => $options.login && $options.login(...args)),
  417. g: common_vendor.o(($event) => $options.goToRegister()),
  418. h: $data.isApp && $data.isAgreePrivacy
  419. }, $data.isApp && $data.isAgreePrivacy ? common_vendor.e({
  420. i: common_vendor.o((...args) => $options.loginWeixin && $options.loginWeixin(...args)),
  421. j: $data.isIos
  422. }, $data.isIos ? {
  423. k: common_vendor.o((...args) => $options.quickAppleLogin && $options.quickAppleLogin(...args))
  424. } : {}) : {}, {
  425. l: !$data.agree,
  426. m: $data.agree,
  427. n: common_vendor.o((...args) => $options.handleAgree && $options.handleAgree(...args)),
  428. o: common_vendor.o(($event) => $options.goToWeb(0)),
  429. p: common_vendor.o(($event) => $options.goToWeb(1))
  430. });
  431. }
  432. var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-cbd6070a"], ["__file", "C:/Users/Administrator/Desktop/\u9879\u76EE/\u76F4\u64AD/liveH5-v3/pages/auth/login.vue"]]);
  433. wx.createPage(MiniProgramPage);