123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- //import * as WxJsApi from '@/utils/wxJsApi.js'
- import * as API from '@/apis/index.js'
- import {
- checkPhone
- } from '@/utils'
- export default {
- data() {
- return {
- readme: true,
- phone: "",
- isReady: false,
- errorType: ['message'],
- rules: {
- phone: [{
- required: true,
- message: '请输入手机号',
- trigger: ['change', 'blur'],
- },
- {
- validator: (rule, value, callback) => {
- // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
- return this.$u.test.mobile(value);
- },
- message: '手机号码不正确',
- // 触发器可以同时用blur和change,二者之间用英文逗号隔开
- trigger: ['change', 'blur'],
- }
- ],
- code: [{
- required: true,
- message: '请输入验证码',
- trigger: ['change', 'blur'],
- },
- {
- type: 'number',
- message: '验证码只能为数字',
- trigger: ['change', 'blur'],
- }
- ]
- }
- }
- },
- components: {
- },
- onLoad(op) {
- //this.id=op.id;
- },
- methods: {
-
- loginByUniverify(provider, res) {
-
- const univerifyInfo = {
- provider,
- ...res.authResult,
- }
- uni.request({
- url: 'https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/univerify-login',
- method: 'POST',
- data: univerifyInfo,
- success: (res) => {
- const data = res.data
- if (data.success) {
- this.phone = phoneNumber;
- } else {
- console.log("111")
- }
-
- },
- fail: (err) => {
- console.log("222")
- }
- })
-
-
- },
- getPhone() {
- uni.login({
- provider: 'univerify',
- success: async (res) => {
- console.log('login success:', res);
- this.loginByUniverify("univerify", res)
- },
- fail: (err) => {
- console.log('login fail:', err);
- // 一键登录点击其他登录方式
- if (err.code == '30002') {
- uni.closeAuthView();
- this.Toast({
- title: '其他登录方式'
- })
- return;
- }
- // 未开通
- if (err.code == 1000) {
- uni.showModal({
- title: '登录失败',
- content: `${err.errMsg}\n,错误码:${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') {
- uni.showModal({
- showCancel: false,
- title: '预登录失败',
- content: this.univerifyErrorMsg || err.errMsg
- });
- return;
- }
- // 一键登录用户关闭验证界面
- if (err.code != '30003') {
- uni.showModal({
- showCancel: false,
- title: '登录失败',
- content: JSON.stringify(err)
- });
- }
- },
- complete: () => {
- this.univerifyBtnLoading = false;
- }
- });
- },
- login() {
- var checkPhoneResult = checkPhone(this.phone);
-
- if(checkPhoneResult){
- uni.showToast({
- title: checkPhoneResult,
-
- })
- return;
- }
- this.$refs.uForm.validate(valid => {
- if (valid) {
- console.log('验证通过');
- } else {
- console.log('验证失败');
- }
- });
- if (!this.readme) {
- uni.showToast({
- title: "请阅读并同意《用户协议》《隐私政策》",
-
- })
- } else {
- uni.navigateTo({
- url:"/pages/login/vCode/vCode?phone="+this.phone
- })
- }
- }
- },
- onReady() {
- //
- this.$refs.uForm.setRules(this.rules);
- //
- this.getPhone()
- this.isReady = true;
- },
- onShow() {
- if (this.isReady) {
- }
- },
- }
|