| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- import {
- uploadFile
- } from "../../utils/upload"
- Page({
- data: {
- avatar: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/avatar-icon.jpg?sign=f5c66c94d189436f82353eb48cb01f08&t=1634538864",
- cameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera-icon.png?sign=11a65871a2800cd04ecaa8991687fccd&t=1634607415",
- newCameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera.png?sign=ad0fe8bead6a46cb20f45f792d4bed67&t=1645502416",
- userName: "",
- phone: "",
- shipName: "",
- shipMmsi: "",
- authModal: false,
- modalText: "位置"
- },
- test() {
- const ctx = wx.createCameraContext()
- ctx.takePhoto({
- quality: 'high',
- success: (res) => {
- let src = res.tempImagePath
- wx.navigateTo({
- url: `/pages/takeBill/canvas/canvas?src=${src}`,
- })
- // wx.getImageInfo({
- // src,
- // success: e => {
- // console.log(e)
- // }
- // })
- }
- })
- },
- goBack() {
- // wx.redirectTo({
- // url: '/pages/takePhoto/takePhoto',
- // })
- wx.navigateBack()
- },
- takePhotoAction: function () {
- const ctx = wx.createCameraContext()
- ctx.takePhoto({
- quality: 'high',
- success: (res) => {
- console.log(res)
- let src = res.tempImagePath
- wx.compressImage({
- src,
- quality: 80, // 压缩质量
- success: async e => {
- console.log("图片压缩成功!", e)
- wx.hideLoading({
- success: (res) => {},
- })
- if (wx.getStorageSync('userName')) {
- wx.showLoading({
- title: '正在上传...',
- })
- let postData = {
- type: 0,
- userId: wx.getStorageSync('userId'),
- }
- postData.location = ''
- let res = await uploadFile(e.tempFilePath, postData)
- console.log("上传结束", res)
- if (res.status == 0) {
- wx.showToast({
- title: res.msg
- })
- wx.setStorageSync('shareImageUrl', res.result.viewUrl)
- console.log(wx.getStorageSync('shareImageUrl'))
- wx.downloadFile({
- url: res.result.viewUrl,
- success: e => {
- console.log("下载调用!", e)
- wx.setStorageSync('cacheImage', e.tempFilePath)
- wx.redirectTo({
- url: '/pages/takeBill/success/success',
- })
- },
- fail: e => {
- console.log("失败3", e)
- }
- })
- } else {
- wx.showToast({
- title: res.msg
- })
- }
- } else {
- // 新用户图片
- console.log("新用户图片", e)
- wx.setStorageSync('type', 1)
- wx.setStorageSync('file', e.tempFilePath)
- wx.redirectTo({
- url: `/pages/newCachePage/newCachePage`,
- })
- }
- },
- fail: e => {
- console.log("失败2", e)
- }
- })
- }
- })
- },
- onLoad() {
- let userName = wx.getStorageSync('userName')
- let userId = wx.getStorageSync('userId')
- let phone = wx.getStorageSync('phone')
- let shipId = wx.getStorageSync('shipId')
- this.setData({
- userName,
- phone,
- userId,
- shipId
- })
- }
- })
|