From ec7b52efb7621a3e212cb37e3442f850f3cadd68 Mon Sep 17 00:00:00 2001 From: YXQ Date: Wed, 5 Jul 2023 09:11:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E4=B8=8A=E4=BC=A0=EF=BC=8C?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=8E=B7=E5=8F=96token=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=86=E9=83=A8=E5=88=86=E5=9B=BE=E7=89=87=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8Chttp.js=E4=B8=AD=E6=B7=BB=E5=8A=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 30 +++++- app.json | 8 +- images/{绑定微信.png => binding_wx.png} | Bin images/{首页1.png => home_not.png} | Bin images/{首页2.png => home_sel.png} | Bin images/{我的1.png => my_not.png} | Bin images/{我的2.png => my_sel.png} | Bin pages/about/about.wxml | 2 +- pages/feedback/feedback.js | 115 +++++++++++++++------ pages/feedback/feedback.wxml | 20 ++-- pages/feedback/feedback.wxss | 53 ++++++---- pages/index/index.js | 4 +- pages/index/index.wxml | 1 - pages/index/index.wxss | 3 + pages/login/login.js | 35 ++++++- pages/login/login.wxml | 3 +- project.config.json | 2 +- project.private.config.json | 4 +- utils/http.js | 126 ++++++++++++++++++++++++ 19 files changed, 333 insertions(+), 73 deletions(-) rename images/{绑定微信.png => binding_wx.png} (100%) rename images/{首页1.png => home_not.png} (100%) rename images/{首页2.png => home_sel.png} (100%) rename images/{我的1.png => my_not.png} (100%) rename images/{我的2.png => my_sel.png} (100%) create mode 100644 utils/http.js diff --git a/app.js b/app.js index 1ed57c4..bb1e811 100644 --- a/app.js +++ b/app.js @@ -13,7 +13,33 @@ App({ } }) }, + globalData: { - userInfo: null - } + // 本地环境 + baseUrl:'http://192.168.51.200:8201/mall-portal', + // 线上环境 + // baseUrl:'https://portal-api.macrozheng.com', + token: '', + userInfo:{}, + bindvx:null + }, + + judLogin(){ + wx.showModal({ + title: '提示', + content: '尊敬的用户您还未登录,请先登录', + confirmText:'去登陆', + complete: (res) => { + if (res.confirm) { + wx.navigateTo({ + url: '../login/login', + }) + }; + if (res.cancel) { + console.log('用户点击取消'); + } + } + }) + }, + }) diff --git a/app.json b/app.json index 5426671..2cd0e7b 100644 --- a/app.json +++ b/app.json @@ -26,14 +26,14 @@ "borderStyle": "black", "list": [ { - "iconPath": "images/首页1.png", - "selectedIconPath": "images/首页2.png", + "iconPath": "images/home_not.png", + "selectedIconPath": "images/home_sel.png", "pagePath": "pages/index/index", "text": "首页" }, { - "iconPath": "images/我的1.png", - "selectedIconPath": "images/我的2.png", + "iconPath": "images/my_not.png", + "selectedIconPath": "images/my_sel.png", "pagePath": "pages/about/about", "text": "我的" } diff --git a/images/绑定微信.png b/images/binding_wx.png similarity index 100% rename from images/绑定微信.png rename to images/binding_wx.png diff --git a/images/首页1.png b/images/home_not.png similarity index 100% rename from images/首页1.png rename to images/home_not.png diff --git a/images/首页2.png b/images/home_sel.png similarity index 100% rename from images/首页2.png rename to images/home_sel.png diff --git a/images/我的1.png b/images/my_not.png similarity index 100% rename from images/我的1.png rename to images/my_not.png diff --git a/images/我的2.png b/images/my_sel.png similarity index 100% rename from images/我的2.png rename to images/my_sel.png diff --git a/pages/about/about.wxml b/pages/about/about.wxml index 2657c1d..a7a60cc 100644 --- a/pages/about/about.wxml +++ b/pages/about/about.wxml @@ -12,7 +12,7 @@ - + 绑定微信 diff --git a/pages/feedback/feedback.js b/pages/feedback/feedback.js index e760799..ca1a321 100644 --- a/pages/feedback/feedback.js +++ b/pages/feedback/feedback.js @@ -1,15 +1,16 @@ // pages/feedback/feedback.js +const request = require('../../utils/http') +const app = getApp(); Page({ /** * 页面的初始数据 */ data: { - array: ['请选择 >','bug问题', '业务问题', '功能使用问题', '其他'], - objectArray: [ - { + array: ['请选择', 'bug问题', '业务问题', '功能使用问题', '其他'], + objectArray: [{ id: 0, - name: '请选择 >' + name: '请选择' }, { id: 1, @@ -29,54 +30,106 @@ Page({ } ], index: 0, - srxI:'' + srxI: '', + + //图片数组 + addImgBtn: { + isBtn: true, + text: "+", + func: "addImage" + }, + imageArr: [] }, - bindPickerChange (e) { + bindPickerChange(e) { this.setData({ index: e.detail.value }) }, - goMyorder(){ - wx.switchTab({ - url: '../about/about', - }) + //提交数据 + goMyorder() { + if(this.data.index === 0){ + wx.showToast({ + title: '请选择问题类型', + }); + return; + } + var problem = objectArray[this.data.index]; //问题类型 + request.post(`/feedBack/push?type=${this.data.index}&describe=${problem}`).then(res=>{ + + }); + // wx.switchTab({ + // url: '../about/about', + // }) + + //判断是否选择问题类型 + //当没有描述时,弹框提示,但不是强制性。 + //判断是否有上传截图 + + //提示成功后,点击确定,返回上一页。 }, - addImage(){ + //添加图片 + addImage() { + var _this = this; wx.chooseMedia({ count: 1, - mediaType: ['image','video'], - sourceType: ['album', 'camera'], - maxDuration: 30, - camera: 'back', - success: res=>{ - this.setData({ - srcI:res.tempFiles[0].tempFilePath - }) - console.log(this.data.srcI) - console.log(res.tempFiles[0].tempFilePath) - // this.up(); + mediaType: ['image'], + sourceType: ['album'], + sizeType:['compressed'], + success: res => { + var imgSrc = res.tempFiles[0].tempFilePath; + _this.addCallBackImage(imgSrc); + _this.upImg(imgSrc); //点击提交时统一上传 } }) }, + //显示回调图片 + addCallBackImage(imageSrc) { + console.log("imgSrc=" + imageSrc); + var temp = { + isBtn: false, + imgUrl: imageSrc, + text: imageSrc, + func: "" + }; + this.data.imageArr.unshift(temp); + this.setData({ + imageArr: this.data.imageArr + }); + }, + //上传图片接口地址 - // up(){ - // console.log(this.data.srcI) - // wx.uploadFile({ - // filePath: this.data.srcI, - // name: 'file', - // url: '', - // }) - // }, + upImg(imageSrc) { + request.upImgFile(`/feedBack/upload`, imageSrc).then(res => { + var resObj = JSON.parse(res.data); + if(resObj.code === 500){ + wx.showModal({ + title: '提示', + content: resObj.message, + complete: (res) => { + if (res.cancel) { + } + if (res.confirm) { + } + //移除图片 + } + }) + } + }); + }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { - + console.log("token=" + app.globalData.token); + //初始化添加按钮 + this.setData({ + imageArr: [this.data.addImgBtn] + }); }, /** diff --git a/pages/feedback/feedback.wxml b/pages/feedback/feedback.wxml index 00fbde8..c08c652 100644 --- a/pages/feedback/feedback.wxml +++ b/pages/feedback/feedback.wxml @@ -1,7 +1,7 @@ - + - + 问题类型 @@ -13,16 +13,18 @@ - 上传图片/截图 + * 上传图片/截图 + - - + + + {{item.text}} + + + + - - - - + \ No newline at end of file diff --git a/pages/feedback/feedback.wxss b/pages/feedback/feedback.wxss index bef583d..7737b51 100644 --- a/pages/feedback/feedback.wxss +++ b/pages/feedback/feedback.wxss @@ -1,27 +1,40 @@ /* pages/feedback/feedback.wxss */ -page{ - background: -webkit-linear-gradient(top,#27adb0,#ebf7f7,#f1f1f1) +page { + background: -webkit-linear-gradient(top, #27adb0, #ebf7f7, #f1f1f1) } -.why{ - border: 1px #333 solid; +.bgColor { + background: -webkit-linear-gradient(top, #27adb0, #ebf7f7, #f1f1f1); + padding: 20rpx; + min-height: 1400rpx; +} + +.cardBg { + background-color: #fff; + padding: 20rpx 30rpx 100rpx 30rpx; + border-radius: 15rpx; +} + +.why { + border: 1px #c5c5c5 solid; display: inline-block; width: 240rpx; - text-align: right; - margin-left: 20rpx; - padding: 3rpx 10rpx; + text-align: center; + margin-left: 25rpx; + padding: 10rpx 10rpx; color: #5f5e5e; border-radius: 5rpx; } -.place{ +.place { color: #b3b1b1; } -.textarea{ +.textarea { border: 2rpx #333 solid; text-align: left; - max-width: 450rpx; + border-radius: 10rpx; + max-width: 95%; height: 180rpx; margin: 0 auto; margin-top: 20rpx; @@ -29,31 +42,33 @@ page{ padding: 20rpx; } -.addimg{ +.addimg { text-align: center; display: flex; flex-wrap: wrap; - justify-content: center; + justify-content: start; margin-top: 20rpx; + width: 100%; } -.addimg image{ + +.addimg image { width: 200rpx; height: 200rpx; border-radius: 15rpx; - margin-right: 10rpx; } -.addimg view{ - border-radius:15rpx ; + +.addimg view { + border-radius: 10rpx; display: flex; justify-content: center; align-items: center; width: 200rpx; height: 200rpx; - border:1rpx #222 solid; + border: 1rpx #c5c5c5 solid; } -.btn{ +.btn { background-color: #5dc2c4; color: #fff; margin-top: 100rpx; -} +} \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index 142e17b..70c5b10 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -25,7 +25,7 @@ function initChart(canvas, width, height, dpr) { xAxis: { type: 'category', - data: ['一月', '二月', '三月', '四月', '五月', '六月'] + data: ['一月', '二月', '三月', '四月', '五月', '六月','七月','八月','九月','十一月','十二月'] }, yAxis: { type: 'value', @@ -67,12 +67,14 @@ Page({ }) }, + //第三方物流 goThreelogistics(){ wx.navigateTo({ url: '../threeLogistics/threeLogistics', }) }, + //货运物流 goHandover(){ wx.navigateTo({ url: '../handover/handover', diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 817919e..06b0c5d 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -10,7 +10,6 @@ 消息:XXX医院样本转运完成,完成时间:2023年6月14日 - diff --git a/pages/index/index.wxss b/pages/index/index.wxss index da510bf..c499b55 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -9,6 +9,9 @@ } .msg{ + border-radius: 5px; + margin-top: 20rpx; + height: 30rpx; background-color: #fff; font-size: 26rpx; padding: 10rpx; diff --git a/pages/login/login.js b/pages/login/login.js index 24469ad..b1b0044 100644 --- a/pages/login/login.js +++ b/pages/login/login.js @@ -1,11 +1,44 @@ // pages/login/login.js +const request = require('../../utils/http') +var app = getApp(); + Page({ /** * 页面的初始数据 */ data: { - + username: "member", //账号 + userpwd: "member123", //密码 + }, + getUsername(e) { + this.setData({ + username: e.detail.value + }) + }, + getUserpwd(e) { + this.setData({ + userpwd: e.detail.value + }) + }, + //登录请求 + login() { + console.log('login run'); + request.post(`/sso/login?username=${this.data.username}&password=${this.data.userpwd}`).then(res => { + console.log(res); + if (res.data.code == 200) { + app.globalData.token = res.data.data.tokenHead + res.data.data.token; + wx.showToast({ + title: '登陆成功' + }) + wx.reLaunch({ + url: '../about/about' + }); + request.get('/sso/info').then(res2 => { + app.globalData.userInfo = res2.data.data + }) + } + }) }, /** diff --git a/pages/login/login.wxml b/pages/login/login.wxml index c750f40..a780c22 100644 --- a/pages/login/login.wxml +++ b/pages/login/login.wxml @@ -1,4 +1,5 @@ + 欢迎回来! @@ -15,4 +16,4 @@ - + \ No newline at end of file diff --git a/project.config.json b/project.config.json index e3a46dd..7f2ff81 100644 --- a/project.config.json +++ b/project.config.json @@ -51,6 +51,6 @@ ], "include": [] }, - "appid": "wxf122cda1b8bbbc37", + "appid": "wxcf3a0f4fb0f7656e", "testRoot": "minitest/" } \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json index 5d988db..4d863e9 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -1,8 +1,8 @@ { "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", - "projectname": "%E7%89%A9%E6%B5%81%E7%AB%AF", + "projectname": "yyt_logistics", "setting": { - "compileHotReLoad": false + "compileHotReLoad": true }, "condition": { "miniprogram": { diff --git a/utils/http.js b/utils/http.js new file mode 100644 index 0000000..a216d80 --- /dev/null +++ b/utils/http.js @@ -0,0 +1,126 @@ +var app = getApp(); //引入全局app.js,我们可以在globalData中定义一些公用的数据,比如baseUrl、token + +const request = function(url, options) { + let header = { + 'content-type': 'application/json;charset=utf-8' + }; + + if (app.globalData.token) { + header.Authorization = app.globalData.token; + } + // 检查外部传递的请求头是否存在 + if (options.header && typeof options.header === 'object') { + // 合并外部传递的请求头 + header = Object.assign({}, header, options.header); + } + return new Promise((resolve, reject) => { + wx.request({ + url: app.globalData.baseUrl + url, + method: options.method, + data: options.data, + header: header, + success: (res) => { + if (res.data.code == 500) { + wx.showModal({ + showCancel: false, + title: '提示', + content: res.data.message + }); + reject(res.data.message); + } else { + resolve(res); + } + }, + fail: (err) => { + reject(err); + } + }); + }); +}; + +const get = function(url, data, header) { + return request(url, { + method: "GET", + data, + header + }); +} + +const post = function(url, data, header) { + return request(url, { + method: "POST", + data, + header + }); +} + + +//上传图片文件 +const upImgFile = function(url, imgSrc) { + let header = { + // 'content-type': 'multipart/form-data' + 'content-type': 'application/json;charset=utf-8' + }; + + if (app.globalData.token) { + header.Authorization = app.globalData.token; + } + // 检查外部传递的请求头是否存在 + // if (options.header && typeof options.header === 'object') { + // // 合并外部传递的请求头 + // header = Object.assign({}, header, options.header); + // } + return new Promise((resolve, reject) => { + + wx.uploadFile({ + url: app.globalData.baseUrl + url, + name: "file", + filePath: imgSrc, + header: header, + formData: { + "file": "upimagefile", + }, + success: function (res) { + if (res.data.code == 500) { + wx.showModal({ + showCancel: false, + title: '提示', + content: res.data.message + }); + reject(res.data.message); + } else { + resolve(res); + } + } + }); + + // wx.request({ + // url: app.globalData.baseUrl + url, + // method: options.method, + // data: options.data, + // header: header, + // success: (res) => { + // if (res.data.code == 500) { + // wx.showModal({ + // showCancel: false, + // title: '提示', + // content: res.data.message + // }); + // reject(res.data.message); + // } else { + // resolve(res); + // } + // }, + // fail: (err) => { + // reject(err); + // } + // }); + }); +}; + +//暴露出去 +module.exports = { + get, + post, + upImgFile +}; \ No newline at end of file