| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- // pages/newCachePage/newCahePage.js
- import cloudApi from "../../apis/cloudApi"
- import {
- postApi
- } from "../../apis/api"
- import {
- uploadFile
- } from "../../utils/upload"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type: "",
- file: "",
- latitude: "",
- longitude: "",
- shipName: "",
- shipMmsi: "",
- agreeModal: false,
- agreeText: false,
- isWxRegister: false
- },
- goBack() {
- wx.redirectTo({
- url: '/pages/index/index',
- })
- },
- async register() {
- if (!this.checkout()) return
- let res = await postApi('/user/wx/register', {
- userId: wx.getStorageSync('userId'),
- shipName: this.data.shipName,
- shipMmsi: this.data.shipMmsi,
- })
- console.log(res)
- if (res.data.status == 0) {
- let {
- shipInfo,
- userInfo
- } = res.data.result
- let data = {
- ...shipInfo,
- ...userInfo
- }
- Object.keys(data).forEach(function (key) {
- wx.setStorageSync(key, data[key])
- })
- wx.compressImage({
- src: wx.getStorageSync('file'),
- quality: 80, // 压缩质量
- success: async e => {
- console.log("图片压缩成功!", e)
- wx.hideLoading({
- success: (res) => {},
- })
- wx.showLoading({
- title: '正在上传...',
- })
- let res = await uploadFile(e.tempFilePath, {
- type: 3,
- userId: wx.getStorageSync('userId'),
- location: `${this.data.longitude},${this.data.latitude}`
- })
- 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.saveImageToPhotosAlbum({
- filePath: e.tempFilePath,
- success: e => {
- if (e.errMsg == "saveImageToPhotosAlbum:ok") {
- wx.showToast({
- title: '保存成功!',
- })
- wx.removeStorageSync('cacheImage')
- }
- },
- fail: e => {
- console.log("失败44", e)
- this.setData({
- authModal: true,
- modalText: "文件存储"
- })
- }
- })
- wx.navigateTo({
- url: '/pages/takePhoto/success/success',
- })
- },
- fail: e => {
- console.log("失败3", e)
- }
- })
- } else {
- wx.showToast({
- title: res.msg
- })
- }
- },
- fail: e => {
- console.log("失败22", e)
- }
- })
- } else {
- }
- },
- checkout() {
- if (!this.data.shipName) {
- wx.showToast({
- title: '请输入船名!',
- icon: "error"
- })
- return
- }
- if (!this.data.shipMmsi) {
- wx.showToast({
- title: '请输入MMSI!',
- icon: "error"
- })
- return
- }
- return true
- },
- agree() {
- this.setData({
- agreeText: false,
- })
- },
- showAgeeeText() {
- this.setData({
- agreeText: true
- })
- },
- hideAgreeText() {
- this.setData({
- agreeText: false
- })
- },
- hideAgreeModal() {
- this.setData({
- agreeModal: false
- })
- },
- showAgreeModal() {
- this.setData({
- agreeModal: true
- })
- },
- async getPhoneNumber(e) {
- try {
- if (e.detail.errMsg == "getPhoneNumber:ok") {
- wx.showLoading({
- title: '正在登录...',
- mask: true
- })
- let {
- data
- } = await postApi('/wx/getPhoneNumber', {
- code: e.detail.code
- })
- let {
- phoneNumber: phone
- } = data.result
- if (phone) {
- wx.setStorageSync('phone', phone)
- try {
- let res = await postApi('/user/wx/login', {
- openId: wx.getStorageSync('openId'),
- phone: 18988988889
- })
- console.log(res)
- if (res.data.status == 0) {
- let {
- shipInfo,
- userInfo
- } = res.data.result
- let data = {
- ...shipInfo,
- ...userInfo
- }
- Object.keys(data).forEach(function (key) {
- wx.setStorageSync(key, data[key])
- })
- wx.compressImage({
- src: wx.getStorageSync('file'),
- quality: 80, // 压缩质量
- success: async e => {
- console.log("图片压缩成功!", e)
- wx.hideLoading({
- success: (res) => {},
- })
- wx.showLoading({
- title: '正在上传...',
- })
- let res = await uploadFile(e.tempFilePath, {
- type: 3,
- userId: wx.getStorageSync('userId'),
- location: `${this.data.longitude},${this.data.latitude}`
- })
- 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.saveImageToPhotosAlbum({
- filePath: e.tempFilePath,
- success: e => {
- if (e.errMsg == "saveImageToPhotosAlbum:ok") {
- wx.showToast({
- title: '保存成功!',
- })
- wx.removeStorageSync('cacheImage')
- }
- },
- fail: e => {
- console.log("失败4", e)
- this.setData({
- authModal: true,
- modalText: "文件存储"
- })
- }
- })
- wx.navigateTo({
- url: '/pages/takePhoto/success/success',
- })
- },
- fail: e => {
- console.log("失败33", e)
- }
- })
- } else {
- wx.showToast({
- title: res.msg
- })
- }
- },
- fail: e => {
- console.log("失败2", e)
- }
- })
- } else {
- let {
- userInfo
- } = res.data.result
- let data = {
- ...userInfo
- }
- Object.keys(data).forEach(function (key) {
- wx.setStorageSync(key, data[key])
- })
- this.setData({
- isWxRegister: true,
- agreeModal: false
- })
- }
- } catch (error) {
- console.log(error)
- } finally {
- wx.hideLoading({
- success: (res) => {},
- })
- }
- } else {
- wx.hideLoading({})
- wx.showToast({
- title: '获取手机号失败',
- duration: 5000
- })
- }
- } else {
- wx.showToast({
- title: '请授权以登录',
- icon: "error"
- })
- }
- } catch (error) {
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- type: wx.getStorageSync('type'),
- file: wx.getStorageSync('file'),
- latitude: wx.getStorageSync('latitude'),
- longitude: wx.getStorageSync('longitude')
- })
- },
- onShareAppMessage: function () {
- }
- })
|