index.vue 5.1 KB

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