From 38df1c43bb78873e84ed3984a859c175303daf01 Mon Sep 17 00:00:00 2001 From: YXQ Date: Thu, 13 Jul 2023 18:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8A=B6=E6=80=81=E5=88=A4?= =?UTF-8?q?=E6=96=AD,=E6=B7=BB=E5=8A=A0=E7=BB=91=E5=AE=9A=E9=80=BB?= =?UTF-8?q?=E8=BE=91,=E8=B0=83=E6=95=B4=E7=95=8C=E9=9D=A2,=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=87=BA=E5=87=BA=E8=B4=A6=E5=8F=B7=E9=80=BB=E8=BE=91?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 20 +- pages/about/about.js | 72 ++++- pages/about/about.wxml | 2 +- pages/feedback/feedback.wxml | 2 +- pages/freiLogistics/freiLogistics.js | 386 ++++++++++++++++++++--- pages/freiLogistics/freiLogistics.wxml | 58 ++-- pages/freiLogistics/freiLogistics.wxss | 10 +- pages/handover/handover.js | 24 +- pages/handover/handover.wxml | 6 +- pages/handover/handover.wxss | 8 +- pages/index/index.js | 113 ++++++- pages/index/index.wxml | 9 +- pages/login/login.js | 16 +- pages/meLogistics/meLogistics.js | 48 +-- pages/meLogistics/meLogistics.wxml | 4 +- pages/meLogistics/meLogistics.wxss | 8 +- pages/queryfrei/queryfrei.js | 127 ++++++-- pages/queryfrei/queryfrei.wxml | 127 ++++---- pages/queryfrei/queryfrei.wxss | 16 +- pages/queryme/queryme.js | 65 ++-- pages/queryme/queryme.wxml | 44 +-- pages/queryme/queryme.wxss | 5 +- pages/querythree/querythree.js | 127 ++++++-- pages/querythree/querythree.wxml | 94 +++--- pages/querythree/querythree.wxss | 13 +- pages/threeLogistics/threeLogistics.js | 359 +++++++++++++++++---- pages/threeLogistics/threeLogistics.wxml | 51 ++- pages/threeLogistics/threeLogistics.wxss | 6 +- utils/dateSetting.js | 17 +- utils/login.js | 37 +++ 30 files changed, 1403 insertions(+), 471 deletions(-) create mode 100644 utils/login.js diff --git a/app.js b/app.js index caa4cff..431df83 100644 --- a/app.js +++ b/app.js @@ -3,7 +3,6 @@ App({ onLaunch() { // 展示本地存储能力 const logs = wx.getStorageSync('logs') || [] - logs.unshift(Date.now()) wx.setStorageSync('logs', logs) // 登录 @@ -16,19 +15,21 @@ App({ globalData: { // 本地环境 - baseUrl:'http://192.168.51.22:8201/mall-portal', + baseUrl: 'http://192.168.51.200:8201/mall-portal', // 线上环境 // baseUrl:'https://portal-api.macrozheng.com', token: '', - userInfo:{}, - bindvx:null + userInfo: {}, + bindvx: false, + openid: '' }, - judLogin(){ + //如果未登录提示跳转到等级界面 + judLogin() { wx.showModal({ title: '提示', - content: '尊敬的用户您还未登录,请先登录', - confirmText:'去登陆', + content: '您还未登录,请先登录', + confirmText: '去登陆', complete: (res) => { if (res.confirm) { wx.navigateTo({ @@ -37,9 +38,8 @@ App({ }; if (res.cancel) { console.log('用户点击取消'); - } + } } }) }, - -}) +}) \ No newline at end of file diff --git a/pages/about/about.js b/pages/about/about.js index 7e7063e..e9b0834 100644 --- a/pages/about/about.js +++ b/pages/about/about.js @@ -1,25 +1,42 @@ // pages/about/about.js +var request = require('../../utils/http') +var login = require('../../utils/login') +var app = getApp(); Page({ - /** * 页面的初始数据 */ data: { - username: '立即登录' + username: '立即登录', + isLogin: false, //是否登录 }, //绑定微信 bindWx() { + var isBindWx = '' + var content = '' + if (app.globalData.bindvx) { + //解绑 + isBindWx = '解除绑定' + content = '平台账号已经与您微信账号绑定,是否进行解绑定?' + } else { + //绑定 + isBindWx = '立刻绑定' + content = '平台账号将与您微信账号绑定,是否进行绑定?' + } + + wx.showModal({ title: '绑定微信', - content: '平台账号与微信账号绑定后,可以直接用微信进行登录,是否进行绑定?', - confirmText: '绑定', + content: content, + confirmText: isBindWx, complete: (res) => { if (res.confirm) { - wx.login({ - success: (res) => { - console.log(res); - }, + login.bindWechat({ + openid: app.globalData.openid + }).then(res1 => { + console.log('res=' + JSON.stringify(res1)); + this.onLoad() }) } if (res.cancel) { @@ -27,6 +44,7 @@ Page({ } } }) + }, //查询跳转 @@ -67,12 +85,50 @@ Page({ }) }, + //退出登录 + outLogin() { + wx.showModal({ + title: '提示', + content: '是否确定退出?', + complete: (res) => { + if (res.cancel) { + + } + + if (res.confirm) { + app.globalData.token = '' + app.globalData.userInfo = {} + + this.setData({ + isLogin: false, + username: '立即登录' + }) + this.onLoad() + } + } + }) + + + }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { + request.post('/sso/checkBind/' + app.globalData.openid).then(res2 => { + console.log('检查是否绑定=' + JSON.stringify(res2.data.data)); + app.globalData.bindvx = res2.data.data + }) + + var userInfo = app.globalData.userInfo + console.log('userInfo' + JSON.stringify(app.globalData.userInfo)); + if (userInfo != undefined && JSON.stringify(userInfo) != '{}') { + this.setData({ + username: userInfo.nickname, + isLogin: true + }) + } }, /** diff --git a/pages/about/about.wxml b/pages/about/about.wxml index 946e53b..f94caff 100644 --- a/pages/about/about.wxml +++ b/pages/about/about.wxml @@ -34,6 +34,6 @@ - 退出登录 + 退出登录 \ No newline at end of file diff --git a/pages/feedback/feedback.wxml b/pages/feedback/feedback.wxml index bf16c31..05364d5 100644 --- a/pages/feedback/feedback.wxml +++ b/pages/feedback/feedback.wxml @@ -15,7 +15,7 @@ * 上传图片/截图 - + {{item.text}} diff --git a/pages/freiLogistics/freiLogistics.js b/pages/freiLogistics/freiLogistics.js index 9118d07..ad55374 100644 --- a/pages/freiLogistics/freiLogistics.js +++ b/pages/freiLogistics/freiLogistics.js @@ -1,95 +1,100 @@ +//货运物流 var datePicker = require('../../utils/dateSetting') +var request = require('../../utils/http') +var dateUtils = require('../../utils/dateUtils') Page({ data: { - list:[ - { - 'id':1, - 'number':'2023050002', - 'time':'2023-5-12 11:32', - 'status':'已签收', - 'name':'张三', - 'num':'M2023055568' - }, - { - 'id':2, - 'number':'2023050002', - 'time':'2023-5-12 11:32', - 'status':'已签收', - 'name':'李四', - 'num':'M2023055568' + selfOrderCode: '', //物流单号 + sampleList: [{ + 'id': 1, + 'number': '2023050002', + 'time': '2023-5-12 11:32', + 'status': '已签收', + 'name': '张三', + 'num': 'M2023055568' } ], - pipenum:'', - ins: ['私家车','大巴',], + pipenum: '', + ins: [], //转运方式 + insIdx: 0, //转运方式下标 date: '', - start:'2020-01-01', - end:'', + start: '2023-07-01', + end: '', + + potoSrc: '../../images/addPoto.png', //默认图片 + poto: [], //车辆&转运箱照片 最大长度 4 time: '', multiArray: [], multiIndex: [0, 0, 0, 0, 0], choose_year: "", - srcArray:[] - + srcArray: [], + phone: '', //物流电话 + boxNum: '', //转运箱号 + cost: '', //物流费用 + numberplate: '', //车牌号 + logisticsMen: '', //物流员 + notes: '', //备注 + sampleCount: '0', //样本数量 + //样本列表 + sampleList: [{ + 'id': 1, + 'number': '2023050002', + 'time': '2023-5-12 11:32', + 'status': '已签收', + 'name': '张三', + 'num': 'M2023055568' + }], }, - scacode(){ + scacode() { wx.scanCode({ - success:(res)=>{ + success: (res) => { console.log(res.result); this.setData({ - pipenum:res.result + pipenum: res.result }) } }) }, - phot(){ + phot() { wx.chooseMedia({ count: 1, - mediaType: ['image','video'], + mediaType: ['image', 'video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', - success: res=>{ + success: res => { console.log(this.data.srcI) console.log(res.tempFiles[0].tempFilePath) // this.up(); } }) }, - //上传图片接口地址 - // up(){ - // console.log(this.data.srcI) - // wx.uploadFile({ - // filePath: this.data.srcI, - // name: 'file', - // url: '', - // }) - // }, - bushPhot(){ + bushPhot() { wx.chooseMedia({ count: 1, - mediaType: ['image','video'], + mediaType: ['image', 'video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', - success: res=>{ + success: res => { // this.up(); } }) }, - boxPhot(){ + boxPhot() { wx.chooseMedia({ count: 1, - mediaType: ['image','video'], + mediaType: ['image', 'video'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', - success: res=>{ + success: res => { // this.up(); } }) @@ -103,10 +108,10 @@ Page({ }, //日期 - bindDateChange(e){ + bindDateChange(e) { // console.log(e.detail.value) this.setData({ - date:e.detail.value + date: e.detail.value }) }, @@ -153,12 +158,263 @@ Page({ - goDetail(){ + goDetail() { wx.navigateTo({ url: '../details/details', }) }, + //物流车拍照 + bushPhot() { + wx.chooseMedia({ + count: 1, + mediaType: ['image', 'video'], + sourceType: ['album', 'camera'], + maxDuration: 30, + camera: 'back', + success: res => { + // this.up(); + } + }) + }, + + //转运箱拍照 + boxPhot(e) { + console.log(e.target.dataset.id); + wx.chooseMedia({ + count: 1, + mediaType: ['image', 'video'], + sourceType: ['album', 'camera'], + maxDuration: 30, + camera: 'back', + success: res => { + // this.up(); + } + }) + }, + + //物流车、转运箱拍照 + photograph(e) { + var potoIdx = 0; + if (e.target.dataset.id == 'car_1') potoIdx = 0 + if (e.target.dataset.id == 'car_2') potoIdx = 1 + if (e.target.dataset.id == 'box_1') potoIdx = 2 + if (e.target.dataset.id == 'box_2') potoIdx = 3 + + //回显所拍摄照片 + var _this = this; + wx.chooseMedia({ + count: 1, + mediaType: ['image', 'video'], + sourceType: ['camera'], + sizeType: ['compressed'], + camera: 'back', + success: res => { + _this.upImg(res.tempFiles[0].tempFilePath, potoIdx) //上传照片 + } + }) + }, + + //上传照片 imageSrc照片临时路径 potoIdx 点击的哪一个图片框 + upImg(imageSrc, potoIdx) { + var _this = this; + request.upImgFile(`/feedBack/upload`, imageSrc).then(res => { + var resObj = JSON.parse(res.data) + console.log('upImgFile data =' + resObj.data.url); + console.log('upImgFile res=' + JSON.stringify(res.data)); + if (resObj.code > 400) { + wx.showModal({ + title: '提示', + content: resObj.message, + complete: (res) => { + if (res.cancel) {} + if (res.confirm) {} + //上传失败后移除图片 + } + }) + } else { + //保存图片路径到数组 + // this.data.upImageArr.push(resObj.data.url); + _this.data.poto[potoIdx] = resObj.data.url + _this.setData({ + poto: _this.data.poto + }) + } + }); + }, + + //显示回调图片 + addCallBackImage(imageSrc) { + var temp = { + isBtn: false, + imgUrl: imageSrc, + text: imageSrc, + func: "delImage" + }; + this.data.imageArr.unshift(temp); + this.setData({ + imageArr: this.data.imageArr + }); + }, + + //保存样本信息 + saveInfo() { + var temp = this.data; + + //处理到达时间 + var endTime = dateUtils.customizeDateFormat(temp.time); + + if (this.showErrInfo(endTime, '到过时间不可为空')) return + + //处理物流车拍照 + var carPoto = [] + var boxPoto = [] + var array = this.data.poto; + for (let index = 0; index < array.length; index++) { + if (index < 2 && array[index] != this.data.potoSrc) { + carPoto.push(array[index]) + } else if (array[index] != this.data.potoSrc) { + boxPoto.push(array[index]) + } + } + + var tempData = { + "barCode": temp.pipenum, //样本条码 + "barCodeImg": "", //物流拍照图 + "boxNum": temp.boxNum, //转运箱号 + "carPics": carPoto.toString(), //物流车图片 逗号分隔 + "boxPics": boxPoto.toString(), // 转运箱图片 逗号分隔 + "cost": 0, // 物流费用 自建没有 + "driverMen": temp.driverMen, //驾驶员 + "entryDate": temp.date, // 录入日期 + "endDate": '', //startTime + "expectedEndTime": endTime, //预计到达时间 endTime + "institutionName": temp.ins[temp.insIdx].orgName, //送检机构名称 + "institutionNo": temp.ins[temp.insIdx].id, //送检机构编号 + "logisticsMen": temp.logisticsMen, //物流员 + "logisticsNo": temp.selfOrderCode, //物流编号 + "logisticsWay": 1, //物流方式 1自建 2第三方 3货运 + "notes": temp.notes, // 物流备注 + "number": temp.number, // 数量 + "numberplate": "", // 车牌号 + "phone": "", //物流电话 + "startTime": '', //出发时间 + "tranType": "1", //物流方式 + "unitType": "", //物流单位 1.顺丰 2.京东(自建物流没有该字段) + "updateBy": 0, + "updateTime": "" + } + + request.post(`/batch/addTranLogistics`, tempData).then(res => { + console.log(JSON.stringify(res.data)); + if (res.data.code == 200) { + //保存成功后,查询底部列表 + this.selSampleList(); + } else { + wx.showModal({ + title: '错误', + content: res.data.message, + showCancel: false, + complete: (res) => { + if (res.confirm) {} + } + }) + } + }) + }, + + //查询底部列表数据 + selSampleList() { + var reqData = { + 'logisticsNo': this.data.selfOrderCode + } + request.post(`/logistics/selectTranLogistics`, reqData).then(res => { + console.log(res.data); + this.setData({ + sampleList: res.data.data, + sampleCount: res.data.data.length + }) + }) + }, + + //显示必选项为空提示 + showErrInfo(field, errInfo) { + if (field === undefined || field.length == 0) { + wx.showToast({ + icon: 'error', + title: errInfo, + }) + return true; + } + }, + + //文本输入信息 + inputTextInfo(e) { + var data_id = e.target.dataset.id; //组件tag + var value = e.detail.value; //输入的文本 + //样本编号 + if (data_id == 'barCode') { + this.setData({ + pipenum: value + }) + } + + //数量 + if (data_id == 'number') { + this.setData({ + number: value + }) + } + + //转运箱号 + if (data_id == 'boxNum') { + this.setData({ + boxNum: value + }) + } + + //车牌号 + if (data_id == 'numberplate') { + this.setData({ + numberplate: value + }) + } + + if(data_id == 'phone'){ + this.setData({ + phone: value + }) + } + + //物流费用 + if (data_id == 'cost') { + this.setData({ + cost: value + }) + } + + //物流员 + if (data_id == 'logisticsMen') { + this.setData({ + logisticsMen: value + }) + } + + //驾驶员 + if (data_id == 'driverMen') { + this.setData({ + driverMen: value + }) + } + + //备注 + if (data_id == 'notes') { + this.setData({ + notes: value + }) + } + }, + /** * 生命周期函数--监听页面加载 */ @@ -167,18 +423,48 @@ Page({ let year = now.getFullYear(); //获取当前年 let month = now.getMonth() + 1; //获取当前月份 this.setData({ - end: '' + year + '-' + (Array(2).join(0) + month).slice(-2) + '-' + (Array(2).join(0) + now.getDate()).slice(-2),//当前的时间 + end: '' + year + '-' + (Array(2).join(0) + month).slice(-2) + '-' + (Array(2).join(0) + now.getDate()).slice(-2), //当前的时间 //开始 - multiArray: - [ + multiArray: [ [year + "年", year + 1 + "年", year + 2 + "年"], datePicker.determineMonth(), datePicker.determineDay(year, month), datePicker.determineHour(), datePicker.determineMinute() ], - }) + }) + + //获取物流单号 1.自建物流 2.第三方物流 3.货运物流 + request.get(`/batch/getBatchsNumber?logisticsWay=3`).then(res => { + console.log('getBatchsNumber=' + JSON.stringify(res.data)) + if (res.data.code == 200) { + this.setData({ + selfOrderCode: res.data.data + }) + } + }) + + //获取送检机构列表 + request.get(`/dict/type/tran_method`).then(res => { + var array = res.data.data + var tempArr = [] + for (let index = 0; index < array.length; index++) { + tempArr.push(array[index].dictLabel) + } + this.setData({ + ins: tempArr + }) + + //查询物流批次列表 + this.selSampleList(); + }) + + //初始化照片按钮 + var tempSrc = [this.data.potoSrc, this.data.potoSrc, this.data.potoSrc, this.data.potoSrc] + this.setData({ + poto: tempSrc + }) }, /** diff --git a/pages/freiLogistics/freiLogistics.wxml b/pages/freiLogistics/freiLogistics.wxml index 7eae274..fcc433c 100644 --- a/pages/freiLogistics/freiLogistics.wxml +++ b/pages/freiLogistics/freiLogistics.wxml @@ -1,81 +1,86 @@ - - + - + 扫 码 - 拍 照 + - + + + + + + + - + - + - + - + - + - + - + - + - + - + 物流车拍照 - + - - + + 转运箱拍照 - + - - + + - 总计:200/管数 - - + 总计:{{sampleCount}}/管数 + + @@ -87,7 +92,7 @@ 物流员 物流单号 - + {{item.id}} {{item.number}} {{item.time}} @@ -97,5 +102,4 @@ - - + \ No newline at end of file diff --git a/pages/freiLogistics/freiLogistics.wxss b/pages/freiLogistics/freiLogistics.wxss index 1b6c8d5..1fb312a 100644 --- a/pages/freiLogistics/freiLogistics.wxss +++ b/pages/freiLogistics/freiLogistics.wxss @@ -2,16 +2,18 @@ .top{ display: flex; - justify-content: center; + justify-content: left; font-size: 28rpx; } .top input{ border: 1rpx #333 solid; - border-radius: 10rpx; + height: 60rpx; + width: 700rpx; + border-radius: 5rpx; padding: 5rpx 10rpx; } .top view{ - width: 135rpx; + width: 305rpx; margin-left: 20rpx; background-color: #eee; display: flex; @@ -75,7 +77,7 @@ height: 230rpx; margin-top: 10rpx; border: 1rpx solid #999; - /* border-radius: 15rpx; */ + border-radius: 15rpx; } .back{ margin-top: 15rpx; diff --git a/pages/handover/handover.js b/pages/handover/handover.js index 685c89b..8d907d5 100644 --- a/pages/handover/handover.js +++ b/pages/handover/handover.js @@ -17,8 +17,7 @@ Page({ //刷新按钮 refresh() { - this.onLoad() - console.log("123"); + this.selTranLogistics() }, bindDateChange(e) { @@ -35,11 +34,18 @@ Page({ pageSize: 100 } request.post(`/batch/selectTranLogistics`, reqData).then(res => { - console.log(JSON.stringify(res)); + // console.log(JSON.stringify(res)); // this.data.logisticsCodeList = res.data.data - this.setData({ - logisticsCodeList: res.data.data - }) + if (res.data.data.length == 0) { + wx.showToast({ + title: '物流单列表无数据', + icon: 'error' + }) + } else { + this.setData({ + logisticsCodeList: res.data.data + }) + } }) }, @@ -120,10 +126,14 @@ Page({ let now = new Date(); //获取时间 let year = now.getFullYear(); //获取当前年 let month = now.getMonth() + 1; //获取当前月份 + var tempDate = '' + year + '-' + (Array(2).join(0) + month).slice(-2) + '-' + (Array(2).join(0) + now.getDate()).slice(-2); this.setData({ - end: '' + year + '-' + (Array(2).join(0) + month).slice(-2) + '-' + (Array(2).join(0) + now.getDate()).slice(-2), + end: tempDate }) //当前的时间 + this.setData({ + date: tempDate + }) this.selTranLogistics() }, diff --git a/pages/handover/handover.wxml b/pages/handover/handover.wxml index f16e31a..1b83d36 100644 --- a/pages/handover/handover.wxml +++ b/pages/handover/handover.wxml @@ -30,9 +30,9 @@ 交接人 状态 - + - {{idx+1}} + {{index+1}} {{item.barCode}} {{item.institutionName}} {{item.entryDate}} @@ -51,7 +51,7 @@ - + diff --git a/pages/handover/handover.wxss b/pages/handover/handover.wxss index 0c85af9..32e5de6 100644 --- a/pages/handover/handover.wxss +++ b/pages/handover/handover.wxss @@ -106,7 +106,7 @@ right: 0; bottom: 0; z-index: 10; - background: rgba(0, 0, 0, 0); + background: rgba(0, 0, 0, 0.05); /* 设置阴影半透明背景如: background: rgba(0, 0, 0, 0.4); */ display: none; } @@ -114,11 +114,11 @@ .zan-dialog__container { position: fixed; bottom: 200rpx; - width: 350rpx; + width: 280rpx; /* 弹窗布局宽 */ - height: 300rpx; + height: 280rpx; /* 弹窗布局高,与下面弹出距离transform有关 */ - margin-left: 180rpx; + margin-left: 220rpx; background: #f8f8f8; transform: translateY(300%); /* 弹框弹出距离,与弹框布局高度有关,如300%表示弹起距离为3倍弹窗高度 */ diff --git a/pages/index/index.js b/pages/index/index.js index ba5dafe..0f8b159 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -1,5 +1,8 @@ // pages/index/index.js +var request = require('../../utils/http') import * as echarts from "../../components/echarts/echarts"; +var app = getApp(); + function initChart(canvas, width, height, dpr) { const chart = echarts.init(canvas, null, { width: width, @@ -7,8 +10,8 @@ function initChart(canvas, width, height, dpr) { devicePixelRatio: dpr }); canvas.setChart(chart); - - var option = { + + var option = { tooltip: { trigger: 'axis', axisPointer: { @@ -23,16 +26,15 @@ function initChart(canvas, width, height, dpr) { containLabel: true }, xAxis: { - + type: 'category', - data: ['一月', '二月', '三月', '四月', '五月', '六月','七月','八月','九月','十一月','十二月'] + data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十一月', '十二月'] }, yAxis: { type: 'value', boundaryGap: [0, 0.01] }, - series: [ - { + series: [{ name: '核收数', type: 'bar', data: [10, 20, 46, 120, 90, 80] @@ -45,7 +47,7 @@ function initChart(canvas, width, height, dpr) { ] }; chart.setOption(option); - + return chart; }; @@ -58,44 +60,127 @@ Page({ ec: { onInit: initChart }, - msg:[], //首页中间消息列表 + msg: [], //首页中间消息列表 }, //跳转对应界面 - goLogisticsType(e){ + goLogisticsType(e) { var tag = e.currentTarget.dataset.id var url //自建物流 - if(tag == 'goMelogistics'){ + if (tag == 'goMelogistics') { url = '../meLogistics/meLogistics' } //第三方 - if(tag == 'goThreelogistics'){ + if (tag == 'goThreelogistics') { url = '../threeLogistics/threeLogistics' } //货运 - if(tag == 'goLogistics'){ + if (tag == 'goLogistics') { url = '../freiLogistics/freiLogistics' } //物流交接 - if(tag == 'goHandover'){ + if (tag == 'goHandover') { url = '../handover/handover' } wx.navigateTo({ url: url, }) }, - + + //判读是否有token + isHaveToken() { + var token = app.globalData.token + if (token == undefined || token == '') { + app.judLogin(); + } else { + console.log('用户已经登录'); + console.log(JSON.stringify(token)); + } + }, + + //判断是否绑定了微信 + isBindWx(openid) { + request.post(`/sso/checkBind/${openid}`).then(res => { + console.log("是否绑定" + JSON.stringify(res)); + if (res.data.data == true) { + //已绑定 获取用户信息 + request.get('/sso/info').then(res1 => { + console.log('res1.data.data =' + JSON.stringify(res1.data.data)); + app.globalData.userInfo = res1.data.data + // console.log(app.globalData.userInfo); + }) + } else { + //未绑定 提示登录 + app.judLogin(); + } + }) + }, + /** * 生命周期函数--监听页面加载 */ onLoad(options) { + if (app.globalData.userInfo == undefined) { + //获取code + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId + request.get(`/wx/getOpenid?code=${res.code}`).then(res1 => { + //记录OpenID + app.globalData.openid = res1.data.openid + this.isBindWx(res1.data.openid) + }) + } + }) + + //检查是否绑定 + // request.post('/sso/checkBind/' + app.globalData.openid).then(res2 => { + // console.log('检查是否绑定=' + JSON.stringify(res2.data.data)); + // app.globalData.bindvx = res2.data.data + // }) + } + + + + wx.login({ + success: res => { + // 发送 res.code 到后台换取 openId, sessionKey, unionId + request.get(`/wx/getOpenid?code=${res.code}`).then(res1 => { + + //记录OpenID + app.globalData.openid = res1.data.openid + this.isBindWx(res1.data.openid) + }) + + // console.log(JSON.stringify(res)); + // if (res.errMsg == 'login:ok') { + // request.post(`/sso/checkBind/` + res.code).then(res => { + // console.log('res=' + JSON.stringify(res)); + // if (res.data.code != 200) { + // //未绑定 + // app.judLogin(); + // } else { + // //已绑定 设置token 与 用户信息 + // } + // }) + // } else { + // wx.showToast({ + // title: res.errMsg, + // icon: 'error' + // }) + // } + } + }) + }, + + /** * 生命周期函数--监听页面初次渲染完成 */ diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 1c6dddf..ec06fa6 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -1,8 +1,5 @@ -