Commit b1fc2f7d authored by 李超鹏's avatar 李超鹏

Merge remote-tracking branch 'origin/dev-photo-v2' into dev-photo-v2

parents 50a5e668 01df1405
...@@ -97,12 +97,14 @@ ...@@ -97,12 +97,14 @@
signUrl:'', signUrl:'',
jumpLoginStatus:true, jumpLoginStatus:true,
settleRecommend:'' settleRecommend:'',
navHeight:0, //导航栏高度
rpxScreenHeight:0,// 照相视框高度
}, },
onLaunch: function() { onLaunch: function() {
this.getSystemInfo()
this.checkUpdate() this.checkUpdate()
var that=this var that=this
...@@ -122,7 +124,18 @@ ...@@ -122,7 +124,18 @@
}, },
onShow: function() {}, onShow: function() {},
methods: { methods: {
getSystemInfo(){
try {
let a = wx.getSystemInfoSync();
// this.globalData.platform = systemInfo.platform, this.globalData.pixelRatio = a.pixelRatio,
// this.globalData.statusBarHeight = a.statusBarHeight, this.globalData.navHeight = a.statusBarHeight / a.screenWidth * 750 + 90,
// this.globalData.rpxScreenHeight = a.screenHeight / a.screenWidth * 750, this.globalData.screenWidth = a.screenWidth,
// this.globalData.screenHeight = a.screenHeight;
this.globalData.navHeight = a.statusBarHeight / a.screenWidth * 750 + 90
this.globalData.rpxScreenHeight = a.screenHeight / a.screenWidth * 750
} catch (a) {}
},
//检查更新 //检查更新
checkUpdate: function () { checkUpdate: function () {
const updateManager = wx.getUpdateManager() const updateManager = wx.getUpdateManager()
......
...@@ -110,25 +110,29 @@ ...@@ -110,25 +110,29 @@
}, },
{ {
"path": "pages/photo/product", "path": "pages/take/detail",
"style": { "style": {
"navigationBarTitleText": "扳手会工单规范" "navigationBarTitleText": "工单详情"
} }
}, },
{ {
"path": "pages/take/detail", "path": "pages/photo/index",
"style": { "style": {
"navigationBarTitleText": "工单详情" "navigationBarTitleText": "拍照小工具首页"
}
},
{
"path": "pages/photo/product",
"style": {
"navigationBarTitleText": "扳手会工单规范"
} }
}, },
{ {
"path": "pages/photo/try", "path": "pages/photo/take",
"style": { "style": {
"navigationStyle":"custom",
"navigationBarTitleText": "拍照", "navigationBarTitleText": "拍照",
"navigationBarBackgroundColor": "#333333", "navigationBarBackgroundColor": "#333333",
"navigationBarTextStyle": "#FFFFFF", "navigationBarTextStyle": "#FFFFFF",
...@@ -136,8 +140,6 @@ ...@@ -136,8 +140,6 @@
} }
}, },
{ {
"path": "pages/photo/detail", "path": "pages/photo/detail",
"style": { "style": {
...@@ -148,10 +150,6 @@ ...@@ -148,10 +150,6 @@
} }
}, },
{ {
"path": "pages/photo/preview", "path": "pages/photo/preview",
"style": { "style": {
...@@ -177,17 +175,6 @@ ...@@ -177,17 +175,6 @@
"navigationBarTitleText": "扳手会工单规范" "navigationBarTitleText": "扳手会工单规范"
} }
}, },
{
"path": "pages/photo/take",
"style": {
"navigationBarTitleText": "拍照-ljd",
"disableScroll": true
}
},
{ {
"path": "pages/index/success", "path": "pages/index/success",
"style": { "style": {
...@@ -289,7 +276,7 @@ ...@@ -289,7 +276,7 @@
"query": "" //启动参数,在页面的onLoad函数里面得到 "query": "" //启动参数,在页面的onLoad函数里面得到
},{ },{
"name": "拍照小工具", //模式名称 "name": "拍照小工具", //模式名称
"path": "pages/photo/try", //启动页面,必选 "path": "pages/photo/take", //启动页面,必选
"query": "" //启动参数,在页面的onLoad函数里面得到 "query": "" //启动参数,在页面的onLoad函数里面得到
},{ },{
"name": "基本信息", //模式名称 "name": "基本信息", //模式名称
......
<template>
<view class="backView">
<view class="topView">
<view :class="activeTop == ikey ? 'topItemView whiteBackColor' : 'topItemView FAbackColor' " @click="topItemClick(ikey,item)" v-for="(item,ikey) in dataList":key="ikey">
<text class="topActiveItemTitle" v-if="activeTop == ikey">{{item.type}}</text>
<text class="topItemTitle" v-if="activeTop != ikey">{{item.type}}</text>
</view>
</view>
<view class="rightView">
<template
v-for="(item,ikey) in rightList"
>
<view :class="['rightItemView',item.clickable ? 'FAbackColor' : '']" @click="rightItemClick(item,ikey)" :key="ikey">
<view :class=" item.images ? 'rightContentView width_50' : 'rightContentView width_100' ">
<text :class=" item.clickable ? 'gray999Color rightTitle u-m-t-30 u-m-l-30' : 'rightTitle u-m-t-30 u-m-l-30' ">{{item.name}} ({{item.image_count}}张)</text>
<text class="rightContent u-m-t-14 u-m-l-30 u-p-b-30">{{item.describe}}</text>
</view>
<view class="rightImageView" v-if="item.images">
<image class="rightImage" :src="item.images[0]" mode=""></image>
</view>
</view>
</template>
<!--template> </view>
<view>
<cover-view class="{{scale=='4_3'?'nav__scale-4-3':scale=='16_9'?'nav__scale-16-9':'nav__scale-full'}}" style="height:{{navHeight}}rpx;">
<cover-image @click="changeScale" class="nav-scaleIcon" mode="aspectFit" src="/image/{{scale}}_{{iconColor}}.png"></cover-image>
<cover-image @click="changeDevicePosition" class="nav-switchIcon" mode="aspectFit" src="/image/switch_{{iconColor}}.png"></cover-image>
<cover-image @click="changeLight" class="nav-lightIcon" mode="aspectFit" src="/image/light_{{light}}_{{iconColor}}.png"></cover-image>
</cover-view>
<camera binderror="binderror" bindinitdone="bindinitdone" bindstop="bindstop" class="camera" devicePosition="{{devicePosition}}" flash="{{light}}" resolution="high" style="height:{{cameraHeight}}rpx;top:{{scale=='4_3'?navHeight:0}}rpx">
<cover-view class="watermark-box" style="color:{{watermarkFontColor}}; {{watermarkStyle}}">
<cover-view class="watermark-box__item" v-if="{{lonLat}}">经度:{{longitudeValue?longitudeValue:'正在获取...'}}</cover-view>
<cover-view class="watermark-box__item" v-if="{{lonLat}}">纬度:{{latitudeValue?latitudeValue:'正在获取...'}}</cover-view>
<cover-view class="watermark-box__item" v-if="{{address}}">地址:{{addressValue?addressValue:'正在获取...'}}</cover-view>
<cover-view class="watermark-box__item" v-if="{{time}}">时间:{{timeValue?timeValue:'正在获取...'}}</cover-view>
<cover-view class="watermark-box__item" v-if="{{altitude}}">海拔:{{altitudeValue?altitudeValue:'正在获取...'}}</cover-view>
<cover-view class="watermark-box__item" v-if="{{weather}}">天气:{{weatherValue?weatherValue:'正在获取...'}}</cover-view>
<cover-view class="weui-flex" v-if="{{remarkArr.length>0}}">
<cover-view>备注:</cover-view>
<cover-view class="weui-flex__item" style="margin-top:1rpx;">
<cover-view v-for="{{remarkArr}}">{{item}}</cover-view>
</cover-view>
</cover-view>
</cover-view>
<cover-image class="{{direction=='normal'?'logoNormal':direction=='left'?'logoLeft':'logoRight'}}" mode="heightFix" src="{{logo}}" style="opacity:{{1-logoTransparency*5/100}};" v-if="{{logoEnable}}"></cover-image>
<cover-image class="{{direction=='normal'?'liveWatermarkNormal':direction=='left'?'liveWatermarkLeft':'liveWatermarkRight'}}" mode="aspectFit" src="{{liveWatermarkValue}}" v-if="{{liveWatermark}}"></cover-image>
<cover-image class="{{direction=='normal'?'handWritingNormal':direction=='left'?'handWritingLeft':'handWritingRight'}}" mode="aspectFit" src="{{handWriting}}"></cover-image>
</camera>
<cover-view class="camera-photoalbumIconBox {{tempImagePath?'':'1hidden'}}">
<cover-image @click="bindPhotoalbum" class="camera-photoalbumIcon" mode="aspectFill" src="{{tempImagePath}}"></cover-image>
</cover-view>
<cover-image @click="bindTakePhoto" class="camera-takeIcon" id="take" mode="aspectFit" src="/image/take.png"></cover-image>
<cover-image @click="bindSetting" class="camera-settingIcon" mode="aspectFit" src="/image/setting_white.png"></cover-image>
</view> </view>
<canvas class="photoCanvas" id="photoCanvas" style="height:{{canvasHeight}}rpx;width:{{canvasWidth}}rpx;" type="2d"></canvas>
</template> </template>
<script> <script>
export default {
// import mp_dialog from '/miniprogram_npm/weui-miniprogram/dialog/dialog';
// import mp_con from '/miniprogram_npm/weui-miniprogram/icon/icon';
// import mp_form_page from '/miniprogram_npm/weui-miniprogram/form-page/form-page';
// import mp_form from '/miniprogram_npm/weui-miniprogram/form/form';
// import mp_cell from '/miniprogram_npm/weui-miniprogram/cell/cell';
// import mp_cells from '/miniprogram_npm/weui-miniprogram/cells/cells';
// import mp_slideview from '/miniprogram_npm/weui-miniprogram/slideview/slideview';
// import mp_toptips from '/miniprogram_npm/weui-miniprogram/toptips/toptips';
// import mp_actionSheet from '/miniprogram_npm/weui-miniprogram/actionsheet/actionsheet';
// import mp_halfScreenDialog from '/miniprogram_npm/weui-miniprogram/half-screen-dialog/half-screen-dialog';
// import mp_msg from '/miniprogram_npm/weui-miniprogram/msg/msg';
// import color_picker from '/miniprogram_npm/mini-color-picker/color-picker';
// export default {
// components: {
// "mp-dialog":mp_dialog,
// "mp-icon":mp_con,
// "mp-form-page":mp_form_page,
// "mp-form":mp_form,
// "mp-cell":mp_cell,
// "mp-cells":mp_cells,
// "mp-slideview":mp_slideview,
// "mp-toptips":mp_toptips,
// "mp-actionSheet":mp_actionSheet,
// "mp-halfScreenDialog":mp_halfScreenDialog,
// "mp-msg":mp_msg,
// "color-picker":color_picker
// },
data() { data() {
return { return {
navHeight: o.globalData.navHeight, topList:[],
scale: "4_3", topTitle:'',
iconColor: "white", activeTop:0,
devicePosition: "back", leftList:[],
light: "off", rightList:[],
canvasWidth: 750, product:'',
canvasHeight: 1e3, product_code:'',
cameraHeight: 1e3, brand:'',
watermarkStyle: "bottom:20rpx;left:20rpx;", brand_code:'',
direction: "normal", dataList:[],
liveWatermarkValue: "/image/live_mark.png",
baiduLocationTimer: null,
wxLocationTimer: null,
netTimeTimer: null,
localTimeTimer: null,
takePhotoTimer: 0,
originalWeather: !1,
a:'',
t:'',
i:'',
o:'',
n:'',
r:'',
l:'',
s:'',
h:''
} }
}, },
// var a onLoad(e) {
// t = require("../../@babel/runtime/helpers/interopRequireDefault"), getApp().trackPage('照片规范列表页')
// e = t(require("../../@babel/runtime/regenerator")), if(e && e.product){
// i = t(require("../../@babel/runtime/helpers/asyncToGenerator")), this.product = e.product
// o = getApp(), n = wx.getRealtimeLogManager(), }
// r = require("../../libs/bmap-wx.min.js"), l = require("../../utils/util.js"),
// s = !0,
// h = new r.BMapWX({
// ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG"
// });
onLoad: function(a) {
this.listeningDeviceMotion(), this.originalWeather = o.globalData.weather, o.globalData.weather && this.baiduWeather(),
setTimeout(function() {
s = !1;
}, 2e3);
this.initabcde()
},
onReady: function() {},
onShow: function() {
wx.startDeviceMotionListening();
var a = o.globalData.remark, t = this.formatRemark(a);
o.globalData.remarkArr = t, this.setData({
lonLat: o.globalData.lonLat,
address: o.globalData.address,
time: o.globalData.time,
altitude: o.globalData.altitude,
weather: o.globalData.weather,
liveWatermark: o.globalData.liveWatermark,
remarkArr: o.globalData.remarkArr,
handWriting: o.globalData.handWriting,
logoEnable: o.globalData.logoEnable,
logo: o.globalData.logo,
latLonFormat: o.globalData.latLonFormat,
watermarkFont: o.globalData.watermarkFont,
watermarkFontColor: o.globalData.watermarkFontColor,
logoTransparency: o.globalData.logoTransparency
}), (o.globalData.lonLat || o.globalData.altitude) && (this.wxLocation(), wx.startLocationUpdate()),
o.globalData.address && this.baiduLocation(), o.globalData.time && this.netTime(),
o.globalData.weather && this.originalWeather != o.globalData.weather && this.baiduWeather(),
this.initWatermarkBoxHeightAndWidth();
},
onHide: function() {
wx.stopDeviceMotionListening().catch(function(a) {
console.log(a);
}), (o.globalData.lonLat || o.globalData.altitude) && wx.stopLocationUpdate().catch(function(a) {
console.log(a);
}), clearInterval(this.baiduLocationTimer), clearInterval(this.wxLocationTimer),
clearInterval(this.netTimeTimer), clearInterval(this.localTimeTimer);
},
onUnload: function() {
wx.stopDeviceMotionListening();
},
onPullDownRefresh: function() {},
onReachBottom: function() {},
onShareAppMessage: function() {},
bindinitdone: function(a) {},
bindstop: function(a) {},
binderror: function(a) {},
if(e && e.product_code){
methods: { this.product_code = e.product_code
}
initabcde: function() { if(e && e.brand){
var a this.brand = e.brand
t = require("../../@babel/runtime/helpers/interopRequireDefault"), uni.setNavigationBarTitle({
e = t(require("../../@babel/runtime/regenerator")), title: this.brand
i = t(require("../../@babel/runtime/helpers/asyncToGenerator")),
o = getApp(),
n = wx.getRealtimeLogManager(),
r = require("../../libs/bmap-wx.min.js"),
l = require("../../utils/util.js"),
s = !0,
h = new r.BMapWX({
ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG"
}); });
}, }
initWatermarkBoxHeightAndWidth: function() { if(e && e.brand_code){
var a = this; this.brand_code = e.brand_code
wx.nextTick(function() { }
wx.createSelectorQuery().select(".watermark-box").boundingClientRect(function(t) {
a.watermarkBoxHeight = t.height, a.watermarkBoxWidth = t.width, a.changeWatermark();
}).exec();
});
},
listeningDeviceMotion: function() {
var a = this;
wx.onDeviceMotionChange(function(t) {
if ("ios" == o.globalData.platform) {
var e = parseFloat(t.alpha);
a.direction = e > 45 && e < 136 ? "left" : e > 225 && e < 316 ? "right" : "normal";
} else t.gamma < -40 && t.gamma > -130 ? a.direction = "right" : t.gamma > 40 && t.gamma < 130 ? a.direction = "left" : a.direction = "normal";
a.direction != a.lastDirection && (a.setData({
direction: a.direction
}), a.changeCanvas(), a.changeWatermark()), a.lastDirection = a.direction;
});
},
changeCanvas: function() {
var a = this, t = this.direction, e = this.data.canvasWidth, i = this.data.canvasHeight;
"normal" == t ? this.setData({
canvasHeight: Math.max(i, e),
canvasWidth: Math.min(i, e)
}) : this.setData({
canvasHeight: Math.min(i, e),
canvasWidth: Math.max(i, e)
}), wx.createSelectorQuery().select("#photoCanvas").fields({
node: !0,
size: !0
}).exec(function(t) {
a.canvas = t[0].node;
var e = t[0].width, i = t[0].height, n = o.globalData.pixelRatio;
a.canvas.width = e * n, a.canvas.height = i * n, a.canvas.getContext("2d").scale(n, n);
});
},
changeScale: function() {
var a, t = this, e = this.data.scale, i = this.direction, n = this.data.canvasWidth, r = this.data.canvasHeight;
"4_3" == e ? (this.setData({
scale: "16_9",
iconColor: "white",
cameraHeight: 16 / 9 * 750
}), a = 16 / 9 * 750) : "16_9" == e ? (this.setData({
scale: "full",
iconColor: "white",
cameraHeight: o.globalData.rpxScreenHeight
}), a = o.globalData.rpxScreenHeight) : (this.setData({
scale: "4_3",
iconColor: "white",
cameraHeight: 1e3
}), a = 1e3), "normal" == i ? this.setData({
canvasHeight: a,
canvasWidth: Math.min(r, n)
}) : this.setData({
canvasWidth: a,
canvasHeight: Math.min(r, n)
}), wx.nextTick(function() {
t.changeCanvas(), setTimeout(function() {
t.changeWatermark();
}, 500);
});
},
changeWatermark: function() {
var a, t = this.data.direction, e = Math.min(this.watermarkBoxWidth, this.watermarkBoxHeight), i = Math.max(this.watermarkBoxWidth, this.watermarkBoxHeight);
a = "left" == t ? [ "top:" + (20 - 2 * e + 10) + "rpx", "left:20rpx", "transform-origin: left bottom", "transform: rotate(90deg)" ].join(";") : "right" == t ? [ "bottom:" + 2 * i + "rpx", "right:20rpx", "transform-origin: right bottom", "transform: rotate(-90deg)" ].join(";") : [ "bottom:20rpx", "left:20rpx" ].join(";"),
this.setData({
watermarkStyle: a
});
},
formatRemark: function(a) {
for (var t = [], e = 0, i = 15; i < a.length; i += 15) t.push(a.substring(15 * e, i)),
e++;
return a.length % 15 != 0 && t.push(a.substring(15 * e, 15 * e + a.length % 15)),
t;
},
changeDevicePosition: function() {
"back" == this.data.devicePosition ? this.setData({
devicePosition: "front"
}) : this.setData({
devicePosition: "back"
});
},
changeLight: function() {
var a = this.data.light;
"torch" == a ? this.setData({
light: "off"
}) : "off" == a ? this.setData({
light: "on"
}) : "on" == a ? this.setData({
light: "auto"
}) : this.setData({
light: "torch"
});
},
bindPhotoalbum: function(a) {
wx.navigateTo({
url: "/pages/photoalbum/photoalbum?photoPath=" + this.data.tempImagePath
});
},
bindSetting: function() {
wx.navigateTo({
url: "/pages/settings/settings"
});
},
bindTakePhoto: function() {
var a = this;
if (!s && 0 == this.takePhotoTimer) {
this.takePhotoTimer = 1, setTimeout(function() {
a.takePhotoTimer = 0;
}, 1500), this.takePhotoAnimate();
wx.createCameraContext().takePhoto({
quality: "high"
}).then(function(t) {
a.drawPhoto(t.tempImagePath);
}).catch(function(a) {
n.error(a), console.log(a);
});
}
},
drawPhoto: (a = (0, i.default)(e.default.mark(function a(t) {
var i, n, r, l, s, h, c, g, u, d, m = this;
return e.default.wrap(function(a) {
for (;;) switch (a.prev = a.next) {
case 0:
return i = this.canvas.getContext("2d"), n = o.globalData.screenHeight / o.globalData.rpxScreenHeight,
r = this.data.canvasWidth * n, l = this.data.canvasHeight * n, a.next = 6, new Promise(function(a) {
var e = m.canvas.createImage();
e.onload = function() {
var t = r, o = l, n = m.data.direction;
"left" == n ? (i.translate(0, o), i.rotate(-Math.PI / 2), i.drawImage(e, 0, 0, o, t),
i.rotate(Math.PI / 2), i.translate(0, -o)) : "right" == n ? (i.translate(t, 0),
i.rotate(Math.PI / 2), i.drawImage(e, 0, 0, o, t), i.rotate(-Math.PI / 2), i.translate(-t, 0)) : i.drawImage(e, 0, 0, t, o),
console.log("已画照片"), a("已画照片");
}, e.onerror = function() {
console.log("照片加载失败"), a();
}, e.src = t;
});
case 6: this.topTitle = this.product + '-' + this.brand
if (!this.data.liveWatermark || !this.data.liveWatermarkValue || "" == this.data.liveWatermarkValue) { this.getListData()
a.next = 9;
break;
}
return a.next = 9, new Promise(function(a) {
var t = m.canvas.createImage();
t.onload = function() {
var e = 360 * n, o = 90 * n, s = r / 2 - e / 2, h = l / 2 - o / 2;
i.drawImage(t, s, h, e, o), console.log("已画现场水印"), a("已画现场水印");
}, t.onerror = function() {
console.log("现场水印加载失败"), a();
}, t.src = m.data.liveWatermarkValue;
});
case 9:
if (!this.data.handWriting || "" == this.data.handWriting) {
a.next = 12;
break;
}
return a.next = 12, new Promise(function(a) {
var t = m.canvas.createImage();
t.onload = function() {
var e = 150 * n, o = 150 * n, s = r - e - 10, h = l - 10;
i.translate(s, h), i.rotate(-Math.PI / 2), i.drawImage(t, 0, 0, e, o), i.rotate(Math.PI / 2),
i.translate(-s, -h), console.log("已画手写签名水印"), a("已画手写签名水印");
}, t.onerror = function() {
console.log("手写签名水印加载失败"), a();
}, t.src = m.data.handWriting;
});
case 12:
if (!this.data.logoEnable || !this.data.logo || "" == this.data.logo) {
a.next = 16;
break;
}
return console.log("画水印LOGO"), a.next = 16, new Promise(function(a) {
var t = m.canvas.createImage();
t.onload = function() {
var e = 150 * n, l = 150 * n, s = r - e - 10, h = 1 - 5 * o.globalData.logoTransparency / 100;
i.globalAlpha = h, i.drawImage(t, s, 10, e, l), i.globalAlpha = 1, console.log("已画水印LOGO"),
a("已画水印LOGO");
}, t.onerror = function() {
console.log("水印LOGO加载失败"), a();
}, t.src = m.data.logo;
});
case 16: },
if (console.log("画水印信息"), i.font = "14px", i.fillStyle = this.data.watermarkFontColor,
s = l - 14, h = 0, (c = this.data.remarkArr) && c.length > 0) { onShow() {
for (g = c.length - 1; g >= 1; g--) u = c[g], i.fillText(u, 52, s - 18 * h++); console.log('onShow 里的rightList:')
d = c[0], i.fillText("备注:" + d, 10, s - 18 * h++); console.log(this.rightList)
} },
this.data.weather && this.data.weatherValue && i.fillText("天气:" + this.data.weatherValue, 10, s - 18 * h++),
this.data.altitude && this.data.altitudeValue && i.fillText("海拔:" + this.data.altitudeValue, 10, s - 18 * h++), methods: {
this.data.time && this.data.timeValue && i.fillText("时间:" + this.data.timeValue, 10, s - 18 * h++),
this.data.address && this.data.addressValue && i.fillText("地址:" + this.data.addressValue, 10, s - 18 * h++),
this.data.lonLat && this.data.latitudeValue && this.data.longitudeValue && (i.fillText("纬度:" + this.data.latitudeValue, 10, s - 18 * h++),
i.fillText("经度:" + this.data.longitudeValue, 10, s - 18 * h++)), this.savaToTempFile();
case 31: getListData: function (){
case "end":
return a.stop(); console.log('getListData:')
} console.log('product_code' + this.product_code)
}, a, this); console.log('brand_code' + this.brand_code)
})), function(t) {
return a.apply(this, arguments); let that = this
}),
savaToTempFile: function() { this.$u.cloudApi.getGroupStandard({product_code:this.product_code,brand_code:this.brand_code}).then(res =>{
var a = this; console.log('获取规范标准数据:')
wx.canvasToTempFilePath({ console.log(res)
canvas: this.canvas if(res.result && res.result.length){
}).then(function(t) { that.handleData(res)
console.log(t), a.setData({ }
tempImagePath: t.tempFilePath })
}), a.saveToPhotosAlbum(t.tempFilePath);
}).catch(function(a) { },
n.error(a), console.log(a);
}); handleData: function (res){
},
saveToPhotosAlbum: function(a) { this.dataList = res.result
wx.getSetting({
success: function(t) { this.dataList.forEach(item => {
t.authSetting["scope.writePhotosAlbum"] ? wx.saveImageToPhotosAlbum({
filePath: a item.list.forEach(subItem => {
}) : wx.authorize({ subItem.isClicked = false
scope: "scope.writePhotosAlbum", })
success: function() {
wx.saveImageToPhotosAlbum({ })
filePath: a
}); console.log('添加 新字段 后的数组:')
}, console.log(this.dataList)
fail: function() {
n.error("已拒绝保存照片到本地相册授权"), console.log("已拒绝保存照片到本地相册授权"); var item = res.result[0]
} this.rightList = item.list
}); },
}
});
},
takePhotoAnimate: function() {
this.animate("#take", [ {
scale: [ 1, 1 ]
}, {
scale: [ .95, .95 ]
}, {
scale: [ 1, 1 ]
} ], 300, function() {
this.clearAnimation("#take");
}.bind(this));
},
baiduWeather: function() {
var a = this;
h.weather({
success: function(t) {
var e = t.currentWeather[0];
console.log("当前天气", e);
var i = e.temperature + " " + e.weatherDesc + " " + e.wind;
a.setData({
weatherValue: i
}), a.initWatermarkBoxHeightAndWidth();
},
fail: function(a) {
n.error(a), console.log(a);
}
});
},
baiduLocation: function() {
var a = this, t = function() {
var t = {
success: function(t) {
var e = t.wxMarkerData[0];
console.log("当前定位", e);
var i = e.address;
a.setData({
addressValue: i
}), o.globalData.addressValue = i, a.initWatermarkBoxHeightAndWidth();
},
fail: function(a) {
n.error(a), console.log(a);
}
};
if ((o.globalData.lonLat || o.globalData.altitude) && a.latitude && a.longitude) {
var e = a.latitude + "," + a.longitude;
t.location = e;
}
h.regeocoding(t);
};
t(), clearInterval(this.baiduLocationTimer), this.baiduLocationTimer = setInterval(t, 6e4);
},
wxLocation: function() {
var a = this;
wx.onLocationChange(function(t) {
a.latitude = t.latitude, a.longitude = t.longitude;
var e = l.formatLonLat(t.latitude, o.globalData.latLonFormat), i = l.formatLonLat(t.longitude, o.globalData.latLonFormat), n = "0米";
t.altitude && (n = t.altitude.toFixed(2) + "米"), a.setData({
latitudeValue: e,
longitudeValue: i,
altitudeValue: n
}), o.globalData.latitudeValue = e, o.globalData.longitudeValue = i, o.globalData.altitudeValue = n;
});
},
netTime: function() {
var a = this, t = function() {
wx.request({
url: "https://www.baidu.com",
success: function(t) {
var e = new Date(t.header.Date);
o.globalData.timestampValue = e.getTime();
var i = l.formatTime(e);
a.setData({
timeValue: i
}), o.globalData.timeValue = i, a.initWatermarkBoxHeightAndWidth();
}
});
};
t(), clearInterval(this.netTimeTimer), clearInterval(this.localTimeTimer), this.netTimeTimer = setInterval(t, 6e4),
this.localTimeTimer = setInterval(function() {
if (o.globalData.timestampValue) {
o.globalData.timestampValue += 1e3;
var t = l.formatTime(new Date(o.globalData.timestampValue));
a.setData({
timeValue: t
}), o.globalData.timeValue = t;
}
}, 1e3);
}
//顶部点击
topItemClick: function (ikey,item) {
this.activeTop = ikey
this.rightList = item.list
uni.pageScrollTo({scrollTop: 0, duration: 0});
},
//右侧点击
rightItemClick: function (item,ikey) {
// for (let i = 0; i < this.rightList.length; i++) {
// var subItem = this.rightList[i]
// if(i == ikey){
// subItem.isClicked = true
// }
// }
// item.clickable = true
this.$set(this.rightList[ikey],'clickable',true)
var current_image = item.images[0]
var current_count = 1
uni.navigateTo({
url:'/pages/photo/detail'
+'?current_image=' + current_image
+'&image_count=' + item.image_count
+'&current_count=' + current_count
+'&images=' + JSON.stringify(item.images)
+'&title=' + item.name,
})
},
} }
...@@ -513,215 +150,162 @@ ...@@ -513,215 +150,162 @@
</script> </script>
<style> <style>
.hidden { .backView{
display: none; background-color: #FAFAFA;
} position: absolute;
top: 0;
.camera { left: 0;
width: 100%; width: 100%;
height: 100vh; display: flex;
z-index: 1; flex-direction: column;
position: absolute; align-items: center;
} }
.nav__scale-4-3 { .topTitle{
background-color: #000; margin-top: 80rpx;
} font-size: 32rpx;
.nav__scale-4-3,.nav__scale-16-9 {
z-index: 5;
position: fixed;
top: 0;
left: 0;
right: 0;
} }
.nav__scale-16-9 { .centerBackView{
background-color: transparent; display: flex;
flex-direction: row;
margin-top: 80rpx;
width: 100%;
} }
.nav__scale-full { .leftView{
z-index: 5; background-color: #FFFFFF;
position: fixed; width: 20%;
top: 0; display: flex;
left: 0; flex-direction: column;
right: 0;
} }
.nav-scaleIcon { .leftItemView{
left: 5rpx; display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 80rpx;
border-bottom: 2rpx solid #F3F3F3;
} }
.nav-scaleIcon,.nav-switchIcon { .leftItemText{
z-index: 5; font-size: 28rpx;
width: 50rpx;
height: 50rpx;
position: absolute;
bottom: 0;
margin: 20rpx;
} }
.nav-switchIcon { .rightView{
left: 120rpx; background-color: #FFFFFF;
width: 100%;
display: flex;
flex-direction: column;
margin-top: 96rpx;
} }
.nav-lightIcon { .rightItemView{
left: 220rpx; width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
border-bottom: 20rpx solid #F3F3F3;
} }
.nav-lightIcon,.nav-moreIcon { .rightContentView{
z-index: 5; display: flex;
width: 50rpx; flex-direction: column;
height: 50rpx; border-left: 2rpx solid #F3F3F3;
position: absolute;
bottom: 0;
margin: 20rpx;
} }
.nav-moreIcon { .rightActiveContentView{
left: 320rpx; background-color: #4CD964;
display: flex;
flex-direction: column;
border-left: 2rpx solid #F3F3F3;
} }
.camera-photoalbumIconBox {
z-index: 5;
width: 80rpx;
height: 80rpx;
position: absolute;
bottom: 60rpx;
left: 25%;
margin-left: -80rpx;
background-color: hsla(0,0%,100%,0);
border: 1rpx solid #fff;
border-radius: 50%;
}
.camera-photoalbumIcon { .width_50{
z-index: 5; width: 480rpx;
} }
.camera-takeIcon { .width_100{
z-index: 5; width: 100%;
width: 150rpx;
height: 150rpx;
position: absolute;
bottom: 25rpx;
left: 50%;
margin-left: -75rpx;
} }
.camera-settingIcon { .rightTitle{
z-index: 5; font-size: 32rpx;
width: 80rpx; color: #4D87EA;
height: 80rpx;
position: absolute;
bottom: 60rpx;
left: 75%;
} }
.photoCanvas { .rightContent{
z-index: -1; font-size: 28rpx;
position: absolute; color: #333333;
left: 9999px; line-height: 40rpx;
} }
.watermark-box { .rightImageView{
z-index: 4; width: 300rpx;
position: absolute; height: 320rpx;
font-size: 14px; display: flex;
line-height: 18px; align-items: center;
color: #fff; justify-content: center;
} }
.watermark-box__item { .rightImage{
margin: 2px 0; background-color: #F3F3F3;
width: 240rpx;
height: 240rpx;
} }
.liveWatermarkNormal {
z-index: 3;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 360rpx;
height: 90rpx;
z-index: 6;
}
.liveWatermarkRight { .topView{
transform-origin: 50% 50%; background-color: #FAFAFA;
transform: rotate(-90deg); width: 100%;
height: 96rpx;
position: fixed;
display: flex;
flex-direction: row;
} }
.liveWatermarkLeft,.liveWatermarkRight { .topItemView{
z-index: 3; width: 210rpx;
position: absolute; height: 96rpx;
left: 25%; display: flex;
top: calc(50% - 45rpx); align-items: center;
width: 360rpx; justify-content: center;
height: 90rpx;
z-index: 6;
} }
.liveWatermarkLeft { .whiteBackColor{
transform-origin: 50% 50%; background-color: #FFFFFF;
transform: rotate(90deg);
} }
.handWritingNormal { .FAbackColor{
transform-origin: 50% 50%; background-color: #FAFAFA;
transform: rotate(-90deg);
right: 20rpx;
} }
.handWritingLeft,.handWritingNormal { .topItemTitle{
z-index: 3; font-size: 32rpx;
position: absolute; color: #999999;
width: 150rpx; padding-left: 30rpx;
height: 150rpx;
bottom: 20rpx;
} }
.handWritingLeft {
transform-origin: 50% 50%;
left: 20rpx;
}
.handWritingRight { .topActiveItemTitle{
transform-origin: 50% 50%; font-size: 32rpx;
transform: rotate(180deg); font-weight: bold;
color: #333333;
padding-left: 30rpx;
} }
.handWritingRight,.logoNormal { .greenBackColor{
z-index: 3; background-color: #4CD964;
position: absolute;
width: 150rpx;
height: 150rpx;
top: 20rpx;
right: 20rpx;
} }
.logoNormal { .gray999Color{
transform-origin: 50% 50%; color: #999999;
} }
.logoLeft {
transform-origin: 50% 50%;
transform: rotate(90deg);
bottom: 20rpx;
right: 20rpx;
}
.logoLeft,.logoRight {
z-index: 3;
position: absolute;
width: 150rpx;
height: 150rpx;
}
.logoRight {
transform-origin: 50% 50%;
transform: rotate(-90deg);
top: 20rpx;
left: 20rpx;
}
</style> </style>
<template> <template>
<view class="container"> <view class="camera-container">
<camera device-position="back" flash="off" style='width:100%; height:100vh;'> <cover-view class="header-box" :style="{'height':navHeight + 'rpx'}">
<cover-view class="locationView"> <cover-view class="inner">
<cover-view class="locationText u-m-l-20 u-m-t-30">{{longitude}}</cover-view> <cover-image bindtap="changeScale" class="icon" mode="aspectFit" src="/static/photo/icon-switch.png"></cover-image>
<cover-view class="locationText u-m-l-20 u-m-t-10">{{latitude}}</cover-view> <cover-image bindtap="changeScale" class="icon" mode="aspectFit" src="/static/photo/icon-light.png"></cover-image>
<cover-view class="locationText u-m-l-20 u-m-t-10">{{address}}</cover-view> <cover-image bindtap="changeScale" class="icon" mode="aspectFit" src="/static/photo/icon-setting.png"></cover-image>
<cover-view class="locationText u-m-l-20 u-m-t-10">{{date}}</cover-view>
</cover-view> </cover-view>
<cover-image class="liveWatermarkNormal" mode="aspectFit" :src="liveWaterMarkImage"></cover-image> </cover-view>
<camera class="camera-box" v-if="cameraChange" device-position="front" flash="on" :style="{'height':cameraHeight + 'rpx'}"
@error="cameraError">
<cover-view class="mark-box">
<cover-view class="txt u-m-l-20 u-m-t-30">经度:{{waterInfo.longitude || '正在获取中...'}}</cover-view>
<cover-view class="txt u-m-l-20 u-m-t-10">维度:{{waterInfo.latitude || '正在获取中...'}}</cover-view>
<cover-view class="txt u-m-l-20 u-m-t-10">地址:{{waterInfo.address || '正在获取中...'}}</cover-view>
<cover-view class="txt u-m-l-20 u-m-t-10">时间:{{waterInfo.date || '正在获取中...'}}</cover-view>
</cover-view>
<cover-image class="mark-water liveWatermarkNormal" mode="aspectFit" :src="waterInfo.markImage"></cover-image>
</camera> </camera>
<cover-view class="bottomView"> <cover-view class="bottom-box">
<!--cover-image class='switchIcon' :src='icon_switch_white' @click="switchClick()"> </cover-image--> <cover-image class="icon" :src="icon_arrow_down" mode="" @click="simpleBack"></cover-image>
<cover-image class='takeIcon' :src='icon_take' @click="takePhoto()"> </cover-image> <cover-image class='icon-take icon' src='/static/photo/icon-take.png' @click="takePhoto"> </cover-image>
<cover-image class="backIcon" :src="icon_arrow_down" mode="" @click="backClick"></cover-image> <cover-view class="txt">拍照要求</cover-view>
<!--cover-image class='flashIcon' :src='icon_light_on_white' @click="flashClick()"> </cover-image-->
</cover-view> </cover-view>
<canvas class="showCanvas" canvas-id="photoCanvas" id="photoCanvas" :style="{width:canvas.sWidth + 'px',height:canvas.sHeight+ 'px'}"></canvas> <canvas v-show='showImage' canvas-id="canvas" :style="{'width':750 + 'rpx','height': cameraHeight + 'rpx'}"></canvas>
</view> </view>
</template> </template>
<script> <script>
let r = require("../../libs/bmap-wx.min.js");
let h = new r.BMapWX({
// ak: "rpVq5d3yxaRCoKzVwmFMo0o4iC524CAG",
ak: "lF1HoyXdiv4uZx6TrGQEZs48F5y8kEHI"
});
export default { export default {
data() { data() {
return { return {
...@@ -34,46 +42,208 @@ ...@@ -34,46 +42,208 @@
image: "", image: "",
showImage: false, showImage: false,
canvas: null, canvas: null,
longitude: '经度:正在获取中...',
latitude: '纬度:正在获取中...', longitude: '正在获取中...',
address: '地址:正在获取中...', latitude: '正在获取中...',
date: '时间:正在获取中...', address: '正在获取中...',
icon_location: 'https://qn-static.banshouhui.com/take_order/icon/location.png', date: '',
scale: "4_3", // icon_location: 'https://qn-static.banshouhui.com/take_order/icon/location.png',
icon_take: 'https://qn-static.banshouhui.com/take.png', // scale: "4_3",
icon_switch_white: 'https://qn-static.banshouhui.com/switch_white.png', // icon_take: 'https://qn-static.banshouhui.com/take.png',
icon_light_on_white: 'https://qn-static.banshouhui.com/light_on_white.png', // icon_switch_white: 'https://qn-static.banshouhui.com/switch_white.png',
liveWaterMarkImage: require('@/static/live_mark.png'), // icon_light_on_white: 'https://qn-static.banshouhui.com/light_on_white.png',
icon_arrow_down: 'https://qn-static.banshouhui.com/arrow_down.png', // liveWaterMarkImage: '/static/live_mark.png',
icon_live_mark: 'https://qn-static.banshouhui.com/live_mark.png', // icon_arrow_down: 'https://qn-static.banshouhui.com/arrow_down.png',
canvas: { // icon_live_mark: 'https://qn-static.banshouhui.com/live_mark.png',
ctx: null, width: '',
sWidth: 750, height: '',
sHeight: 0, markPath: '',
canvasWidth: 0,
canvasHeight: 0,
restuleImage: '',
waterInfo: {
longitude: '', // 经度
latitude: '', // 维度
address: '', //地址
date: '', //日期
markImage:'/static/live_mark.png'
},
authSetting: {
camera: false, // 相机授权
location: false, // 位置授权
}, },
waterMarkerTemp:'' navHeight: 0,
cameraHeight: 1000, // (4 / 3 * 750) 图片比例4:3
cameraChange: true,
} }
}, },
onLoad(e) { onLoad(e) {
getApp().trackPage('拍照页') getApp().trackPage('拍照页')
this.ctx = uni.createCameraContext(); this.ctx = uni.createCameraContext();
this.date = '时间:' + this.getTime() this.date = this.getTime()
this.getLocation() this.getLocation()
this.getMarkPath()
this.getSystemInfo() this.getSystemInfo()
uni.setNavigationBarColor({ uni.setNavigationBarColor({
frontColor: '#FFFFFF', frontColor: '#FFFFFF',
backgroundColor: '#333333', backgroundColor: '#333333',
}) })
this.downloadImageH5(this.liveWaterMarkImage)
//this.address = '' //this.address = ''
}, },
compute: {},
watch: {
'authSetting.camera'(val) {
if (val) {
// this.cameraChange = true
}
}
},
onShow() {
this.initData()
// this.cameraHeight = globalData.rpxScreenHeight
// uni.authorize({
// scope: 'scope.writePhotosAlbum',
// success() {
// console.log('userLocation')
// // uni.getLocation()
// }
// })
},
methods: { methods: {
initData() {
const globalData = getApp().globalData
this.navHeight = globalData.navHeight
// this.cameraHeight = globalData.rpxScreenHeight
},
baiduLocation() {
// 百度sdk解析经纬度
let a = this,
t = function() {
let t = {
success: function(res) {
let e = res.wxMarkerData[0];
let i = e.address;
a.address = i
},
fail: function(a) {
console.log(a, 'a')
}
};
if (a.latitude && a.longitude) {
let e = a.latitude + "," + a.longitude;
t.location = e;
}
h.regeocoding(t);
};
t()
},
cameraError: function(e) {
const {
errMsg
} = e.detail
console.log(e.detail, 'e.detail')
if (errMsg !== 'insertCamera:fail auth deny') {
return
}
this.showSettingModal('camera')
},
//获取位置
getLocation() {
let that = this
uni.getLocation({
type: 'gcj02',
success: function(res) {
console.log(res, 'res')
that.longitude = parseFloat(res.longitude).toFixed(4)
that.latitude = parseFloat(res.latitude).toFixed(3)
console.log(that.longitude, 'that.longitude', that.latitude, 'that.latitude')
that.baiduLocation()
},
fail(err) {
console.log('err-location', 'err')
that.showSettingModal('location')
// that.showLocationAuthModal('')
}
});
},
showSettingModal(type) {
console.log(type, 'showModal-type')
type = type || 'camera'
const self = this
let authSetting = {
'camera': {
content: '将无法进行拍照',
method: ''
},
'location': {
content: '将无法定位当前位置',
method: ''
},
'writePhotosAlbum': {
content: '将无法保存图片到本地',
method: ''
}
}
let content = authSetting[type].content
uni.showModal({
content: '拒绝授权' + content + ',是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success(res) {
if (res.confirm) {
self.openSetting()
}
},
fail() {}
})
},
openSetting() {
// 打开设置
let self = this
this.cameraChange = false
wx.openSetting({
success(res) {
console.log(res, 'res-setting')
const authSetting = res.authSetting
if (authSetting['scope.userLocation']) {
// 位置授权成功
self.authSetting.location = true
self.getLocation()
}
if (res.authSetting['scope.camera']) {
this.cameraChange = true
self.authSetting.camera = true
}
if (res.authSetting['scope.writePhotosAlbum']) {
self.authSetting.writePhotosAlbum = true
}
//切换前后 }
switchClick() { })
}, },
goBack() {
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2]; //上一个页面
prevPage.$vm.done_count++;
uni.navigateBack({
//delta: 2
});
},
getSystemInfo() {
// 获取设备信息
try {
const res = uni.getSystemInfoSync();
this.canvasWidth = res.windowWidth * 2
this.canvasHeight = res.windowHeight * 2
} catch (e) {
// error
}
},
//返回 点击 //返回 点击
backClick: function() { backClick: function() {
uni.navigateBack({ uni.navigateBack({
...@@ -81,99 +251,248 @@ ...@@ -81,99 +251,248 @@
}) })
}, },
//获取位置
getLocation() {
//定位 再次授权弹窗
showLocationAuthModal: function() {
let that = this let that = this
uni.getLocation({ uni.showModal({
type: 'wgs84', content: '拒绝授权将无法定位当前位置,是否去设置打开?',
success: function(res) { confirmText: "确认",
that.longitude = '经度:' + res.longitude cancelText: '取消',
that.latitude = '纬度:' + res.latitude success(res) {
console.log('当前位置的经度:' + res.longitude); if (res.confirm) {
console.log('当前位置的纬度:' + res.latitude);
console.log('当前位置的地址:' + res.address); that.openLocationSetting()
}
if (res.cancel) {
uni.navigateBack({
})
}
},
fail() {
console.log('')
} }
})
},
//定位设置界面
// openLocationSetting() {
// let that = this
// wx.openSetting({
// success(res) {
// console.log(res, 'openSetting.res')
// console.log(res.authSetting, 'openSetting.res.authSetting')
// console.log(res.authSetting['scope.camera'], 'openSetting.res.authSetting.scope.camera')
// console.log(res.authSetting['scope.userLocation'], 'openSetting.res.authSetting.scope.userLocation')
// if( res.authSetting['scope.userLocation'] && res.authSetting['scope.userLocation'] == true){
// console.log('33333location reload page')
// that.getLocation()
// }else{
// that.showLocationAuthModal()
// console.log('444444')
// }
// }
// })
// },
//刷新当前页
reloadPage: function() {
uni.redirectTo({
url: '/pages/photo/try'
}); });
}, },
//拍照 //获取 水印 本地缓存路径
getMarkPath: function() {
let that = this
uni.downloadFile({
url: this.icon_live_mark, //仅为示例,并非真实的资源
success: (res) => {
if (res.statusCode === 200) {
that.markPath = res.tempFilePath
}
},
fail() {
// console.log('水印图片 下载失败')
}
})
},
callback(res) {
console.log(res, 'res-callback')
},
//相机设置界面
openCameraSetting() {
let that = this
wx.openSetting({
success(res) {
console.log(res, 'openSetting.res')
console.log(res.authSetting, 'openSetting.res.authSetting')
console.log(res.authSetting['scope.camera'], 'openSetting.res.authSetting.scope.camera')
console.log(res.authSetting['scope.userInfo'], 'openSetting.res.authSetting.scope.userInfo')
if (res.authSetting['scope.camera'] && res.authSetting['scope.camera'] == true) {
that.reloadPage()
} else {
that.showCameraAuthModal()
}
}
})
},
//相机 再次授权弹窗
showCameraAuthModal: function() {
let that = this
uni.showModal({
content: '拒绝授权将无法拍照,是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success(res) {
if (res.confirm) {
that.openCameraSetting()
}
if (res.cancel) {
uni.navigateBack({
})
}
},
fail() {
console.log('')
}
})
},
//相机拒绝授权
cameraRefuse: function() {
console.log('相机拒绝授权')
this.showCameraAuthModal()
},
//第一步: 拍照
takePhoto() { takePhoto() {
console.log((new Date).getTime(), '开始渲染')
this.ctx.takePhoto({ this.ctx.takePhoto({
quality: 'high', quality: 'high',
success: (res) => { success: (res) => {
console.log('拍照成功')
console.log(res) console.log(res)
this.imageChange(res) //this.imageChange(res)
//this.getImageInfo(res.tempImagePath) this.getImageInfo(res.tempImagePath)
//this.saveToLocal(res.tempImagePath) //this.saveToLocal(res.tempImagePath)
} }
}); });
}, },
//获取图片信息
//第二步: 获取图片信息
getImageInfo(tempImagePath) { getImageInfo(tempImagePath) {
let that = this let that = this
uni.getImageInfo({ uni.getImageInfo({
src: tempImagePath, src: tempImagePath,
success(res) { success(res) {
//that.saveToLocal(res.) that.width = res.width + 'px';
that.height = res.height + 'px';
that.drawCanvas(tempImagePath, res)
} }
}) })
}, },
//保存到本地相册 //第三步: 绘制画布
saveToLocal(tempImagePath) { drawCanvas: function(tempImagePath, res) {
uni.saveImageToPhotosAlbum({ uni.showLoading({
filePath: tempImagePath, title: '数据处理中...',
success() { icon: 'loading'
console.log('保存本地相册 成功')
},
fail() {
console.log('保存本地相册 失败')
}
}) })
}, let canvasWidth = this.canvasWidth
getSystemInfo() { let canvasHeight = this.canvasHeight
// 获取设备信息 this.showImage = true
try { //将原图画到canvas上面
const res = uni.getSystemInfoSync(); this.canvas = uni.createCanvasContext("canvas", this)
this.canvas.sWidth = res.windowWidth this.canvas.rect(0, 0, canvasWidth, canvasHeight)
this.canvas.sHeight = res.windowHeight this.canvas.drawImage(tempImagePath, 0, 0, canvasWidth, canvasHeight)
console.log(res.windowWidth, 'res.windowWidth', res.windowHeight, 'res.windowHeight') // this.canvas.draw()
} catch (e) {
// error //加入 水印文字
} this.canvas.setFontSize(28)
}, this.canvas.setFillStyle('#f2f2f2')
let h = 1
downloadImageH5(image) { let txtHeight = 36
let self = this
console.log('downloadImageH5',image) this.canvas.fillText('经度: ' + this.longitude, 20, canvasHeight - txtHeight * h++);
// 图片下载本地 this.canvas.fillText('维度: ' + this.latitude, 20, canvasHeight - txtHeight * h++);
uni.downloadFile({ this.canvas.fillText('地址: ' + this.address, 20, canvasHeight - txtHeight * h++);
url: image, //仅为示例,并非真实的资源 this.canvas.fillText('时间: ' + this.date, 20, canvasHeight - txtHeight * h++);
success: (res) => { //加入 水印图片
console.log(res,'res-水印图片') this.canvas.drawImage(this.markPath, canvasWidth / 2 - 200, canvasHeight / 2 - 50, 400, 100)
if (res.statusCode === 200) {
self.waterMarkerTemp = res.tempFilePath this.canvasImage()
} // this.canvas.draw()
}
}); // uni.showLoading({
// title: '数据处理中...',
// icon: 'loading'
// })
// this.exportCanvasTempFilePath(res.width,res.height)
}, },
canvasImage() { canvasImage() {
let self = this let self = this
this.canvas.ctx.draw(false, setTimeout(() => { this.canvas.draw(false,
setTimeout(() => { setTimeout(() => {
console.log((new Date).getTime(), '结束渲染')
uni.canvasToTempFilePath({ uni.canvasToTempFilePath({
x: 0, // x: 0,
y: 0, // y: 0,
width: Number(this.canvas.sWidth), width: Number(this.canvasWidth),
height: Number(this.canvas.sHeight), height: Number(this.canvasHeight),
canvasId: 'photoCanvas', canvasId: 'canvas',
success: (res) => { success: (res) => {
self.saveToLocal(res.tempFilePath)
const FileSystemManager = wx.getFileSystemManager()
FileSystemManager.saveFile({
tempFilePath: res.tempFilePath,
success(res) {
console.log(res, 'res-saveFile')
}
})
// this.$emit('canvasImage', res.tempFilePath); // this.$emit('canvasImage', res.tempFilePath);
// if (this.showPreview) { // if (this.showPreview) {
self.showPreviewFn(res.tempFilePath); // this.restultImage = res.tempFilePath
// self.showPreviewFn(res.tempFilePath);
// } // }
}, },
fail: (res) => { fail: (res) => {
...@@ -183,151 +502,159 @@ ...@@ -183,151 +502,159 @@
uni.hideLoading(); uni.hideLoading();
} }
}, this); }, this);
}, 500); }, 500));
}));
}, },
showPreviewFn (img) { showPreviewFn(img) {
uni.previewImage({ uni.previewImage({
current: 0, current: 0,
urls: [img] urls: [img]
}); });
}, },
//照片处理 //第五步: 保存到本地相册
imageChange(options) { saveToLocal(tempImagePath) {
let self = this let that = this
// let ctx = uni.createCanvasContext("photoCanvas") // canvas绘制对象 uni.saveImageToPhotosAlbum({
let ctx = uni.createCanvasContext('photoCanvas', this); filePath: tempImagePath,
let sWidth = this.canvas.sWidth //绘图宽度 success() {
let sHeight = this.canvas.sHeight // 绘图高度 uni.showToast({
this.canvas.ctx = ctx icon: 'none',
ctx.setStrokeStyle("#00ff00") title: '已将照片保存到本地相册'
ctx.setLineWidth(5) })
ctx.rect(0, 0, sWidth, sHeight) let timer = setTimeout(() => {
ctx.drawImage(options.tempImagePath, 0, 0, sWidth, sHeight) that.goBack()
ctx.setFontSize(20) }, 1500)
ctx.fillText('Hello', 20, 20)
ctx.fillText('MINA', 100, 100)
// if(this.waterMarkerTemp){
// ctx.drawImage(this.waterMarkerTemp, sWidth/2 - 100, sHeight/2 - 20, 200, 40)
// }
ctx.drawImage(options.tempImagePath, sWidth/2 - 100, sHeight/2 - 20, 200, 40);
self.canvasImage()
// self.path = options.tempImagePath
return
// uni.getImageInfo({
// src: that.path,
// success: function(res) {
// }
// })
var that = this
//原图片信息
var _width = options.width
var _height = options.height
that.path = options.tempImagePath
console.log('原照片信息')
console.log('宽:' + options.width)
console.log('高:' + options.height)
console.log('路径:' + options.tempImagePath)
//需要的图片信息
var image_x = parseInt(_width * 0.1);
var image_y = parseInt(_height * 0.09);
var image_width = parseInt(_width * 0.8);
var image_height = parseInt(_height * 0.87);
console.log('需要的图片信息')
console.log('x:' + image_x)
console.log('y:' + image_y)
console.log('宽:' + image_width)
console.log('高:' + image_height)
},
fail() {
// console.log('保存本地相册 失败')
///*
uni.showToast({
icon: 'none',
title: '保存本地相册失败'
})
uni.setStorage({
key: 'photo_tempPath',
data: tempImagePath,
success: function() {
console.log('tempImagePath save success');
let timer = setTimeout(() => {
that.showAlbumAuthModal()
}, 1500)
}
});
//*/
uni.getImageInfo({
src: that.path,
success: function(res) {
that.showImage = true
//将原图画到canvas上面
that.canvas = uni.createCanvasContext("canvas", that)
//that.canvas.drawImage(that.path, 0, 0, _width, _height)
that.canvas.drawImage(that.path, 0, 0, res.width * 3, res.height * 3)
/* /*
//----------------------------- let txt = '保存本地相册失败'
// let ctx = uni.createCanvasContext('firstCanvas'); // 创建画布
// //将图片src放到cancas内,宽高为图片大小 uni.getSetting({
// ctx.drawImage(res.tempFilePaths[0], 0, 0, ress.width / 3, ress.height / 3) success(res) {
that.canvas.setFontSize(18) let authSetting = res.authSetting
// that.canvas.setFillStyle('#8a2929') if (!authSetting['scope.writePhotosAlbum']) {
// that.canvas.rotate(-Math.PI / 2); txt = '请打开相册权限'
let textToWidth = res.width / 3 * 0.5;
let textToHeight = res.height / 3 * 0.3;
that.canvas.fillText('我是水印', 10, 90)
//. 除了上面的文字水印,这里也可以加入图片水印
// ctx.drawImage('/static/watermark.png', 0, 0, res.width / 3, ress.height / 3)
that.canvas.drawImage('/static/live_mark.png', 0, 0, 200, 200)
//-----------------------------
*/
that.canvas.draw()
uni.showLoading({
title: '数据处理中...',
icon: 'loading',
duration: 10000
})
that.canvas.draw()
setTimeout(function() {
//导出自己需要的图片
uni.canvasToTempFilePath({
canvasId: "canvas",
x: image_x,
y: image_y,
width: image_width,
height: image_height,
destWidth: image_width,
destHeight: image_height,
success: function(ress) {
that.image = ress.tempFilePath //处理好的图片
uni.hideLoading()
console.log('处理图片 成功:')
console.log(ress.tempFilePath)
uni.showToast({
icon: 'none',
title: '处理成功'
})
setTimeout(function() {
that.saveToLocal(ress.tempFilePath)
uni.previewImage({
urls: [ress.tempFilePath],
current: 0
});
// uni.navigateTo({
// url:'/pages/photo/preview'+'?path=' + res.tempFilePath
// })
}, 1000);
//TODO........
},
fail: function(e) {
uni.hideLoading()
uni.showToast({
title: '出错啦...',
icon: 'loading'
})
console.log('处理图片 失败:')
console.log(e)
} }
}); uni.showToast({
}, 1000); icon: 'none',
title: txt
})
}
})
*/
// wx.openSetting({
// success (res) {
// console.log(res.authSetting,'openSetting')
// // res.authSetting = {
// // "scope.userInfo": true,
// // "scope.userLocation": true
// // }
// }
// })
// uni.authorize({
// scope: 'scope.writePhotosAlbum',
// success() {
// console.log('userLocation')
// uni.openSetting({
// success(res) {
// console.log(res,'openSetting')
// }
// });
// }
// })
} }
}) })
}, },
//相册 再次授权弹窗
showAlbumAuthModal: function() {
let that = this
uni.showModal({
content: '拒绝授权照片将无法保存到本地相册,是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success(res) {
if (res.confirm) {
that.openAlbumSetting()
}
if (res.cancel) {
uni.navigateBack({
})
}
},
fail() {
console.log('')
}
})
},
//相机设置界面
openAlbumSetting() {
let that = this
wx.openSetting({
success(res) {
console.log(res, 'openSetting.res')
console.log(res.authSetting, 'openSetting.res.authSetting')
console.log(res.authSetting['scope.writePhotosAlbum'], 'openSetting.res.authSetting.scope.writePhotosAlbum')
if (res.authSetting['scope.writePhotosAlbum'] && res.authSetting['scope.writePhotosAlbum'] == true) {
console.log('11111camera reload page')
uni.getStorage({
key: 'photo_tempPath',
success: function(res) {
that.saveToLocal(res.data)
}
})
//that.reloadPage()
} else {
that.showAlbumAuthModal()
console.log('222222')
}
}
})
},
//获取当前时间 //获取当前时间
getTime: function() { getTime: function() {
...@@ -343,81 +670,44 @@ ...@@ -343,81 +670,44 @@
var timer = year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second; var timer = year + '/' + month + '/' + day + ' ' + hour + ':' + minute + ':' + second;
return timer; return timer;
}, },
} }
} }
</script> </script>
<style scoped lang="scss">
<style> .camera-container {
.bottomView { // padding-top:var(--status-bar-height);
background-color: #000000; min-height: 100vh;
z-index: 5; background-color: black;
width: 100%;
height: 200rpx;
position: absolute;
bottom: 0;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.switchIcon {
background-color: #000000;
width: 50rpx;
height: 50rpx;
} }
.takeIcon { .header-box {
background-color: #000000; // padding:10rpx 20rpx;
width: 150rpx; position: relative;
height: 150rpx;
}
.flashIcon { .inner {
background-color: #000000; display: flex;
width: 50rpx; position: absolute;
height: 50rpx; left: 0;
margin-left: 100rpx; right: 0;
} bottom: 0;
}
.locationView { .icon {
/* z-index: 5; margin: 20rpx;
width: 300rpx; display: block;
position: absolute; width: 50rpx;
left: 0; height: 50rpx;
bottom: 200rpx; }
display: flex;
flex-direction: column;
padding-bottom: 20rpx;
padding-right: 20rpx; */
bottom: 200rpx;
padding-bottom: 20rpx;
padding-right: 20rpx;
z-index: 4;
position: absolute;
font-size: 14px;
line-height: 18px;
color: #fff;
} }
.locationText { .camera-box {
/* font-size: 24rpx; position: relative;
color: #999999; width: 100%;
width: 260rpx; */ // height: 100vh;
margin: 2px 0; z-index: 1;
} }
.liveWatermarkNormal { .mark-water {
z-index: 3;
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 50%; top: 50%;
...@@ -427,26 +717,137 @@ ...@@ -427,26 +717,137 @@
z-index: 6; z-index: 6;
} }
.backIcon { .mark-box {
background-color: #FFFFFF; position: absolute;
width: 54rpx; left: 0;
height: 54rpx; bottom: 20rpx;
border-radius: 27rpx; padding: 20rpx;
position: fixed;
left: 60rpx;
bottom: 50rpx;
}
.container { .txt {
position: relative; color: #fff;
}
} }
.showCanvas { .bottom-box {
position: absolute; position: absolute;
left: 0; left: 0;
/* top: 0; */ right: 0;
z-index: -1; bottom: 0;
opacity: 0; z-index: 5;
height: 160rpx;
display: flex;
justify-content: space-between;
padding: 20rpx;
align-items: center;
background-color: black;
.txt {
line-height: 60rpx;
color: #fff;
}
.icon {
display: block;
width: 60rpx;
height: 60rpx;
&.icon-take {
width: 150rpx;
height: 150rpx;
}
}
}
// .blackBackColor {
// background-color: #000000;
// overflow: hidden;
// }
// .bottomView {
// background-color: #333333;
// z-index: 5;
// width: 100%;
// height: 200rpx;
// position: absolute;
// bottom: 0;
// display: flex;
// flex-direction: row;
// align-items: center;
// justify-content: center;
// }
// .switchIcon {
// background-color: #000000;
// width: 50rpx;
// height: 50rpx;
// }
// .takeIcon {
// background-color: #333333;
// width: 150rpx;
// height: 150rpx;
// }
// .flashIcon {
// background-color: #000000;
// width: 50rpx;
// height: 50rpx;
// margin-left: 100rpx;
// }
// .locationView {
// /* z-index: 5;
// width: 300rpx;
// position: absolute;
// left: 0;
// bottom: 200rpx;
// display: flex;
// flex-direction: column;
// padding-bottom: 20rpx;
// padding-right: 20rpx; */
// bottom: 200rpx;
// padding-bottom: 20rpx;
// padding-right: 20rpx;
// z-index: 4;
// position: absolute;
// font-size: 14px;
// line-height: 18px;
// color: #fff;
// }
// .locationText {
// /* font-size: 24rpx;
// color: #999999;
// width: 260rpx; */
// margin: 2px 0;
// }
// .liveWatermarkNormal {
// z-index: 3;
// position: absolute;
// left: 50%;
// top: 50%;
// transform: translate(-50%, -50%);
// width: 360rpx;
// height: 90rpx;
// z-index: 6;
// }
// // .backIcon {
// // background-color: #FFFFFF;
// // width: 54rpx;
// // height: 54rpx;
// // border-radius: 27rpx;
// // position: fixed;
// // left: 60rpx;
// // bottom: 50rpx;
// // border: 2rpx solid #aaa;
// // }
.showCanvas {
background-color: #007AFF; background-color: #007AFF;
width: 100%;
height: 100%;
} }
</style> </style>
...@@ -185,10 +185,12 @@ ...@@ -185,10 +185,12 @@
getLocation() { getLocation() {
let that = this let that = this
uni.getLocation({ uni.getLocation({
type: 'wgs84', type: 'gcj02',
success: function(res) { success: function(res) {
that.longitude = res.longitude console.log(res,'res')
that.latitude = res.latitude that.longitude = parseFloat(res.longitude).toFixed(4)
that.latitude = parseFloat(res.latitude).toFixed(3)
console.log(that.longitude,'that.longitude',that.latitude,'that.latitude')
that.baiduLocation() that.baiduLocation()
}, },
fail() { fail() {
...@@ -342,7 +344,8 @@ ...@@ -342,7 +344,8 @@
//第一步: 拍照 //第一步: 拍照
takePhoto() { takePhoto() {
this.getLocation()
return
let that = this let that = this
this.ctx.takePhoto({ this.ctx.takePhoto({
quality: 'high', quality: 'high',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment