shopTour.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view>
  3. <web-view @message="onmessage" src="/hybrid/html/video.html"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. import { clzConfirm,saveBase64ToAliOss } from '@/libs/tools.js'
  8. export default {
  9. data() {
  10. return {
  11. wv: null,
  12. isClose: false, // 是否关闭当前窗口
  13. isEditImg: false, // 是否正在编辑图片
  14. showPz: false, // 是否正在拍照
  15. };
  16. },
  17. methods: {
  18. // 监听html页面事件
  19. onmessage(event) {
  20. let data = event.detail.data[0]
  21. // console.log(data)
  22. // webview 窗口传过来的页面状态
  23. if(data.action == 'getWinStatus'){
  24. let d = JSON.parse(data.msg)
  25. this[d.key] = d.val
  26. }
  27. // 保存编辑后的图片
  28. if(data.action == 'saveEditImg'){
  29. this.uploadImg(data.msg)
  30. }
  31. },
  32. // 上传编辑后的图片到阿里云
  33. uploadImg(formData) {
  34. const _this = this;
  35. saveBase64ToAliOss(formData,function(res){
  36. // console.log(res);
  37. // 关闭编辑图片
  38. _this.wv.evalJS("vm.closeImgsEdit()")
  39. // 更新编辑后的图片
  40. _this.wv.evalJS("vm.updateItemImg('"+res.data+"')")
  41. })
  42. }
  43. },
  44. onReady() {
  45. let _this = this
  46. // #ifdef APP-PLUS
  47. //获取当前页面的webview对象
  48. var currentWebview = this.$mp.page.$getAppWebview()
  49. //如果是页面初始化调用时,需要延时一下
  50. setTimeout(function() {
  51. _this.wv = currentWebview.children()[0]
  52. }, 500);
  53. // #endif
  54. },
  55. // 监听返回键
  56. onBackPress() {
  57. console.log(this.isEditImg,'onBackPress')
  58. let _this = this
  59. if(!_this.isClose){
  60. // 正在编辑图片
  61. if(this.isEditImg){
  62. // 关闭编辑图片
  63. _this.wv.evalJS("vm.closeImgsEdit()")
  64. }
  65. // 正在拍照
  66. else if(this.showPz){
  67. // 关闭拍照弹框
  68. _this.wv.evalJS("vm.onClosePz()")
  69. }else{
  70. clzConfirm({
  71. title: '提示',
  72. content: '巡店还未完成,确定退出吗?',
  73. success: function(res) {
  74. if (res.confirm || res.index == 0) {
  75. _this.isClose = true
  76. uni.navigateBack({
  77. delta: 1
  78. });
  79. }
  80. }
  81. });
  82. }
  83. return true
  84. }
  85. },
  86. // 添加考评模板
  87. onNavigationBarButtonTap(e) {
  88. // 且当前没编辑图片或抓拍图片
  89. if(e.index==0 && !this.isEditImg && !this.showPz){
  90. console.log(e.text)
  91. }
  92. },
  93. }
  94. </script>
  95. <style>
  96. </style>