完善本地存储部分功能,完善前后端接口部分,其实差不多写完了吧,功德+0.732,目前余额-5354.216

This commit is contained in:
539943419 committed 2023-11-12 02:40:55 +08:00
1 parent 5e90a8b670
commit a3d512a681
1 file changed
+222 -153
+222 -153
View File
@@ -32,63 +32,66 @@ Page({
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, // 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: []} , // 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, // hasCollect: false,
},{ // }, {
id:3, // 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: []} , // 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, // hasCollect: false,
},{ // }, {
id:4, // 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: []} , // 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, // hasCollect: false,
},{ // }, {
id:5, // 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: []} , // 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, // hasCollect: false,
},{ // }, {
id:6, // 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: []} , // 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, // hasCollect: false,
}, // },
], "2023.2.10": [ // ], "2023.2.10": [
{ // {
id:7, // 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: []} , // 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, // hasCollect: false,
} // }
], "2023.2.11": [ // ], "2023.2.11": [
{ // {
id:8, // 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: []} , // 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, // hasCollect: false,
} // }
], "2023.2.12": [ // ], "2023.2.12": [
{ // {
id:9, // 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: []} , // 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, // hasCollect: false,
} // }
], "2023.2.13": [ // ], "2023.2.13": [
{ // {
id:10, // 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: []} , // 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, // 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": "低风险"由前端实现
@@ -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()
}, },
//开始界面的按钮相关动画 //开始界面的按钮相关动画
@@ -560,6 +521,7 @@ Page({
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]) { switch (this.data.pageStack[this.data.pageStack.length - 1]) {
case "collect": { case "collect": {
tr = "delete" tr = "delete"
@@ -576,6 +538,16 @@ Page({
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
@@ -603,10 +575,13 @@ Page({
this.data.data_resultPage.tr = "delete" this.data.data_resultPage.tr = "delete"
this.setData( this.setData(
{data_collect:this.data.data_collect, {
data_collect: this.data.data_collect,
data_history: this.data.data_history, data_history: this.data.data_history,
data_resultPage:this.data.data_resultPage} data_resultPage: this.data.data_resultPage
}
) )
this.save2storage()
this.exit_setRemark() this.exit_setRemark()
}, },
@@ -625,10 +600,13 @@ Page({
} }
this.setData( this.setData(
{data_collect:this.data.data_collect, {
data_collect: this.data.data_collect,
data_history: this.data.data_history, data_history: this.data.data_history,
data_resultPage:this.data.data_resultPage} data_resultPage: this.data.data_resultPage
}
) )
this.save2storage()
this.exit_editRemark() this.exit_editRemark()
}, },
@@ -650,10 +628,13 @@ Page({
this.data.data_resultPage.tr = "heart" this.data.data_resultPage.tr = "heart"
this.setData( this.setData(
{data_collect:this.data.data_collect, {
data_collect: this.data.data_collect,
data_history: this.data.data_history, data_history: this.data.data_history,
data_resultPage:this.data.data_resultPage} data_resultPage: this.data.data_resultPage
}
) )
this.save2storage()
this.exit_removeCollectionVerify() this.exit_removeCollectionVerify()
}, },
@@ -681,12 +662,12 @@ Page({
return res return res
}, },
//收到搜索结果处理 //收到搜索结果处理(并没有写)
receive_result() { receive_result() {
}, },
//收到成分数据更新处理 //收到成分数据更新处理(并没有写)
receive_lib() { receive_lib() {
}, },
@@ -713,9 +694,11 @@ Page({
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)
@@ -740,6 +723,7 @@ Page({
this.setData( this.setData(
{ "data_history": data } { "data_history": data }
) )
this.save2storage()
}, },
fail(res) { fail(res) {
console.log(res) console.log(res)
@@ -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)
}
})
}
})
} }
}) })
}, },
@@ -958,6 +946,33 @@ Page({
}, },
// 将各种数据存入本地
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