index.vue 4.9 KB

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