| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- // components/getPhoneButton/getPhoneButton.js
- import {
- wxSetSessionKey
- } from "../../utils/wxUtils"
- import {
- postApi
- } from "../../apis/api"
- import cloudApi from "../../apis/cloudApi"
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- style: String,
- type: String
- },
- data: {
- },
- methods: {
- async getPhoneNumber(e) {
- try {
- if (e.detail.errMsg == "getPhoneNumber:ok") {
- let session_key = wx.getStorageSync('session_key')
- let {
- result
- } = await cloudApi("getWxPhoneNumber", {
- ...e.detail,
- session_key
- })
- let {
- phone,
- } = result
- let res = await postApi("/user/wx/login", {
- openId: wx.getStorageSync('openId'),
- phone
- })
- if (res.data.status == 0) {
- let data = res.data.result
- Object.keys(data).forEach(function (key) {
- wx.setStorageSync(key, data[key])
- })
- wx.switchTab({
- url: '/pages/index/index',
- })
- } else {
- wx.showToast({
- icon: "none",
- title: res.data.msg
- })
- }
- } else {
- wx.showToast({
- title: '请授权以登录',
- icon: "error"
- })
- }
- } catch (error) {
- wxSetSessionKey()
- wx.showToast({
- icon: "none",
- title: '请重试或联系管理员',
- })
- }
- }
- }
- })
|