index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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" @click="navTo()">
  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. navTo() {
  65. uni.navigateTo({
  66. url: "/pages_user/tongue/ques"
  67. })
  68. },
  69. switchCamera(){
  70. this.device = this.device === 'back' ? 'front' : 'back';
  71. },
  72. back(){
  73. uni.navigateBack()
  74. },
  75. error(err) {
  76. console.log(err)
  77. },
  78. takePhoto(){
  79. this.$emit('takePhoto')
  80. },
  81. handleInstruct(instruct) {
  82. switch (instruct) {
  83. // 返回
  84. case 'back':
  85. this.$emit('back')
  86. break;
  87. // 快门
  88. case 'shutter':
  89. this.cameraContext.takePhoto({
  90. quality: 'high',
  91. success: (res) => {
  92. // console.log(res)
  93. this.$emit('getImage', res.tempImagePath)
  94. }
  95. })
  96. break;
  97. // 反转
  98. case 'reversal':
  99. this.device = this.device === 'back' ? 'front' : 'back'
  100. break;
  101. // 相册
  102. case 'album':
  103. uni.chooseImage({
  104. count: 1, //默认9
  105. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  106. sourceType: ['album'], //从相册选择
  107. success: (res) => {
  108. uni.setStorageSync("tongueUrl",res.tempFilePaths[0])
  109. this.$emit('getImage')
  110. }
  111. })
  112. break;
  113. }
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. @mixin u-flex($flexD, $alignI, $justifyC) {
  120. display: flex;
  121. flex-direction: $flexD;
  122. align-items: $alignI;
  123. justify-content: $justifyC;
  124. }
  125. .imagebox {
  126. width: 100%;
  127. margin-top: 30rpx;
  128. @include u-flex(column, center, center);
  129. }
  130. .tongue {
  131. width: 531rpx;
  132. height: 592rpx;
  133. margin: 0 auto;
  134. margin-top: 30rpx;
  135. }
  136. .cover-view {
  137. width: 100%;
  138. position: absolute;
  139. z-index: 99;
  140. top: 0;
  141. left: 0;
  142. }
  143. .title {
  144. margin-top: calc(var(--status-bar-height) + 130rpx);;
  145. font-family: SourceHanSansCN-Medium;
  146. font-weight: 500;
  147. font-size: 43rpx;
  148. color: #FFFFFF;
  149. text-align: center;
  150. }
  151. .tips {
  152. margin-top: 38rpx;
  153. font-family: SourceHanSansSC-Regular;
  154. font-weight: 400;
  155. font-size: 24rpx;
  156. color: #FFFFFF;
  157. text-align: center;
  158. }
  159. .uni-nav-bar {
  160. position: fixed;
  161. top: 0;
  162. left: 0;
  163. width: 100%;
  164. z-index: 999;
  165. overflow: hidden;
  166. font-family: PingFang SC, PingFang SC;
  167. font-weight: 500;
  168. color: #FFFFFF;
  169. .uni-nav-barbox {
  170. width: 100%;
  171. height: 88rpx;
  172. padding: 0 24rpx;
  173. box-sizing: border-box;
  174. @include u-flex(row, center, space-between);
  175. position: relative;
  176. font-size: 32rpx;
  177. }
  178. .uni-nav-title {
  179. flex-shrink: 0;
  180. font-family: SourceHanSansSC;
  181. font-weight: 400;
  182. // font-size: 32rpx;
  183. color: #FFFFFF;
  184. /* #ifdef APP-PLUS */
  185. font-size: 32rpx;
  186. /* #endif */
  187. /* #ifndef APP-PLUS */
  188. font-size: 32rpx;
  189. /* #endif */
  190. @include u-flex(row, center, flex-start);
  191. .ques {
  192. flex-shrink: 0;
  193. width: 33rpx;
  194. height: 33rpx;
  195. margin-left: 9rpx;
  196. }
  197. }
  198. .uni-nav-back {
  199. width: 100%;
  200. height: 88rpx;
  201. line-height: 88rpx;
  202. }
  203. }
  204. .camera {
  205. position: relative;
  206. }
  207. </style>