login.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_login = require("../../api/login.js");
  4. const common_assets = require("../../common/assets.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: "请输入帐号",
  59. icon: "none"
  60. });
  61. return;
  62. }
  63. if (this.$isEmpty(this.password)) {
  64. common_vendor.index.showToast({
  65. title: "请输入密码",
  66. icon: "none"
  67. });
  68. return;
  69. }
  70. if (!this.agree) {
  71. common_vendor.index.showToast({
  72. title: "请同意相关协议",
  73. icon: "none"
  74. });
  75. return;
  76. }
  77. var data = {
  78. phone: this.userName,
  79. password: this.password,
  80. // jpushId: this.registrationID,
  81. loginType: 1
  82. // source: this.source
  83. };
  84. var that = this;
  85. common_vendor.index.showLoading({
  86. title: "处理中..."
  87. });
  88. api_login.loginByApp(data).then(
  89. (res) => {
  90. common_vendor.index.hideLoading();
  91. console.log("qxj res:" + JSON.stringify(res));
  92. if (res.code == 200) {
  93. common_vendor.index.setStorageSync("AppToken", res.token);
  94. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  95. common_vendor.index.$emit("refreshIM");
  96. common_vendor.index.$emit("showHealthButler");
  97. that.goPage();
  98. } else {
  99. common_vendor.index.showToast({
  100. title: res.msg,
  101. icon: "none"
  102. });
  103. }
  104. },
  105. (rej) => {
  106. console.log("qxj rej:" + JSON.stringify(rej));
  107. }
  108. );
  109. },
  110. quickAppleLogin() {
  111. let that = this;
  112. if (!this.agree) {
  113. common_vendor.index.showToast({
  114. title: "请同意相关协议",
  115. icon: "none"
  116. });
  117. return;
  118. }
  119. common_vendor.index.getProvider({
  120. service: "oauth",
  121. success: function(res) {
  122. if (res.provider.indexOf("apple")) {
  123. common_vendor.index.login({
  124. provider: "apple",
  125. success: function(loginRes) {
  126. that.appleKey = loginRes.authResult.openid;
  127. that.loginByAppleAct(loginRes.authResult);
  128. },
  129. fail: function(err) {
  130. console.log(err);
  131. }
  132. });
  133. }
  134. }
  135. });
  136. },
  137. async loginByAppleAct(authResult) {
  138. let loginDevice = "";
  139. if (plus.runtime.isAgreePrivacy()) {
  140. const info = await common_vendor.index.getPushClientId();
  141. common_vendor.index.setStorageSync("registrationID", info.cid);
  142. this.registrationID = info.cid;
  143. let devinfo = await common_vendor.index.getDeviceInfo();
  144. if (devinfo != null) {
  145. loginDevice += devinfo.deviceBrand ? devinfo.deviceBrand : "";
  146. loginDevice += devinfo.deviceModel ? " " + devinfo.deviceModel : "";
  147. loginDevice += devinfo.system ? " " + devinfo.system : "";
  148. }
  149. }
  150. const params = {
  151. loginDevice,
  152. jpushId: this.registrationID,
  153. source: this.source,
  154. appleKey: authResult.openid
  155. };
  156. common_vendor.index.showLoading({
  157. title: "登陆中"
  158. });
  159. loginByApple(params).then((res) => {
  160. common_vendor.index.hideLoading();
  161. if (res.user != null) {
  162. common_vendor.index.hideLoading();
  163. common_vendor.index.setStorageSync("AppToken", res.token);
  164. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  165. common_vendor.index.closeAuthView();
  166. common_vendor.index.$emit("refreshIM");
  167. common_vendor.index.$emit("showHealthButler");
  168. common_vendor.index.$emit("refreshUserInfo", {});
  169. this.goPage();
  170. } else {
  171. if (res.isNew) {
  172. this.bindMobile("apple");
  173. }
  174. }
  175. }).catch(() => {
  176. common_vendor.index.hideLoading();
  177. });
  178. },
  179. loginWeixin() {
  180. if (!this.agree) {
  181. common_vendor.index.showToast({
  182. title: "请同意相关协议",
  183. icon: "none"
  184. });
  185. return;
  186. }
  187. common_vendor.index.login({
  188. provider: "weixin",
  189. onlyAuthorize: true,
  190. success: async (res) => {
  191. common_vendor.index.showLoading({
  192. title: "处理中..."
  193. });
  194. const params = {
  195. code: res.code,
  196. jpushId: this.registrationID,
  197. source: this.source
  198. };
  199. this.loginByWeChatAct(params);
  200. },
  201. fail: (err) => {
  202. console.log("qxj loginWeixin fail:", JSON.stringify(err));
  203. if (err.code == 1e3) {
  204. common_vendor.index.showModal({
  205. title: "登录失败",
  206. content: `${err.errMsg}
  207. ,错误码:${err.code}`,
  208. confirmText: "开通指南",
  209. cancelText: "确定",
  210. success: (res) => {
  211. if (res.confirm) {
  212. setTimeout(() => {
  213. plus.runtime.openWeb(
  214. "https://ask.dcloud.net.cn/article/37965"
  215. );
  216. }, 500);
  217. }
  218. }
  219. });
  220. return;
  221. }
  222. if (err.code == "30005") {
  223. common_vendor.index.showModal({
  224. showCancel: false,
  225. title: "预登录失败",
  226. content: err.errMsg
  227. });
  228. return;
  229. }
  230. if (err.code != "30003") {
  231. common_vendor.index.showModal({
  232. showCancel: false,
  233. title: "登录失败",
  234. content: JSON.stringify(err)
  235. });
  236. }
  237. },
  238. complete: () => {
  239. }
  240. });
  241. },
  242. goToRegister() {
  243. this.$navTo("./register");
  244. },
  245. goToFindPass() {
  246. this.$navTo("./findpass");
  247. },
  248. doUniverify(authResult) {
  249. common_vendor.tr.callFunction({
  250. name: "loginByMobile",
  251. // 你的云函数名称
  252. data: {
  253. access_token: authResult.access_token,
  254. // 客户端一键登录接口返回的access_token
  255. openid: authResult.openid
  256. // 客户端一键登录接口返回的openid
  257. }
  258. }).then((res) => {
  259. common_vendor.index.closeAuthView();
  260. if (res.result.errCode == 0) {
  261. this.userName = res.result.phoneNumber;
  262. } else {
  263. common_vendor.index.showToast({
  264. title: res.result.message,
  265. icon: "none"
  266. });
  267. }
  268. }).catch((err) => {
  269. console.error("调用云函数失败:", err);
  270. console.error("错误信息:", err.errMsg);
  271. });
  272. },
  273. loginByWeChatAct(params) {
  274. api_login.loginByWeChat(params).then(
  275. (res) => {
  276. if (res.code == 200) {
  277. if (res.user != null) {
  278. common_vendor.index.hideLoading();
  279. common_vendor.index.setStorageSync("AppToken", res.token);
  280. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  281. common_vendor.index.closeAuthView();
  282. common_vendor.index.$emit("refreshIM");
  283. common_vendor.index.$emit("showHealthButler");
  284. common_vendor.index.$emit("refreshUserInfo", {});
  285. this.goPage();
  286. } else {
  287. this.unionid = res.unionid;
  288. if (res.isNew) {
  289. this.bindMobile();
  290. }
  291. }
  292. } else {
  293. common_vendor.index.hideLoading();
  294. common_vendor.index.showToast({
  295. title: res.msg,
  296. icon: "none"
  297. });
  298. }
  299. },
  300. (rej) => {
  301. }
  302. );
  303. },
  304. bindMobile(type) {
  305. },
  306. loginByUniverify(authResult, type) {
  307. common_vendor.tr.callFunction({
  308. name: "loginByMobile",
  309. // 你的云函数名称
  310. data: {
  311. access_token: authResult.access_token,
  312. // 客户端一键登录接口返回的access_token
  313. openid: authResult.openid
  314. // 客户端一键登录接口返回的openid
  315. }
  316. }).then((res) => {
  317. console.log("qxj doUniverify:", JSON.stringify(res));
  318. if (res.result.errCode == 0) {
  319. userPhone = res.result.phoneNumber;
  320. if (type == 3) {
  321. this.setPhoneAct(3, userPhone, this.unionid);
  322. } else {
  323. this.setPhoneAct(1, userPhone, this.unionid);
  324. }
  325. } else {
  326. common_vendor.index.showToast({
  327. title: res.result.message,
  328. icon: "none"
  329. });
  330. }
  331. }).catch((err) => {
  332. console.error("调用云函数失败:", err);
  333. console.error("错误信息:", err.errMsg);
  334. });
  335. },
  336. setPhoneAct(type, phone, unionId) {
  337. let params = {
  338. phone,
  339. unionId
  340. };
  341. if (type == 3) {
  342. params = {
  343. phone,
  344. unionId,
  345. appleKey: this.appleKey
  346. };
  347. }
  348. setPhone(params).then(
  349. (res) => {
  350. common_vendor.index.hideLoading();
  351. if (res.code == 200) {
  352. common_vendor.index.setStorageSync("AppToken", res.token);
  353. common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
  354. common_vendor.index.closeAuthView();
  355. common_vendor.index.$emit("refreshIM");
  356. this.goPage();
  357. } else {
  358. common_vendor.index.showToast({
  359. title: res.msg,
  360. icon: "none"
  361. });
  362. common_vendor.index.closeAuthView();
  363. }
  364. },
  365. (rej) => {
  366. }
  367. );
  368. },
  369. getRegistrationID() {
  370. this.registrationID = common_vendor.index.getStorageSync("registrationID");
  371. if (this.registrationID == null || this.registrationID == "") {
  372. common_vendor.index.getPushClientId({
  373. success: (res) => {
  374. common_vendor.index.setStorageSync("registrationID", res.cid);
  375. this.registrationID = res.cid;
  376. }
  377. });
  378. }
  379. },
  380. goBack() {
  381. console.log("qxj goBack");
  382. common_vendor.index.$emit("showHealthButler");
  383. common_vendor.index.redirectTo({
  384. url: "/pages/auth/loginIndex"
  385. });
  386. },
  387. handleAgree() {
  388. this.agree = !this.agree;
  389. if (this.isIos) {
  390. if (this.agree) {
  391. plus.runtime.agreePrivacy();
  392. this.getRegistrationID();
  393. } else {
  394. plus.runtime.disagreePrivacy();
  395. }
  396. }
  397. },
  398. goToWeb(index) {
  399. common_vendor.index.setStorageSync("url", index == 0 ? "https://userapp.his.cdwjyyh.com/web/userAgreement" : "https://userapp.his.cdwjyyh.com/web/privacyPolicy");
  400. common_vendor.index.navigateTo({
  401. url: "/pages/index/h5"
  402. });
  403. },
  404. goPage() {
  405. let pages = getCurrentPages();
  406. pages[pages.length - 1];
  407. let openUrl = common_vendor.index.getStorageSync("openUrl");
  408. if (openUrl) {
  409. common_vendor.index.navigateTo({
  410. url: openUrl,
  411. success: function(res) {
  412. common_vendor.index.removeStorageSync("openUrl");
  413. }
  414. });
  415. } else {
  416. common_vendor.index.reLaunch({
  417. url: "/pages/list/index",
  418. animationType: "none",
  419. animationDuration: 2e3
  420. });
  421. return;
  422. }
  423. this.$updateMsgDot();
  424. this.$setSource();
  425. }
  426. }
  427. };
  428. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  429. return common_vendor.e({
  430. a: common_vendor.o(($event) => $options.goBack()),
  431. b: common_assets._imports_0$5,
  432. c: $data.userName,
  433. d: common_vendor.o(($event) => $data.userName = $event.detail.value),
  434. e: $data.password,
  435. f: common_vendor.o(($event) => $data.password = $event.detail.value),
  436. g: common_vendor.o((...args) => $options.login && $options.login(...args)),
  437. h: common_vendor.o(($event) => $options.goToRegister()),
  438. i: $data.isApp && $data.isAgreePrivacy
  439. }, $data.isApp && $data.isAgreePrivacy ? common_vendor.e({
  440. j: common_assets._imports_1$3,
  441. k: common_vendor.o((...args) => $options.loginWeixin && $options.loginWeixin(...args)),
  442. l: $data.isIos
  443. }, $data.isIos ? {
  444. m: common_assets._imports_2$2,
  445. n: common_vendor.o((...args) => $options.quickAppleLogin && $options.quickAppleLogin(...args))
  446. } : {}) : {}, {
  447. o: common_assets._imports_0$4,
  448. p: !$data.agree,
  449. q: common_assets._imports_1$2,
  450. r: $data.agree,
  451. s: common_vendor.o((...args) => $options.handleAgree && $options.handleAgree(...args)),
  452. t: common_vendor.o(($event) => $options.goToWeb(0)),
  453. v: common_vendor.o(($event) => $options.goToWeb(1))
  454. });
  455. }
  456. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2cc9f8c3"]]);
  457. wx.createPage(MiniProgramPage);