#私藏项目实操分享#
uniapp
data: {
avatar: '',
}
upload() {
uni.chooseImage({
count: 1,//图片张数
success: (res) => {
this.avatar = res.tempFilePaths[0];//第一张本地图片上传地址路径
}
}),
del() {
},
uni.uploadFile({
url:'',
filePath: '',
name: '',
header: {},
success: (res => {})
})
}
avatar: '',
/*upload(){ uni.chooseImage({ count:1, success: (res)=>{ this.avatar=res.tempFilePaths[0] console.log("res===", res); } }) }, sub() { uni.uploadFile({ url: this.$commonImage.pageBasePath + '/fileApi/upload?itemCode=0020010049&batchCode=' + this.$utils.randomNum(20), //仅为示例,非真实的接口地址
filePath: this.avatar, name: 'file', header: { 'Api-Version': "2.0", 'Call-Source': "WEB", 'Authorization': uni.getStorageSync('Authorization') !== undefined ? uni.getStorageSync('Authorization') : '', }, success: (res => { console.log("res===", res); }) }) },*/
wei
chooseImageWeiXin('image');//传值上传什么类型图片
chooseImageWeiXin(who){
uni.chooseImage({
count: 1,//最多可以选择图片张数
success: (res) => {
let tempFileSize=res.tempFiles[0].size;
let tempFilePaths = res.tempFilePaths;
if(tempFileSize {
console.log(err);
}
})
}
//上传图片
upLoadImg(filePath,who,itemCode){//拿到图片临时路径+图片类型名+图片域名code上传图片
let _self=this;
uni.uploadFile({
url: this.$commonImage.pageBasePath+'/fileApi/upload?itemCode='+itemCode+'&batchCode='+this.$utils.randomNum(20), //仅为示例,非真实的接口地址
filePath: filePath,
name: 'file',
header: {
'Api-Version': "2.0",
'Call-Source': "WEB",
'Authorization': uni.getStorageSync('Authorization') !== undefined ? uni.getStorageSync('Authorizatio服务器托管网n') : '',
},
success: (res) => {
let upImgObj = JSON.parse(res.data);
//upImgObj.data.serverPath
if(who==='storeIcon'){
_self.storeIcon=upImgObj.data.serverPath;//返回上传cdn图片路径
}
else if(who==='urlFront'){
_self.urlFront = upImgObj.data.serverPath;
}
else if(who==='urlBack'){
_self.urlBack = upImgObj.data.serverPath;
}
else if(who==='storeLicense'){
_self.storeLicense = upImgObj.data.serverPath;
}
else{
_self.image=upImgObj.data.serverPath;
}
// this.urlFront服务器托管网 = urlFront;
},
})
},
//没有图片显示默认图片
//有图片显示上传的图片加删除按钮
d
Request URL: https://finder-assistant.mp.video.tencent-cloud.com/snsuploadsimple
Request Method: POST
Status Code: 200 OK
e.detail = {avatarUrl: "http://tmp/q2zhQY6hNl2eb075c0f4921337c978c6606a1fb99cc7.png"}
api
api接口 https://lingdianyi.gfcylm.com/api/fileApi/upload
参数 ?itemCode=0020010003&batchCode=2022126978281728
方法 post
生成随机数 console.log((beginNum + endNum).length, beginNum + endNum); //18 "202212693810681762"
返回 res.data.data.serverPath
General {
Request URL: https://lingdianyi.gfcylm.com/api//fileApi/upload?itemCode=0020010003&batchCode=2022126978281728
Request Method: post
Status Code: 200
}
Request Hdaders {
Api-Version: 2.0
Call-Source: WEB
Authorization: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXJyZW50VGltZU1pbGxpcyI6IjE2NzAyNDY3MDg3MTkiLCJleHAiOjE2NzAyNDczMDgsInVzZXJuYW1lIjoibWVtYmVyXzE4MTM3MjY3NTEwIn0.cS_rZM4CxM2P_hmh0ixKCtI1aTPVWA5ZiPWnewIxhVI
}
itemCode:'0020010003',//图片上传到哪里
memberInfo: {}
async onLoad() {
let memberInfo = await this.$utils.memberInfo();
this.memberInfo = memberInfo;
},
//上传图片
upLoadImg(filePath){
let _self=this;
uni.uploadFile({
url: this.$commonImage.pageBasePath+'/fileApi/upload?itemCode='+this.itemCode+'&batchCode='+this.$utils.randomNum(20), //仅为示例,非真实的接口地址
filePath: filePath,
name: 'file',
header: {
'Api-Version': "2.0",
'Call-Source': "WEB",
'Authorization': uni.getStorageSync('Authorization') !== undefined ? uni.getStorageSync('Authorization') : '',
},
success: (res) => {
let upImgObj = JSON.parse(res.data);
//更新资料
let member = {
id: uni.getStorageSync("accountId"),
avatar: upImgObj.data.serverPath,
};
this.$Request.post(_self.$api.user.account + member.id, 'PUT', member).then(result => {
if (result.data.code === 1) {
uni.showToast({title: "修改成功!"});
this.memberInfo.avatar=upImgObj.data.serverPath;
}
});
},
})
},
async onChooseAvatar(e) {
let wc = 'https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqJcCoK0QXlGrkKbvgQHRWQNNq1GbhLUNt1C2ianWFB0ibON9GB8Fsy2UfzcAMqx8yS3ibFNOaHib2Yww/132';
console.log("e",e.detail);
let filePath = e.detail.avatarUrl;
let _self = this;
uni.uploadFile({
url: this.$commonImage.pageBasePath+'/fileApi/upload?itemCode='+this.itemCode+'&batchCode='+this.$utils.randomNum(20), //仅为示例,非真实的接口地址
filePath: filePath,
name: 'file',
header: {
'Api-Version': "2.0",
'Call-Source': "WEB",
'Authorization': uni.getStorageSync('Authorization') !== undefined ? uni.getStorageSync('Authorization') : '',
},
success: res => {
let upImgObj = JSON.parse(res.data);
console.log("upImgObj===", upImgObj);
let member = {
id: uni.getStorageSync("accountId"),
avatar: upImgObj.data.serverPath,
}
if (upImgObj.code===1) {
_self.$Request.post(_self.$api.user.account + member.id, "PUT", member).then(res => {
if (res.data.code === 1) {
uni.showToast({title: '修改成功!'});
_self.memberInfo.avatar = upImgObj.data.serverPath;
}
}, err => {
console.log("err: ", err)
});
} else {
uni.showToast({
icon: 'none',
title: '图片太大,请重新选择!'
})
}
},
fail: err => {
console.log("err: ",err);
},
})
},
code: 1
data: {
extensionName: "png"
fileId: "23dd270f2da74ffcabc4227cb8c84cee"
fileName: "V6clpYfaHHflb075c0f4921337c978c6606a1fb99cc7"
fileSize: 19013
serverPath: "upload/account/avatar/20221206_636423.png"
}
msg: ""
Request URL: https://lingdianyi.gfcylm.com/api/accountApi/aa7056504a484feb89510811cfa38c3d
Request Method: PUT
Status Code: 200
avatar: "upload/account/avatar/20221206_979149.png"
id: "aa7056504a484feb89510811cfa38c3d"
code: 1
data: {
accountRole: null
activateStatus: null
avatar: "upload/account/avatar/20221206_070527.png"
createPerson: "6f7202a2fb9947a6aa2d21a766483afc"
createTime: "2022-06-07 15:25:49"
description: null
email: ""
id: "aa7056504a484feb89510811cfa38c3d"
isDel: 0
lastLoginIp: "125.40.67.94"
lastLoginTime: "2022-12-05 11:58:41"
loginIp: "125.40.67.94"
loginNumber: 236
loginTime: "2022-12-05 21:25:09"
mobile: "18137267510"
nickName: null
password: "4b713369184a896b818f54621494466c6440f3fcc2f4149cb71add64"
randomSum: null
status: 1
updatePerson: null
updateTime: "2022-12-06 08:58:44"
username: "18137267510"
}
msg: "成功"
微信小程序中如何实现相册选择和拍照
这篇文章主要介绍微信小程序中如何实现相册选择和拍照,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
微信小程序 拍照和相机选择详解
前言:
小程序中获取图片可通过两种方式得到,第一种是直接打开微信内部自己的样式,第一格就是相机拍照,后面是图片,第二种是弹框提示用户是要拍照还是从相册选择,下面一一来看。
选择相册要用到wx.chooseImage(OBJECT)函数,具体参数如下:
直接来看打开相机相册的代码:
Page({
data: {
tempFilePaths: ''
},
onLoad: function () {
},
chooseimage: function () {
var that = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
that.setData({
tempFilePaths: res.tempFilePaths
})
}
})
},
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
每次聊到代码优化,都会有很多人说理论、架构、核心思路,其实我觉得代码优化这事说简单也很简单,说复杂吧它也有一定的难度。 写代码首选得遵循一个良好的编码习惯,今天分享一下我认为几个不错的代码优化小技巧,看完以后你的小伙伴也会说我你的代码像诗。 1. 定义配置文件…