Layout.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!-- 公共布局组件 -->
  2. <template>
  3. <view class="custom-camera">
  4. <view class="camera-wrap" :style="{height:cameraHeight+'px'}">
  5. <slot></slot>
  6. </view>
  7. <view class="camera-footer" id="camera-footer">
  8. <view class="usenum">当前可免费试用<text style="color: #F54D04;margin: 0 6rpx;">{{counts || 0}}</text>次</view>
  9. <view class="camera-options">
  10. <view class="camera-options-left camera-item">
  11. <image :src="baseUrl+'/images/album_icon.png'" mode="scaleToFill" style="width: 65rpx;height:60rpx;" @click="handleClikFn('album')"></image>
  12. <text>相册上传</text>
  13. </view>
  14. <view class="camera-options-center camera-item" @click="takePhoto()">
  15. <view class="photograph-btn"></view>
  16. </view>
  17. <view class="camera-options-ritht camera-item" @click="switchCamera()">
  18. <image :src="baseUrl+'/images/tongue_info.png'" mode="scaleToFill" style="width: 67rpx;height:60rpx;" @click="handleClikFn('reportlist')"></image>
  19. <text>切换摄像头</text>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import {getCount} from '@/api/healthTongue.js'
  27. // 提供一个相机的插槽位置
  28. // 底部可以自定义最右侧按钮(相册/反转)
  29. export default {
  30. data() {
  31. return {
  32. baseUrl:uni.getStorageSync('requestPath'),
  33. cameraHeight: '', //相机画面宽度
  34. optionsHeight: '', //操作区域
  35. counts: 0,
  36. url:null,
  37. }
  38. },
  39. onLoad() {
  40. this.getCount()
  41. },
  42. methods: {
  43. switchCamera(){
  44. this.$emit('switchCamera')
  45. },
  46. getCount(){
  47. getCount().then(
  48. res => {
  49. if(res.code==200){
  50. this.counts=res.data;
  51. }else{
  52. uni.showToast({
  53. icon:'none',
  54. title: "请求失败",
  55. });
  56. }
  57. },
  58. rej => {}
  59. );
  60. },
  61. takePhoto() {
  62. let that= this
  63. const ctx = wx.createCameraContext()
  64. console.log("ctx", ctx);
  65. ctx.takePhoto({
  66. quality: 'high',
  67. success: (res) => {
  68. uni.setStorageSync("tongueUrl",res.tempImagePath)
  69. console.log("res", res.tempImagePath);
  70. this.$emit('takePhoto')
  71. }
  72. })
  73. },
  74. handleClikFn(instruct) {
  75. this.$emit('instruct', instruct)
  76. }
  77. },
  78. mounted() {
  79. const query = uni.createSelectorQuery().in(this);
  80. query
  81. .select("#camera-footer")
  82. .boundingClientRect((data) => {
  83. this.cameraHeight = uni.getSystemInfoSync().screenHeight - data.height
  84. })
  85. .exec();
  86. },
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .custom-camera {
  91. height: 100vh;
  92. background-color: #000;
  93. .usenum {
  94. font-family: SourceHanSansCN;
  95. font-weight: 400;
  96. font-size: 24rpx;
  97. color: #FFFFFF;
  98. padding: 14rpx;
  99. text-align: center;
  100. }
  101. .camera-options {
  102. width: 100%;
  103. padding-top: 13rpx;
  104. padding-bottom: 60rpx;
  105. box-sizing: border-box;
  106. font-family: SourceHanSansCN;
  107. font-weight: 400;
  108. font-size: 27rpx;
  109. color: #FFFFFF;
  110. display: flex;
  111. align-items: center;
  112. justify-content: space-evenly;
  113. .camera-item {
  114. display: flex;
  115. flex-direction: column;
  116. align-items: center;
  117. image {
  118. margin-bottom: 21rpx;
  119. }
  120. }
  121. .camera-options-center {
  122. width: 131rpx;
  123. height: 131rpx;
  124. border-radius: 50%;
  125. border: 3px solid #FFFFFF;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. }
  130. .photograph-btn {
  131. width: 109rpx;
  132. height: 109rpx;
  133. background: #F54D04;
  134. border-radius: 50%;
  135. }
  136. }
  137. }
  138. </style>