123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import dayjs from 'dayjs'
- import AuthApi from '../../services/auth'
- import { isLogin } from '../../utils/util'
- // components/pop-right/pop-right.ts
- Component({
- /**
- * 组件的属性列表
- */
- properties: {},
- data: {
- innerShow: false,
- loading: false,
- },
- lifetimes: {
- ready: function () {
- const status = isLogin()
- const self = this
- if (!status) {
- // self.setData({
- // innerShow: true,
- // })
- // return
- wx.login({
- async success(res) {
- if (res.code) {
- AuthApi.Authenticate({
- providerAccessCode: res.code,
- }).then((rsp) => {
- if (rsp.result) {
- if (rsp.result.signature) {
- self.okfunc(rsp.result)
- } else {
- self.setData({
- innerShow: true,
- })
- }
- }
- })
- }
- },
- })
- } else {
- this.triggerEvent('ok')
- }
- },
- },
- /**
- * 组件的方法列表
- */
- methods: {
- close() {
- this.setData({
- innerShow: false,
- })
- },
- disagree() {
- this.triggerEvent('disagree')
- },
- getPhoneNumber(
- e: WechatMiniprogram.CustomEvent<{ encryptedData: string; iv: string; errMsg: string }>,
- ) {
- if (e.detail.errMsg !== 'getPhoneNumber:ok') {
- return
- }
- const self = this
- wx.login({
- async success(res) {
- if (res.code) {
- AuthApi.Authenticate({
- providerAccessCode: res.code,
- }).then((rsp) => {
- if (rsp.result) {
- if (rsp.result.providerKey) {
- const providerKey = rsp.result.providerKey
- console.log('get Authenticate', providerKey)
- AuthApi.Entrance({
- seCode: providerKey,
- encryptedData: e.detail.encryptedData,
- iv: e.detail.iv,
- }).then((rsp2) => {
- console.log('get Entrance', rsp2)
- if (rsp2.result) {
- self.okfunc(rsp2.result)
- return
- }
- self.setData({
- loading: false,
- prepare: 'need',
- })
- })
- } else if (rsp.result.signature) {
- self.okfunc(rsp.result)
- }
- }
- })
- } else {
- self.setData({
- loading: false,
- })
- }
- },
- })
- },
- okfunc(info: any) {
- info.expiration = dayjs().add(info.expiration, 'second') as any
- wx.setStorageSync('__uvx', JSON.stringify(info))
- this.triggerEvent('ok')
- this.setData({
- loading: false,
- innerShow: false,
- })
- },
- openPrivacyContract() {
- wx.openPrivacyContract({
- success: (res) => {
- console.log('openPrivacyContract success')
- },
- fail: (res) => {
- console.error('openPrivacyContract fail', res)
- },
- })
- },
- },
- })
|