// pages/securityCheck/securityCheck.js import { postApi } from "../../apis/api" import { apiUrl } from "../../apis/apiConfig" import { isImage } from "../../utils/utils" Page({ data: { list: [], loginStatus: wx.getStorageSync('userId') }, async login() { if (!wx.getStorageSync('openId')) return let res1 = await postApi("/user/wx/openId/login", { openId: wx.getStorageSync('openId') }) if (res1.data.status == 0) { let data = { ...res1.data.result.userInfo, ...res1.data.result.shipInfo, } Object.keys(data).forEach(function (key) { wx.setStorageSync(key, data[key]) }) this.setData({ loginStatus: true }) this.getList() } else { wx.switchTab({ url: '/pages/takePhoto/takePhoto', }) } }, async getList() { if (!wx.getStorageSync('userId')) { wx.showToast({ title: '尚未登录', icon: 'error' }) return } let { data } = await postApi('/security/check/list', { userId: wx.getStorageSync('userId'), shipId: wx.getStorageSync('shipId') }) wx.stopPullDownRefresh() if (data.status == 0) { for (let i of data.result) { i.isImage = isImage(i.fileKey) } this.setData({ list: data.result }) } else { this.setData({ list: [] }) } }, uploadMedia(e) { let { id: itemId } = e.currentTarget.dataset wx.showLoading({ title: '高精度定位中...' }) wx.getLocation({ type: 'gcj02', isHighAccuracy: true, success: e => { let { latitude, longitude } = e wx.chooseMedia({ count: 1, mediaType: ['image', 'video'], sourceType: ['album', 'camera'], sizeType: ['original', 'compressed'], success: e => { console.log("获取媒体成功!", e) let filePath = e.tempFiles[0].tempFilePath wx.showLoading({ title: '正在上传...' }) wx.uploadFile({ url: `${apiUrl}/security/check/upload/file`, filePath, name: 'file', formData: { itemId, userId: wx.getStorageSync('userId'), location: `${longitude},${latitude}` }, success: async e => { let data = JSON.parse(e.data) if (data.status == 0) { this.getList() wx.showToast({ title: data.msg, duration: 1500 }) } else { wx.showToast({ title: data.msg, icon: "error", duration: 2000 }) } }, fail: err => { wx.showToast({ title: data.msg, icon: "error", duration: 2000 }) } }) }, fail: e => { console.log("失败1", e) } }) }, fail: e => { this.setData({ authModal: true, modalText: "位置信息" }) }, complete: e => { wx.hideLoading({ success: (res) => {}, }) } }) }, onPullDownRefresh() { this.getList() }, onShow() { this.setData({ loginStatus: wx.getStorageSync('userId') }) }, onLoad(options) { // this.getList() }, })