123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_login = require("../../api/login.js");
- const common_assets = require("../../common/assets.js");
- const _sfc_main = {
- data() {
- return {
- userName: "",
- password: "",
- registrationID: "",
- unionid: "",
- userPhone: "",
- loginType: 0,
- isApp: false,
- agree: false,
- isAgreePrivacy: false,
- isIos: false,
- from: "",
- source: "",
- appleKey: ""
- };
- },
- onLoad(option) {
- this.from = option.from || "";
- let that = this;
- common_vendor.index.$on("getRegistrationID", function(data) {
- that.registrationID = data;
- });
- },
- onShow() {
- if (this.$isLogin()) {
- this.goPage();
- }
- },
- onUnload() {
- common_vendor.index.$off("getRegistrationID");
- },
- mounted() {
- },
- methods: {
- initUniverify() {
- const callback = (res) => {
- univerifyManager.getCheckBoxState({
- success(res2) {
- console.log("getCheckBoxState res: ", res2);
- if (res2.state) {
- univerifyManager.close();
- }
- }
- });
- };
- univerifyManager.onButtonsClick(callback);
- univerifyManager.offButtonsClick(callback);
- },
- login() {
- if (this.$isEmpty(this.userName)) {
- common_vendor.index.showToast({
- title: "请输入帐号",
- icon: "none"
- });
- return;
- }
- if (this.$isEmpty(this.password)) {
- common_vendor.index.showToast({
- title: "请输入密码",
- icon: "none"
- });
- return;
- }
- if (!this.agree) {
- common_vendor.index.showToast({
- title: "请同意相关协议",
- icon: "none"
- });
- return;
- }
- var data = {
- phone: this.userName,
- password: this.password,
- // jpushId: this.registrationID,
- loginType: 1
- // source: this.source
- };
- var that = this;
- common_vendor.index.showLoading({
- title: "处理中..."
- });
- api_login.loginByApp(data).then(
- (res) => {
- common_vendor.index.hideLoading();
- console.log("qxj res:" + JSON.stringify(res));
- if (res.code == 200) {
- common_vendor.index.setStorageSync("AppToken", res.token);
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
- common_vendor.index.$emit("refreshIM");
- common_vendor.index.$emit("showHealthButler");
- that.goPage();
- } else {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- }
- },
- (rej) => {
- console.log("qxj rej:" + JSON.stringify(rej));
- }
- );
- },
- quickAppleLogin() {
- let that = this;
- if (!this.agree) {
- common_vendor.index.showToast({
- title: "请同意相关协议",
- icon: "none"
- });
- return;
- }
- common_vendor.index.getProvider({
- service: "oauth",
- success: function(res) {
- if (res.provider.indexOf("apple")) {
- common_vendor.index.login({
- provider: "apple",
- success: function(loginRes) {
- that.appleKey = loginRes.authResult.openid;
- that.loginByAppleAct(loginRes.authResult);
- },
- fail: function(err) {
- console.log(err);
- }
- });
- }
- }
- });
- },
- async loginByAppleAct(authResult) {
- let loginDevice = "";
- if (plus.runtime.isAgreePrivacy()) {
- const info = await common_vendor.index.getPushClientId();
- common_vendor.index.setStorageSync("registrationID", info.cid);
- this.registrationID = info.cid;
- let devinfo = await common_vendor.index.getDeviceInfo();
- if (devinfo != null) {
- loginDevice += devinfo.deviceBrand ? devinfo.deviceBrand : "";
- loginDevice += devinfo.deviceModel ? " " + devinfo.deviceModel : "";
- loginDevice += devinfo.system ? " " + devinfo.system : "";
- }
- }
- const params = {
- loginDevice,
- jpushId: this.registrationID,
- source: this.source,
- appleKey: authResult.openid
- };
- common_vendor.index.showLoading({
- title: "登陆中"
- });
- loginByApple(params).then((res) => {
- common_vendor.index.hideLoading();
- if (res.user != null) {
- common_vendor.index.hideLoading();
- common_vendor.index.setStorageSync("AppToken", res.token);
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
- common_vendor.index.closeAuthView();
- common_vendor.index.$emit("refreshIM");
- common_vendor.index.$emit("showHealthButler");
- common_vendor.index.$emit("refreshUserInfo", {});
- this.goPage();
- } else {
- if (res.isNew) {
- this.bindMobile("apple");
- }
- }
- }).catch(() => {
- common_vendor.index.hideLoading();
- });
- },
- loginWeixin() {
- if (!this.agree) {
- common_vendor.index.showToast({
- title: "请同意相关协议",
- icon: "none"
- });
- return;
- }
- common_vendor.index.login({
- provider: "weixin",
- onlyAuthorize: true,
- success: async (res) => {
- common_vendor.index.showLoading({
- title: "处理中..."
- });
- const params = {
- code: res.code,
- jpushId: this.registrationID,
- source: this.source
- };
- this.loginByWeChatAct(params);
- },
- fail: (err) => {
- console.log("qxj loginWeixin fail:", JSON.stringify(err));
- if (err.code == 1e3) {
- common_vendor.index.showModal({
- title: "登录失败",
- content: `${err.errMsg}
- ,错误码:${err.code}`,
- confirmText: "开通指南",
- cancelText: "确定",
- success: (res) => {
- if (res.confirm) {
- setTimeout(() => {
- plus.runtime.openWeb(
- "https://ask.dcloud.net.cn/article/37965"
- );
- }, 500);
- }
- }
- });
- return;
- }
- if (err.code == "30005") {
- common_vendor.index.showModal({
- showCancel: false,
- title: "预登录失败",
- content: err.errMsg
- });
- return;
- }
- if (err.code != "30003") {
- common_vendor.index.showModal({
- showCancel: false,
- title: "登录失败",
- content: JSON.stringify(err)
- });
- }
- },
- complete: () => {
- }
- });
- },
- goToRegister() {
- this.$navTo("./register");
- },
- goToFindPass() {
- this.$navTo("./findpass");
- },
- doUniverify(authResult) {
- common_vendor.tr.callFunction({
- name: "loginByMobile",
- // 你的云函数名称
- data: {
- access_token: authResult.access_token,
- // 客户端一键登录接口返回的access_token
- openid: authResult.openid
- // 客户端一键登录接口返回的openid
- }
- }).then((res) => {
- common_vendor.index.closeAuthView();
- if (res.result.errCode == 0) {
- this.userName = res.result.phoneNumber;
- } else {
- common_vendor.index.showToast({
- title: res.result.message,
- icon: "none"
- });
- }
- }).catch((err) => {
- console.error("调用云函数失败:", err);
- console.error("错误信息:", err.errMsg);
- });
- },
- loginByWeChatAct(params) {
- api_login.loginByWeChat(params).then(
- (res) => {
- if (res.code == 200) {
- if (res.user != null) {
- common_vendor.index.hideLoading();
- common_vendor.index.setStorageSync("AppToken", res.token);
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
- common_vendor.index.closeAuthView();
- common_vendor.index.$emit("refreshIM");
- common_vendor.index.$emit("showHealthButler");
- common_vendor.index.$emit("refreshUserInfo", {});
- this.goPage();
- } else {
- this.unionid = res.unionid;
- if (res.isNew) {
- this.bindMobile();
- }
- }
- } else {
- common_vendor.index.hideLoading();
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- }
- },
- (rej) => {
- }
- );
- },
- bindMobile(type) {
- },
- loginByUniverify(authResult, type) {
- common_vendor.tr.callFunction({
- name: "loginByMobile",
- // 你的云函数名称
- data: {
- access_token: authResult.access_token,
- // 客户端一键登录接口返回的access_token
- openid: authResult.openid
- // 客户端一键登录接口返回的openid
- }
- }).then((res) => {
- console.log("qxj doUniverify:", JSON.stringify(res));
- if (res.result.errCode == 0) {
- userPhone = res.result.phoneNumber;
- if (type == 3) {
- this.setPhoneAct(3, userPhone, this.unionid);
- } else {
- this.setPhoneAct(1, userPhone, this.unionid);
- }
- } else {
- common_vendor.index.showToast({
- title: res.result.message,
- icon: "none"
- });
- }
- }).catch((err) => {
- console.error("调用云函数失败:", err);
- console.error("错误信息:", err.errMsg);
- });
- },
- setPhoneAct(type, phone, unionId) {
- let params = {
- phone,
- unionId
- };
- if (type == 3) {
- params = {
- phone,
- unionId,
- appleKey: this.appleKey
- };
- }
- setPhone(params).then(
- (res) => {
- common_vendor.index.hideLoading();
- if (res.code == 200) {
- common_vendor.index.setStorageSync("AppToken", res.token);
- common_vendor.index.setStorageSync("userInfo", JSON.stringify(res.user));
- common_vendor.index.closeAuthView();
- common_vendor.index.$emit("refreshIM");
- this.goPage();
- } else {
- common_vendor.index.showToast({
- title: res.msg,
- icon: "none"
- });
- common_vendor.index.closeAuthView();
- }
- },
- (rej) => {
- }
- );
- },
- getRegistrationID() {
- this.registrationID = common_vendor.index.getStorageSync("registrationID");
- if (this.registrationID == null || this.registrationID == "") {
- common_vendor.index.getPushClientId({
- success: (res) => {
- common_vendor.index.setStorageSync("registrationID", res.cid);
- this.registrationID = res.cid;
- }
- });
- }
- },
- goBack() {
- console.log("qxj goBack");
- common_vendor.index.$emit("showHealthButler");
- common_vendor.index.redirectTo({
- url: "/pages/auth/loginIndex"
- });
- },
- handleAgree() {
- this.agree = !this.agree;
- if (this.isIos) {
- if (this.agree) {
- plus.runtime.agreePrivacy();
- this.getRegistrationID();
- } else {
- plus.runtime.disagreePrivacy();
- }
- }
- },
- goToWeb(index) {
- common_vendor.index.setStorageSync("url", index == 0 ? "https://userapp.his.cdwjyyh.com/web/userAgreement" : "https://userapp.his.cdwjyyh.com/web/privacyPolicy");
- common_vendor.index.navigateTo({
- url: "/pages/index/h5"
- });
- },
- goPage() {
- let pages = getCurrentPages();
- pages[pages.length - 1];
- let openUrl = common_vendor.index.getStorageSync("openUrl");
- if (openUrl) {
- common_vendor.index.navigateTo({
- url: openUrl,
- success: function(res) {
- common_vendor.index.removeStorageSync("openUrl");
- }
- });
- } else {
- common_vendor.index.reLaunch({
- url: "/pages/list/index",
- animationType: "none",
- animationDuration: 2e3
- });
- return;
- }
- this.$updateMsgDot();
- this.$setSource();
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.o(($event) => $options.goBack()),
- b: common_assets._imports_0$5,
- c: $data.userName,
- d: common_vendor.o(($event) => $data.userName = $event.detail.value),
- e: $data.password,
- f: common_vendor.o(($event) => $data.password = $event.detail.value),
- g: common_vendor.o((...args) => $options.login && $options.login(...args)),
- h: common_vendor.o(($event) => $options.goToRegister()),
- i: $data.isApp && $data.isAgreePrivacy
- }, $data.isApp && $data.isAgreePrivacy ? common_vendor.e({
- j: common_assets._imports_1$3,
- k: common_vendor.o((...args) => $options.loginWeixin && $options.loginWeixin(...args)),
- l: $data.isIos
- }, $data.isIos ? {
- m: common_assets._imports_2$2,
- n: common_vendor.o((...args) => $options.quickAppleLogin && $options.quickAppleLogin(...args))
- } : {}) : {}, {
- o: common_assets._imports_0$4,
- p: !$data.agree,
- q: common_assets._imports_1$2,
- r: $data.agree,
- s: common_vendor.o((...args) => $options.handleAgree && $options.handleAgree(...args)),
- t: common_vendor.o(($event) => $options.goToWeb(0)),
- v: common_vendor.o(($event) => $options.goToWeb(1))
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2cc9f8c3"]]);
- wx.createPage(MiniProgramPage);
|