From 5788b742493037e5a99255298c7a3a29b4e23963 Mon Sep 17 00:00:00 2001 From: "3075067877@qq.com" <3075067877@qq.com> Date: Thu, 23 May 2024 10:52:43 +0800 Subject: [PATCH] fix party login upload company image --- .../popup-content/miniapp-change-category.vue | 1 + src/subpackage/party/pages/login/regist.vue | 18 +++++--- src/utils/util.js | 49 +++++++++++++++++++++- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/subpackage/party/components/popup-content/miniapp-change-category.vue b/src/subpackage/party/components/popup-content/miniapp-change-category.vue index 7f7e6c4..1b451bc 100644 --- a/src/subpackage/party/components/popup-content/miniapp-change-category.vue +++ b/src/subpackage/party/components/popup-content/miniapp-change-category.vue @@ -366,6 +366,7 @@ export default { let {exterList} = this exterList[i].url = await this.getLocalImg(); + console.log("clickUploadImg-local:", exterList[i].url) exterList[i].mediaid = await this.getUploadImgMediaId(exterList[i].url); console.log("clickUploadImg-mediaid:", exterList[i].mediaid) diff --git a/src/subpackage/party/pages/login/regist.vue b/src/subpackage/party/pages/login/regist.vue index d98f74c..b7b759b 100644 --- a/src/subpackage/party/pages/login/regist.vue +++ b/src/subpackage/party/pages/login/regist.vue @@ -448,6 +448,7 @@ let ocr_type = 'BizLicenseOCR' console.log("clickUploadImg"); let img = await this.getLocalImg(); + let img_info = await util.checkFileInfo(img) console.log("getLocalImg:", img) let img_url = await this.getUploadImgURL(img); console.log("getUploadImgURL:", img_url) @@ -458,11 +459,13 @@ this.setOcrResult(ocr_type,ocr_res) this.submitData.business_license = img_url }, + // IDCardOCR async clickUploadIDCardImg() { let ocr_type = 'IDCardOCR' console.log("clickUploadIDCardImg"); let img = await this.getLocalImg(); + let img_info = await util.checkFileInfo(img) console.log("getLocalImg:", img) let img_url = await this.getUploadImgURL(img); console.log("getUploadImgURL:", img_url) @@ -476,6 +479,7 @@ async clickUploadIDCardBackImg() { console.log("clickUploadIDCardBackImg"); let img = await this.getLocalImg(); + let img_info = await util.checkFileInfo(img) console.log("getLocalImg:", img) let img_url = await this.getUploadImgURL(img); console.log("getUploadImgURL:", img_url) @@ -554,7 +558,8 @@ this.submitData.extension.legal_person_name = res.Response.Person; this.submitData.agency_code = res.Response.RegNum; const t = this.company_types.find(item => item.label === res.Response.Type); - this.submitData.extension.company_type = t.value; + if(t&&t.value)this.submitData.extension.company_type = t.value; //设置企业类型 + if (res.Response.Capital) { const num = res.Response.Capital.split('元')[0] this.submitData.extension.registered_capital = this.chineseToNumber(num) @@ -574,7 +579,7 @@ this.submitData.extension.credit_end_date = `${year}-${month}-${day}` } } - if(res.Response.Type){ + if(res.Response.Type){//当命中微信所需企业类型时, 自动回显并填充 let _index = "" const t = this.company_types.find((item,index) => { if(item.label === res.Response.Type){ @@ -583,9 +588,12 @@ return item } }); - this.submitData.extension.company_type = t.value - this.company_type_index = _index - this.company_type_show = this.company_types_arr[_index] + if(t&&t.value){ + this.submitData.extension.company_type = t.value + this.company_type_index = _index + this.company_type_show = this.company_types_arr[_index] + } + } } else { this.submitData.extension.business_id_card = res.Response.IdNum diff --git a/src/utils/util.js b/src/utils/util.js index 163389a..259e57b 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -398,6 +398,52 @@ function order_pay_type_txt(status = ''){ return _obj[status] || '-' } +function checkFileInfo(url){//获取文件信息, 超过2M时提醒太大, 文件格式要求JPG、JPEG、PNG + let util = this + return new Promise((rs,rj)=>{ + try{ + let MAX_SIZE = 2048; //最大size限制 + + let type = url.split(".")[1]||"" + // JPG、JPEG、PNG + let need_type = [,'jpeg','jpg','png','JPG','JPEG','PNG'] + if(need_type.indexOf(type)>0){ + console.log("文件格式符合预期:",type) + }else{ + util.showNone(`当前文件格式${type}不符合预期,请重新上传`) + rj(false) + } + rs(true) + + console.log(wx.env.USER_DATA_PATH,123,url) + + const fs = wx.getFileSystemManager() + // const fd = fs.openSync({ + const fd = fs.openSync({ + // filePath: `${wx.env.USER_DATA_PATH}/hello.txt`, + filePath:url, + flag: 'a+' + }) + const stats = fs.fstatSync({fd: fd}) + let size = stats.size||0 + size = size/1024 + + if(size>MAX_SIZE){ + util.showNone(`上传图片最大为${MAX_SIZE/1024}M,当前为:${(size/1024).toFixed(2)}M`) + rj(false) + } + if(!size){ + util.showNone("请上传正确的图片") + rj(false) + } + rs(stats) + }catch(e){ + util.showNone(e); + rj(e) + } + }) +} + export default { formatTime, formatNumber, @@ -430,5 +476,6 @@ export default { isProfile, $_once, $_emit, - order_pay_type_txt + order_pay_type_txt, + checkFileInfo, }