完善本地存储部分功能,完善前后端接口部分,其实差不多写完了吧,功德+0.732,目前余额-5354.216
This commit is contained in:
1 parent
5e90a8b670
commit
a3d512a681
1 file changed
+313
-244
+313
-244
@@ -21,74 +21,77 @@ Page({
|
|||||||
tip_hidden: false,
|
tip_hidden: false,
|
||||||
active_Page: "startPage",
|
active_Page: "startPage",
|
||||||
currentDate: '',
|
currentDate: '',
|
||||||
remarkTemp:'',
|
remarkTemp: '',
|
||||||
resultTitle:"查询结果",
|
resultTitle: "查询结果",
|
||||||
|
|
||||||
pageStack:[],
|
pageStack: [],
|
||||||
|
|
||||||
curtain_hidden: true,
|
curtain_hidden: true,
|
||||||
curtain2_hidden: true,
|
curtain2_hidden: true,
|
||||||
|
|
||||||
imgUrl_test:"https://tse4-mm.cn.bing.net/th/id/OIP-C.2MyVJAPY4CWrMUIKfruz9AHaHa?w=199&h=199&c=7&r=0&o=5&dpr=1.3&pid=1.7",
|
imgUrl_test: "https://tse4-mm.cn.bing.net/th/id/OIP-C.2MyVJAPY4CWrMUIKfruz9AHaHa?w=199&h=199&c=7&r=0&o=5&dpr=1.3&pid=1.7",
|
||||||
|
|
||||||
//有点误导性
|
// 有点误导性
|
||||||
// 瞬间开启摄像头影响流畅性了
|
// 瞬间开启摄像头会导致卡顿,所以还是注释掉吧
|
||||||
// camera_hidden:true,
|
// camera_hidden:true,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 历史记录data
|
// 历史记录data
|
||||||
data_history: {
|
data_history: {
|
||||||
"2023.2.30": [
|
// "2023.2.30": [
|
||||||
{
|
// {
|
||||||
id:1,
|
// // 时间复杂度需求哪有那么高。。。
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: ["山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾","山梨酸钾",]},
|
// id: 1,
|
||||||
hasCollect:false,//目前全是false。。。
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: ["山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾", "山梨酸钾",] },
|
||||||
},{
|
// hasCollect: false,//目前全是false。。。
|
||||||
|
// }, {
|
||||||
id:2,
|
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 75, arr: []} ,
|
// id: 2,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 75, arr: [] },
|
||||||
},{
|
// hasCollect: false,
|
||||||
id:3,
|
// }, {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 3,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
},{
|
// hasCollect: false,
|
||||||
id:4,
|
// }, {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 4,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
},{
|
// hasCollect: false,
|
||||||
id:5,
|
// }, {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 5,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
},{
|
// hasCollect: false,
|
||||||
id:6,
|
// }, {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 6,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
},
|
// hasCollect: false,
|
||||||
], "2023.2.10": [
|
// },
|
||||||
{
|
// ], "2023.2.10": [
|
||||||
id:7,
|
// {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 7,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
}
|
// hasCollect: false,
|
||||||
], "2023.2.11": [
|
// }
|
||||||
{
|
// ], "2023.2.11": [
|
||||||
id:8,
|
// {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 8,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
}
|
// hasCollect: false,
|
||||||
], "2023.2.12": [
|
// }
|
||||||
{
|
// ], "2023.2.12": [
|
||||||
id:9,
|
// {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 9,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
}
|
// hasCollect: false,
|
||||||
], "2023.2.13": [
|
// }
|
||||||
{
|
// ], "2023.2.13": [
|
||||||
id:10,
|
// {
|
||||||
imgUrl:"https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1" , res:{scores: 1, arr: []} ,
|
// id: 10,
|
||||||
hasCollect:false,
|
// imgUrl: "https://tse3-mm.cn.bing.net/th/id/OIP-C.qM9D7c-Ow-C-xLARJdSwQwHaIO?pid=ImgDet&rs=1", res: { scores: 1, arr: [] },
|
||||||
}
|
// hasCollect: false,
|
||||||
],
|
// }
|
||||||
|
// ],
|
||||||
},
|
},
|
||||||
|
|
||||||
//收藏夹data
|
//收藏夹data
|
||||||
@@ -102,46 +105,6 @@ Page({
|
|||||||
// "riskBgColor": "springgreen",
|
// "riskBgColor": "springgreen",
|
||||||
// "riskStr": "低风险",
|
// "riskStr": "低风险",
|
||||||
// },
|
// },
|
||||||
// {
|
|
||||||
// "date": "2023.5.6",
|
|
||||||
// "res":{scores: 99, arr: []} ,
|
|
||||||
// "imgUrl": "./static/icons/history.svg",
|
|
||||||
// "remark": "一二三四五六七",
|
|
||||||
// "riskBgColor": "sandybrown",
|
|
||||||
// "riskStr": "中风险"
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "date": "2023.5.6",
|
|
||||||
// "res":{scores: 99, arr: []} ,
|
|
||||||
// "imgUrl": "./static/icons/history.svg",
|
|
||||||
// "remark": "一二三四五六七",
|
|
||||||
// "riskBgColor": "tomato",
|
|
||||||
// "riskStr": "高风险"
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "date": "2023.15.16",
|
|
||||||
// "res":{scores: 99, arr: []} ,
|
|
||||||
// "imgUrl": "./static/icons/history.svg",
|
|
||||||
// "remark": "方师傅康便面",
|
|
||||||
// "riskBgColor": "springgreen",
|
|
||||||
// "riskStr": "低风险"
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "date": "2023.5.6",
|
|
||||||
// "res":{scores: 1, arr: []} ,
|
|
||||||
// "imgUrl": "./static/icons/history.svg",
|
|
||||||
// "remark": "一二三四五六七",
|
|
||||||
// "riskBgColor": "tomato",
|
|
||||||
// "riskStr": "高风险"
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "date": "2023.5.6",
|
|
||||||
// "res":{scores: 99, arr: []} ,
|
|
||||||
// "imgUrl": "./static/icons/history.svg",
|
|
||||||
// "remark": "一二三四五六七",
|
|
||||||
// "riskBgColor": "tomato",
|
|
||||||
// "riskStr": "高风险"
|
|
||||||
// },
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// 存储所有成分的信息, hidden: false, "riskBgColor": "springgreen", "riskStr": "低风险"由前端实现
|
// 存储所有成分的信息, hidden: false, "riskBgColor": "springgreen", "riskStr": "低风险"由前端实现
|
||||||
@@ -196,13 +159,13 @@ Page({
|
|||||||
],
|
],
|
||||||
|
|
||||||
// 知识库搜索用
|
// 知识库搜索用
|
||||||
hidden_lib:{},
|
hidden_lib: {},
|
||||||
|
|
||||||
// 查询结果搜索用
|
// 查询结果搜索用
|
||||||
hidden_result:{},
|
hidden_result: {},
|
||||||
|
|
||||||
|
|
||||||
data_lib_map:{},
|
data_lib_map: {},
|
||||||
|
|
||||||
//查询展示用
|
//查询展示用
|
||||||
data_resultPage: {
|
data_resultPage: {
|
||||||
@@ -210,11 +173,11 @@ Page({
|
|||||||
circleClip: "",
|
circleClip: "",
|
||||||
circleColor: "",
|
circleColor: "",
|
||||||
arr: [],
|
arr: [],
|
||||||
tr:null,//top right
|
tr: null,//top right
|
||||||
},
|
},
|
||||||
|
|
||||||
//收藏/取消收藏用
|
//收藏/取消收藏用
|
||||||
resultId:-1,
|
resultId: -1,
|
||||||
|
|
||||||
// 收到的查询结果信息
|
// 收到的查询结果信息
|
||||||
data_rcv: {
|
data_rcv: {
|
||||||
@@ -222,8 +185,6 @@ Page({
|
|||||||
arr: ["山梨酸钾"],
|
arr: ["山梨酸钾"],
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sessionKey: "",
|
sessionKey: "",
|
||||||
userInfo: {},
|
userInfo: {},
|
||||||
hasUserInfo: false,
|
hasUserInfo: false,
|
||||||
@@ -240,7 +201,7 @@ Page({
|
|||||||
// this.updateSession()
|
// this.updateSession()
|
||||||
// },60*1000*5)
|
// },60*1000*5)
|
||||||
// console.log(this.data.sessionKey)
|
// console.log(this.data.sessionKey)
|
||||||
|
this.readStorageData()
|
||||||
},
|
},
|
||||||
|
|
||||||
//开始界面的按钮相关动画
|
//开始界面的按钮相关动画
|
||||||
@@ -394,7 +355,7 @@ Page({
|
|||||||
this.startPage_Bottons_in()
|
this.startPage_Bottons_in()
|
||||||
this.animate('#page_lib', [
|
this.animate('#page_lib', [
|
||||||
{ opacity: 1, translateY: "-100%" }, { opacity: 0, translateY: "0", ease: 'ease-in-out' },
|
{ opacity: 1, translateY: "-100%" }, { opacity: 0, translateY: "0", ease: 'ease-in-out' },
|
||||||
], 1000, ()=>{
|
], 1000, () => {
|
||||||
// for(var n of this.data.data_lib){
|
// for(var n of this.data.data_lib){
|
||||||
// n.hidden=false
|
// n.hidden=false
|
||||||
// }
|
// }
|
||||||
@@ -459,7 +420,7 @@ Page({
|
|||||||
], 600)
|
], 600)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
exit_result() {
|
exit_result() {
|
||||||
this.hide_curtain()
|
this.hide_curtain()
|
||||||
this.animate('#page_result', [
|
this.animate('#page_result', [
|
||||||
@@ -529,131 +490,151 @@ Page({
|
|||||||
this.hide_curtain2()
|
this.hide_curtain2()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// 根据传入的包含scores和arr的object更新this.data.data_resultPage并popup_result
|
// 根据传入的包含scores和arr的object更新this.data.data_resultPage并popup_result
|
||||||
show_result(res: { scores: any,arr:Array<any> } ,tr:string) {
|
show_result(res: { scores: any, arr: Array<any> }, tr: string) {
|
||||||
// console.log(res)
|
// console.log(res)
|
||||||
var data_resultPage={
|
var data_resultPage = {
|
||||||
scores: res.scores,
|
scores: res.scores,
|
||||||
arr: [],
|
arr: [],
|
||||||
tr:tr,
|
tr: tr,
|
||||||
}
|
}
|
||||||
console.log(tr)
|
console.log(tr)
|
||||||
for(var name of res.arr){
|
for (var name of res.arr) {
|
||||||
// 有时间去写个时间复杂度更低的,不过感觉也够用了
|
// 有时间去写个时间复杂度更低的,不过感觉也够用了
|
||||||
for(var n of this.data.data_lib){
|
for (var n of this.data.data_lib) {
|
||||||
if(n.name.zh.includes(name) || n.name.en.includes(name)){
|
if (n.name.zh.includes(name) || n.name.en.includes(name)) {
|
||||||
data_resultPage.arr.push(n)
|
data_resultPage.arr.push(n)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.setData({
|
this.setData({
|
||||||
"data_resultPage":data_resultPage
|
"data_resultPage": data_resultPage
|
||||||
})
|
})
|
||||||
// console.log(data_resultPage)
|
// console.log(data_resultPage)
|
||||||
this.popup_result()
|
this.popup_result()
|
||||||
},
|
},
|
||||||
show_result_wxml(e:any){
|
show_result_wxml(e: any) {
|
||||||
var res=e.currentTarget.dataset.index;
|
var res = e.currentTarget.dataset.index;
|
||||||
console.log(res)
|
console.log(res)
|
||||||
this.data.resultId=res.id
|
this.data.resultId = res.id
|
||||||
// console.log(this.data.resultId)
|
// console.log(this.data.resultId)
|
||||||
var tr = ""
|
var tr = ""
|
||||||
switch(this.data.pageStack[this.data.pageStack.length-1]){
|
// 不太好吧
|
||||||
case "collect":{
|
switch (this.data.pageStack[this.data.pageStack.length - 1]) {
|
||||||
|
case "collect": {
|
||||||
tr = "delete"
|
tr = "delete"
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "history":{
|
case "history": {
|
||||||
if(res.hasCollect)
|
if (res.hasCollect)
|
||||||
tr = "delete"
|
tr = "delete"
|
||||||
else
|
else
|
||||||
tr = "heart"
|
tr = "heart"
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res=res.res
|
res = res.res
|
||||||
this.show_result(res,tr)
|
this.show_result(res, tr)
|
||||||
|
},
|
||||||
|
show_result_byId(id: any) {
|
||||||
|
for (var date in this.data.data_history) {
|
||||||
|
for (var n of this.data.data_history[date]) {
|
||||||
|
if (n.id == id) {
|
||||||
|
this.data.resultId = id
|
||||||
|
this.show_result(n.res, "heart")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getInputRemark(e:any){
|
getInputRemark(e: any) {
|
||||||
this.data.remarkTemp = e.detail.value
|
this.data.remarkTemp = e.detail.value
|
||||||
},
|
},
|
||||||
|
|
||||||
// 收藏当前页面
|
// 收藏当前页面
|
||||||
add_collection(){
|
add_collection() {
|
||||||
var r = this.id2resultAndDate(this.data.resultId)
|
var r = this.id2resultAndDate(this.data.resultId)
|
||||||
if(r == null)return
|
if (r == null) return
|
||||||
var result = r.result
|
var result = r.result
|
||||||
var date = r.date
|
var date = r.date
|
||||||
var remark = this.data.remarkTemp
|
var remark = this.data.remarkTemp
|
||||||
|
|
||||||
console.log(result,date,remark)
|
console.log(result, date, remark)
|
||||||
this.data.data_collect.push({
|
this.data.data_collect.push({
|
||||||
"id":this.data.resultId,
|
"id": this.data.resultId,
|
||||||
"date":date,
|
"date": date,
|
||||||
"res":result.res,
|
"res": result.res,
|
||||||
"imgUrl":result.imgUrl,
|
"imgUrl": result.imgUrl,
|
||||||
"remark":this.data.remarkTemp,
|
"remark": this.data.remarkTemp,
|
||||||
"riskBgColor":this.scores2map(result.res.scores).color,
|
"riskBgColor": this.scores2map(result.res.scores).color,
|
||||||
"riskStr": this.scores2map(result.res.scores).content,
|
"riskStr": this.scores2map(result.res.scores).content,
|
||||||
})
|
})
|
||||||
result.hasCollect=true
|
result.hasCollect = true
|
||||||
this.data.data_resultPage.tr="delete"
|
this.data.data_resultPage.tr = "delete"
|
||||||
|
|
||||||
this.setData(
|
this.setData(
|
||||||
{data_collect:this.data.data_collect,
|
{
|
||||||
data_history:this.data.data_history,
|
data_collect: this.data.data_collect,
|
||||||
data_resultPage:this.data.data_resultPage}
|
data_history: this.data.data_history,
|
||||||
|
data_resultPage: this.data.data_resultPage
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
this.save2storage()
|
||||||
this.exit_setRemark()
|
this.exit_setRemark()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
editRemark(){
|
editRemark() {
|
||||||
var r = this.id2resultAndDate(this.data.resultId)
|
var r = this.id2resultAndDate(this.data.resultId)
|
||||||
if(r == null)return
|
if (r == null) return
|
||||||
var result = r.result
|
var result = r.result
|
||||||
var date = r.date
|
var date = r.date
|
||||||
var remark = this.data.remarkTemp
|
var remark = this.data.remarkTemp
|
||||||
|
|
||||||
for(var i in this.data.data_collect){
|
for (var i in this.data.data_collect) {
|
||||||
if (this.data.data_collect[i].id == this.data.resultId){
|
if (this.data.data_collect[i].id == this.data.resultId) {
|
||||||
this.data.data_collect[i].remark=remark
|
this.data.data_collect[i].remark = remark
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setData(
|
this.setData(
|
||||||
{data_collect:this.data.data_collect,
|
{
|
||||||
data_history:this.data.data_history,
|
data_collect: this.data.data_collect,
|
||||||
data_resultPage:this.data.data_resultPage}
|
data_history: this.data.data_history,
|
||||||
|
data_resultPage: this.data.data_resultPage
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
this.save2storage()
|
||||||
this.exit_editRemark()
|
this.exit_editRemark()
|
||||||
},
|
},
|
||||||
|
|
||||||
//取消收藏。。。。
|
//取消收藏。。。。
|
||||||
remove_collection(){
|
remove_collection() {
|
||||||
var flag = true
|
var flag = true
|
||||||
var r = this.id2resultAndDate(this.data.resultId)
|
var r = this.id2resultAndDate(this.data.resultId)
|
||||||
if(r == null) flag = false
|
if (r == null) flag = false
|
||||||
if(flag){
|
if (flag) {
|
||||||
var result = r.result
|
var result = r.result
|
||||||
result.hasCollect=false
|
result.hasCollect = false
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i in this.data.data_collect){
|
for (var i in this.data.data_collect) {
|
||||||
if (this.data.data_collect[i].id == this.data.resultId){
|
if (this.data.data_collect[i].id == this.data.resultId) {
|
||||||
this.data.data_collect.splice(i,1)
|
this.data.data_collect.splice(i, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.data.data_resultPage.tr="heart"
|
this.data.data_resultPage.tr = "heart"
|
||||||
|
|
||||||
this.setData(
|
this.setData(
|
||||||
{data_collect:this.data.data_collect,
|
{
|
||||||
data_history:this.data.data_history,
|
data_collect: this.data.data_collect,
|
||||||
data_resultPage:this.data.data_resultPage}
|
data_history: this.data.data_history,
|
||||||
|
data_resultPage: this.data.data_resultPage
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
this.save2storage()
|
||||||
this.exit_removeCollectionVerify()
|
this.exit_removeCollectionVerify()
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -681,95 +662,98 @@ Page({
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
//收到搜索结果处理
|
//收到搜索结果处理(并没有写)
|
||||||
receive_result(){
|
receive_result() {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//收到成分数据更新处理
|
//收到成分数据更新处理(并没有写)
|
||||||
receive_lib(){
|
receive_lib() {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//更新成分数据
|
//更新成分数据
|
||||||
updateLib(){
|
updateLib() {
|
||||||
wx.request({
|
wx.request({
|
||||||
url: 'http://'+serverAddr+'/getLib', //仅为示例,并非真实的接口地址
|
url: 'http://' + serverAddr + '/getLib', //仅为示例,并非真实的接口地址
|
||||||
data: {
|
data: {
|
||||||
},
|
},
|
||||||
method:"GET",
|
method: "GET",
|
||||||
header: {
|
header: {
|
||||||
'content-type': 'application/json' // 默认值
|
'content-type': 'application/json' // 默认值
|
||||||
},
|
},
|
||||||
success:res=> {
|
success: res => {
|
||||||
// console.log(res)
|
// console.log(res)
|
||||||
var data = res.data
|
var data = res.data
|
||||||
console.log(data)
|
console.log(data)
|
||||||
// 能跑
|
// 能跑
|
||||||
for(var n of data){
|
for (var n of data) {
|
||||||
var scores = n.scores;
|
var scores = n.scores;
|
||||||
var map = this.scores2map(scores)
|
var map = this.scores2map(scores)
|
||||||
n.hidden = false
|
n.hidden = false
|
||||||
n.riskBgColor = map.color
|
n.riskBgColor = map.color
|
||||||
n.riskStr = map.content
|
n.riskStr = map.content
|
||||||
}
|
}
|
||||||
|
this.data.data_lib = data
|
||||||
this.setData(
|
this.setData(
|
||||||
{"data_lib" : data}
|
{ "data_lib": data }
|
||||||
)
|
)
|
||||||
|
this.save2storage()
|
||||||
},
|
},
|
||||||
fail(res){
|
fail(res) {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
//更新历史记录
|
//更新历史记录
|
||||||
updateHistory(){
|
updateHistory() {
|
||||||
wx.request({
|
wx.request({
|
||||||
url: 'http://'+serverAddr+'/getHistory', //仅为示例,并非真实的接口地址
|
url: 'http://' + serverAddr + '/getHistory', //仅为示例,并非真实的接口地址
|
||||||
data: {
|
data: {
|
||||||
userCode:this.data.sessionKey
|
userCode: this.data.sessionKey
|
||||||
},
|
},
|
||||||
method:"POST",
|
method: "POST",
|
||||||
header: {
|
header: {
|
||||||
'content-type': 'application/json' // 默认值
|
'content-type': 'application/json' // 默认值
|
||||||
},
|
},
|
||||||
success:res=> {
|
success: res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
var data = res.data
|
var data = res.data
|
||||||
this.setData(
|
this.setData(
|
||||||
{"data_history" : data}
|
{ "data_history": data }
|
||||||
)
|
)
|
||||||
|
this.save2storage()
|
||||||
},
|
},
|
||||||
fail(res){
|
fail(res) {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 更新session
|
// 更新session
|
||||||
updateSession(){
|
updateSession() {
|
||||||
return new Promise((resolve, reject)=>{
|
return new Promise((resolve, reject) => {
|
||||||
this.getCode().then(code => {
|
this.getCode().then(code => {
|
||||||
wx.request({
|
wx.request({
|
||||||
url: 'http://'+serverAddr+'/updateSession', //仅为示例,并非真实的接口地址
|
url: 'http://' + serverAddr + '/updateSession', //仅为示例,并非真实的接口地址
|
||||||
data: {
|
data: {
|
||||||
userCode:code
|
userCode: code
|
||||||
},
|
},
|
||||||
method:"POST",
|
method: "POST",
|
||||||
header: {
|
header: {
|
||||||
'content-type': 'application/json' // 默认值
|
'content-type': 'application/json' // 默认值
|
||||||
},
|
},
|
||||||
success:res=> {
|
success: res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
var data = res.data
|
var data = res.data
|
||||||
this.setData(
|
this.setData(
|
||||||
{"sessionKey" : data}
|
{ "sessionKey": data }
|
||||||
)
|
)
|
||||||
resolve()
|
resolve()
|
||||||
// setTimeout(this.updateSession,1000*60*5)
|
// setTimeout(this.updateSession,1000*60*5)
|
||||||
},
|
},
|
||||||
fail:res=>{
|
fail: res => {
|
||||||
console.log(res)
|
console.log(res)
|
||||||
// setTimeout(this.updateSession,1000)
|
// setTimeout(this.updateSession,1000)
|
||||||
reject()
|
reject()
|
||||||
@@ -779,6 +763,57 @@ Page({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 上传照片并
|
||||||
|
uploadImg(tempImagePath: any) {
|
||||||
|
wx.getFileSystemManager().readFile({
|
||||||
|
filePath: tempImagePath,
|
||||||
|
encoding: 'base64',
|
||||||
|
success: res => {
|
||||||
|
// console.log('data:image/png;base64,' + res.data)
|
||||||
|
const imgBase64 = res.data
|
||||||
|
wx.request({
|
||||||
|
url: 'http://' + serverAddr + '/rcvImg', //仅为示例,并非真实的接口地址
|
||||||
|
data: {
|
||||||
|
imgBase64: imgBase64
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
header: {
|
||||||
|
'content-type': 'application/json' // 默认值
|
||||||
|
},
|
||||||
|
success: res => {
|
||||||
|
var data = res.data
|
||||||
|
console.log(res.data)
|
||||||
|
var nowdate = new Date();
|
||||||
|
var nowyear = nowdate.getFullYear();
|
||||||
|
var nowmonth = nowdate.getMonth() + 1;
|
||||||
|
var nowday = nowdate.getDate();
|
||||||
|
var dateStr = nowyear + '.' + nowmonth + '.' + nowday
|
||||||
|
if (!this.data.data_history[dateStr]) {
|
||||||
|
this.data.data_history[dateStr] = []
|
||||||
|
}
|
||||||
|
var historyTemp =
|
||||||
|
{
|
||||||
|
id: data.id,
|
||||||
|
imgUrl: data.imgUrl,
|
||||||
|
res: data.res,
|
||||||
|
hasCollect: false,//目前全是false。。。
|
||||||
|
}
|
||||||
|
this.data.data_history[dateStr].push(historyTemp)
|
||||||
|
this.setData({
|
||||||
|
data_history: this.data.data_history
|
||||||
|
})
|
||||||
|
this.sortHistory()
|
||||||
|
this.show_result_byId(data.id)
|
||||||
|
this.save2storage()
|
||||||
|
},
|
||||||
|
fail: res => {
|
||||||
|
console.log(res)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
//拍照
|
//拍照
|
||||||
takePhoto() {
|
takePhoto() {
|
||||||
const ctx = wx.createCameraContext()
|
const ctx = wx.createCameraContext()
|
||||||
@@ -790,30 +825,7 @@ Page({
|
|||||||
const tempImagePath = res.tempImagePath
|
const tempImagePath = res.tempImagePath
|
||||||
console.log(tempImagePath)
|
console.log(tempImagePath)
|
||||||
console.log(res)
|
console.log(res)
|
||||||
wx.getFileSystemManager().readFile({
|
this.uploadImg(tempImagePath)
|
||||||
filePath: tempImagePath, //选择图片返回的相对路径
|
|
||||||
encoding: 'base64', //编码格式
|
|
||||||
success: res => { //成功的回调
|
|
||||||
console.log('data:image/png;base64,' + res.data)
|
|
||||||
const imgBase64 = res.data
|
|
||||||
wx.request({
|
|
||||||
url: 'http://'+serverAddr+'/rcvImg', //仅为示例,并非真实的接口地址
|
|
||||||
data: {
|
|
||||||
imgBase64:imgBase64
|
|
||||||
},
|
|
||||||
method:"POST",
|
|
||||||
header: {
|
|
||||||
'content-type': 'application/json' // 默认值
|
|
||||||
},
|
|
||||||
success (res) {
|
|
||||||
console.log(res)
|
|
||||||
},
|
|
||||||
fail(res){
|
|
||||||
console.log(res)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -825,35 +837,11 @@ Page({
|
|||||||
sourceType: ['album'],
|
sourceType: ['album'],
|
||||||
sizeType: ["compressed"],
|
sizeType: ["compressed"],
|
||||||
count: 1,
|
count: 1,
|
||||||
success(res) {
|
success: res => {
|
||||||
const tempImagePath = res.tempFiles[0].tempFilePath
|
const tempImagePath = res.tempFiles[0].tempFilePath
|
||||||
console.log(tempImagePath)
|
console.log(tempImagePath)
|
||||||
console.log(res)
|
console.log(res)
|
||||||
wx.getFileSystemManager().readFile({
|
this.uploadImg(tempImagePath)
|
||||||
filePath: tempImagePath, //选择图片返回的相对路径
|
|
||||||
encoding: 'base64', //编码格式
|
|
||||||
success: res => { //成功的回调
|
|
||||||
console.log('data:image/png;base64,' + res.data)
|
|
||||||
const imgBase64 = res.data
|
|
||||||
// 发送图片
|
|
||||||
wx.request({
|
|
||||||
url: 'http://'+serverAddr+'/rcvImg', //仅为示例,并非真实的接口地址
|
|
||||||
data: {
|
|
||||||
imgBase64:imgBase64
|
|
||||||
},
|
|
||||||
method:"POST",
|
|
||||||
header: {
|
|
||||||
'content-type': 'application/json' // 默认值
|
|
||||||
},
|
|
||||||
success (res) {
|
|
||||||
console.log(res)
|
|
||||||
},
|
|
||||||
fail(res){
|
|
||||||
console.log(res)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -947,17 +935,44 @@ Page({
|
|||||||
return { "color": "tomato", "content": "高风险" };
|
return { "color": "tomato", "content": "高风险" };
|
||||||
},
|
},
|
||||||
|
|
||||||
id2resultAndDate(id:number){
|
id2resultAndDate(id: number) {
|
||||||
for(var i in this.data.data_history){
|
for (var i in this.data.data_history) {
|
||||||
for(var n of this.data.data_history[i])
|
for (var n of this.data.data_history[i])
|
||||||
if(n.id == id){
|
if (n.id == id) {
|
||||||
return {result:n,date:i}
|
return { result: n, date: i }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// 将各种数据存入本地
|
||||||
|
save2storage() {
|
||||||
|
var list = ['data_history', 'data_collect', 'data_lib']
|
||||||
|
for (var k of list) {
|
||||||
|
wx.setStorage({
|
||||||
|
key: k,
|
||||||
|
data: this.data[k],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 从本地读取各种数据
|
||||||
|
readStorageData(){
|
||||||
|
var list = ['data_history', 'data_collect', 'data_lib']
|
||||||
|
for (var k of list) {
|
||||||
|
this.data[k]=wx.getStorageSync(k)
|
||||||
|
console.log(wx.getStorageSync(k))
|
||||||
|
}
|
||||||
|
this.setData(
|
||||||
|
{
|
||||||
|
data_history:this.data["data_history"],
|
||||||
|
data_collect:this.data["data_collect"],
|
||||||
|
data_lib:this.data["data_lib"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
// 事件处理函数
|
// 事件处理函数
|
||||||
bindViewTap() {
|
bindViewTap() {
|
||||||
@@ -998,6 +1013,60 @@ Page({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 根据日期排序历史记录
|
||||||
|
sortHistory: function () {
|
||||||
|
let keysSorted = Object.keys(this.data.data_history).sort((a, b) => { return this.cmpDate(a, b) })
|
||||||
|
// console.log(keysSorted)
|
||||||
|
var data_history_new = {}
|
||||||
|
for (var i of keysSorted) {
|
||||||
|
data_history_new[i] = this.data.data_history[i]
|
||||||
|
}
|
||||||
|
// console.log(data_history_new)
|
||||||
|
// console.log(arrayObj)
|
||||||
|
// var data_history_new = new Map(arrayObj.map(i => [i[0], i[1]]));
|
||||||
|
this.setData({
|
||||||
|
data_history: data_history_new
|
||||||
|
})
|
||||||
|
// console.log(this.data.data_history)
|
||||||
|
// this.data.data_history.sort()
|
||||||
|
},
|
||||||
|
|
||||||
|
cmpDate: function (date0: string, date1: string) {
|
||||||
|
// console.log(date0,date1)
|
||||||
|
date0 = date0.split('.')
|
||||||
|
date1 = date1.split('.')
|
||||||
|
var y0 = parseInt(date0[0]),
|
||||||
|
y1 = parseInt(date1[0]),
|
||||||
|
m0 = parseInt(date0[1]),
|
||||||
|
m1 = parseInt(date1[1]),
|
||||||
|
d0 = parseInt(date0[2]),
|
||||||
|
d1 = parseInt(date1[2])
|
||||||
|
console.log(date0, date1, y0, y1, m0, m1, d0, d1)
|
||||||
|
var res = 0
|
||||||
|
if (y1 != y0) {
|
||||||
|
if (y1 > y0) {
|
||||||
|
res = -1
|
||||||
|
} else if (y1 < y0) {
|
||||||
|
res = 1
|
||||||
|
}
|
||||||
|
} else if (m1 != m0) {
|
||||||
|
if (m1 > m0) {
|
||||||
|
res = -1
|
||||||
|
} else if (m1 < m0) {
|
||||||
|
res = 1
|
||||||
|
}
|
||||||
|
} else if (d1 != d0) {
|
||||||
|
if (d1 > d0) {
|
||||||
|
res = -1
|
||||||
|
} else if (d1 < d0) {
|
||||||
|
res = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res = -res
|
||||||
|
console.log(res)
|
||||||
|
return res
|
||||||
|
},
|
||||||
|
|
||||||
// 获取用户code,以给服务端换取openId
|
// 获取用户code,以给服务端换取openId
|
||||||
getCode: async function () {
|
getCode: async function () {
|
||||||
var code
|
var code
|
||||||
@@ -1030,7 +1099,7 @@ Page({
|
|||||||
const tempFilePaths = res.tempFilePaths
|
const tempFilePaths = res.tempFilePaths
|
||||||
console.log(tempFilePaths)
|
console.log(tempFilePaths)
|
||||||
wx.uploadFile({
|
wx.uploadFile({
|
||||||
url: 'http://'+serverAddr+'/rcvImg', //仅为示例,非真实的接口地址
|
url: 'http://' + serverAddr + '/rcvImg', //仅为示例,非真实的接口地址
|
||||||
filePath: tempFilePaths[0],
|
filePath: tempFilePaths[0],
|
||||||
name: 'Img',
|
name: 'Img',
|
||||||
formData: {
|
formData: {
|
||||||
|
|||||||
Reference in new issue
Block a user