适配后端返回的数据
This commit is contained in:
1 parent
f5b22e498a
commit
77cd23b6a9
1 file changed
+29
-2
@@ -196,11 +196,13 @@ Page({
|
||||
// 启动时获取session
|
||||
async onLoad() {
|
||||
// wx.authorize()
|
||||
// await this.updateSession()
|
||||
await this.updateSession()
|
||||
// setInterval(()=>{
|
||||
// this.updateSession()
|
||||
// },60*1000*5)
|
||||
// console.log(this.data.sessionKey)
|
||||
this.updateLib()
|
||||
this.updateHistory()
|
||||
this.readStorageData()
|
||||
},
|
||||
|
||||
@@ -686,8 +688,32 @@ Page({
|
||||
success: res => {
|
||||
// console.log(res)
|
||||
var data = res.data
|
||||
console.log(data)
|
||||
// console.log(data)
|
||||
// 能跑
|
||||
|
||||
// name: {
|
||||
// zh: "山梨酸钾",
|
||||
// en: "Potassium sorbate"
|
||||
// },
|
||||
// scores: 73,
|
||||
// info: "山梨酸钾,又名2,4-己二烯酸钾,是山梨酸的钾盐,分子式为C6H7O2K,无色或白色鳞片状结晶或结晶性粉末。 [1] 无臭或微有臭味,长期暴露在空气中易吸潮、被氧化分解而变色。易溶于水(67.6g/100mL 20℃),溶于丙二醇(5.8g/100mL)和乙醇(0.3g/10 mL)。山梨酸钾和山梨酸是常用的有机防腐剂,广泛用于食品、化状品、饲料的防腐。易于被人体吸收代谢,在体内无残留,无毒性。",
|
||||
// extra: [],
|
||||
// ADI: "",
|
||||
// 适配后端返回数据
|
||||
for(var n of data){
|
||||
n.name = {}
|
||||
n.name.zh = n.chinese_name
|
||||
n.name.en = n.english_name
|
||||
n.scores = n.rating
|
||||
n.extra = []
|
||||
for(var i of n.effects){
|
||||
n.extra.push({ 'type': "safe", 'name': i },)
|
||||
}
|
||||
for(var i of n.potential_risk_people){
|
||||
n.extra.push({ 'type': "unsafe", 'name': "风险人群:" + i })
|
||||
}
|
||||
n.ADI = n.daily_intake_recommendation
|
||||
}
|
||||
for (var n of data) {
|
||||
var scores = n.scores;
|
||||
var map = this.scores2map(scores)
|
||||
@@ -724,6 +750,7 @@ Page({
|
||||
this.setData(
|
||||
{ "data_history": data }
|
||||
)
|
||||
this.sortHistory()
|
||||
this.save2storage()
|
||||
},
|
||||
fail(res) {
|
||||
|
||||
Reference in new issue
Block a user