Layout.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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" :style="{visibility: isLogin? 'visible':'hidden'}">当前可免费试用<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. isLogin: false
  38. }
  39. },
  40. onShow() {
  41. this.$isLogin().then(
  42. res => {
  43. if(res){
  44. this.isLogin = true
  45. this.getCount()
  46. } else{
  47. this.isLogin = false
  48. }
  49. }
  50. );
  51. },
  52. methods: {
  53. switchCamera(){
  54. if(!this.isLogin){
  55. uni.navigateTo({
  56. url:'/pages/auth/login'
  57. })
  58. return
  59. }
  60. this.$emit('switchCamera')
  61. },
  62. getCount(){
  63. getCount().then(
  64. res => {
  65. if(res.code==200){
  66. this.counts=res.data;
  67. }else{
  68. uni.showToast({
  69. icon:'none',
  70. title: "请求失败",
  71. });
  72. }
  73. },
  74. rej => {}
  75. );
  76. },
  77. takePhoto() {
  78. if(!this.isLogin){
  79. uni.navigateTo({
  80. url:'/pages/auth/login'
  81. })
  82. return
  83. }
  84. let that= this
  85. const ctx = wx.createCameraContext()
  86. console.log("ctx", ctx);
  87. ctx.takePhoto({
  88. quality: 'high',
  89. success: (res) => {
  90. uni.setStorageSync("tongueUrl",res.tempImagePath)
  91. console.log("res", res.tempImagePath);
  92. this.$emit('takePhoto')
  93. }
  94. })
  95. },
  96. handleClikFn(instruct) {
  97. if(this.isLogin){
  98. this.$emit('instruct', instruct)
  99. } else{
  100. uni.navigateTo({
  101. url:'/pages/auth/login'
  102. })
  103. }
  104. }
  105. },
  106. mounted() {
  107. const query = uni.createSelectorQuery().in(this);
  108. query
  109. .select("#camera-footer")
  110. .boundingClientRect((data) => {
  111. this.cameraHeight = uni.getSystemInfoSync().screenHeight - data.height
  112. })
  113. .exec();
  114. },
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. .custom-camera {
  119. height: 100vh;
  120. background-color: #000;
  121. .usenum {
  122. font-family: SourceHanSansCN;
  123. font-weight: 400;
  124. font-size: 24rpx;
  125. color: #FFFFFF;
  126. padding: 14rpx;
  127. text-align: center;
  128. }
  129. .camera-options {
  130. width: 100%;
  131. padding-top: 13rpx;
  132. padding-bottom: 60rpx;
  133. box-sizing: border-box;
  134. font-family: SourceHanSansCN;
  135. font-weight: 400;
  136. font-size: 27rpx;
  137. color: #FFFFFF;
  138. display: flex;
  139. align-items: center;
  140. justify-content: space-evenly;
  141. .camera-item {
  142. display: flex;
  143. flex-direction: column;
  144. align-items: center;
  145. image {
  146. margin-bottom: 21rpx;
  147. }
  148. }
  149. .camera-options-center {
  150. width: 131rpx;
  151. height: 131rpx;
  152. border-radius: 50%;
  153. border: 3px solid #FFFFFF;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. }
  158. .photograph-btn {
  159. width: 109rpx;
  160. height: 109rpx;
  161. background: #F54D04;
  162. border-radius: 50%;
  163. }
  164. }
  165. }
  166. </style>