diff --git a/pages/contractors/qualification.vue b/pages/contractors/qualification.vue index ee2de68c..725727eb 100644 --- a/pages/contractors/qualification.vue +++ b/pages/contractors/qualification.vue @@ -133,6 +133,15 @@ this.scrollHeight = screenHeight - this.barBoxHeight; console.log('this.scrollHeight', this.scrollHeight); }, + isJSON(str) { + try { + JSON.parse(str); + } catch (e) { + // 转换出错,抛出异常 + return false; + } + return true; + }, getListData(){ this.searchForm.enterpriseId = this.id // let data = { @@ -145,7 +154,8 @@ success: res => { console.log("enterpriseQualification", res); this.listData = res.result.map(item => { - item.logoUrl = this.url_config+'image/'+ JSON.parse(item.fileUrl)[0].url + const fileUrl = this.isJSON(item.fileUrl) && JSON.parse(item.fileUrl) instanceof Array ? JSON.parse(item.fileUrl)[0].url : item.fileUrl; + item.logoUrl = this.url_config+'image/'+ fileUrl return item }) } @@ -157,7 +167,8 @@ // uni.previewImage({ // urls: [url] // }) - let url = this.url_config + 'image/' + JSON.parse(item.fileUrl)[0].url + const fileUrl = this.isJSON(item.fileUrl) ? JSON.parse(item.fileUrl)[0].url: item.fileUrl; + let url = this.url_config + 'image/' + fileUrl console.log(url) uni.downloadFile({ url: url,