Browse Source

更新 移除视频拍摄;新增 水印图片本地保存

wangzhihui 4 years ago
parent
commit
4ffca967f6

+ 3 - 1
miniprogram/app.json

@@ -2,7 +2,9 @@
   "pages": [
     "pages/index/index",
     "pages/takePhoto/takePhoto",
-    "pages/cachePage/cachePage"
+    "pages/cachePage/cachePage",
+    "pages/takePhoto/success/success",
+    "pages/share/share"
   ],
   "window": {
     "backgroundColor": "#F6F6F6",

+ 12 - 0
miniprogram/pages/index/index.js

@@ -1,5 +1,8 @@
 // pages/index/index.js
 import cloudApi from "../../apis/cloudApi"
+import {
+  wxSetSessionKey,
+} from "../../utils/wxUtils"
 import {
   postApi
 } from "../../apis/api"
@@ -39,6 +42,15 @@ Page({
         url: '/pages/takePhoto/takePhoto',
       })
     } else {
+      let session_key = wx.getStorageSync('session_key')
+      let openId = wx.getStorageSync('openId')
+
+      wx.clearStorage({
+        success: (res) => {
+          wx.setStorageSync('session_key', session_key)
+          wx.setStorageSync('openId', openId)
+        },
+      })
 
     }
 

+ 66 - 0
miniprogram/pages/share/share.js

@@ -0,0 +1,66 @@
+// pages/share/share.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
miniprogram/pages/share/share.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 2 - 0
miniprogram/pages/share/share.wxml

@@ -0,0 +1,2 @@
+<!--pages/share/share.wxml-->
+<text>pages/share/share.wxml</text>

+ 1 - 0
miniprogram/pages/share/share.wxss

@@ -0,0 +1 @@
+/* pages/share/share.wxss */

+ 55 - 7
miniprogram/pages/takePhoto/takePhoto.js

@@ -9,13 +9,35 @@ Page({
     phone: "",
     shipName: "",
     shipMmsi: "",
-    locationModal: false
+    authModal: false,
+    modalText: "位置"
   },
   openSetting() {
     this.setData({
-      locationModal: false
+      authModal: false,
+    })
+    wx.openSetting({
+      complete: e => {
+        console.log(e)
+        if (e.authSetting["scope.writePhotosAlbum"]) {
+          if (wx.getStorageSync('cacheImage')) {
+            wx.saveImageToPhotosAlbum({
+              filePath: wx.getStorageSync('cacheImage'),
+              success: e => {
+                wx.showToast({
+                  title: '保存成功!',
+                })
+                wx.removeStorageSync('cacheImage')
+              },
+              complete: e => {
+                console.log(e)
+              }
+            })
+          }
+
+        }
+      }
     })
-    wx.openSetting({})
   },
   takePhoto() {
     wx.getLocation({
@@ -29,7 +51,7 @@ Page({
         wx.setStorageSync('latitude', latitude)
         wx.setStorageSync('longitude', longitude)
         wx.chooseMedia({
-          // sourceType: ["camera", "album"],
+          mediaType: ["image"],
           sourceType: ["camera"],
           success: e => {
             let src = e.tempFiles[0].tempFilePath
@@ -104,9 +126,34 @@ Page({
                       wx.showToast({
                         title: res.msg
                       })
-                      wx.navigateTo({
-                        url: '/pages/takePhoto/success/success',
+                      wx.downloadFile({
+                        url: res.result.viewUrl,
+                        success: 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 => {
+                              this.setData({
+                                authModal: true,
+                                modalText: "文件存储"
+                              })
+                            }
+                          })
+                          wx.navigateTo({
+                            url: '/pages/takePhoto/success/success',
+                          })
+                        }
                       })
+
+
                     } else {
                       wx.showToast({
                         title: res.msg
@@ -132,7 +179,8 @@ Page({
       },
       fail: e => {
         this.setData({
-          locationModal: true
+          authModal: true,
+          modalText: "位置信息"
         })
       }
     })

+ 2 - 2
miniprogram/pages/takePhoto/takePhoto.wxml

@@ -4,9 +4,9 @@
 </view>
 <image class="camera-icon" bindtap="takePhoto" src="{{cameraIcon}}"></image>
 
-<view class="auth-modal" wx:if="{{locationModal}}">
+<view class="auth-modal" wx:if="{{authModal}}">
   <view class="modal">
     <view class="service">为了更好的提供服务</view>
-    <view class="auth-btn" bindtap="openSetting">请授权位置信息</view>
+    <view class="auth-btn" bindtap="openSetting">请授权{{modalText}}</view>
   </view>
 </view>