index.vue 5.7 KB

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