123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- const util = require('../utils/util.js');
- const openidStatus = () => {
- return new Promise((resolve, reject) => {
- wx.login({
- success: (res) => {
- if (res.code) {
- wx.request({
- url: util.globalData.publicUrl + '/wx/user/wxbfa171fdd4000e03/login',
- method: "GET",
- data: {
- code: res.code
- },
- success: res => {
- console.log(res.data.openid,'我是wx.login的openid')
- console.log(res.data.sessionKey,'我是wx.login的sessionKey')
- if (res.statusCode == 200) {
- wx.setStorageSync('openId', res.data.openid)
- wx.setStorageSync('sessionKey', res.data.sessionKey)
- resolve([res.data.openid, res.data.sessionKey]);
- }
- }
- });
- } else {
- reject(res.errMsg);
- }
- }
- })
- })
- };
- function formatTime(date) {
- var year = date.getFullYear()
- return year
- }
- const formDetails = (type) => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/options',
- method: "GET",
- data: {
- type
- },
- success: res => {
- // console.log(res)
- if (res.data.code == 0) {
- if (res.data.options) {
- let labelArr = res.data.options.map((obj, index) => {
- return obj.dictLabel;
- })
- let valueArr = res.data.options.map((obj, index) => {
- return obj.dictValue;
- })
- resolve([labelArr, valueArr])
- }
- } else {
- reject(res)
- }
- }
- })
- })
- };
- // 判断是否登录
- const isLogin = () => {
- // return new Promise((resolve, reject) => {
- // wx.getSetting({
- // success: res => {
- // console.log(res)
- // if (res.authSetting['scope.userInfo']) {
- // wx.getUserInfo({
- // success: res => {
- // resolve(res)
- // }
- // })
- // } else {
- // reject(false)
- // }
- // }
- // })
- // })
- return new Promise((resolve, reject) => {
- wx.request({
- url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/info',
- method: "get",
- success: (res) => {
- if (res.data.code == 0&&res.data.info.avatar&&res.data.info.nickName) {
- resolve(true)
- } else {
- reject(false)
- }
- }
- })
- })
- };
- // 判断是否完善个人信息
- const isFinishInfo = () => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/info',
- method: "get",
- success: (res) => {
- // console.log(res,'99999999999999999')
- if (res.data.code == 0&&res.data.info.name&&res.data.info.height) {
- resolve(res.data.info)
- } else {
- reject(res.data.info)
- }
- }
- })
- })
- };
- // 判断是否完善择偶条件
- const isFinishTargetInfo = () => {
- return new Promise((resolve, reject) => {
- wx.request({
- url: util.globalData.publicUrl + '/wx/member/' + wx.getStorageSync('openId') + '/standard',
- method: "get",
- success: (res) => {
- console.log(res)
- if (res.data.code == 0) {
- resolve(res.data.standard);
- } else {
- reject(res.data.code)
- }
- }
- })
- })
- };
- module.exports = {
- openidStatus,
- formDetails,
- formatTime,
- isLogin,
- isFinishInfo,
- isFinishTargetInfo
- }
|