index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <Layout @instruct="handleInstruct">
  3. <camera class="camera" mode="normal" :device-position="device" @error="error"
  4. style="width: 100%; height: 100%;">
  5. <cover-view class="cover-view">
  6. <cover-view class="uni-nav-bar">
  7. <cover-view :style="{height: statusBarHeight,width: '100%'}"></cover-view>
  8. <cover-view class="uni-nav-barbox" :style="{width: menuLeft}">
  9. <cover-view class="uni-nav-back">
  10. <cover-image src="@/static/images/ai_right_icon.png" mode="aspectFill"></cover-image>
  11. </cover-view>
  12. <cover-view class="uni-nav-title">
  13. <cover-view>使用教程</cover-view>
  14. <cover-image class="ques" src="@/static/images/ques.png" mode="aspectFill"></cover-image>
  15. </cover-view>
  16. </cover-view>
  17. </cover-view>
  18. <cover-view class="title">请拍摄舌面</cover-view>
  19. <cover-view class="tips">舌尖放松,舌面平展,舌尖略向下,口张大不要太用力</cover-view>
  20. <cover-view class="imagebox">
  21. <!-- <cover-image class="tongue" src="@/static/images/tongue.png" mode="aspectFill"></cover-image> -->
  22. </cover-view>
  23. </cover-view>
  24. <!-- <cover-image v-if="coverImage" :src="coverImage" style="width: 100%;height: 100%;"></cover-image> -->
  25. </camera>
  26. </Layout>
  27. </template>
  28. <script>
  29. import Layout from './Layout.vue'
  30. export default {
  31. components: {
  32. Layout
  33. },
  34. data() {
  35. return {
  36. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  37. // 前置或后置摄像头,值为front, back
  38. device: 'back',
  39. cameraContext: null,
  40. shutterShow: false,
  41. coverImage: null,
  42. menuLeft: '100%'
  43. }
  44. },
  45. mounted() {
  46. uni.getSystemInfo({
  47. success: (result) => {
  48. // 获取右侧胶囊的信息 单位px
  49. //#ifndef H5 || APP-PLUS
  50. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  51. //left: 胶囊左侧距离屏幕左侧的距离
  52. this.menuLeft = menuButtonInfo.left + 'px'
  53. //#endif
  54. },
  55. fail: (error) => {
  56. console.log(error)
  57. }
  58. })
  59. this.cameraContext = uni.createCameraContext();
  60. // this.coverImage = '/static/images/portrait.jpg'
  61. },
  62. methods: {
  63. error(err) {
  64. console.log(err)
  65. },
  66. handleInstruct(instruct) {
  67. switch (instruct) {
  68. // 返回
  69. case 'back':
  70. this.$emit('back')
  71. break;
  72. // 快门
  73. case 'shutter':
  74. this.cameraContext.takePhoto({
  75. quality: 'high',
  76. success: (res) => {
  77. // console.log(res)
  78. this.$emit('getImage', res.tempImagePath)
  79. }
  80. })
  81. break;
  82. // 反转
  83. case 'reversal':
  84. this.device = this.device === 'back' ? 'front' : 'back'
  85. break;
  86. // 相册
  87. case 'album':
  88. uni.chooseImage({
  89. count: 1, //默认9
  90. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  91. sourceType: ['album'], //从相册选择
  92. success: (res) => {
  93. this.$emit('getImage', res.tempFilePaths[0])
  94. }
  95. })
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. @mixin u-flex($flexD, $alignI, $justifyC) {
  104. display: flex;
  105. flex-direction: $flexD;
  106. align-items: $alignI;
  107. justify-content: $justifyC;
  108. }
  109. .imagebox {
  110. width: 100%;
  111. margin-top: 30rpx;
  112. @include u-flex(column, center, center);
  113. }
  114. .tongue {
  115. width: 531rpx;
  116. height: 592rpx;
  117. margin: 0 auto;
  118. margin-top: 30rpx;
  119. }
  120. .cover-view {
  121. width: 100%;
  122. position: absolute;
  123. z-index: 99;
  124. top: 0;
  125. left: 0;
  126. }
  127. .title {
  128. margin-top: calc(var(--status-bar-height) + 130rpx);;
  129. font-family: SourceHanSansCN-Medium;
  130. font-weight: 500;
  131. font-size: 43rpx;
  132. color: #FFFFFF;
  133. text-align: center;
  134. }
  135. .tips {
  136. margin-top: 38rpx;
  137. font-family: SourceHanSansSC-Regular;
  138. font-weight: 400;
  139. font-size: 24rpx;
  140. color: #FFFFFF;
  141. text-align: center;
  142. }
  143. .uni-nav-bar {
  144. position: fixed;
  145. top: 0;
  146. left: 0;
  147. width: 100%;
  148. z-index: 999;
  149. overflow: hidden;
  150. font-family: PingFang SC, PingFang SC;
  151. font-weight: 500;
  152. color: #FFFFFF;
  153. .uni-nav-barbox {
  154. width: 100%;
  155. height: 88rpx;
  156. padding: 0 24rpx;
  157. box-sizing: border-box;
  158. @include u-flex(row, center, space-between);
  159. position: relative;
  160. font-size: 24rpx;
  161. }
  162. .uni-nav-title {
  163. flex-shrink: 0;
  164. font-family: SourceHanSansSC;
  165. font-weight: 400;
  166. // font-size: 32rpx;
  167. color: #FFFFFF;
  168. /* #ifdef APP-PLUS */
  169. font-size: 32rpx;
  170. /* #endif */
  171. /* #ifndef APP-PLUS */
  172. font-size: 14px;
  173. /* #endif */
  174. @include u-flex(row, center, flex-start);
  175. .ques {
  176. flex-shrink: 0;
  177. width: 33rpx;
  178. height: 33rpx;
  179. margin-left: 9rpx;
  180. }
  181. }
  182. .uni-nav-back {
  183. height: 32rpx;
  184. width: 32rpx;
  185. }
  186. }
  187. .camera {
  188. position: relative;
  189. }
  190. </style>