图片上传,登录获取token,修改了部分图片名称,http.js中添加图片上传方法。

main
YXQ 1 year ago
parent a2c031743c
commit ec7b52efb7
  1. 28
      app.js
  2. 8
      app.json
  3. 0
      images/binding_wx.png
  4. 0
      images/home_not.png
  5. 0
      images/home_sel.png
  6. 0
      images/my_not.png
  7. 0
      images/my_sel.png
  8. 2
      pages/about/about.wxml
  9. 115
      pages/feedback/feedback.js
  10. 18
      pages/feedback/feedback.wxml
  11. 51
      pages/feedback/feedback.wxss
  12. 4
      pages/index/index.js
  13. 1
      pages/index/index.wxml
  14. 3
      pages/index/index.wxss
  15. 35
      pages/login/login.js
  16. 1
      pages/login/login.wxml
  17. 2
      project.config.json
  18. 4
      project.private.config.json
  19. 126
      utils/http.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('用户点击取消');
}
}
})
},
})

@ -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": "我的"
}

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

@ -12,7 +12,7 @@
<view class="back">
<view class="com">
<view class="con">
<image src="../../images/绑定微信.png" bindtap="bindWx"></image>
<image src="../../images/binding_wx.png" bindtap="bindWx"></image>
<view class="text">绑定微信</view>
</view>
<view class="con" bindtap="goQueryme">

@ -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]
});
},
/**

@ -1,7 +1,7 @@
<!--pages/feedback/feedback.wxml-->
<view style="background: -webkit-linear-gradient(top,#27adb0,#ebf7f7,#f1f1f1);padding:20rpx;min-height: 1400rpx;" >
<view class="bgColor">
<view style="background-color: #fff;padding: 20rpx 30rpx 100rpx 30rpx;border-radius: 15rpx;">
<view class="cardBg">
<view style="font-size: 28rpx;">
<view style="display: flex;">
<text>问题类型</text>
@ -13,16 +13,18 @@
</view>
<view style="margin-top: 60rpx; font-size: 26rpx;">
<view>上传图片/截图</view>
<view><text style="color: red;">*</text> 上传图片/截图</view>
<view class="addimg">
<image src="../../images/banner.png"></image>
<view bindtap="addImage">+</view>
<block wx:for="{{imageArr}}">
<view wx:if="{{item.isBtn}}" bindtap="{{item.func}}">{{item.text}}</view>
<view wx:else style="display: flex;">
<image src="{{item.text}}"></image>
</view>
</block>
</view>
</view>
</view>
<button class="btn" bindtap="goMyorder">提 交</button>
</view>

@ -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,30 +42,32 @@ 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;

@ -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',

@ -10,7 +10,6 @@
<view class="msg">消息:XXX医院样本转运完成,完成时间:2023年6月14日</view>
<view style="padding: 20rpx;">
<view class="back">
<view class="produck-type" bindtap="goMelogistics">

@ -9,6 +9,9 @@
}
.msg{
border-radius: 5px;
margin-top: 20rpx;
height: 30rpx;
background-color: #fff;
font-size: 26rpx;
padding: 10rpx;

@ -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
})
}
})
},
/**

@ -1,4 +1,5 @@
<!--pages/login/login.wxml-->
<view style="padding: 40rpx 50rpx;font-size: 55rpx;color: #fff;font-weight: 600; font-family: 'Courier New', Courier, monospace;">欢迎回来!</view>
<view style="background-color: #fff; width: 650rpx; border-radius: 20rpx; margin: 0 auto; padding: 30rpx 0;">

@ -51,6 +51,6 @@
],
"include": []
},
"appid": "wxf122cda1b8bbbc37",
"appid": "wxcf3a0f4fb0f7656e",
"testRoot": "minitest/"
}

@ -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": {

@ -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
};
Loading…
Cancel
Save