Files
sykl-new/pages/record/index.js
2023-12-15 17:53:08 +08:00

160 lines
3.9 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
isFixedTop : 0,
barHeight : getApp().globalData.statusBarHeight, // 状态栏高度
needBase : '', // 是否需要完善资料
typesState : false, // 拍摄结果弹出
baseState : false // 是否完善资料弹出
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 获取登录状态
if(wx.getStorageSync("token")){
// 获取初始化
this.initInfo();
}
},
/**
* 初始化
*/
initInfo () {
wx.$api.water.Init().then(res => {
this.setData({
needBase: res.data.need_base
})
}).catch(err => {})
},
/**
* 上传图片信息
*/
uploadPhoto() {
if(wx.getStorageSync("token")){
// 是否需要完善资料
if(this.data.needBase) {
this.setData({
baseState: true
})
return
}
// 拍摄
wx.chooseMedia({
count : 1,
mediaType: ['image'],
sourceType: ['camera'],
camera : 'front',
success : path => {
if(wx.cropImage){
wx.cropImage({
src: path.tempFiles[0].tempFilePath, // 图片路径
cropScale: '3:4', // 裁剪比例
success: res=> {
// 上传图片
wx.$api.file.uploadImg(res.tempFilePath, {}).then(res=>{
// 获取舌诊检测接口
this.checkEnter(res.url);
this.setData({
typesState: true
})
})
},
complete: err => {}
})
return
}
// 上传图片
wx.$api.file.uploadImg(path.tempFiles[0].tempFilePath, {}).then(res=>{
this.checkEnter(res.url);
this.setData({
typesState: true
})
})
}
})
}else {
// 去登录
wx.navigateTo({
url: "/pages/login/index"
})
}
},
/**
* 皮肤检测接口
*/
checkEnter(img) {
wx.$api.record.tongue({image: img}).then(res => {
wx.navigateTo({
url: "/pages/record/detail/detail?tongue_id=" + res.data.tongue_id
})
this.setData({
typesState: false
})
}).catch(err => {
this.setData({
typesState: false
})
})
},
/**
* 处理未登录时的转跳
*/
userNav(e){
let pageUrl = e.currentTarget.dataset.url
if(wx.getStorageSync("token")){
wx.navigateTo({
url: pageUrl
})
}else{
// 去登录
wx.navigateTo({
url: "/pages/login/index"
})
}
},
/**
* 关闭完善资料弹出
*/
establish() {
this.setData({
baseState: false
})
},
/**
* 完善资料跳转
*/
perfect() {
this.setData({
baseState: false
})
wx.navigateTo({
url: '/pages/clock/base/base'
})
}
})