From f5fb22787e4f65695d51d3a0e27eadde8526608e Mon Sep 17 00:00:00 2001 From: xpz2018 <107107461@qq.com> Date: Fri, 8 Jan 2021 16:32:20 +0800 Subject: [PATCH] no message --- pages/api/article.js | 20 +++++++++ pages/api/payment.js | 20 +++++++++ pages/api/recycle.js | 20 +++++++++ pages/api/user.js | 15 ++++--- pages/login/index.js | 97 ++++++++++++++++---------------------------- 5 files changed, 101 insertions(+), 71 deletions(-) create mode 100644 pages/api/article.js create mode 100644 pages/api/payment.js create mode 100644 pages/api/recycle.js diff --git a/pages/api/article.js b/pages/api/article.js new file mode 100644 index 0000000..974ec44 --- /dev/null +++ b/pages/api/article.js @@ -0,0 +1,20 @@ +/** + * Copyright © 2020-present LiuDanYang. All rights Reserved. + */ +import { mGet, mPost } from "./request" +const app = getApp() + +const aconfig = { + baseUrl: app.release ? `https://psc.qniao.cn` : `http://psc-dev.qniao.cn` +} +// *******************************************************************账户业务*********************************************************** +// /credit/get/self-enterprise-credit-by-enterprise-id查看个人的采购额度 +const getCreditInfo = (params) => mGet(`/payment-settlement-center/credit/get/self-enterprise-credit-by-enterprise-id`, params, aconfig) + +const paymentInfo = (params) => mPost(`/payment-settlement-center/pay`, params, aconfig) + +export { + aconfig, + getCreditInfo, + paymentInfo +} \ No newline at end of file diff --git a/pages/api/payment.js b/pages/api/payment.js new file mode 100644 index 0000000..f8acf28 --- /dev/null +++ b/pages/api/payment.js @@ -0,0 +1,20 @@ +/** + * Copyright © 2020-present LiuDanYang. All rights Reserved. + */ +import { mGet, mPost } from "./request" +const app = getApp() + +const pconfig = { + baseUrl: app.release ? `https://psc.qniao.cn` : `http://psc-dev.qniao.cn` +} +// *******************************************************************账户业务*********************************************************** +// /credit/get/self-enterprise-credit-by-enterprise-id查看个人的采购额度recycle +const getCreditInfo = (params) => mGet(`/payment-settlement-center/credit/get/self-enterprise-credit-by-enterprise-id`, params, pconfig) + +const paymentInfo = (params) => mPost(`/payment-settlement-center/pay`, params, pconfig) + +export { + pconfig, + getCreditInfo, + paymentInfo +} \ No newline at end of file diff --git a/pages/api/recycle.js b/pages/api/recycle.js new file mode 100644 index 0000000..81010b2 --- /dev/null +++ b/pages/api/recycle.js @@ -0,0 +1,20 @@ +/** + * Copyright © 2020-present LiuDanYang. All rights Reserved. + */ +import { mGet, mPost } from "./request" +const app = getApp() + +const rconfig = { + baseUrl: app.release ? `https://psc.qniao.cn` : `http://psc-dev.qniao.cn` +} +// *******************************************************************账户业务*********************************************************** +// /credit/get/self-enterprise-credit-by-enterprise-id查看个人的采购额度 +const getCreditInfo = (params) => mGet(`/payment-settlement-center/credit/get/self-enterprise-credit-by-enterprise-id`, params, rconfig) + +const paymentInfo = (params) => mPost(`/payment-settlement-center/pay`, params, rconfig) + +export { + rconfig, + getCreditInfo, + paymentInfo +} \ No newline at end of file diff --git a/pages/api/user.js b/pages/api/user.js index e56e1a1..42c11d4 100644 --- a/pages/api/user.js +++ b/pages/api/user.js @@ -7,14 +7,14 @@ const storage = require('../../utils/storage') const app = getApp() const config = { - baseUrl: app.release ? 'https://uec.qniao.cn' : 'http://47.107.97.166:9000', - header: { - 'Authorization': `QNT ` + storage.get('Authorization') - } + baseUrl: app.release ? 'https://uec.qniao.cn' : 'http://47.107.97.166:9000' } // /uec/get/wechat-applet-session const wechatApplet = (params) => mPost('/uec/get/wechat-applet-session', params, config) - +// /uec/authorize/by-captcha +const loginCaptcha = (params) => mPost(`/uec/authorize/by-captcha`, params, config) +// /uec/get/auth-captcha +const postCaptcha = (params) => mPost(`/uec/get/auth-captcha`, params, config) const getUserInfo = (params) => mGet('/uec/get/user-info', params, config) const getAuthSession = () => mGet('/uec/create/identity-auth-session', null, config) @@ -22,7 +22,6 @@ const getAuthSession = () => mGet('/uec/create/identity-auth-session', null, con const certificateImage = (params) => mPost('/uec/recognize/certificate-img', params, config) const certificateIdentity = (params) => mPost('/uec/identify/identity', params, config) const getAddressList = () => mGet(`/uec/get/enterprise-shipping-address-list/by-userId`, null, config) -const getAddressInfo = (id) => mGet(`/uec/get/enterprise-shipping-address-list/by-userId`, null, config) const saveAddress = (params) => mPost(`/uec/save/enterprise-shipping-address`, params, config) // /uec/delete/enterprise-shipping-address/{id} const deleteAddress = (id) => mDelete(`/uec/delete/enterprise-shipping-address/${id}`, null, config) @@ -88,7 +87,6 @@ function unionWechat(form, resolve, reject) { data: form, method: 'POST', success: function (result) { - wx.hideLoading() if (result.data.code == 0) { storage.remove('tempToken') resolve(result.data) @@ -185,6 +183,8 @@ export { finalizeToken, wechatApplet, getUserInfo, + postCaptcha, + loginCaptcha, getAuthSession, certificateImage, certificateIdentity, @@ -192,6 +192,5 @@ export { loginWechat, getAddressList, saveAddress, - getAddressInfo, deleteAddress } \ No newline at end of file diff --git a/pages/login/index.js b/pages/login/index.js index 0f38a1b..8aa77f7 100644 --- a/pages/login/index.js +++ b/pages/login/index.js @@ -1,5 +1,6 @@ //获取应用实例 import { $wuxCountDown } from '../../components/index' +import { config, postCaptcha, loginCaptcha, wechatApplet, getUserInfo, loginWechat } from "../api/user" const storage = require('../../utils/storage') const request = require('../../utils/request') //导入模块 const util = require('../../utils/util') @@ -29,6 +30,7 @@ Page({ if (options.mobile) { this.setData({ ['form.mobile']: options.mobile }) } + this.wxLogin() var check = wx.getStorageSync('AgreeCheck') app.globalData.kg = wx.getStorageSync('ztb-kg') if (check) { @@ -38,42 +40,29 @@ Page({ wxLogin: function(){ wx.login({ success: res => { - // 获取openId - wx.request({ - header: { 'X-APP-ID': app.xAppId }, - url: app.httpUrl + '/recycle-service/authorize/wechat-applet/user', - data: { authCode: res.code }, - method: 'POST', - success: function (result) { - if (result.data.code == 0) { - storage.put('tempToken', result.data.data.tmpAuthToken, 98) - } - } + wechatApplet({ authCode: res.code }).then(result => { + storage.put('tmpAuthToken', result.data.tmpAuthToken, 98) }) } }) }, - checkLogin: function () { - var authorization = wx.getStorageSync('Authorization') - // console.log('authorization>>>' + authorization) - if (authorization) { - app.globalData.token = authorization - var userToken = wx.getStorageSync('accessToken') - if (userToken) { - app.globalData.userToken = userToken - } - this.setData({ loging: true}) - // /front/customer/myInfo 用户信息 - request.get('/recycle-service/user/get/base-info').then(result => { - this.doLoginResponse(result) - }).catch(err => { - //异常回调 - this.setData({ loging: false}) - this.wxLogin() - }) - } else { - this.wxLogin() + fetchUserInfo: function () { + var authorization = app.globalData.token || wx.getStorageSync('Authorization') + if (util.isEmpty(authorization)) { + return } + app.globalData.token = authorization + config.header = { 'Authorization': 'QNT ' + authorization } + getUserInfo().then(result => { + app.globalData.userInfo = result.data + this.setData({ loging: false}) + event.emit('EventMessage', { what: 888, desc: 'Logined' }) + wx.hideLoading() + wx.navigateBack() + }).catch(err => { + wx.hideLoading() + this.setData({ loging: false}) + }) }, changePwd: function () { if (this.data.pwdType === 'password') { @@ -117,37 +106,19 @@ Page({ return } wx.showLoading({ title: '登录中', mask: true }) - // this.data.form.password = md5.hexMD5(this.data.form.password).toUpperCase() - var url = '/recycle-service/authorize/by-captcha' if (this.data.type == 1) { // /authorize/by-captcha 验证码认证 - url = '/recycle-service/authorize/by-captcha' + loginCaptcha(this.data.form).then(result => { + wx.setStorageSync('Authorization', result.data.token) + app.globalData.token = result.data.token + this.fetchUserInfo() + }).catch(error => { + wx.hideLoading() + util.showToast(error) + }) } else { // authorize/by-password 密码登录 - url = '/recycle-service/authorize/by-password' - } - request.post(url, this.data.form).then(result => { - wx.setStorageSync('accessToken', result.data.userToken) - wx.setStorageSync('Authorization', result.data.token) - app.globalData.token = result.data.token - app.globalData.userToken = result.data.userToken - this.checkLogin() - }).catch(error => { - wx.hideLoading() - util.showToast(error) - }) - }, - // 进行登录处理; - doLoginResponse: function (result) { - if (result.data.token) { - wx.setStorageSync('accessToken', result.data.userToken) - wx.setStorageSync('Authorization', result.data.token) - app.globalData.token = result.data.token - app.globalData.userToken = result.data.userToken } - app.globalData.userInfo = result.data - event.emit('EventMessage', { what: 888, desc: 'Logined' }) - wx.navigateBack() }, changeType: function () { if (this.data.type == 1) { @@ -164,7 +135,7 @@ Page({ if (this.second && this.second.interval) return !1 wx.showLoading({ title: '正在获取', mask: true }) // /send/captcha 发送验证码 - request.post('/recycle-service/send/captcha', { account: this.data.form.account, accountType: 'MOBILE', purpose: 'RECYCLE_CLIENT_LOGIN' }).then(result => { + postCaptcha({ verifiableAccount: this.data.form.account, verifiableAccountType: 1, purpose: 1 }).then(result => { wx.hideLoading() this.setData({ codeEnable: false }) util.showToast('验证码已经发送') @@ -192,13 +163,14 @@ Page({ wx.navigateTo({ url: '/pages/html/agreement/index' }) }, onGotUserInfo: function (e) { - request.loginWechat({ encryptedData: e.detail.encryptedData, iv: e.detail.iv }).then(result => { - wx.setStorageSync('accessToken', result.data.userToken) + this.setData({ loging: true }) + loginWechat({ encryptedData: e.detail.encryptedData, iv: e.detail.iv }).then(result => { wx.setStorageSync('Authorization', result.data.token) app.globalData.token = result.data.token - app.globalData.userToken = result.data.userToken - this.checkLogin() + this.fetchUserInfo() }).catch(error => { + wx.hideLoading() + this.setData({ loging: false }) if (error && error.data) { if (error.code == 200101) { this.setData({ wxflag: true }) @@ -215,5 +187,4 @@ Page({ this.wuxCountDown = null } } - }) \ No newline at end of file